Skip to content

Commit cb0cd3a

Browse files
Moved rich annotations flag into Disassembler options
This change refactors how the `--rich` flag is handled, based on code review feedback. - Removed the `enable_rich_annotations` boolean from the API signatures of: - Disassembler::Disassemble(...) - Disassembler::PrintInstructions(...) - StackFrame::Disassemble(...) - Added a new Disassembler::Option enum value: eOptionRichAnnotations. - The `--rich` CLI flag now sets the new option bit in CommandObjectDisassemble::DoExecute: options |= Disassembler::eOptionRichAnnotations; - Disassembler::PrintInstructions checks the bit to determine whether to enable rich annotations: const bool enable_rich = (options & eOptionRichAnnotations) != 0; The SB API remains unchanged and defaults to non-rich output. Tested via the existing test using `disassemble --rich -f`.
1 parent b784868 commit cb0cd3a

File tree

5 files changed

+28
-31
lines changed

5 files changed

+28
-31
lines changed

lldb/include/lldb/Core/Disassembler.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ class Disassembler : public std::enable_shared_from_this<Disassembler>,
398398
eOptionMarkPCAddress =
399399
(1u << 3), // Mark the disassembly line the contains the PC
400400
eOptionShowControlFlowKind = (1u << 4),
401+
eOptionRichAnnotations = (1u << 5),
401402
};
402403

403404
enum HexImmediateStyle {
@@ -444,11 +445,10 @@ class Disassembler : public std::enable_shared_from_this<Disassembler>,
444445
const ExecutionContext &exe_ctx, const Address &start,
445446
Limit limit, bool mixed_source_and_assembly,
446447
uint32_t num_mixed_context_lines, uint32_t options,
447-
Stream &strm, bool enable_rich_annotations = false);
448+
Stream &strm);
448449

449450
static bool Disassemble(Debugger &debugger, const ArchSpec &arch,
450-
StackFrame &frame, Stream &strm,
451-
bool enable_rich_annotations = false);
451+
StackFrame &frame, Stream &strm);
452452

453453
// Constructors and Destructors
454454
Disassembler(const ArchSpec &arch, const char *flavor);
@@ -458,7 +458,7 @@ class Disassembler : public std::enable_shared_from_this<Disassembler>,
458458
const ExecutionContext &exe_ctx,
459459
bool mixed_source_and_assembly,
460460
uint32_t num_mixed_context_lines, uint32_t options,
461-
Stream &strm, bool enable_rich_annotations = false);
461+
Stream &strm);
462462

