Skip to content

Commit 2dbf6c5

Browse files
labathfrederik-h
authored andcommitted
[lldb] Support discontinuous functions in another Disasembler overload (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.
1 parent b443c1d commit 2dbf6c5

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

lldb/source/Core/Disassembler.cpp

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -552,28 +552,46 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
552552

553553
bool Disassembler::Disassemble(Debugger &debugger, const ArchSpec &arch,
554554
StackFrame &frame, Stream &strm) {
555-
AddressRange range;
555+
constexpr const char *plugin_name = nullptr;
556+
constexpr const char *flavor = nullptr;
557+
constexpr const char *cpu = nullptr;
558+
constexpr const char *features = nullptr;
559+
constexpr bool mixed_source_and_assembly = false;
560+
constexpr uint32_t num_mixed_context_lines = 0;
561+
constexpr uint32_t options = 0;
562+
556563
SymbolContext sc(
557564
frame.GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol));
558565
if (sc.function) {
559-
range = sc.function->GetAddressRange();
560-
} else if (sc.symbol && sc.symbol->ValueIsAddress()) {
566+
if (DisassemblerSP disasm_sp = DisassembleRange(
567+
arch, plugin_name, flavor, cpu, features, *frame.CalculateTarget(),
568+
sc.function->GetAddressRanges())) {
569+
disasm_sp->PrintInstructions(debugger, arch, frame,
570+
mixed_source_and_assembly,
571+
num_mixed_context_lines, options, strm);
572+
return true;
573+
}
574+
return false;
575+
}
576+
577+
AddressRange range;
578+
if (sc.symbol && sc.symbol->ValueIsAddress()) {
561579
range.GetBaseAddress() = sc.symbol->GetAddressRef();
562580
range.SetByteSize(sc.symbol->GetByteSize());
563581
} else {
564582
range.GetBaseAddress() = frame.GetFrameCodeAddress();
565583
}
566584

567-
if (range.GetBaseAddress().IsValid() && range.GetByteSize() == 0)
568-
range.SetByteSize(DEFAULT_DISASM_BYTE_SIZE);
585+
if (range.GetBaseAddress().IsValid() && range.GetByteSize() == 0)
586+
range.SetByteSize(DEFAULT_DISASM_BYTE_SIZE);
569587

570-
Disassembler::Limit limit = {Disassembler::Limit::Bytes,
571-
range.GetByteSize()};
572-
if (limit.value == 0)
573-
limit.value = DEFAULT_DISASM_BYTE_SIZE;
588+
Disassembler::Limit limit = {Disassembler::Limit::Bytes, range.GetByteSize()};
589+
if (limit.value == 0)
590+
limit.value = DEFAULT_DISASM_BYTE_SIZE;
574591

575-
return Disassemble(debugger, arch, nullptr, nullptr, nullptr, nullptr,
576-
frame, range.GetBaseAddress(), limit, false, 0, 0, strm);
592+
return Disassemble(debugger, arch, plugin_name, flavor, cpu, features, frame,
593+
range.GetBaseAddress(), limit, mixed_source_and_assembly,
594+
num_mixed_context_lines, options, strm);
577595
}
578596

579597
Instruction::Instruction(const Address &address, AddressClass addr_class)

0 commit comments

Comments
 (0)