Skip to content

[lldb] Additional pieces towards OpenBSD support #74198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2023

Conversation

brad0
Copy link
Contributor

@brad0 brad0 commented Dec 2, 2023

No description provided.

@brad0 brad0 requested a review from JDevlieghere as a code owner December 2, 2023 15:23
@llvmbot llvmbot added the lldb label Dec 2, 2023
@llvmbot
Copy link
Member

llvmbot commented Dec 2, 2023

@llvm/pr-subscribers-lldb

Author: Brad Smith (brad0)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/74198.diff

8 Files Affected:

  • (modified) lldb/source/Core/FormatEntity.cpp (+4-3)
  • (modified) lldb/source/Host/common/SocketAddress.cpp (+4-2)
  • (modified) lldb/source/Host/posix/DomainSocket.cpp (+2-1)
  • (modified) lldb/source/Initialization/SystemInitializerCommon.cpp (+4-2)
  • (modified) lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp (+1)
  • (modified) lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp (+4-3)
  • (modified) lldb/test/API/api/multithreaded/common.h (+2-1)
  • (modified) lldb/test/API/tools/lldb-server/thread-name/main.cpp (+2)
diff --git a/lldb/source/Core/FormatEntity.cpp b/lldb/source/Core/FormatEntity.cpp
index d8047b4242065..04ae5398c9a3f 100644
--- a/lldb/source/Core/FormatEntity.cpp
+++ b/lldb/source/Core/FormatEntity.cpp
@@ -1245,9 +1245,10 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
             llvm::Triple::OSType ostype = arch.IsValid()
                                               ? arch.GetTriple().getOS()
                                               : llvm::Triple::UnknownOS;
