Skip to content

Commit 35c036f

Browse files
committed
[lldb] [disassembler] chore: enhance VariableAnnotator to return structured data: replace llvm::formatv with stream, formatting
Signed-off-by: Nikita B <[email protected]>
1 parent f10922f commit 35c036f

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

lldb/include/lldb/Core/Disassembler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ class VariableAnnotator {
592592
llvm::DenseMap<lldb::user_id_t, VariableAnnotation> m_live_vars;
593593

594594
static constexpr const char *kUndefLocation = "undef";
595+
static const std::string kUndefLocationFormatted;
595596

596597
public:
597598
/// Compute annotation strings for a single instruction and update `Live_`.

lldb/source/Core/Disassembler.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ bool Disassembler::ElideMixedSourceAndDisassemblyLine(
286286
return false;
287287
}
288288

289+
const std::string VariableAnnotator::kUndefLocationFormatted =
290+
llvm::formatv("<{0}>", kUndefLocation).str();
291+
289292
// For each instruction, this block attempts to resolve in-scope variables
290293
// and determine if the current PC falls within their
291294
// DWARF location entry. If so, it prints a simplified annotation using the
@@ -309,15 +312,16 @@ std::vector<std::string> VariableAnnotator::Annotate(Instruction &inst,
309312

310313
for (const auto &annotation : structured_annotations) {
311314
std::string display_string;
312-
display_string =
313-
llvm::formatv(
314-
"{0} = {1}", annotation.variable_name,
315-
annotation.location_description == VariableAnnotator::kUndefLocation
316-
? llvm::formatv("<{0}>", VariableAnnotator::kUndefLocation)
317-
.str()
318-
: annotation.location_description)
319-
.str();
320-
events.push_back(display_string);
315+
llvm::raw_string_ostream os(display_string);
316+
317+
os << annotation.variable_name;
318+
os << " = ";
319+
os << (annotation.location_description == VariableAnnotator::kUndefLocation
320+
? VariableAnnotator::kUndefLocationFormatted
321+
: annotation.location_description);
322+
os.flush();
323+
324+
events.push_back(std::move(display_string));
321325
}
322326

323327
return events;
@@ -423,11 +427,11 @@ VariableAnnotator::AnnotateStructured(Instruction &inst, Target &target,
423427
if (const char *type_str = type->GetName().AsCString())
424428
type_name = type_str;
425429

426-
current_vars.try_emplace(v->GetID(),
427-
VariableAnnotation{std::string(name), std::string(loc),
428-
true, entry.expr->GetRegisterKind(),
429-
entry.file_range, decl_file,
430-
decl_line, type_name});
430+
current_vars.try_emplace(
431+
v->GetID(),
432+
VariableAnnotation{std::string(name), std::string(loc), true,
433+
entry.expr->GetRegisterKind(), entry.file_range,
434+
decl_file, decl_line, type_name});
431435
}
432436

433437
// Diff m_live_vars → current_vars.

0 commit comments

Comments
 (0)