Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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::SBExecutionContext *exe_ctx = nullptr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this can now take the private type (i.e. ExecutionContext*). All the SB API objects are PIMPL objects so it feels a bit weird to take their address.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯


private:
lldb::DisassemblerSP m_opaque_sp;
Expand Down
23 changes: 19 additions & 4 deletions lldb/source/API/SBInstructionList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@

#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"
#include <memory>

using namespace lldb;
using namespace lldb_private;
Expand Down Expand Up @@ -138,7 +141,14 @@ 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);
return GetDescription(stream.ref(), &exe_ctx);
}

bool SBInstructionList::GetDescription(Stream &sref,
lldb::SBExecutionContext *exe_ctx) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could take the private type (e.g. ExecutionContext*).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯


if (m_opaque_sp) {
size_t num_instructions = GetSize();
Expand All @@ -148,10 +158,15 @@ 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;

std::shared_ptr<ExecutionContext> exe_ctx_ptr;
if (nullptr != exe_ctx) {
exe_ctx_ptr = std::make_shared<ExecutionContext>(exe_ctx->get());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nits:

  1. No braces around single-line ifs.
  2. Do we actually need to wrap this in a shared pointer? The underlying object will already live long enough, right? Anyway the current code doesn't look safe unless the underlying object inherits from enable_shared_from_this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯


// Expected address of the next instruction. Used to print an empty line
// for non-contiguous blocks of insns.
std::optional<Address> next_addr;
Expand All @@ -172,8 +187,8 @@ 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,
&format, 0);
/*show_control_flow_kind=*/false, exe_ctx_ptr.get(), &sc,
&prev_sc, &format, 0);
sref.EOL();
next_addr = addr;
next_addr->Slide(inst->GetOpcode().GetByteSize());
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