Skip to content

Commit 41adf6e

Browse files
committed
[lldb] [disassembler] chore: enhance VariableAnnotator to return structured data: introduce VariableAnnotator::AnnotateStructured method: introduce static helper function AddVariableAnnotationToVector to reduce code duplication
Signed-off-by: Nikita B <[email protected]>
1 parent b4058bf commit 41adf6e

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

lldb/source/Core/Disassembler.cpp

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,16 @@ bool Disassembler::ElideMixedSourceAndDisassemblyLine(
288288

289289
static constexpr const llvm::StringLiteral kUndefLocation = "undef";
290290
static constexpr const llvm::StringLiteral kUndefLocationFormatted = "<undef>";
291+
static void
292+
AddVariableAnnotationToVector(std::vector<VariableAnnotation> &annotations,
293+
VariableAnnotation annotation_entity,
294+
const bool is_live) {
295+
annotation_entity.is_live = is_live;
296+
if (!is_live) {
297+
annotation_entity.location_description = kUndefLocation;
298+
}
299+
annotations.push_back(std::move(annotation_entity));
300+
}
291301

292302
// For each instruction, this block attempts to resolve in-scope variables
293303
// and determine if the current PC falls within their
@@ -330,12 +340,8 @@ VariableAnnotator::AnnotateStructured(Instruction &inst) {
330340

331341
// If we lost module context, mark all live variables as UndefLocation.
332342
if (!module_sp) {
333-
for (const auto &KV : m_live_vars) {
334-
VariableAnnotation annotation_entity = KV.second;
335-
annotation_entity.is_live = false;
336-
annotation_entity.location_description = kUndefLocation;
337-
annotations.push_back(std::move(annotation_entity));
338-
}
343+
for (const auto &KV : m_live_vars)
344+
AddVariableAnnotationToVector(annotations, KV.second, false);
339345
m_live_vars.clear();
340346
return annotations;
341347
}
@@ -347,12 +353,8 @@ VariableAnnotator::AnnotateStructured(Instruction &inst) {
347353
if (!module_sp->ResolveSymbolContextForAddress(iaddr, mask, sc) ||
348354
!sc.function) {
349355
// No function context: everything dies here.
350-
for (const auto &KV : m_live_vars) {
351-
VariableAnnotation annotation_entity = KV.second;
352-
annotation_entity.is_live = false;
353-
annotation_entity.location_description = kUndefLocation;
354-
annotations.push_back(std::move(annotation_entity));
355-
}
356+
for (const auto &KV : m_live_vars)
357+
AddVariableAnnotationToVector(annotations, KV.second, false);
356358
m_live_vars.clear();
357359
return annotations;
358360
}
@@ -437,26 +439,19 @@ VariableAnnotator::AnnotateStructured(Instruction &inst) {
437439
auto it = m_live_vars.find(KV.first);
438440
if (it == m_live_vars.end()) {
439441
// Newly live.
440-
VariableAnnotation annotation_entity = KV.second;
441-
annotation_entity.is_live = true;
442-
annotations.push_back(std::move(annotation_entity));
442+
AddVariableAnnotationToVector(annotations, KV.second, true);
443443
} else if (it->second.location_description !=
444444
KV.second.location_description) {
445445
// Location changed.
446-
VariableAnnotation annotation_entity = KV.second;
447-
annotation_entity.is_live = true;
448-
annotations.push_back(std::move(annotation_entity));
446+
AddVariableAnnotationToVector(annotations, KV.second, true);
449447
}
450448
}
451449

452450
// 2) Ends: anything that was live but is not in current_vars becomes
453451
// UndefLocation.
454452
for (const auto &KV : m_live_vars)
455453
if (!current_vars.count(KV.first)) {
456-
auto annotation_entity = KV.second;
457-
annotation_entity.is_live = false;
458-
annotation_entity.location_description = kUndefLocation;
459-
annotations.push_back(std::move(annotation_entity));
454+
AddVariableAnnotationToVector(annotations, KV.second, false);
460455
}
461456

462457
// Commit new state.

0 commit comments

Comments
 (0)