[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:

![Screenshot From 2025-04-22
21-33-56](https://github.com/user-attachments/assets/c3febd48-8335-4932-a270-5a87f48122fe)


After:

![Screenshot From 2025-04-22
21-54-51](https://github.com/user-attachments/assets/b2f44595-8ab2-4f28-aded-9233c53a589b)
This commit is contained in:
Ely Ronnen
2025-04-23 22:04:39 +02:00
committed by GitHub
parent f07511a0e0
commit 563ab56497
4 changed files with 24 additions and 6 deletions

View File

@@ -55,6 +55,7 @@ public:
SBFrame GetFrame() const;
protected:
friend class SBInstructionList;
friend class lldb_private::python::SWIGBridge;
friend class lldb_private::ScriptInterpreter;

View File

@@ -54,6 +54,11 @@ public:
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 @@ protected:
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;

View File

@@ -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;

View File

@@ -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"};