[lldb] [llvm] Stateful variable-location annotations in Disassembler::PrintInstructions() (follow-up to #147460) (PR #152887)
Abdullah Mohammad Amin via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 11 16:55:40 PDT 2025
================
@@ -376,6 +380,143 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
}
}
+ // Add rich variable location annotations to the disassembly output.
+ //
+ // For each instruction, this block attempts to resolve in-scope variables
+ // and determine if the current PC falls within their
+ // DWARF location entry. If so, it prints a simplified annotation using the
+ // variable name and its resolved location (e.g., "var = reg; " ).
+ //
+ // Annotations are only included if the variable has a valid DWARF location
+ // entry, and the location string is non-empty after filtering. Decoding
+ // errors and DWARF opcodes are intentionally omitted to keep the output
+ // concise and user-friendly.
+ //
+ // The goal is to give users helpful live variable hints alongside the
+ // disassembled instruction stream, similar to how debug information
+ // enhances source-level debugging.
+
+ struct VarState {
+ std::string name; // display name
+ std::string last_loc; // last printed location (empty means <undef>)
+ bool seen_this_inst = false;
+ };
+
+ // Track live variables across instructions (keyed by stable LLDB user_id_t)
+ std::unordered_map<lldb::user_id_t, VarState> live_vars;
+
+ // Stateful annotator: updates live_vars and returns only what should be
+ // printed for THIS instruction.
+ auto annotate_variables = [&](Instruction &inst) -> std::vector<std::string> {
+ std::vector<std::string> events;
+
+ StackFrame *frame = exe_ctx.GetFramePtr();
+ TargetSP target_sp = exe_ctx.GetTargetSP();
+ ProcessSP process_sp = exe_ctx.GetProcessSP();
+ if (!frame || !target_sp || !process_sp)
+ return events;
+
+ // Reset "seen" flags for this instruction
----------------
UltimateForce21 wrote:
Sorry, I keep forgetting to do this, thank you for all the reminders. Updating them now.
https://github.com/llvm/llvm-project/pull/152887
More information about the llvm-commits
mailing list