1313#include " Protocol/ProtocolUtils.h"
1414#include " lldb/API/SBAddress.h"
1515#include " lldb/API/SBCompileUnit.h"
16- #include " lldb/API/SBDebugger.h"
1716#include " lldb/API/SBDeclaration.h"
1817#include " lldb/API/SBEnvironment.h"
1918#include " lldb/API/SBError.h"
@@ -492,99 +491,6 @@ CreateExceptionBreakpointFilter(const ExceptionBreakpoint &bp) {
492491 return filter;
493492}
494493
495- static std::string GetLoadAddressString (const lldb::addr_t addr) {
496- std::string result;
497- llvm::raw_string_ostream os (result);
498- os << llvm::format_hex (addr, 18 );
499- return result;
500- }
501-
502- static bool ShouldDisplayAssemblySource (
503- lldb::SBAddress address,
504- lldb::StopDisassemblyType stop_disassembly_display) {
505- if (stop_disassembly_display == lldb::eStopDisassemblyTypeNever)
506- return false ;
507-
508- if (stop_disassembly_display == lldb::eStopDisassemblyTypeAlways)
509- return true ;
510-
511- // A line entry of 0 indicates the line is compiler generated i.e. no source
512- // file is associated with the frame.
513- auto line_entry = address.GetLineEntry ();
514- auto file_spec = line_entry.GetFileSpec ();
515- if (!file_spec.IsValid () || line_entry.GetLine () == 0 ||
516- line_entry.GetLine () == LLDB_INVALID_LINE_NUMBER)
517- return true ;
518-
519- if (stop_disassembly_display == lldb::eStopDisassemblyTypeNoSource &&
520- !file_spec.Exists ()) {
521- return true ;
522- }
523-
524- return false ;
525- }
526-
527- static protocol::Source CreateAssemblySource (const lldb::SBTarget &target,
528- lldb::SBAddress address) {
529- protocol::Source source;
530-
531- auto symbol = address.GetSymbol ();
532- std::string name;
533- if (symbol.IsValid ()) {
534- source.sourceReference = symbol.GetStartAddress ().GetLoadAddress (target);
535- name = symbol.GetName ();
536- } else {
537- const auto load_addr = address.GetLoadAddress (target);
538- source.sourceReference = load_addr;
539- name = GetLoadAddressString (load_addr);
540- }
541-
542- lldb::SBModule module = address.GetModule ();
543- if (module .IsValid ()) {
544- lldb::SBFileSpec file_spec = module .GetFileSpec ();
545- if (file_spec.IsValid ()) {
546- std::string path = GetSBFileSpecPath (file_spec);
547- if (!path.empty ())
548- source.path = path + ' `' + name;
549- }
550- }
551-
552- source.name = std::move (name);
553-
554- // Mark the source as deemphasized since users will only be able to view
555- // assembly for these frames.
556- source.presentationHint =
557- protocol::Source::PresentationHint::eSourcePresentationHintDeemphasize;
558-
559- return source;
560- }
561-
562- protocol::Source CreateSource (const lldb::SBFileSpec &file) {
563- protocol::Source source;
564- if (file.IsValid ()) {
565- const char *name = file.GetFilename ();
566- if (name)
567- source.name = name;
568- char path[PATH_MAX] = " " ;
569- if (file.GetPath (path, sizeof (path)) &&
570- lldb::SBFileSpec::ResolvePath (path, path, PATH_MAX))
571- source.path = path;
572- }
573- return source;
574- }
575-
576- protocol::Source CreateSource (lldb::SBAddress address, lldb::SBTarget &target) {
577- lldb::SBDebugger debugger = target.GetDebugger ();
578- lldb::StopDisassemblyType stop_disassembly_display =
579- GetStopDisassemblyDisplay (debugger);
580- if (!ShouldDisplayAssemblySource (address, stop_disassembly_display)) {
581- lldb::SBLineEntry line_entry = GetLineEntryForAddress (target, address);
582- return CreateSource (line_entry.GetFileSpec ());
583- }
584-
585- return CreateAssemblySource (target, address);
586- }
587-
588494// "StackFrame": {
589495// "type": "object",
590496// "description": "A Stackframe contains the source location.",
@@ -666,7 +572,7 @@ llvm::json::Value CreateStackFrame(lldb::SBFrame &frame,
666572 if (frame_name.empty ()) {
667573 // If the function name is unavailable, display the pc address as a 16-digit
668574 // hex string, e.g. "0x0000000000012345"
669- frame_name = GetLoadAddressString (frame.GetPC ());
575+ frame_name = protocol:: GetLoadAddressString (frame.GetPC ());
670576 }
671577
672578 // We only include `[opt]` if a custom frame format is not specified.
@@ -676,7 +582,7 @@ llvm::json::Value CreateStackFrame(lldb::SBFrame &frame,
676582 EmplaceSafeString (object, " name" , frame_name);
677583
678584 auto target = frame.GetThread ().GetProcess ().GetTarget ();
679- auto source = CreateSource (frame.GetPCAddress (), target);
585+ auto source = protocol:: CreateSource (frame.GetPCAddress (), target);
680586 if (!IsAssemblySource (source)) {
681587 // This is a normal source with a valid line entry.
682588 auto line_entry = frame.GetLineEntry ();
0 commit comments