Skip to content

[lldb][lldb-dap] Use the default disassembly flavour if none is provided. #141424

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 2 commits into from
May 30, 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
21 changes: 20 additions & 1 deletion lldb/source/API/SBTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,17 @@ lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
const size_t bytes_read =
target_sp->ReadMemory(*addr_ptr, data.GetBytes(), data.GetByteSize(),
error, force_live_memory, &load_addr);

const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
if (!flavor_string || flavor_string[0] == '\0') {
// FIXME - we don't have the mechanism in place to do per-architecture
// settings. But since we know that for now we only support flavors on
// x86 & x86_64,
const llvm::Triple::ArchType arch =
target_sp->GetArchitecture().GetTriple().getArch();
if (arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64)
flavor_string = target_sp->GetDisassemblyFlavor();
}
sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
target_sp->GetArchitecture(), nullptr, flavor_string,
target_sp->GetDisassemblyCPU(), target_sp->GetDisassemblyFeatures(),
Expand Down Expand Up @@ -2098,7 +2108,16 @@ SBTarget::GetInstructionsWithFlavor(lldb::SBAddress base_addr,
if (base_addr.get())
addr = *base_addr.get();

const bool data_from_file = true;
constexpr bool data_from_file = true;
if (!flavor_string || flavor_string[0] == '\0') {
// FIXME - we don't have the mechanism in place to do per-architecture
// settings. But since we know that for now we only support flavors on
// x86 & x86_64,
const llvm::Triple::ArchType arch =
target_sp->GetArchitecture().GetTriple().getArch();
if (arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64)
flavor_string = target_sp->GetDisassemblyFlavor();
}

sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
target_sp->GetArchitecture(), nullptr, flavor_string,
Expand Down
1 change: 0 additions & 1 deletion lldb/source/Commands/CommandObjectDisassemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ void CommandObjectDisassemble::CommandOptions::OptionParsingStarting(
// architecture. For now GetDisassemblyFlavor is really only valid for x86
// (and for the llvm assembler plugin, but I'm papering over that since that
// is the only disassembler plugin we have...
// This logic is duplicated in `Handler/DisassembleRequestHandler`.
if (target->GetArchitecture().GetTriple().getArch() == llvm::Triple::x86 ||
target->GetArchitecture().GetTriple().getArch() ==
llvm::Triple::x86_64) {
Expand Down
17 changes: 1 addition & 16 deletions lldb/tools/lldb-dap/Handler/DisassembleRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,6 @@ DisassembleRequestHandler::Run(const DisassembleArguments &args) const {
return llvm::make_error<DAPError>(
"Memory reference not found in the current binary.");

std::string flavor_string;
const auto target_triple = llvm::StringRef(dap.target.GetTriple());
// This handles both 32 and 64bit x86 architecture. The logic is duplicated in
// `CommandObjectDisassemble::CommandOptions::OptionParsingStarting`
if (target_triple.starts_with("x86")) {
const lldb::SBStructuredData flavor =
dap.debugger.GetSetting("target.x86-disassembly-flavor");

const size_t str_length = flavor.GetStringValue(nullptr, 0);
if (str_length != 0) {
flavor_string.resize(str_length + 1);
flavor.GetStringValue(flavor_string.data(), flavor_string.length());
}
}

// Offset (in instructions) to be applied after the byte offset (if any)
// before disassembling. Can be negative.
int64_t instruction_offset = args.instructionOffset.value_or(0);
Expand All @@ -219,7 +204,7 @@ DisassembleRequestHandler::Run(const DisassembleArguments &args) const {
"Unexpected error while disassembling instructions.");

lldb::SBInstructionList insts = dap.target.ReadInstructions(
disassemble_start_addr, args.instructionCount, flavor_string.c_str());
disassemble_start_addr, args.instructionCount);
if (!insts.IsValid())
return llvm::make_error<DAPError>(
"Unexpected error while disassembling instructions.");
Expand Down
Loading