Skip to content

Commit b16fde9

Browse files
da-vipersivan-shani
authored andcommitted
[lldb][lldb-dap] Use the default disassembly flavour if none is provided. (llvm#141424)
This is the currently the default for `SBTarget::ReadInstructions(SBAddress, uint32_t)`. But not for others, to make it consistent used the user assigned instruction flavour.
1 parent af992b8 commit b16fde9

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

lldb/source/API/SBTarget.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,17 @@ lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
19601960
const size_t bytes_read =
19611961
target_sp->ReadMemory(*addr_ptr, data.GetBytes(), data.GetByteSize(),
19621962
error, force_live_memory, &load_addr);
1963+
19631964
const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
1965+
if (!flavor_string || flavor_string[0] == '\0') {
1966+
// FIXME - we don't have the mechanism in place to do per-architecture
1967+
// settings. But since we know that for now we only support flavors on
1968+
// x86 & x86_64,
1969+
const llvm::Triple::ArchType arch =
1970+
target_sp->GetArchitecture().GetTriple().getArch();
1971+
if (arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64)
1972+
flavor_string = target_sp->GetDisassemblyFlavor();
1973+
}
19641974
sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
19651975
target_sp->GetArchitecture(), nullptr, flavor_string,
19661976
target_sp->GetDisassemblyCPU(), target_sp->GetDisassemblyFeatures(),
@@ -2017,7 +2027,16 @@ SBTarget::GetInstructionsWithFlavor(lldb::SBAddress base_addr,
20172027
if (base_addr.get())
20182028
addr = *base_addr.get();
20192029

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

20222041
sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
20232042
target_sp->GetArchitecture(), nullptr, flavor_string,

lldb/source/Commands/CommandObjectDisassemble.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ void CommandObjectDisassemble::CommandOptions::OptionParsingStarting(
190190
// architecture. For now GetDisassemblyFlavor is really only valid for x86
191191
// (and for the llvm assembler plugin, but I'm papering over that since that
192192
// is the only disassembler plugin we have...
193-
// This logic is duplicated in `Handler/DisassembleRequestHandler`.
194193
if (target->GetArchitecture().GetTriple().getArch() == llvm::Triple::x86 ||
195194
target->GetArchitecture().GetTriple().getArch() ==
196195
llvm::Triple::x86_64) {

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -193,21 +193,6 @@ DisassembleRequestHandler::Run(const DisassembleArguments &args) const {
193193
return llvm::make_error<DAPError>(
194194
"Memory reference not found in the current binary.");
195195

196-
std::string flavor_string;
197-
const auto target_triple = llvm::StringRef(dap.target.GetTriple());
198-
// This handles both 32 and 64bit x86 architecture. The logic is duplicated in
199-
// `CommandObjectDisassemble::CommandOptions::OptionParsingStarting`
200-
if (target_triple.starts_with("x86")) {
201-
const lldb::SBStructuredData flavor =
202-
dap.debugger.GetSetting("target.x86-disassembly-flavor");
203-
204-
const size_t str_length = flavor.GetStringValue(nullptr, 0);
205-
if (str_length != 0) {
206-
flavor_string.resize(str_length + 1);
207-
flavor.GetStringValue(flavor_string.data(), flavor_string.length());
208-
}
209-
}
210-
211196
// Offset (in instructions) to be applied after the byte offset (if any)
212197
// before disassembling. Can be negative.
213198
int64_t instruction_offset = args.instructionOffset.value_or(0);
@@ -220,7 +205,7 @@ DisassembleRequestHandler::Run(const DisassembleArguments &args) const {
220205
"Unexpected error while disassembling instructions.");
221206

222207
lldb::SBInstructionList insts = dap.target.ReadInstructions(
223-
disassemble_start_addr, args.instructionCount, flavor_string.c_str());
208+
disassemble_start_addr, args.instructionCount);
224209
if (!insts.IsValid())
225210
return llvm::make_error<DAPError>(
226211
"Unexpected error while disassembling instructions.");

0 commit comments

Comments
 (0)