463463
size_t ParseInstructions(Target &target, Address address, Limit limit,
464464
Stream *error_strm_ptr,

lldb/include/lldb/Target/StackFrame.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ class StackFrame : public ExecutionContextScope,
321321
///
322322
/// \return
323323
/// C string with the assembly instructions for this function.
324-
const char *Disassemble(bool enable_rich_annotations = false);
324+
const char *Disassemble();
325325

326326
/// Print a description of this frame using the provided frame format.
327327
///

lldb/source/Commands/CommandObjectDisassemble.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,9 @@ void CommandObjectDisassemble::DoExecute(Args &command,
533533
if (m_options.raw)
534534
options |= Disassembler::eOptionRawOuput;
535535

536+
if (m_options.enable_rich_annotations)
537+
options |= Disassembler::eOptionRichAnnotations;
538+
536539
llvm::Expected<std::vector<AddressRange>> ranges =
537540
GetRangesForSelectedMode(result);
538541
if (!ranges) {
@@ -555,8 +558,7 @@ void CommandObjectDisassemble::DoExecute(Args &command,
555558
cpu_string, features_string, m_exe_ctx, cur_range.GetBaseAddress(),
556559
limit, m_options.show_mixed,
557560
m_options.show_mixed ? m_options.num_lines_context : 0, options,
558-
result.GetOutputStream(),
559-
/*enable_rich_annotations=*/m_options.enable_rich_annotations)) {
561+
result.GetOutputStream())) {
560562
result.SetStatus(eReturnStatusSuccessFinishResult);
561563
} else {
562564
if (m_options.symbol_containing_addr != LLDB_INVALID_ADDRESS) {

lldb/source/Core/Disassembler.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,14 @@ Disassembler::DisassembleBytes(const ArchSpec &arch, const char *plugin_name,
169169
return disasm_sp;
170170
}
171171

172-
bool Disassembler::Disassemble(
173-
Debugger &debugger, const ArchSpec &arch, const char *plugin_name,
174-
const char *flavor, const char *cpu, const char *features,
175-
const ExecutionContext &exe_ctx, const Address &address, Limit limit,
176-
bool mixed_source_and_assembly, uint32_t num_mixed_context_lines,
177-
uint32_t options, Stream &strm, bool enable_rich_annotations) {
172+
bool Disassembler::Disassemble(Debugger &debugger, const ArchSpec &arch,
173+
const char *plugin_name, const char *flavor,
174+
const char *cpu, const char *features,
175+
const ExecutionContext &exe_ctx,
176+
const Address &address, Limit limit,
177+
bool mixed_source_and_assembly,
178+
uint32_t num_mixed_context_lines,
179+
uint32_t options, Stream &strm) {
178180
if (!exe_ctx.GetTargetPtr())
179181
return false;
180182

@@ -189,10 +191,9 @@ bool Disassembler::Disassemble(
189191
if (bytes_disassembled == 0)
190192
return false;
191193

192-
disasm_sp->PrintInstructions(
193-
debugger, arch, exe_ctx, mixed_source_and_assembly,
194-
num_mixed_context_lines, options, strm,
195-
/*enable_rich_annotations=*/enable_rich_annotations);
194+
disasm_sp->PrintInstructions(debugger, arch, exe_ctx,
195+
mixed_source_and_assembly,
196+
num_mixed_context_lines, options, strm);
196197
return true;
197198
}
198199

@@ -287,8 +288,7 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
287288
const ExecutionContext &exe_ctx,
288289
bool mixed_source_and_assembly,
289290
uint32_t num_mixed_context_lines,
290-
uint32_t options, Stream &strm,
291-
bool enable_rich_annotations) {
291+
uint32_t options, Stream &strm) {
292292
// We got some things disassembled...
293293
size_t num_instructions_found = GetInstructionList().GetSize();
294294

@@ -688,7 +688,7 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
688688
show_control_flow_kind, &exe_ctx, &sc, &prev_sc, nullptr,
689689
address_text_size);
690690

691-
if (enable_rich_annotations) {
691+
if (options & eOptionRichAnnotations) {
692692
std::vector<std::string> annotations = annotate_variables(*inst);
693693
if (!annotations.empty()) {
694694
const size_t annotation_column = 100;
@@ -708,8 +708,7 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
708708
}
709709

710710
bool Disassembler::Disassemble(Debugger &debugger, const ArchSpec &arch,
711-
StackFrame &frame, Stream &strm,
712-
bool enable_rich_annotations) {
711+
StackFrame &frame, Stream &strm) {
713712
constexpr const char *plugin_name = nullptr;
714713
constexpr const char *flavor = nullptr;
715714
constexpr const char *cpu = nullptr;

lldb/source/Target/StackFrame.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -262,20 +262,16 @@ bool StackFrame::ChangePC(addr_t pc) {
262262
return true;
263263
}
264264

265-
const char *StackFrame::Disassemble(bool enable_rich_annotations) {
265+
const char *StackFrame::Disassemble() {
266266
std::lock_guard<std::recursive_mutex> guard(m_mutex);
267267

268-
// Keep the existing cache only for the plain (non-rich) path.
269-
if (!enable_rich_annotations) {
270-
if (!m_disassembly.Empty())
271-
return m_disassembly.GetData();
272-
}
268+
if (!m_disassembly.Empty())
269+
return m_disassembly.GetData();
273270

274271
ExecutionContext exe_ctx(shared_from_this());
275272
if (Target *target = exe_ctx.GetTargetPtr()) {
276-
Disassembler::Disassemble(
277-
target->GetDebugger(), target->GetArchitecture(), *this, m_disassembly,
278-
/*enable_rich_annotations=*/enable_rich_annotations);
273+
Disassembler::Disassemble(target->GetDebugger(), target->GetArchitecture(),
274+
*this, m_disassembly);
279275
}
280276

281277
return m_disassembly.Empty() ? nullptr : m_disassembly.GetData();

0 commit comments

Comments
 (0)