Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lldb/include/lldb/Core/Disassembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -581,13 +581,13 @@ class VariableAnnotator {
};

// Live state from the previous instruction, keyed by Variable::GetID().
llvm::DenseMap<lldb::user_id_t, VarState> Live_;
llvm::DenseMap<lldb::user_id_t, VarState> m_live_vars;

public:
/// Compute annotation strings for a single instruction and update `Live_`.
/// Returns only the events that should be printed *at this instruction*.
std::vector<std::string> annotate(Instruction &inst, Target &target,
const lldb::ModuleSP &module_sp);
/// Compute annotation strings for a single instruction and update
/// `m_live_vars`. Returns only the events that should be printed *at this
/// instruction*.
std::vector<std::string> Annotate(Instruction &inst);
};

} // namespace lldb_private
Expand Down
44 changes: 22 additions & 22 deletions lldb/source/Core/Disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,16 @@ bool Disassembler::ElideMixedSourceAndDisassemblyLine(
// The goal is to give users helpful live variable hints alongside the
// disassembled instruction stream, similar to how debug information
// enhances source-level debugging.
std::vector<std::string>
VariableAnnotator::annotate(Instruction &inst, Target &target,
const lldb::ModuleSP &module_sp) {
std::vector<std::string> VariableAnnotator::Annotate(Instruction &inst) {
std::vector<std::string> events;

auto module_sp = inst.GetAddress().GetModule();

// If we lost module context, everything becomes <undef>.
if (!module_sp) {
for (const auto &KV : Live_)
for (const auto &KV : m_live_vars)
events.emplace_back(llvm::formatv("{0} = <undef>", KV.second.name).str());
Live_.clear();
m_live_vars.clear();
return events;
}

Expand All @@ -319,13 +319,13 @@ VariableAnnotator::annotate(Instruction &inst, Target &target,
if (!module_sp->ResolveSymbolContextForAddress(iaddr, mask, sc) ||
!sc.function) {
// No function context: everything dies here.
for (const auto &KV : Live_)
for (const auto &KV : m_live_vars)
events.emplace_back(llvm::formatv("{0} = <undef>", KV.second.name).str());
Live_.clear();
m_live_vars.clear();
return events;
}

// Collect in-scope variables for this instruction into Current.
// Collect in-scope variables for this instruction into current_vars.
VariableList var_list;
// Innermost block containing iaddr.
if (Block *B = sc.block) {
Expand All @@ -341,15 +341,15 @@ VariableAnnotator::annotate(Instruction &inst, Target &target,
const lldb::addr_t func_file = sc.function->GetAddress().GetFileAddress();

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

llvm::DIDumpOptions opts;
opts.ShowAddresses = false;
// Prefer "register-only" output when we have an ABI.
opts.PrintRegisterOnly = static_cast<bool>(abi_sp);

llvm::DenseMap<lldb::user_id_t, VarState> Current;
llvm::DenseMap<lldb::user_id_t, VarState> current_vars;

for (size_t i = 0, e = var_list.GetSize(); i != e; ++i) {
lldb::VariableSP v = var_list.GetVariableAtIndex(i);
Expand All @@ -376,16 +376,16 @@ VariableAnnotator::annotate(Instruction &inst, Target &target,
if (loc.empty())
continue;

Current.try_emplace(v->GetID(),
VarState{std::string(name), std::string(loc)});
current_vars.try_emplace(v->GetID(),
VarState{std::string(name), std::string(loc)});
}

// Diff Live_Current.
// Diff m_live_varscurrent_vars.

// 1) Starts/changes: iterate Current and compare with Live_.
for (const auto &KV : Current) {
auto it = Live_.find(KV.first);
if (it == Live_.end()) {
// 1) Starts/changes: iterate current_vars and compare with m_live_vars.
for (const auto &KV : current_vars) {
auto it = m_live_vars.find(KV.first);
if (it == m_live_vars.end()) {
// Newly live.
events.emplace_back(
llvm::formatv("{0} = {1}", KV.second.name, KV.second.last_loc).str());
Expand All @@ -396,14 +396,14 @@ VariableAnnotator::annotate(Instruction &inst, Target &target,
}
}

// 2) Ends: anything that was live but is not in Current becomes <undef>.
for (const auto &KV : Live_) {
if (!Current.count(KV.first))
// 2) Ends: anything that was live but is not in current_vars becomes <undef>.
for (const auto &KV : m_live_vars) {
if (!current_vars.count(KV.first))
events.emplace_back(llvm::formatv("{0} = <undef>", KV.second.name).str());
}

// Commit new state.
Live_ = std::move(Current);
m_live_vars = std::move(current_vars);
return events;
}

Expand Down Expand Up @@ -676,7 +676,7 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
address_text_size);

if ((options & eOptionVariableAnnotations) && target_sp) {
auto annotations = annot.annotate(*inst, *target_sp, module_sp);
auto annotations = annot.Annotate(*inst);
if (!annotations.empty()) {
const size_t annotation_column = 100;
inst_line.FillLastLineToColumn(annotation_column, ' ');
Expand Down