Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/SBFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class LLDB_API SBFrame {
friend class SBBlock;
friend class SBExecutionContext;
friend class SBInstruction;
friend class SBInstructionList;
friend class SBThread;
friend class SBValue;

Expand Down
7 changes: 5 additions & 2 deletions lldb/include/lldb/API/SBInstructionList.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class LLDB_API SBInstructionList {

bool GetDescription(lldb::SBStream &description);

// Writes assembly instructions to `description` with load addresses using
// `frame`.
bool GetDescription(lldb::SBStream &description, lldb::SBFrame &frame);
Copy link
Member

Choose a reason for hiding this comment

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

We'd want this API to be as generic as possible. Since you only need the execution context, that means this should take an SBExecutionContext, which you can create from a frame or thread or process.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

💯


bool DumpEmulationForAllInstructions(const char *triple);

protected:
Expand All @@ -62,8 +66,7 @@ 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::SBFrame *frame);
Copy link
Member

Choose a reason for hiding this comment

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

Let's give this a default argument so you don't need to pass nullptr everywhere.

Suggested change
bool GetDescription(lldb_private::Stream &description, lldb::SBFrame *frame);
bool GetDescription(lldb_private::Stream &description, lldb::SBExecutionContext *exe_ctx = nullptr);

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
29 changes: 21 additions & 8 deletions lldb/source/API/SBInstructionList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#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 @@ -114,31 +116,37 @@ void SBInstructionList::Print(FILE *out) {
if (out == nullptr)
return;
StreamFile stream(out, false);
GetDescription(stream);
GetDescription(stream, nullptr);
}

void SBInstructionList::Print(SBFile out) {
LLDB_INSTRUMENT_VA(this, out);
if (!out.IsValid())
return;
StreamFile stream(out.m_opaque_sp);
GetDescription(stream);
GetDescription(stream, nullptr);
}

void SBInstructionList::Print(FileSP out_sp) {
LLDB_INSTRUMENT_VA(this, out_sp);
if (!out_sp || !out_sp->IsValid())
return;
StreamFile stream(out_sp);
GetDescription(stream);
GetDescription(stream, nullptr);
}

bool SBInstructionList::GetDescription(lldb::SBStream &stream) {
LLDB_INSTRUMENT_VA(this, stream);
return GetDescription(stream.ref());
return GetDescription(stream.ref(), nullptr);
}

bool SBInstructionList::GetDescription(Stream &sref) {
bool SBInstructionList::GetDescription(lldb::SBStream &stream,
lldb::SBFrame &frame) {
LLDB_INSTRUMENT_VA(this, stream);
return GetDescription(stream.ref(), &frame);
}

bool SBInstructionList::GetDescription(Stream &sref, lldb::SBFrame *frame) {

if (m_opaque_sp) {
size_t num_instructions = GetSize();
Expand All @@ -148,10 +156,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> exec_ctx;
if (nullptr != frame) {
exec_ctx = std::make_shared<ExecutionContext>(frame->GetFrameSP());
}

// 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 +185,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, exec_ctx.get(), &sc,
&prev_sc, &format, 0);
sref.EOL();
next_addr = addr;
next_addr->Slide(inst->GetOpcode().GetByteSize());
Expand Down
2 changes: 1 addition & 1 deletion lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ SourceRequestHandler::Run(const protocol::SourceArguments &args) const {

lldb::SBInstructionList insts = frame.GetSymbol().GetInstructions(dap.target);
lldb::SBStream stream;
insts.GetDescription(stream);
insts.GetDescription(stream, frame);

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