Author: Ely Ronnen Date: 2025-04-23T13:04:39-07:00 New Revision: 563ab56497104199b9fd57df9bd162f2b02cbe92
URL: https://github.com/llvm/llvm-project/commit/563ab56497104199b9fd57df9bd162f2b02cbe92 DIFF: https://github.com/llvm/llvm-project/commit/563ab56497104199b9fd57df9bd162f2b02cbe92.diff LOG: [lldb-dap] Show load addresses in disassembly (#136755) Improves the lldb-dap disassembly by showing load addresses in disassembly, same as in a regular LLDB `disassemble` command by default. Before:  After:  Added: Modified: lldb/include/lldb/API/SBExecutionContext.h lldb/include/lldb/API/SBInstructionList.h lldb/source/API/SBInstructionList.cpp lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/API/SBExecutionContext.h b/lldb/include/lldb/API/SBExecutionContext.h index e1e08fe3f4aae..20584271ff36c 100644 --- a/lldb/include/lldb/API/SBExecutionContext.h +++ b/lldb/include/lldb/API/SBExecutionContext.h @@ -55,6 +55,7 @@ class LLDB_API SBExecutionContext { SBFrame GetFrame() const; protected: + friend class SBInstructionList; friend class lldb_private::python::SWIGBridge; friend class lldb_private::ScriptInterpreter; diff --git a/lldb/include/lldb/API/SBInstructionList.h b/lldb/include/lldb/API/SBInstructionList.h index 4c26ec9a294e0..4c6bab9c8ccc7 100644 --- a/lldb/include/lldb/API/SBInstructionList.h +++ b/lldb/include/lldb/API/SBInstructionList.h @@ -54,6 +54,11 @@ class LLDB_API SBInstructionList { bool GetDescription(lldb::SBStream &description); + // Writes assembly instructions to `description` with load addresses using + // `exe_ctx`. + bool GetDescription(lldb::SBStream &description, + lldb::SBExecutionContext &exe_ctx); + bool DumpEmulationForAllInstructions(const char *triple); protected: @@ -62,8 +67,8 @@ class LLDB_API SBInstructionList { friend class SBTarget; void SetDisassembler(const lldb::DisassemblerSP &opaque_sp); - bool GetDescription(lldb_private::Stream &description); - + bool GetDescription(lldb_private::Stream &description, + lldb_private::ExecutionContext *exe_ctx = nullptr); private: lldb::DisassemblerSP m_opaque_sp; diff --git a/lldb/source/API/SBInstructionList.cpp b/lldb/source/API/SBInstructionList.cpp index c18204375dff1..0d958c6ae93ef 100644 --- a/lldb/source/API/SBInstructionList.cpp +++ b/lldb/source/API/SBInstructionList.cpp @@ -8,6 +8,7 @@ #include "lldb/API/SBInstructionList.h" #include "lldb/API/SBAddress.h" +#include "lldb/API/SBExecutionContext.h" #include "lldb/API/SBFile.h" #include "lldb/API/SBInstruction.h" #include "lldb/API/SBStream.h" @@ -15,6 +16,7 @@ #include "lldb/Core/Module.h" #include "lldb/Host/StreamFile.h" #include "lldb/Symbol/SymbolContext.h" +#include "lldb/Target/ExecutionContext.h" #include "lldb/Utility/Instrumentation.h" #include "lldb/Utility/Stream.h" @@ -138,7 +140,15 @@ bool SBInstructionList::GetDescription(lldb::SBStream &stream) { return GetDescription(stream.ref()); } -bool SBInstructionList::GetDescription(Stream &sref) { +bool SBInstructionList::GetDescription(lldb::SBStream &stream, + lldb::SBExecutionContext &exe_ctx) { + LLDB_INSTRUMENT_VA(this, stream); + ExecutionContext exe_ctx_wrapper(exe_ctx.get()); + return GetDescription(stream.ref(), &exe_ctx_wrapper); +} + +bool SBInstructionList::GetDescription( + Stream &sref, lldb_private::ExecutionContext *exe_ctx) { if (m_opaque_sp) { size_t num_instructions = GetSize(); @@ -148,7 +158,7 @@ bool SBInstructionList::GetDescription(Stream &sref) { const uint32_t max_opcode_byte_size = m_opaque_sp->GetInstructionList().GetMaxOpcocdeByteSize(); FormatEntity::Entry format; - FormatEntity::Parse("${addr}: ", format); + FormatEntity::Parse("${addr-file-or-load}: ", format); SymbolContext sc; SymbolContext prev_sc; @@ -172,7 +182,7 @@ bool SBInstructionList::GetDescription(Stream &sref) { if (next_addr && *next_addr != addr) sref.EOL(); inst->Dump(&sref, max_opcode_byte_size, true, false, - /*show_control_flow_kind=*/false, nullptr, &sc, &prev_sc, + /*show_control_flow_kind=*/false, exe_ctx, &sc, &prev_sc, &format, 0); sref.EOL(); next_addr = addr; diff --git a/lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp index 1a7a13d9f267a..327198bab0395 100644 --- a/lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp @@ -11,6 +11,7 @@ #include "LLDBUtils.h" #include "Protocol/ProtocolRequests.h" #include "Protocol/ProtocolTypes.h" +#include "lldb/API/SBExecutionContext.h" #include "lldb/API/SBFrame.h" #include "lldb/API/SBInstructionList.h" #include "lldb/API/SBProcess.h" @@ -43,7 +44,8 @@ SourceRequestHandler::Run(const protocol::SourceArguments &args) const { lldb::SBInstructionList insts = frame.GetSymbol().GetInstructions(dap.target); lldb::SBStream stream; - insts.GetDescription(stream); + lldb::SBExecutionContext exe_ctx(frame); + insts.GetDescription(stream, exe_ctx); return protocol::SourceResponseBody{/*content=*/stream.GetData(), /*mimeType=*/"text/x-lldb.disassembly"}; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits