[Lldb-commits] [lldb] r125152 - in /lldb/trunk: include/lldb/Host/File.h include/lldb/Host/freebsd/Config.h include/lldb/Host/linux/Config.h include/lldb/Host/macosx/Config.h include/lldb/Host/mingw/Config.h source/Host/common/File.cpp

Stephen Wilson wilsons at start.ca
Tue Feb 8 19:12:04 PST 2011


Hi Greg,

Here is an implementation of File::GetFileSpec for linux.

The patch also adds a few missing includes, and removes an annoying
trailing comma from lldb-enumerations.h that generates tons of warnings.


Finally, could you take a look at a patch I sent earlier:

  http://lists.cs.uiuc.edu/pipermail/lldb-commits/Week-of-Mon-20110207/002077.html


Thanks,

diff --git a/include/lldb/Host/File.h b/include/lldb/Host/File.h
index 9493247..8f66e45 100644
--- a/include/lldb/Host/File.h
+++ b/include/lldb/Host/File.h
@@ -11,6 +11,8 @@
 #define liblldb_File_h_
 #if defined(__cplusplus)
 
+#include <stdio.h>
+
 #include "lldb/lldb-private.h"
 
 namespace lldb_private {
diff --git a/include/lldb/lldb-enumerations.h b/include/lldb/lldb-enumerations.h
index 0a58052..c609deb 100644
--- a/include/lldb/lldb-enumerations.h
+++ b/include/lldb/lldb-enumerations.h
@@ -85,7 +85,7 @@ typedef enum ByteOrder
     eByteOrderInvalid   = 0,
     eByteOrderBig       = 1,
     eByteOrderPDP       = 2,
-    eByteOrderLittle    = 4,
+    eByteOrderLittle    = 4
 } ByteOrder;
 
 //----------------------------------------------------------------------
diff --git a/source/Host/common/File.cpp b/source/Host/common/File.cpp
index e8ba529..0901127 100644
--- a/source/Host/common/File.cpp
+++ b/source/Host/common/File.cpp
@@ -11,6 +11,7 @@
 #include "lldb/Host/File.h"
 
 #include <fcntl.h>
+#include <stdarg.h>
 
 #include "lldb/Core/Error.h"
 #include "lldb/Host/Config.h"
@@ -269,8 +270,24 @@ File::GetFileSpec (FileSpec &file_spec) const
     {
         error.SetErrorString("invalid file handle");
     }
+#elif defined(__linux__)
+    char proc[64];
+    char path[PATH_MAX];
+    if (::snprintf(proc, sizeof(proc), "/proc/self/fd/%d", GetDescriptor()) < 0)
+        error.SetErrorString ("Cannot resolve file descriptor\n");
+    else
+    {
+        ssize_t len;
+        if ((len = ::readlink(proc, path, sizeof(path) - 1)) == -1)
+            error.SetErrorToErrno();
+        else
+        {
+            path[len] = '\0';
+            file_spec.SetFile (path, false);
+        }
+    }
 #else
-    error.SetErrorString ("fcntl (fd, F_GETPATH, ...) is not supported on this platform");
+    error.SetErrorString ("File::GetFileSpec is not supported on this platform");
 #endif
 
     if (error.Fail())



More information about the lldb-commits mailing list