@@ -397,15 +397,16 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
397
397
// enhances source-level debugging.
398
398
399
399
struct VarState {
400
- std::string name; // display name
401
- std::string last_loc; // last printed location (empty means <undef>)
400
+ std::string name; // display name
401
+ std::string last_loc; // last printed location (empty means <undef>)
402
402
bool seen_this_inst = false ;
403
403
};
404
404
405
405
// Track live variables across instructions (keyed by stable LLDB user_id_t)
406
406
std::unordered_map<lldb::user_id_t , VarState> live_vars;
407
407
408
- // Stateful annotator: updates live_vars and returns only what should be printed for THIS instruction.
408
+ // Stateful annotator: updates live_vars and returns only what should be
409
+ // printed for THIS instruction.
409
410
auto annotate_variables = [&](Instruction &inst) -> std::vector<std::string> {
410
411
std::vector<std::string> events;
411
412
@@ -420,16 +421,18 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
420
421
kv.second .seen_this_inst = false ;
421
422
422
423
addr_t current_pc = inst.GetAddress ().GetLoadAddress (target_sp.get ());
423
- addr_t original_pc = frame->GetFrameCodeAddress ().GetLoadAddress (target_sp.get ());
424
+ addr_t original_pc =
425
+ frame->GetFrameCodeAddress ().GetLoadAddress (target_sp.get ());
424
426
425
- // We temporarily move the frame PC so variable locations resolve at this inst
427
+ // We temporarily move the frame PC so variable locations resolve at this
428
+ // inst
426
429
if (!frame->ChangePC (current_pc))
427
430
return events;
428
431
429
432
VariableListSP var_list_sp = frame->GetInScopeVariableList (true );
430
433
if (!var_list_sp) {
431
434
// No variables in scope: everything previously live becomes <undef>
432
- for (auto it = live_vars.begin (); it != live_vars.end (); ) {
435
+ for (auto it = live_vars.begin (); it != live_vars.end ();) {
433
436
events.push_back (llvm::formatv (" {0} = <undef>" , it->second .name ).str ());
434
437
it = live_vars.erase (it);
435
438
}
@@ -438,16 +441,16 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
438
441
}
439
442
440
443
SymbolContext sc = frame->GetSymbolContext (eSymbolContextFunction);
441
- addr_t func_load_addr = sc. function
442
- ? sc.function ->GetAddress ().GetLoadAddress (target_sp.get ())
443
- : LLDB_INVALID_ADDRESS;
444
+ addr_t func_load_addr =
445
+ sc. function ? sc.function ->GetAddress ().GetLoadAddress (target_sp.get ())
446
+ : LLDB_INVALID_ADDRESS;
444
447
445
448
// Walk all in-scope variables and try to resolve a location
446
449
for (const VariableSP &var_sp : *var_list_sp) {
447
450
if (!var_sp)
448
451
continue ;
449
452
450
- const auto var_id = var_sp->GetID (); // lldb::user_id_t – stable key
453
+ const auto var_id = var_sp->GetID (); // lldb::user_id_t – stable key
451
454
const char *name_cstr = var_sp->GetName ().AsCString ();
452
455
llvm::StringRef name = name_cstr ? name_cstr : " <anon>" ;
453
456
@@ -456,7 +459,8 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
456
459
continue ;
457
460
458
461
// Try to get the expression entry for this PC
459
- auto entry_or_err = expr_list.GetExpressionEntryAtAddress (func_load_addr, current_pc);
462
+ auto entry_or_err =
463
+ expr_list.GetExpressionEntryAtAddress (func_load_addr, current_pc);
460
464
if (!entry_or_err)
461
465
continue ;
462
466
@@ -484,19 +488,22 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
484
488
auto it = live_vars.find (var_id);
485
489
if (it == live_vars.end ()) {
486
490
// New var → print
487
- live_vars.emplace (var_id, VarState{std::string (name), loc_clean.str (), true });
491
+ live_vars.emplace (var_id,
492
+ VarState{std::string (name), loc_clean.str (), true });
488
493
events.push_back (llvm::formatv (" {0} = {1}" , name, loc_clean).str ());
489
494
} else {
490
495
it->second .seen_this_inst = true ;
491
496
if (it->second .last_loc != loc_clean) {
492
497
it->second .last_loc = loc_clean.str ();
493
- events.push_back (llvm::formatv (" {0} = {1}" , it->second .name , loc_clean).str ());
498
+ events.push_back (
499
+ llvm::formatv (" {0} = {1}" , it->second .name , loc_clean).str ());
494
500
}
495
501
}
496
502
}
497
503
498
- // Anything previously live that we didn't see a location for at this inst is now <undef>
499
- for (auto it = live_vars.begin (); it != live_vars.end (); ) {
504
+ // Anything previously live that we didn't see a location for at this inst
505
+ // is now <undef>
506
+ for (auto it = live_vars.begin (); it != live_vars.end ();) {
500
507
if (!it->second .seen_this_inst ) {
501
508
events.push_back (llvm::formatv (" {0} = <undef>" , it->second .name ).str ());
502
509
it = live_vars.erase (it);
@@ -678,10 +685,10 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
678
685
StreamString inst_line;
679
686
680
687
inst->Dump (&inst_line, max_opcode_byte_size, true , show_bytes,
681
- show_control_flow_kind, &exe_ctx, &sc, &prev_sc, nullptr ,
682
- address_text_size);
688
+ show_control_flow_kind, &exe_ctx, &sc, &prev_sc, nullptr ,
689
+ address_text_size);
683
690
684
- if (enable_rich_annotations){
691
+ if (enable_rich_annotations) {
685
692
std::vector<std::string> annotations = annotate_variables (*inst);
686
693
if (!annotations.empty ()) {
687
694
const size_t annotation_column = 100 ;
@@ -694,7 +701,6 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
694
701
strm.PutCString (inst_line.GetString ());
695
702
strm.EOL ();
696
703
697
-
698
704
} else {
699
705
break ;
700
706
}
0 commit comments