[lldb-dev] lldb patches for OpenBSD

Amit Kulkarni amitkulz at gmail.com
Thu Mar 31 20:47:35 PDT 2011


I have several small fixes for OpenBSD, I am just compiling lldb, not
at all meaning to run it for now. Please give feedback.

1) C99 discourages LONG_LONG_MAX, ULONG_LONG_MAX, and relatives? Can
this be fixed properly by complete replacement or
you would settle for ifndef in the code? I don't know if it exists on
Mac OSX and Linux, so can you please change appropriately? I have
included a ugly ifndef in a DataExtractor.cpp and DNBDataRef.cpp.

2) File.cpp needs <sys/stat.h> because all the permissions like
S_IRUSR, S_IWUSR, S_IROTH, S_IXOTH etc are defined there in OpenBSD
and FreeBSD (both -current or head sources). I don't have any Linux
sources around but Linux knowledgeable people will correct me, if its
needed there, if not we can add ifndef?

3) DT_WHT won't be defined in <sys/dirent.h> on OpenBSD. In fact, it
was specifically removed.

4) return (uint64_t) (pthread_self()); is a poor hack for getting
thread id in Host.cpp. I hope to correct that in with feedback from
more knowledgeable people here on this board. I privately sent a email
to an OpenBSD developer, Matt Dempsky who wrote.

> llvm/tools/lldb/source/Host/common/Host.cpp:410: error: cast from
> 'pthread*' to 'lldb::tid_t' loses precision

"That's because tid_t is a uint32_t, but on 64-bit arches pthread_t is
a pointer, and so it's a 64-bit value.  It would probably be better to
change tid_t to a uint64_t.  I don't imagine that would be a
controversial change, and it affects all 64-bit non-Apple platforms, I

Also, is there any interest in convert the Makefiles into CMakeLists.txt?


Index: include/lldb/Host/Config.h
--- include/lldb/Host/Config.h	(revision 128703)
+++ include/lldb/Host/Config.h	(working copy)
@@ -18,7 +18,7 @@

 #include "lldb/Host/linux/Config.h"

-#elif defined(__FreeBSD__)
+#elif defined(__FreeBSD__) || defined(__OpenBSD__)

 #include "lldb/Host/freebsd/Config.h"

Index: source/Expression/DWARFExpression.cpp
--- source/Expression/DWARFExpression.cpp	(revision 128703)
+++ source/Expression/DWARFExpression.cpp	(working copy)
@@ -2175,9 +2175,9 @@

                 Scalar &index_scalar =
index_val.ResolveValue(exe_ctx, ast_context);
-                int64_t index = index_scalar.SLongLong(LONG_LONG_MAX);
+                int64_t index = index_scalar.SLongLong(LLONG_MAX);

-                if (index == LONG_LONG_MAX)
+                if (index == LLONG_MAX)
                     if (error_ptr)
                         error_ptr->SetErrorString("Invalid array index.");
Index: source/Symbol/ClangASTContext.cpp
--- source/Symbol/ClangASTContext.cpp	(revision 128703)
+++ source/Symbol/ClangASTContext.cpp	(working copy)
@@ -4266,7 +4266,7 @@
         if (member_type)
             *member_type =
         if (size)
-            *size =
+            *size =
         return true;
     case clang::Type::IncompleteArray:
         if (member_type)
Index: source/Core/DataExtractor.cpp
--- source/Core/DataExtractor.cpp	(revision 128703)
+++ source/Core/DataExtractor.cpp	(working copy)
@@ -886,6 +886,11 @@
 DataExtractor::GetGNUEHPointer (uint32_t *offset_ptr, uint32_t
eh_ptr_enc, lldb::addr_t pc_rel_addr, lldb::addr_t text_addr,
lldb::addr_t data_addr)//, BSDRelocs *data_relocs) const
     if (eh_ptr_enc == DW_EH_PE_omit)
         return ULONG_LONG_MAX;  // Value isn't in the buffer...

Index: source/Host/common/File.cpp
--- source/Host/common/File.cpp	(revision 128703)
+++ source/Host/common/File.cpp	(working copy)
@@ -12,6 +12,7 @@

 #include <fcntl.h>
 #include <stdarg.h>
+#include <sys/stat.h>

 #include "lldb/Core/Error.h"
 #include "lldb/Host/Config.h"
Index: source/Host/common/FileSpec.cpp
--- source/Host/common/FileSpec.cpp	(revision 128703)
+++ source/Host/common/FileSpec.cpp	(working copy)
@@ -904,7 +904,9 @@
                 case DT_REG:        file_type = eFileTypeRegular;
  call_callback = find_files;         break;
                 case DT_LNK:        file_type =
eFileTypeSymbolicLink;  call_callback = find_other;         break;
                 case DT_SOCK:       file_type = eFileTypeSocket;
  call_callback = find_other;         break;
+#if !defined(__OpenBSD__)
                 case DT_WHT:        file_type = eFileTypeOther;
  call_callback = find_other;         break;

                 if (call_callback)
Index: source/Host/common/Host.cpp
--- source/Host/common/Host.cpp	(revision 128703)
+++ source/Host/common/Host.cpp	(working copy)
@@ -37,9 +37,8 @@
 #include <mach-o/dyld.h>
 #include <sys/sysctl.h>

+#elif defined (__linux__) || defined (__OpenBSD__)

-#elif defined (__linux__)
 #include <sys/wait.h>

@@ -409,6 +408,8 @@
 #if defined (__APPLE__)
     return ::mach_thread_self();
+#elif defined (__OpenBSD__)
+    return (uint64_t) (pthread_self());
     return lldb::tid_t(pthread_self());
Index: tools/debugserver/source/DNBDataRef.cpp
--- tools/debugserver/source/DNBDataRef.cpp	(revision 128703)
+++ tools/debugserver/source/DNBDataRef.cpp	(working copy)
@@ -206,6 +206,11 @@
 DNBDataRef::GetDwarfEHPtr(offset_t *offset_ptr, uint32_t encoding) const
     if (encoding == DW_EH_PE_omit)
         return ULONG_LONG_MAX;    // Value isn't in the buffer...

More information about the lldb-dev mailing list