Skip to content

Commit 31e91cf

Browse files
committed
[lldb] [disassembler] chore: enhance VariableAnnotator to return structured data: use AddressRange instead of start_address and end_address
Signed-off-by: Nikita B <[email protected]>
1 parent c688f70 commit 31e91cf

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

lldb/include/lldb/Core/Disassembler.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,14 +571,12 @@ struct VariableAnnotation {
571571
std::string variable_name;
572572
/// Location description (e.g., "r15", "undef", "const_0").
573573
std::string location_description;
574-
/// Where this annotation starts being valid.
575-
lldb::addr_t start_address;
576-
/// Where this annotation ends being valid.
577-
lldb::addr_t end_address;
578574
/// Whether variable is live at this instruction.
579575
bool is_live;
580576
/// Register numbering scheme for location interpretation.
581577
lldb::RegisterKind register_kind;
578+
/// Where this annotation is valid.
579+
std::optional<lldb_private::AddressRange> address_range;
582580
/// Source file where variable was declared.
583581
std::optional<std::string> decl_file;
584582
/// Line number where variable was declared.

lldb/source/API/SBInstruction.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,16 @@ SBInstruction::GetVariableAnnotations(lldb::SBTarget target) {
384384
dict_sp->AddStringItem("variable_name", ann.variable_name);
385385
dict_sp->AddStringItem("location_description", ann.location_description);
386386
dict_sp->AddBooleanItem("is_live", ann.is_live);
387-
dict_sp->AddItem(
388-
"start_address",
389-
std::make_shared<StructuredData::UnsignedInteger>(ann.start_address));
390-
dict_sp->AddItem(
391-
"end_address",
392-
std::make_shared<StructuredData::UnsignedInteger>(ann.end_address));
387+
if (ann.address_range.has_value()) {
388+
const auto &range = *ann.address_range;
389+
dict_sp->AddItem("start_address",
390+
std::make_shared<StructuredData::UnsignedInteger>(
391+
range.GetBaseAddress().GetFileAddress()));
392+
dict_sp->AddItem(
393+
"end_address",
394+
std::make_shared<StructuredData::UnsignedInteger>(
395+
range.GetBaseAddress().GetFileAddress() + range.GetByteSize()));
396+
}
393397
dict_sp->AddItem(
394398
"register_kind",
395399
std::make_shared<StructuredData::UnsignedInteger>(ann.register_kind));

lldb/source/Core/Disassembler.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,6 @@ VariableAnnotator::AnnotateStructured(Instruction &inst, Target &target,
408408
if (loc.empty())
409409
continue;
410410

411-
lldb::addr_t start_addr = inst.GetAddress().GetFileAddress();
412-
lldb::addr_t end_addr = LLDB_INVALID_ADDRESS;
413-
if (entry.file_range.has_value()) {
414-
start_addr = entry.file_range->GetBaseAddress().GetFileAddress();
415-
end_addr = start_addr + entry.file_range->GetByteSize();
416-
}
417-
418411
std::optional<std::string> decl_file;
419412
std::optional<uint32_t> decl_line;
420413
std::optional<std::string> type_name;
@@ -432,9 +425,9 @@ VariableAnnotator::AnnotateStructured(Instruction &inst, Target &target,
432425

433426
Current.try_emplace(v->GetID(),
434427
VariableAnnotation{std::string(name), std::string(loc),
435-
start_addr, end_addr, true,
436-
entry.expr->GetRegisterKind(),
437-
decl_file, decl_line, type_name});
428+
true, entry.expr->GetRegisterKind(),
429+
entry.file_range, decl_file,
430+
decl_line, type_name});
438431
}
439432

440433
// Diff Live_ → Current.

0 commit comments

Comments
 (0)