[Lldb-commits] [lldb] [lldb] Support discontinuous functions in another Disasembler overload (PR #130987)

via lldb-commits lldb-commits at lists.llvm.org
Wed Mar 12 09:26:08 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)

<details>
<summary>Changes</summary>

This overload is taking a StackFrame, so we just need to change how we obtain the ranges out of it. A slightly fiddly aspect is the code which tries to provide a default dissassembly range for the case where we don't have a real one. I believe this case is only relevant for symbol-based stack frames as debug info always has size/range for the functions (if it didn't we wouldn't even resolve the stack frame to a function), which is why I've split the handling of the two cases.

We already have a test case for disassembly of discontinuous functions (in test/Shell/Commands/command-disassemble.s), so I'm not creating another one as this is just a slightly different entry point into the same code.

---
Full diff: https://github.com/llvm/llvm-project/pull/130987.diff


1 Files Affected:

- (modified) lldb/source/Core/Disassembler.cpp (+18-11) 


``````````diff
diff --git a/lldb/source/Core/Disassembler.cpp b/lldb/source/Core/Disassembler.cpp
index b05be7e1a46d7..9b1d4e9316cb0 100644
--- a/lldb/source/Core/Disassembler.cpp
+++ b/lldb/source/Core/Disassembler.cpp
@@ -552,28 +552,35 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
 
 bool Disassembler::Disassemble(Debugger &debugger, const ArchSpec &arch,
                                StackFrame &frame, Stream &strm) {
-  AddressRange range;
   SymbolContext sc(
       frame.GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol));
   if (sc.function) {
-    range = sc.function->GetAddressRange();
-  } else if (sc.symbol && sc.symbol->ValueIsAddress()) {
+    if (DisassemblerSP disasm_sp = DisassembleRange(
+        arch, nullptr, nullptr, nullptr, nullptr, *frame.CalculateTarget(),
+        sc.function->GetAddressRanges())) {
+      disasm_sp->PrintInstructions(debugger, arch, frame, false, 0, 0, strm);
+      return true;
+    }
+    return false;
+  }
+
+  AddressRange range;
+  if (sc.symbol && sc.symbol->ValueIsAddress()) {
     range.GetBaseAddress() = sc.symbol->GetAddressRef();
     range.SetByteSize(sc.symbol->GetByteSize());
   } else {
     range.GetBaseAddress() = frame.GetFrameCodeAddress();
   }
 
-    if (range.GetBaseAddress().IsValid() && range.GetByteSize() == 0)
-      range.SetByteSize(DEFAULT_DISASM_BYTE_SIZE);
+  if (range.GetBaseAddress().IsValid() && range.GetByteSize() == 0)
+    range.SetByteSize(DEFAULT_DISASM_BYTE_SIZE);
 
-    Disassembler::Limit limit = {Disassembler::Limit::Bytes,
-                                 range.GetByteSize()};
-    if (limit.value == 0)
-      limit.value = DEFAULT_DISASM_BYTE_SIZE;
+  Disassembler::Limit limit = {Disassembler::Limit::Bytes, range.GetByteSize()};
+  if (limit.value == 0)
+    limit.value = DEFAULT_DISASM_BYTE_SIZE;
 
-    return Disassemble(debugger, arch, nullptr, nullptr, nullptr, nullptr,
-                       frame, range.GetBaseAddress(), limit, false, 0, 0, strm);
+  return Disassemble(debugger, arch, nullptr, nullptr, nullptr, nullptr, frame,
+                     range.GetBaseAddress(), limit, false, 0, 0, strm);
 }
 
 Instruction::Instruction(const Address &address, AddressClass addr_class)

``````````

</details>


https://github.com/llvm/llvm-project/pull/130987


More information about the lldb-commits mailing list