[Lldb-commits] [lldb] [lldb] Teach LocateExecutableSymbolFile to look into LOCALBASE on FreeBSD (PR #81355)

Gleb Popov via lldb-commits lldb-commits at lists.llvm.org
Sat Feb 10 03:20:18 PST 2024


https://github.com/arrowd created https://github.com/llvm/llvm-project/pull/81355

Relevant change on the FreeBSD side: https://reviews.freebsd.org/D43515

@emaste @brooksdavis 

>From 3c49dd6cd794facda5b17d66f9f7b4d62cb1b0fc Mon Sep 17 00:00:00 2001
From: Gleb Popov <6yearold at gmail.com>
Date: Sat, 10 Feb 2024 14:15:49 +0300
Subject: [PATCH] [lldb] Teach LocateExecutableSymbolFile to look into
 LOCALBASE on FreeBSD.

Relevant change on the FreeBSD side: https://reviews.freebsd.org/D43515
---
 lldb/source/Symbol/LocateSymbolFile.cpp | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/lldb/source/Symbol/LocateSymbolFile.cpp b/lldb/source/Symbol/LocateSymbolFile.cpp
index 0d0e5300668fc1..4f06518170ffc4 100644
--- a/lldb/source/Symbol/LocateSymbolFile.cpp
+++ b/lldb/source/Symbol/LocateSymbolFile.cpp
@@ -22,6 +22,10 @@
 
 #include "llvm/Support/FileSystem.h"
 
+#if defined(__FreeBSD__)
+#include <sys/sysctl.h>
+#endif
+
 // From MacOSX system header "mach/machine.h"
 typedef int cpu_type_t;
 typedef int cpu_subtype_t;
@@ -300,6 +304,24 @@ Symbols::LocateExecutableSymbolFile(const ModuleSpec &module_spec,
       FileSystem::Instance().Resolve(file_spec);
       debug_file_search_paths.AppendIfUnique(file_spec);
     }
+#if defined(__FreeBSD__)
+    // Add $LOCALBASE/lib/debug directory, where
+    // LOCALBASE is usually /usr/local, but may be adjusted by the end user
+    {
+      int mib[2];
+      char buf[PATH_MAX];
+      size_t len = PATH_MAX;
+
+      mib[0] = CTL_USER;
+      mib[1] = USER_LOCALBASE;
+      if (::sysctl(mib, 2, buf, &len, NULL, 0) == 0) {
+        std::string localbase(buf);
+        FileSpec file_spec(localbase + "/lib/debug");
+        FileSystem::Instance().Resolve(file_spec);
+        debug_file_search_paths.AppendIfUnique(file_spec);
+      }
+    }
+#endif // __FreeBSD__
 #endif
 #endif // _WIN32
   }



More information about the lldb-commits mailing list