Skip to content

Commit 651b407

Browse files
committed
[lldb] [disassembler] chore: enhance VariableAnnotator to return structured data: remove target and module from Annotate methods signature
Signed-off-by: Nikita B <[email protected]>
1 parent 6fe62e4 commit 651b407

File tree

5 files changed

+16
-23
lines changed

5 files changed

+16
-23
lines changed

lldb/include/lldb/API/SBInstruction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class LLDB_API SBInstruction {
8989
/// - "decl_file": string path to the file where variable is declared
9090
/// - "decl_line": unsigned integer line number where variable is declared
9191
/// - "type_name": string type name of the variable
92-
lldb::SBStructuredData GetVariableAnnotations(lldb::SBTarget target);
92+
lldb::SBStructuredData GetVariableAnnotations();
9393

9494
protected:
9595
friend class SBInstructionList;

lldb/include/lldb/Core/Disassembler.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -597,13 +597,10 @@ class VariableAnnotator {
597597
public:
598598
/// Compute annotation strings for a single instruction and update `Live_`.
599599
/// Returns only the events that should be printed *at this instruction*.
600-
std::vector<std::string> Annotate(Instruction &inst, Target &target,
601-
lldb::ModuleSP module_sp);
600+
std::vector<std::string> Annotate(Instruction &inst);
602601

603602
/// Returns structured data for all variables relevant at this instruction.
604-
std::vector<VariableAnnotation> AnnotateStructured(Instruction &inst,
605-
Target &target,
606-
lldb::ModuleSP module_sp);
603+
std::vector<VariableAnnotation> AnnotateStructured(Instruction &inst);
607604
};
608605

609606
} // namespace lldb_private

lldb/source/API/SBInstruction.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -351,19 +351,16 @@ bool SBInstruction::TestEmulation(lldb::SBStream &output_stream,
351351
return false;
352352
}
353353

354-
lldb::SBStructuredData
355-
SBInstruction::GetVariableAnnotations(lldb::SBTarget target) {
356-
LLDB_INSTRUMENT_VA(this, target);
354+
lldb::SBStructuredData SBInstruction::GetVariableAnnotations() {
355+
LLDB_INSTRUMENT_VA(this);
357356

358357
SBStructuredData result;
359358

360-
if (!m_opaque_sp || !m_opaque_sp->IsValid() || !target.IsValid())
359+
if (!m_opaque_sp || !m_opaque_sp->IsValid())
361360
return result;
362361

363362
lldb::InstructionSP inst_sp = m_opaque_sp->GetSP();
364-
lldb::TargetSP target_sp = target.GetSP();
365-
366-
if (!inst_sp || !target_sp)
363+
if (!inst_sp)
367364
return result;
368365

369366
const Address &addr = inst_sp->GetAddress();
@@ -374,7 +371,7 @@ SBInstruction::GetVariableAnnotations(lldb::SBTarget target) {
374371

375372
VariableAnnotator annotator;
376373
std::vector<VariableAnnotation> annotations =
377-
annotator.AnnotateStructured(*inst_sp, *target_sp, module_sp);
374+
annotator.AnnotateStructured(*inst_sp);
378375

379376
auto array_sp = std::make_shared<StructuredData::Array>();
380377

lldb/source/Core/Disassembler.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,8 @@ const std::string VariableAnnotator::kUndefLocationFormatted =
302302
// The goal is to give users helpful live variable hints alongside the
303303
// disassembled instruction stream, similar to how debug information
304304
// enhances source-level debugging.
305-
std::vector<std::string> VariableAnnotator::Annotate(Instruction &inst,
306-
Target &target,
307-
lldb::ModuleSP module_sp) {
308-
auto structured_annotations = AnnotateStructured(inst, target, module_sp);
305+
std::vector<std::string> VariableAnnotator::Annotate(Instruction &inst) {
306+
auto structured_annotations = AnnotateStructured(inst);
309307

310308
std::vector<std::string> events;
311309
events.reserve(structured_annotations.size());
@@ -328,10 +326,11 @@ std::vector<std::string> VariableAnnotator::Annotate(Instruction &inst,
328326
}
329327

330328
std::vector<VariableAnnotation>
331-
VariableAnnotator::AnnotateStructured(Instruction &inst, Target &target,
332-
lldb::ModuleSP module_sp) {
329+
VariableAnnotator::AnnotateStructured(Instruction &inst) {
333330
std::vector<VariableAnnotation> annotations;
334331

332+
ModuleSP module_sp = inst.GetAddress().GetModule();
333+
335334
// If we lost module context, mark all live variables as undefined.
336335
if (!module_sp) {
337336
for (const auto &KV : m_live_vars) {
@@ -377,7 +376,7 @@ VariableAnnotator::AnnotateStructured(Instruction &inst, Target &target,
377376
const lldb::addr_t func_file = sc.function->GetAddress().GetFileAddress();
378377

379378
// ABI from Target (pretty reg names if plugin exists). Safe to be null.
380-
lldb::ABISP abi_sp = ABI::FindPlugin(nullptr, target.GetArchitecture());
379+
lldb::ABISP abi_sp = ABI::FindPlugin(nullptr, module_sp->GetArchitecture());
381380
ABI *abi = abi_sp.get();
382381

383382
llvm::DIDumpOptions opts;
@@ -737,7 +736,7 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
737736
address_text_size);
738737

739738
if ((options & eOptionVariableAnnotations) && target_sp) {
740-
auto annotations = annot.Annotate(*inst, *target_sp, module_sp);
739+
auto annotations = annot.Annotate(*inst);
741740
if (!annotations.empty()) {
742741
const size_t annotation_column = 100;
743742
inst_line.FillLastLineToColumn(annotation_column, ' ');

lldb/test/API/functionalities/disassembler-variables/TestVariableAnnotationsDisassembler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def test_structured_annotations_api(self):
146146
inst = instructions.GetInstructionAtIndex(i)
147147
self.assertTrue(inst.IsValid(), f"Invalid instruction at index {i}")
148148

149-
annotations = inst.GetVariableAnnotations(target)
149+
annotations = inst.GetVariableAnnotations()
150150

151151
self.assertIsInstance(annotations, lldb.SBStructuredData,
152152
"GetVariableAnnotations should return SBStructuredData")

0 commit comments

Comments
 (0)