Skip to content

Commit c1c0728

Browse files
committed
[lldb-dap]: show load addresses in disassembly
1 parent 11d5c4d commit c1c0728

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

lldb/include/lldb/API/SBFrame.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class LLDB_API SBFrame {
221221
friend class SBBlock;
222222
friend class SBExecutionContext;
223223
friend class SBInstruction;
224+
friend class SBInstructionList;
224225
friend class SBThread;
225226
friend class SBValue;
226227

lldb/include/lldb/API/SBInstructionList.h

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

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

57+
// Writes assembly instructions to `description` with load addresses using
58+
// `frame`.
59+
bool GetDescription(lldb::SBStream &description, lldb::SBFrame &frame);
60+
5761
bool DumpEmulationForAllInstructions(const char *triple);
5862

5963
protected:
@@ -62,8 +66,7 @@ class LLDB_API SBInstructionList {
6266
friend class SBTarget;
6367

6468
void SetDisassembler(const lldb::DisassemblerSP &opaque_sp);
65-
bool GetDescription(lldb_private::Stream &description);
66-
69+
bool GetDescription(lldb_private::Stream &description, lldb::SBFrame *frame);
6770

6871
private:
6972
lldb::DisassemblerSP m_opaque_sp;

lldb/source/API/SBInstructionList.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
#include "lldb/Core/Module.h"
1616
#include "lldb/Host/StreamFile.h"
1717
#include "lldb/Symbol/SymbolContext.h"
18+
#include "lldb/Target/ExecutionContext.h"
1819
#include "lldb/Utility/Instrumentation.h"
1920
#include "lldb/Utility/Stream.h"
21+
#include <memory>
2022

2123
using namespace lldb;
2224
using namespace lldb_private;
@@ -114,31 +116,37 @@ void SBInstructionList::Print(FILE *out) {
114116
if (out == nullptr)
115117
return;
116118
StreamFile stream(out, false);
117-
GetDescription(stream);
119+
GetDescription(stream, nullptr);
118120
}
119121

120122
void SBInstructionList::Print(SBFile out) {
121123
LLDB_INSTRUMENT_VA(this, out);
122124
if (!out.IsValid())
123125
return;
124126
StreamFile stream(out.m_opaque_sp);
125-
GetDescription(stream);
127+
GetDescription(stream, nullptr);
126128
}
127129

128130
void SBInstructionList::Print(FileSP out_sp) {
129131
LLDB_INSTRUMENT_VA(this, out_sp);
130132
if (!out_sp || !out_sp->IsValid())
131133
return;
132134
StreamFile stream(out_sp);
133-
GetDescription(stream);
135+
GetDescription(stream, nullptr);
134136
}
135137

136138
bool SBInstructionList::GetDescription(lldb::SBStream &stream) {
137139
LLDB_INSTRUMENT_VA(this, stream);
138-
return GetDescription(stream.ref());
140+
return GetDescription(stream.ref(), nullptr);
139141
}
140142

141-
bool SBInstructionList::GetDescription(Stream &sref) {
143+
bool SBInstructionList::GetDescription(lldb::SBStream &stream,
144+
lldb::SBFrame &frame) {
145+
LLDB_INSTRUMENT_VA(this, stream);
146+
return GetDescription(stream.ref(), &frame);
147+
}
148+
149+
bool SBInstructionList::GetDescription(Stream &sref, lldb::SBFrame *frame) {
142150

143151
if (m_opaque_sp) {
144152
size_t num_instructions = GetSize();
@@ -148,10 +156,15 @@ bool SBInstructionList::GetDescription(Stream &sref) {
148156
const uint32_t max_opcode_byte_size =
149157
m_opaque_sp->GetInstructionList().GetMaxOpcocdeByteSize();
150158
FormatEntity::Entry format;
151-
FormatEntity::Parse("${addr}: ", format);
159+
FormatEntity::Parse("${addr-file-or-load}: ", format);
152160
SymbolContext sc;
153161
SymbolContext prev_sc;
154162

163+
std::shared_ptr<ExecutionContext> exec_ctx;
164+
if (nullptr != frame) {
165+
exec_ctx = std::make_shared<ExecutionContext>(frame->GetFrameSP());
166+
}
167+
155168
// Expected address of the next instruction. Used to print an empty line
156169
// for non-contiguous blocks of insns.
157170
std::optional<Address> next_addr;
@@ -172,8 +185,8 @@ bool SBInstructionList::GetDescription(Stream &sref) {
172185
if (next_addr && *next_addr != addr)
173186
sref.EOL();
174187
inst->Dump(&sref, max_opcode_byte_size, true, false,
175-
/*show_control_flow_kind=*/false, nullptr, &sc, &prev_sc,
176-
&format, 0);
188+
/*show_control_flow_kind=*/false, exec_ctx.get(), &sc,
189+
&prev_sc, &format, 0);
177190
sref.EOL();
178191
next_addr = addr;
179192
next_addr->Slide(inst->GetOpcode().GetByteSize());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ SourceRequestHandler::Run(const protocol::SourceArguments &args) const {
4343

4444
lldb::SBInstructionList insts = frame.GetSymbol().GetInstructions(dap.target);
4545
lldb::SBStream stream;
46-
insts.GetDescription(stream);
46+
insts.GetDescription(stream, frame);
4747

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

0 commit comments

Comments
 (0)