Skip to content

[lldb] Support discontinuous functions in another Disasembler overload #130987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 14, 2025

Conversation

labath
Copy link
Collaborator

@labath labath commented Mar 12, 2025

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.

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.
@labath labath requested a review from DavidSpickett March 12, 2025 16:25
@labath labath requested a review from JDevlieghere as a code owner March 12, 2025 16:25
@llvmbot llvmbot added the lldb label Mar 12, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 12, 2025

@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)

Changes

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 --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)

Copy link

github-actions bot commented Mar 12, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Collaborator

@DavidSpickett DavidSpickett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@labath labath merged commit f2e1027 into llvm:main Mar 14, 2025
10 checks passed
@labath labath deleted the disasm branch March 14, 2025 07:24
frederik-h pushed a commit to frederik-h/llvm-project that referenced this pull request Mar 18, 2025
llvm#130987)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants