@@ -497,34 +497,33 @@ static std::string GetLoadAddressString(const lldb::addr_t addr) {
497
497
return result;
498
498
}
499
499
500
- protocol::Source CreateSource (const lldb::SBFileSpec &file) {
501
- protocol::Source source;
502
- if (file.IsValid ()) {
503
- const char *name = file.GetFilename ();
504
- if (name)
505
- source.name = name;
506
- char path[PATH_MAX] = " " ;
507
- if (file.GetPath (path, sizeof (path)) &&
508
- lldb::SBFileSpec::ResolvePath (path, path, PATH_MAX))
509
- source.path = path;
510
- }
511
- return source;
512
- }
500
+ static bool ShouldDisplayAssemblySource (
501
+ lldb::SBAddress address,
502
+ lldb::StopDisassemblyType stop_disassembly_display) {
503
+ if (stop_disassembly_display == lldb::eStopDisassemblyTypeNever)
504
+ return false ;
513
505
514
- protocol::Source CreateSource (const lldb::SBLineEntry &line_entry) {
515
- return CreateSource (line_entry.GetFileSpec ());
516
- }
506
+ if (stop_disassembly_display == lldb::eStopDisassemblyTypeAlways)
507
+ return true ;
517
508
518
- protocol::Source CreateSource (llvm::StringRef source_path) {
519
- protocol::Source source;
520
- llvm::StringRef name = llvm::sys::path::filename (source_path);
521
- source.name = name;
522
- source.path = source_path;
523
- return source;
509
+ // A line entry of 0 indicates the line is compiler generated i.e. no source
510
+ // file is associated with the frame.
511
+ auto line_entry = address.GetLineEntry ();
512
+ auto file_spec = line_entry.GetFileSpec ();
513
+ if (!file_spec.IsValid () || line_entry.GetLine () == 0 ||
514
+ line_entry.GetLine () == LLDB_INVALID_LINE_NUMBER)
515
+ return true ;
516
+
517
+ if (stop_disassembly_display == lldb::eStopDisassemblyTypeNoSource &&
518
+ !file_spec.Exists ()) {
519
+ return true ;
520
+ }
521
+
522
+ return false ;
524
523
}
525
524
526
- protocol::Source CreateAssemblySource (const lldb::SBTarget &target,
527
- lldb::SBAddress & address) {
525
+ static protocol::Source CreateAssemblySource (const lldb::SBTarget &target,
526
+ lldb::SBAddress address) {
528
527
protocol::Source source;
529
528
530
529
auto symbol = address.GetSymbol ();
@@ -558,28 +557,36 @@ protocol::Source CreateAssemblySource(const lldb::SBTarget &target,
558
557
return source;
559
558
}
560
559
561
- bool ShouldDisplayAssemblySource (
562
- const lldb::SBLineEntry &line_entry,
563
- lldb::StopDisassemblyType stop_disassembly_display) {
564
- if (stop_disassembly_display == lldb::eStopDisassemblyTypeNever)
565
- return false ;
566
-
567
- if (stop_disassembly_display == lldb::eStopDisassemblyTypeAlways)
568
- return true ;
560
+ protocol::Source CreateSource (const lldb::SBFileSpec &file) {
561
+ protocol::Source source;
562
+ if (file.IsValid ()) {
563
+ const char *name = file.GetFilename ();
564
+ if (name)
565
+ source.name = name;
566
+ char path[PATH_MAX] = " " ;
567
+ if (file.GetPath (path, sizeof (path)) &&
568
+ lldb::SBFileSpec::ResolvePath (path, path, PATH_MAX))
569
+ source.path = path;
570
+ }
571
+ return source;
572
+ }
569
573
570
- // A line entry of 0 indicates the line is compiler generated i.e. no source
571
- // file is associated with the frame.
572
- auto file_spec = line_entry. GetFileSpec ();
573
- if (!file_spec. IsValid () || line_entry. GetLine () == 0 ||
574
- line_entry. GetLine () == LLDB_INVALID_LINE_NUMBER )
575
- return true ;
574
+ protocol::Source CreateSource (lldb::SBAddress address,
575
+ lldb::SBDebugger &debugger) {
576
+ lldb::StopDisassemblyType stop_disassembly_display =
577
+ GetStopDisassemblyDisplay (debugger);
578
+ if (! ShouldDisplayAssemblySource (address, stop_disassembly_display) )
579
+ return CreateSource (address. GetLineEntry (). GetFileSpec ()) ;
576
580
577
- if (stop_disassembly_display == lldb::eStopDisassemblyTypeNoSource &&
578
- !file_spec.Exists ()) {
579
- return true ;
580
- }
581
+ return CreateAssemblySource (debugger.GetSelectedTarget (), address);
582
+ }
581
583
582
- return false ;
584
+ protocol::Source CreateSource (llvm::StringRef source_path) {
585
+ protocol::Source source;
586
+ llvm::StringRef name = llvm::sys::path::filename (source_path);
587
+ source.name = name;
588
+ source.path = source_path;
589
+ return source;
583
590
}
584
591
585
592
// "StackFrame": {
@@ -643,9 +650,8 @@ bool ShouldDisplayAssemblySource(
643
650
// },
644
651
// "required": [ "id", "name", "line", "column" ]
645
652
// }
646
- llvm::json::Value
647
- CreateStackFrame (lldb::SBFrame &frame, lldb::SBFormat &format,
648
- lldb::StopDisassemblyType stop_disassembly_display) {
653
+ llvm::json::Value CreateStackFrame (lldb::SBFrame &frame, lldb::SBFormat &format,
654
+ lldb::SBDebugger &debugger) {
649
655
llvm::json::Object object;
650
656
int64_t frame_id = MakeDAPFrameID (frame);
651
657
object.try_emplace (" id" , frame_id);
@@ -673,22 +679,17 @@ CreateStackFrame(lldb::SBFrame &frame, lldb::SBFormat &format,
673
679
674
680
EmplaceSafeString (object, " name" , frame_name);
675
681
676
- auto line_entry = frame.GetLineEntry ();
677
- if (!ShouldDisplayAssemblySource (line_entry, stop_disassembly_display)) {
678
- object.try_emplace (" source" , CreateSource (line_entry));
682
+ auto source = CreateSource (frame.GetPCAddress (), debugger);
683
+ if (!source.IsAssemblySource ()) {
684
+ // This is a normal source with valid line entry.
685
+ auto line_entry = frame.GetLineEntry ();
679
686
object.try_emplace (" line" , line_entry.GetLine ());
680
687
auto column = line_entry.GetColumn ();
681
688
object.try_emplace (" column" , column);
682
689
} else if (frame.GetSymbol ().IsValid ()) {
683
- // If no source is associated with the frame, use the DAPFrameID to track
684
- // the 'source' and generate assembly.
685
- auto frame_address = frame.GetPCAddress ();
686
- object.try_emplace (" source" , CreateAssemblySource (
687
- frame.GetThread ().GetProcess ().GetTarget (),
688
- frame_address));
689
-
690
- // Calculate the line of the current PC from the start of the current
691
- // symbol.
690
+ // This is a source where the disassembly is used, but there is a valid
691
+ // symbol. Calculate the line of the current PC from the start of the
692
+ // current symbol.
692
693
lldb::SBTarget target = frame.GetThread ().GetProcess ().GetTarget ();
693
694
lldb::SBInstructionList inst_list = target.ReadInstructions (
694
695
frame.GetSymbol ().GetStartAddress (), frame.GetPCAddress (), nullptr );
@@ -699,14 +700,12 @@ CreateStackFrame(lldb::SBFrame &frame, lldb::SBFormat &format,
699
700
object.try_emplace (" column" , 1 );
700
701
} else {
701
702
// No valid line entry or symbol.
702
- auto frame_address = frame.GetPCAddress ();
703
- object.try_emplace (" source" , CreateAssemblySource (
704
- frame.GetThread ().GetProcess ().GetTarget (),
705
- frame_address));
706
703
object.try_emplace (" line" , 1 );
707
704
object.try_emplace (" column" , 1 );
708
705
}
709
706
707
+ object.try_emplace (" source" , std::move (source));
708
+
710
709
const auto pc = frame.GetPC ();
711
710
if (pc != LLDB_INVALID_ADDRESS) {
712
711
std::string formatted_addr = " 0x" + llvm::utohexstr (pc);
0 commit comments