Skip to content

Commit 9e597c6

Browse files
eronnenIanWood1
authored andcommitted
[lldb-dap] Show load addresses in disassembly (llvm#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)
1 parent f2e12a7 commit 9e597c6

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

lldb/include/lldb/API/SBExecutionContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class LLDB_API SBExecutionContext {
5555
SBFrame GetFrame() const;
5656

5757
protected:
58+
friend class SBInstructionList;
5859
friend class lldb_private::python::SWIGBridge;
5960
friend class lldb_private::ScriptInterpreter;
6061

lldb/include/lldb/API/SBInstructionList.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ class LLDB_API SBInstructionList {
5454

5555
bool GetDescription(lldb::SBStream &description);
5656

57+
// Writes assembly instructions to `description` with load addresses using
58+
// `exe_ctx`.
59+
bool GetDescription(lldb::SBStream &description,
60+
lldb::SBExecutionContext &exe_ctx);
61+
5762
bool DumpEmulationForAllInstructions(const char *triple);
5863

5964
protected:
@@ -62,8 +67,8 @@ class LLDB_API SBInstructionList {
6267
friend class SBTarget;
6368

6469
void SetDisassembler(const lldb::DisassemblerSP &opaque_sp);
65-
bool GetDescription(lldb_private::Stream &description);
66-
70+
bool GetDescription(lldb_private::Stream &description,
71+
lldb_private::ExecutionContext *exe_ctx = nullptr);
6772

6873
private:
6974
lldb::DisassemblerSP m_opaque_sp;

lldb/source/API/SBInstructionList.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88

99
#include "lldb/API/SBInstructionList.h"
1010
#include "lldb/API/SBAddress.h"
11+
#include "lldb/API/SBExecutionContext.h"
1112
#include "lldb/API/SBFile.h"
1213
#include "lldb/API/SBInstruction.h"
1314
#include "lldb/API/SBStream.h"
1415
#include "lldb/Core/Disassembler.h"
1516
#include "lldb/Core/Module.h"
1617
#include "lldb/Host/StreamFile.h"
1718
#include "lldb/Symbol/SymbolContext.h"
19+
#include "lldb/Target/ExecutionContext.h"
1820
#include "lldb/Utility/Instrumentation.h"
1921
#include "lldb/Utility/Stream.h"
2022

@@ -138,7 +140,15 @@ bool SBInstructionList::GetDescription(lldb::SBStream &stream) {
138140
return GetDescription(stream.ref());
139141
}
140142

141-
bool SBInstructionList::GetDescription(Stream &sref) {
143+
bool SBInstructionList::GetDescription(lldb::SBStream &stream,
144+
lldb::SBExecutionContext &exe_ctx) {
145+
LLDB_INSTRUMENT_VA(this, stream);
146+
ExecutionContext exe_ctx_wrapper(exe_ctx.get());
147+
return GetDescription(stream.ref(), &exe_ctx_wrapper);
148+
}
149+
150+
bool SBInstructionList::GetDescription(
151+
Stream &sref, lldb_private::ExecutionContext *exe_ctx) {
142152

143153
if (m_opaque_sp) {
144154
size_t num_instructions = GetSize();
@@ -148,7 +158,7 @@ bool SBInstructionList::GetDescription(Stream &sref) {
148158
const uint32_t max_opcode_byte_size =
149159
m_opaque_sp->GetInstructionList().GetMaxOpcocdeByteSize();
150160
FormatEntity::Entry format;
151-
FormatEntity::Parse("${addr}: ", format);
161+
FormatEntity::Parse("${addr-file-or-load}: ", format);
152162
SymbolContext sc;
153163
SymbolContext prev_sc;
154164

@@ -172,7 +182,7 @@ bool SBInstructionList::GetDescription(Stream &sref) {
172182
if (next_addr && *next_addr != addr)
173183
sref.EOL();
174184
inst->Dump(&sref, max_opcode_byte_size, true, false,
175-
/*show_control_flow_kind=*/false, nullptr, &sc, &prev_sc,
185+
/*show_control_flow_kind=*/false, exe_ctx, &sc, &prev_sc,
176186
&format, 0);
177187
sref.EOL();
178188
next_addr = addr;

lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "LLDBUtils.h"
1212
#include "Protocol/ProtocolRequests.h"
1313
#include "Protocol/ProtocolTypes.h"
14+
#include "lldb/API/SBExecutionContext.h"
1415
#include "lldb/API/SBFrame.h"
1516
#include "lldb/API/SBInstructionList.h"
1617
#include "lldb/API/SBProcess.h"
@@ -43,7 +44,8 @@ SourceRequestHandler::Run(const protocol::SourceArguments &args) const {
4344

4445
lldb::SBInstructionList insts = frame.GetSymbol().GetInstructions(dap.target);
4546
lldb::SBStream stream;
46-
insts.GetDescription(stream);
47+
lldb::SBExecutionContext exe_ctx(frame);
48+
insts.GetDescription(stream, exe_ctx);
4749

4850
return protocol::SourceResponseBody{/*content=*/stream.GetData(),
4951
/*mimeType=*/"text/x-lldb.disassembly"};

0 commit comments

Comments
 (0)