-            if ((ostype == llvm::Triple::FreeBSD) ||
-                (ostype == llvm::Triple::Linux) ||
-                (ostype == llvm::Triple::NetBSD)) {
+            if (ostype == llvm::Triple::Linux ||
+                ostype == llvm::Triple::FreeBSD ||
+                ostype == llvm::Triple::NetBSD ||
+                ostype == llvm::Triple::OpenBSD) {
               format = "%" PRIu64;
             }
           } else {
diff --git a/lldb/source/Host/common/SocketAddress.cpp b/lldb/source/Host/common/SocketAddress.cpp
index 3f47d32d4652d..6a23c633e54bf 100644
--- a/lldb/source/Host/common/SocketAddress.cpp
+++ b/lldb/source/Host/common/SocketAddress.cpp
@@ -113,7 +113,8 @@ static socklen_t GetFamilyLength(sa_family_t family) {
 }
 
 socklen_t SocketAddress::GetLength() const {
-#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) ||       \
+    defined(__OpenBSD__)
   return m_socket_addr.sa.sa_len;
 #else
   return GetFamilyLength(GetFamily());
@@ -128,7 +129,8 @@ sa_family_t SocketAddress::GetFamily() const {
 
 void SocketAddress::SetFamily(sa_family_t family) {
   m_socket_addr.sa.sa_family = family;
-#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) ||       \
+    defined(__OpenBSD__)
   m_socket_addr.sa.sa_len = GetFamilyLength(family);
 #endif
 }
diff --git a/lldb/source/Host/posix/DomainSocket.cpp b/lldb/source/Host/posix/DomainSocket.cpp
index ddbd983abb81d..9b44c2a8368ed 100644
--- a/lldb/source/Host/posix/DomainSocket.cpp
+++ b/lldb/source/Host/posix/DomainSocket.cpp
@@ -48,7 +48,8 @@ static bool SetSockAddr(llvm::StringRef name, const size_t name_offset,
     saddr_un_len =
         offsetof(struct sockaddr_un, sun_path) + name_offset + name.size();
 
-#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) ||       \
+    defined(__OpenBSD__)
   saddr_un->sun_len = saddr_un_len;
 #endif
 
diff --git a/lldb/source/Initialization/SystemInitializerCommon.cpp b/lldb/source/Initialization/SystemInitializerCommon.cpp
index 40e54cd7f0e09..1a172a95aa147 100644
--- a/lldb/source/Initialization/SystemInitializerCommon.cpp
+++ b/lldb/source/Initialization/SystemInitializerCommon.cpp
@@ -18,7 +18,8 @@
 #include "lldb/Utility/Timer.h"
 #include "lldb/Version/Version.h"
 
-#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) ||       \
+    defined(__OpenBSD__)
 #include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
 #endif
 
@@ -77,7 +78,8 @@ llvm::Error SystemInitializerCommon::Initialize() {
 
   process_gdb_remote::ProcessGDBRemoteLog::Initialize();
 
-#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) ||       \
+    defined(__OpenBSD__)
   ProcessPOSIXLog::Initialize();
 #endif
 #if defined(_WIN32)
diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
index a0b6f44bed0e7..1a9c4593b1b4f 100644
--- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
+++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
@@ -549,6 +549,7 @@ bool DYLDRendezvous::SOEntryIsMainExecutable(const SOEntry &entry) {
   switch (triple.getOS()) {
   case llvm::Triple::FreeBSD:
   case llvm::Triple::NetBSD:
+  case llvm::Triple::OpenBSD:
     return entry.file_spec == m_exe_file_spec;
   case llvm::Triple::Linux:
     if (triple.isAndroid())
diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
index 3d65f49674209..c2705728e9f6a 100644
--- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -51,9 +51,10 @@ DynamicLoader *DynamicLoaderPOSIXDYLD::CreateInstance(Process *process,
   if (!create) {
     const llvm::Triple &triple_ref =
         process->GetTarget().GetArchitecture().GetTriple();
-    if (triple_ref.getOS() == llvm::Triple::FreeBSD ||
-        triple_ref.getOS() == llvm::Triple::Linux ||
-        triple_ref.getOS() == llvm::Triple::NetBSD)
+    if (triple_ref.getOS() == llvm::Triple::Linux ||
+        triple_ref.getOS() == llvm::Triple::FreeBSD ||
+        triple_ref.getOS() == llvm::Triple::NetBSD ||
+        triple_ref.getOS() == llvm::Triple::OpenBSD)
       create = true;
   }
 
diff --git a/lldb/test/API/api/multithreaded/common.h b/lldb/test/API/api/multithreaded/common.h
index dad8bba07a3f3..2ef1cb7c5664d 100644
--- a/lldb/test/API/api/multithreaded/common.h
+++ b/lldb/test/API/api/multithreaded/common.h
@@ -58,7 +58,8 @@ class multithreaded_queue {
 
 /// Allocates a char buffer with the current working directory
 inline char* get_working_dir() {
-#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) ||       \
+    defined(__OpenBSD__)
     return getwd(0);
 #else
     return get_current_dir_name();
diff --git a/lldb/test/API/tools/lldb-server/thread-name/main.cpp b/lldb/test/API/tools/lldb-server/thread-name/main.cpp
index 02eea12ca98a0..185fdece1a980 100644
--- a/lldb/test/API/tools/lldb-server/thread-name/main.cpp
+++ b/lldb/test/API/tools/lldb-server/thread-name/main.cpp
@@ -6,6 +6,8 @@ void set_thread_name(const char *name) {
   ::pthread_setname_np(name);
 #elif defined(__FreeBSD__) || defined(__linux__)
   ::pthread_setname_np(::pthread_self(), name);
+#elif defined(__OpenBSD__)
+  ::pthread_set_name_np(::pthread_self(), name);
 #elif defined(__NetBSD__)
   ::pthread_setname_np(::pthread_self(), "%s", const_cast<char *>(name));
 #endif

Copy link

github-actions bot commented Dec 2, 2023

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff f6c7baea098aac03687f5041fc860ca95f070e4e 312bd79cfbe847a7553534714649ff2a4b7979b5 -- lldb/source/Core/FormatEntity.cpp lldb/source/Host/common/SocketAddress.cpp lldb/source/Host/posix/DomainSocket.cpp lldb/source/Initialization/SystemInitializerCommon.cpp lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp lldb/test/API/api/multithreaded/common.h lldb/test/API/tools/lldb-server/thread-name/main.cpp
View the diff from clang-format here.
diff --git a/lldb/test/API/api/multithreaded/common.h b/lldb/test/API/api/multithreaded/common.h
index 2ef1cb7c56..e80023f3f4 100644
--- a/lldb/test/API/api/multithreaded/common.h
+++ b/lldb/test/API/api/multithreaded/common.h
@@ -60,7 +60,7 @@ public:
 inline char* get_working_dir() {
 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) ||       \
     defined(__OpenBSD__)
-    return getwd(0);
+  return getwd(0);
 #else
     return get_current_dir_name();
 #endif

@brad0 brad0 requested a review from bulbazord December 2, 2023 15:25
@brad0 brad0 force-pushed the lldb_openbsd_support branch from 3281024 to 864c2a5 Compare December 2, 2023 15:43
@brad0 brad0 force-pushed the lldb_openbsd_support branch from 864c2a5 to f79dcfc Compare December 2, 2023 16:49
@brad0 brad0 requested a review from emaste December 2, 2023 16:53
@brad0 brad0 force-pushed the lldb_openbsd_support branch from f79dcfc to 3ae1151 Compare December 3, 2023 10:22
Copy link
Member

@bulbazord bulbazord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall, small nit

@brad0 brad0 force-pushed the lldb_openbsd_support branch from 3ae1151 to 312bd79 Compare December 4, 2023 20:02
@brad0 brad0 merged commit a2e61bc into llvm:main Dec 4, 2023
@brad0 brad0 deleted the lldb_openbsd_support branch December 4, 2023 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants