[Lldb-commits] [lldb] [lldb][OpenBSD] Implement HostInfoOpenBSD::GetProgramFileSpec() (PR #235230)

Brad Smith via lldb-commits lldb-commits at lists.llvm.org
Sun Oct 25 23:44:27 PDT 2026


https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/235230

>From cda7a60bbb040268f3d5251e4d17cde4ee85b5d8 Mon Sep 17 00:00:00 2001
From: Brad Smith <brad at comstyle.com>
Date: Fri, 23 Oct 2026 23:19:06 -0400
Subject: [PATCH] [lldb][OpenBSD] Implement
 HostInfoOpenBSD::GetProgramFileSpec()

GetProgramFileSpec() on OpenBSD always returned an empty FileSpec.

Use getexecpath(3) to look up the path of the running executable.

getexecpath() is only available on newer OpenBSD releases, so add a
HAVE_GETEXECPATH check to LLDB's generated config, as LLVM Support
does for getMainExecutable().
---
 lldb/cmake/modules/LLDBGenerateConfig.cmake  |  1 +
 lldb/include/lldb/Host/Config.h.cmake        |  2 ++
 lldb/source/Host/openbsd/HostInfoOpenBSD.cpp | 12 ++++++++++++
 3 files changed, 15 insertions(+)

diff --git a/lldb/cmake/modules/LLDBGenerateConfig.cmake b/lldb/cmake/modules/LLDBGenerateConfig.cmake
index 5acb7d873db498..7da4527a1988ab 100644
--- a/lldb/cmake/modules/LLDBGenerateConfig.cmake
+++ b/lldb/cmake/modules/LLDBGenerateConfig.cmake
@@ -8,6 +8,7 @@ include(CheckLibraryExists)
 set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
 check_symbol_exists(ppoll poll.h HAVE_PPOLL)
 check_symbol_exists(ptsname_r stdlib.h HAVE_PTSNAME_R)
+check_symbol_exists(getexecpath unistd.h HAVE_GETEXECPATH)
 set(CMAKE_REQUIRED_DEFINITIONS)
 check_cxx_symbol_exists(accept4 "sys/socket.h" HAVE_ACCEPT4)
 
diff --git a/lldb/include/lldb/Host/Config.h.cmake b/lldb/include/lldb/Host/Config.h.cmake
index efda80d4544fa7..8272b69919d436 100644
--- a/lldb/include/lldb/Host/Config.h.cmake
+++ b/lldb/include/lldb/Host/Config.h.cmake
@@ -19,6 +19,8 @@
 
 #cmakedefine01 HAVE_PTSNAME_R
 
+#cmakedefine01 HAVE_GETEXECPATH
+
 #cmakedefine01 HAVE_PROCESS_VM_READV
 
 #cmakedefine01 HAVE_NR_PROCESS_VM_READV
diff --git a/lldb/source/Host/openbsd/HostInfoOpenBSD.cpp b/lldb/source/Host/openbsd/HostInfoOpenBSD.cpp
index b30c7a83243c07..bac12e36092cce 100644
--- a/lldb/source/Host/openbsd/HostInfoOpenBSD.cpp
+++ b/lldb/source/Host/openbsd/HostInfoOpenBSD.cpp
@@ -7,13 +7,16 @@
 //===----------------------------------------------------------------------===//
 
 #include "lldb/Host/openbsd/HostInfoOpenBSD.h"
+#include "lldb/Host/Config.h"
 
+#include <climits>
 #include <cstdio>
 #include <cstring>
 #include <optional>
 #include <sys/sysctl.h>
 #include <sys/types.h>
 #include <sys/utsname.h>
+#include <unistd.h>
 
 using namespace lldb_private;
 
@@ -48,5 +51,14 @@ std::optional<std::string> HostInfoOpenBSD::GetOSBuildString() {
 
 FileSpec HostInfoOpenBSD::GetProgramFileSpec() {
   static FileSpec g_program_filespec;
+
+#if HAVE_GETEXECPATH
+  if (!g_program_filespec) {
+    char path[PATH_MAX];
+
+    if (getexecpath(path, sizeof(path)) != -1)
+      g_program_filespec.SetFile(path, FileSpec::Style::native);
+  }
+#endif
   return g_program_filespec;
 }



More information about the lldb-commits mailing list