[Lldb-commits] [lldb] [lldb-dap] Reuse source object logics (PR #141426)

Ely Ronnen via lldb-commits lldb-commits at lists.llvm.org
Tue May 27 23:48:02 PDT 2025


================
@@ -558,28 +558,38 @@ protocol::Source CreateAssemblySource(const lldb::SBTarget &target,
   return source;
 }
 
-bool ShouldDisplayAssemblySource(
-    const lldb::SBLineEntry &line_entry,
-    lldb::StopDisassemblyType stop_disassembly_display) {
-  if (stop_disassembly_display == lldb::eStopDisassemblyTypeNever)
-    return false;
-
-  if (stop_disassembly_display == lldb::eStopDisassemblyTypeAlways)
-    return true;
-
-  // A line entry of 0 indicates the line is compiler generated i.e. no source
-  // file is associated with the frame.
-  auto file_spec = line_entry.GetFileSpec();
-  if (!file_spec.IsValid() || line_entry.GetLine() == 0 ||
-      line_entry.GetLine() == LLDB_INVALID_LINE_NUMBER)
-    return true;
+protocol::Source CreateSource(const lldb::SBFileSpec &file) {
+  protocol::Source source;
+  if (file.IsValid()) {
+    const char *name = file.GetFilename();
+    if (name)
+      source.name = name;
+    char path[PATH_MAX] = "";
+    if (file.GetPath(path, sizeof(path)) &&
+        lldb::SBFileSpec::ResolvePath(path, path, PATH_MAX))
+      source.path = path;
+  }
+  return source;
+}
 
-  if (stop_disassembly_display == lldb::eStopDisassemblyTypeNoSource &&
-      !file_spec.Exists()) {
-    return true;
+protocol::Source CreateSource(lldb::SBAddress address, lldb::SBTarget &target) {
+  lldb::SBDebugger debugger = target.GetDebugger();
+  lldb::StopDisassemblyType stop_disassembly_display =
+      GetStopDisassemblyDisplay(debugger);
+  if (!ShouldDisplayAssemblySource(address, stop_disassembly_display)) {
+    lldb::SBLineEntry line_entry = GetLineEntryForAddress(target, address);
+    return CreateSource(line_entry.GetFileSpec());
   }
 
-  return false;
+  return CreateAssemblySource(target, address);
+}
+
+protocol::Source CreateSource(llvm::StringRef source_path) {
+  protocol::Source source;
+  llvm::StringRef name = llvm::sys::path::filename(source_path);
+  source.name = name;
+  source.path = source_path;
+  return source;
----------------
eronnen wrote:

:100: 

https://github.com/llvm/llvm-project/pull/141426


More information about the lldb-commits mailing list