@@ -490,6 +490,13 @@ CreateExceptionBreakpointFilter(const ExceptionBreakpoint &bp) {
490490 return filter;
491491}
492492
493+ static std::string GetLoadAddressString (const lldb::addr_t addr) {
494+ std::string result;
495+ llvm::raw_string_ostream os (result);
496+ os << llvm::format_hex (addr, 18 );
497+ return result;
498+ }
499+
493500protocol::Source CreateSource (const lldb::SBFileSpec &file) {
494501 protocol::Source source;
495502 if (file.IsValid ()) {
@@ -516,6 +523,43 @@ protocol::Source CreateSource(llvm::StringRef source_path) {
516523 return source;
517524}
518525
526+ protocol::Source CreateAssemblySource (const lldb::SBTarget &target,
527+ lldb::SBAddress &address) {
528+ protocol::Source source;
529+
530+ auto symbol = address.GetSymbol ();
531+ std::string name;
532+ if (symbol.IsValid ()) {
533+ source.sourceReference = symbol.GetStartAddress ().GetLoadAddress (target);
534+ name = symbol.GetName ();
535+ } else {
536+ const auto load_addr = address.GetLoadAddress (target);
537+ source.sourceReference = load_addr;
538+ name = GetLoadAddressString (load_addr);
539+ }
540+
541+ lldb::SBModule module = address.GetModule ();
542+ if (module .IsValid ()) {
543+ lldb::SBFileSpec file_spec = module .GetFileSpec ();
544+ if (file_spec.IsValid ()) {
545+ lldb::SBStream module_path;
546+ if (file_spec.GetPath (module_path)) {
547+ std::string path = module_path.GetData ();
548+ source.path = path + ' `' + name;
549+ }
550+ }
551+ }
552+
553+ source.name = std::move (name);
554+
555+ // Mark the source as deemphasized since users will only be able to view
556+ // assembly for these frames.
557+ source.presentationHint =
558+ protocol::Source::PresentationHint::eSourcePresentationHintDeemphasize;
559+
560+ return source;
561+ }
562+
519563bool ShouldDisplayAssemblySource (
520564 const lldb::SBLineEntry &line_entry,
521565 lldb::StopDisassemblyType stop_disassembly_display) {
@@ -619,12 +663,10 @@ CreateStackFrame(lldb::SBFrame &frame, lldb::SBFormat &format,
619663 frame_name = name;
620664 }
621665
622- if (frame_name.empty ()) {
666+ if (frame_name.empty ())
623667 // If the function name is unavailable, display the pc address as a 16-digit
624668 // hex string, e.g. "0x0000000000012345"
625- llvm::raw_string_ostream os (frame_name);
626- os << llvm::format_hex (frame.GetPC (), 18 );
627- }
669+ frame_name = GetLoadAddressString (frame.GetPC ());
628670
629671 // We only include `[opt]` if a custom frame format is not specified.
630672 if (!format && frame.GetFunction ().GetIsOptimized ())
@@ -641,17 +683,10 @@ CreateStackFrame(lldb::SBFrame &frame, lldb::SBFormat &format,
641683 } else if (frame.GetSymbol ().IsValid ()) {
642684 // If no source is associated with the frame, use the DAPFrameID to track
643685 // the 'source' and generate assembly.
644- llvm::json::Object source;
645- EmplaceSafeString (source, " name" , frame_name);
646- char buf[PATH_MAX] = {0 };
647- size_t size = frame.GetModule ().GetFileSpec ().GetPath (buf, PATH_MAX);
648- EmplaceSafeString (source, " path" ,
649- std::string (buf, size) + ' `' + frame_name);
650- source.try_emplace (" sourceReference" , MakeDAPFrameID (frame));
651- // Mark the source as deemphasized since users will only be able to view
652- // assembly for these frames.
653- EmplaceSafeString (source, " presentationHint" , " deemphasize" );
654- object.try_emplace (" source" , std::move (source));
686+ auto frame_address = frame.GetPCAddress ();
687+ object.try_emplace (" source" , CreateAssemblySource (
688+ frame.GetThread ().GetProcess ().GetTarget (),
689+ frame_address));
655690
656691 // Calculate the line of the current PC from the start of the current
657692 // symbol.
@@ -665,12 +700,10 @@ CreateStackFrame(lldb::SBFrame &frame, lldb::SBFormat &format,
665700 object.try_emplace (" column" , 1 );
666701 } else {
667702 // No valid line entry or symbol.
668- llvm::json::Object source;
669- EmplaceSafeString (source, " name" , frame_name);
670- source.try_emplace (" sourceReference" , MakeDAPFrameID (frame));
671- EmplaceSafeString (source, " presentationHint" , " deemphasize" );
672- object.try_emplace (" source" , std::move (source));
673-
703+ auto frame_address = frame.GetPCAddress ();
704+ object.try_emplace (" source" , CreateAssemblySource (
705+ frame.GetThread ().GetProcess ().GetTarget (),
706+ frame_address));
674707 object.try_emplace (" line" , 1 );
675708 object.try_emplace (" column" , 1 );
676709 }
0 commit comments