Skip to content

[lldb-dap] Show load addresses in disassembly #136755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lldb/include/lldb/API/SBExecutionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 7 additions & 2 deletions lldb/include/lldb/API/SBInstructionList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
Expand Down
16 changes: 13 additions & 3 deletions lldb/source/API/SBInstructionList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@

#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"
#include "lldb/Core/Disassembler.h"
#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"

Expand Down Expand Up @@ -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();
Expand All @@ -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;

Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"};
Expand Down
Loading