1010#include " DAP.h"
1111#include " ExceptionBreakpoint.h"
1212#include " LLDBUtils.h"
13+ #include " ProtocolUtils.h"
1314#include " lldb/API/SBAddress.h"
1415#include " lldb/API/SBCompileUnit.h"
1516#include " lldb/API/SBDeclaration.h"
@@ -490,98 +491,6 @@ CreateExceptionBreakpointFilter(const ExceptionBreakpoint &bp) {
490491 return filter;
491492}
492493
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-
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- }
513-
514- protocol::Source CreateSource (const lldb::SBLineEntry &line_entry) {
515- return CreateSource (line_entry.GetFileSpec ());
516- }
517-
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;
524- }
525-
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- std::string path = GetSBFileSpecPath (file_spec);
546- if (!path.empty ())
547- source.path = path + ' `' + name;
548- }
549- }
550-
551- source.name = std::move (name);
552-
553- // Mark the source as deemphasized since users will only be able to view
554- // assembly for these frames.
555- source.presentationHint =
556- protocol::Source::PresentationHint::eSourcePresentationHintDeemphasize;
557-
558- return source;
559- }
560-
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 ;
569-
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 ;
576-
577- if (stop_disassembly_display == lldb::eStopDisassemblyTypeNoSource &&
578- !file_spec.Exists ()) {
579- return true ;
580- }
581-
582- return false ;
583- }
584-
585494// "StackFrame": {
586495// "type": "object",
587496// "description": "A Stackframe contains the source location.",
@@ -643,9 +552,8 @@ bool ShouldDisplayAssemblySource(
643552// },
644553// "required": [ "id", "name", "line", "column" ]
645554// }
646- llvm::json::Value
647- CreateStackFrame (lldb::SBFrame &frame, lldb::SBFormat &format,
648- lldb::StopDisassemblyType stop_disassembly_display) {
555+ llvm::json::Value CreateStackFrame (lldb::SBFrame &frame,
556+ lldb::SBFormat &format) {
649557 llvm::json::Object object;
650558 int64_t frame_id = MakeDAPFrameID (frame);
651559 object.try_emplace (" id" , frame_id);
@@ -673,22 +581,18 @@ CreateStackFrame(lldb::SBFrame &frame, lldb::SBFormat &format,
673581
674582 EmplaceSafeString (object, " name" , frame_name);
675583
676- auto line_entry = frame.GetLineEntry ();
677- if (!ShouldDisplayAssemblySource (line_entry, stop_disassembly_display)) {
678- object.try_emplace (" source" , CreateSource (line_entry));
584+ auto target = frame.GetThread ().GetProcess ().GetTarget ();
585+ auto source = CreateSource (frame.GetPCAddress (), target);
586+ if (!IsAssemblySource (source)) {
587+ // This is a normal source with a valid line entry.
588+ auto line_entry = frame.GetLineEntry ();
679589 object.try_emplace (" line" , line_entry.GetLine ());
680590 auto column = line_entry.GetColumn ();
681591 object.try_emplace (" column" , column);
682592 } 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.
593+ // This is a source where the disassembly is used, but there is a valid
594+ // symbol. Calculate the line of the current PC from the start of the
595+ // current symbol.
692596 lldb::SBTarget target = frame.GetThread ().GetProcess ().GetTarget ();
693597 lldb::SBInstructionList inst_list = target.ReadInstructions (
694598 frame.GetSymbol ().GetStartAddress (), frame.GetPCAddress (), nullptr );
@@ -699,14 +603,12 @@ CreateStackFrame(lldb::SBFrame &frame, lldb::SBFormat &format,
699603 object.try_emplace (" column" , 1 );
700604 } else {
701605 // 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));
706606 object.try_emplace (" line" , 1 );
707607 object.try_emplace (" column" , 1 );
708608 }
709609
610+ object.try_emplace (" source" , std::move (source));
611+
710612 const auto pc = frame.GetPC ();
711613 if (pc != LLDB_INVALID_ADDRESS) {
712614 std::string formatted_addr = " 0x" + llvm::utohexstr (pc);
0 commit comments