[Lldb-commits] [lldb] r216210 - Move GetUsername and GetGroupname to HostInfoPosix

Zachary Turner zturner at google.com
Thu Aug 21 13:02:18 PDT 2014


Author: zturner
Date: Thu Aug 21 15:02:17 2014
New Revision: 216210

URL: http://llvm.org/viewvc/llvm-project?rev=216210&view=rev
Log:
Move GetUsername and GetGroupname to HostInfoPosix

Modified:
    lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h
    lldb/trunk/source/Host/common/Host.cpp
    lldb/trunk/source/Host/posix/HostInfoPosix.cpp
    lldb/trunk/source/Host/windows/Host.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
    lldb/trunk/source/Target/Platform.cpp

Modified: lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h?rev=216210&r1=216209&r2=216210&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h (original)
+++ lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h Thu Aug 21 15:02:17 2014
@@ -22,6 +22,8 @@ class HostInfoPosix : public HostInfoBas
   public:
     static size_t GetPageSize();
     static bool GetHostname(std::string &s);
+    static bool LookupUserName(uint32_t uid, std::string &user_name);
+    static bool LookupGroupName(uint32_t gid, std::string &group_name);
 
   protected:
     static bool ComputeSupportExeDirectory(FileSpec &file_spec);

Modified: lldb/trunk/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=216210&r1=216209&r2=216210&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Host.cpp (original)
+++ lldb/trunk/source/Host/common/Host.cpp Thu Aug 21 15:02:17 2014
@@ -867,65 +867,6 @@ Host::GetModuleFileSpecForHostAddress (c
 
 #ifndef _WIN32
 
-const char *
-Host::GetUserName (uint32_t uid, std::string &user_name)
-{
-    struct passwd user_info;
-    struct passwd *user_info_ptr = &user_info;
-    char user_buffer[PATH_MAX];
-    size_t user_buffer_size = sizeof(user_buffer);
-    if (::getpwuid_r (uid,
-                      &user_info,
-                      user_buffer,
-                      user_buffer_size,
-                      &user_info_ptr) == 0)
-    {
-        if (user_info_ptr)
-        {
-            user_name.assign (user_info_ptr->pw_name);
-            return user_name.c_str();
-        }
-    }
-    user_name.clear();
-    return NULL;
-}
-
-const char *
-Host::GetGroupName (uint32_t gid, std::string &group_name)
-{
-    char group_buffer[PATH_MAX];
-    size_t group_buffer_size = sizeof(group_buffer);
-    struct group group_info;
-    struct group *group_info_ptr = &group_info;
-    // Try the threadsafe version first
-    if (::getgrgid_r (gid,
-                      &group_info,
-                      group_buffer,
-                      group_buffer_size,
-                      &group_info_ptr) == 0)
-    {
-        if (group_info_ptr)
-        {
-            group_name.assign (group_info_ptr->gr_name);
-            return group_name.c_str();
-        }
-    }
-    else
-    {
-        // The threadsafe version isn't currently working
-        // for me on darwin, but the non-threadsafe version 
-        // is, so I am calling it below.
-        group_info_ptr = ::getgrgid (gid);
-        if (group_info_ptr)
-        {
-            group_name.assign (group_info_ptr->gr_name);
-            return group_name.c_str();
-        }
-    }
-    group_name.clear();
-    return NULL;
-}
-
 uint32_t
 Host::GetUserID ()
 {
@@ -952,23 +893,6 @@ Host::GetEffectiveGroupID ()
 
 #endif
 
-#if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__FreeBSD_kernel__) \
-    && !defined(__linux__) && !defined(_WIN32)
-uint32_t
-Host::FindProcesses (const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &process_infos)
-{
-    process_infos.Clear();
-    return process_infos.GetSize();
-}
-
-bool
-Host::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)
-{
-    process_info.Clear();
-    return false;
-}
-#endif
-
 #if !defined(__linux__)
 bool
 Host::FindProcessThreads (const lldb::pid_t pid, TidMap &tids_to_attach)

Modified: lldb/trunk/source/Host/posix/HostInfoPosix.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/HostInfoPosix.cpp?rev=216210&r1=216209&r2=216210&view=diff
==============================================================================
--- lldb/trunk/source/Host/posix/HostInfoPosix.cpp (original)
+++ lldb/trunk/source/Host/posix/HostInfoPosix.cpp Thu Aug 21 15:02:17 2014
@@ -15,8 +15,11 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/raw_ostream.h"
 
-#include <netdb.h>
+#include <grp.h>
 #include <limits.h>
+#include <netdb.h>
+#include <pwd.h>
+#include <sys/types.h>
 #include <unistd.h>
 
 using namespace lldb_private;
@@ -45,6 +48,56 @@ HostInfoPosix::GetHostname(std::string &
 }
 
 bool
+HostInfoPosix::LookupUserName(uint32_t uid, std::string &user_name)
+{
+    struct passwd user_info;
+    struct passwd *user_info_ptr = &user_info;
+    char user_buffer[PATH_MAX];
+    size_t user_buffer_size = sizeof(user_buffer);
+    if (::getpwuid_r(uid, &user_info, user_buffer, user_buffer_size, &user_info_ptr) == 0)
+    {
+        if (user_info_ptr)
+        {
+            user_name.assign(user_info_ptr->pw_name);
+            return user_name.c_str();
+        }
+    }
+    user_name.clear();
+    return NULL;
+}
+
+bool
+HostInfoPosix::LookupGroupName(uint32_t gid, std::string &group_name)
+{
+    char group_buffer[PATH_MAX];
+    size_t group_buffer_size = sizeof(group_buffer);
+    struct group group_info;
+    struct group *group_info_ptr = &group_info;
+    // Try the threadsafe version first
+    if (::getgrgid_r(gid, &group_info, group_buffer, group_buffer_size, &group_info_ptr) == 0)
+    {
+        if (group_info_ptr)
+        {
+            group_name.assign(group_info_ptr->gr_name);
+            return group_name.c_str();
+        }
+    }
+    else
+    {
+        // The threadsafe version isn't currently working for me on darwin, but the non-threadsafe version
+        // is, so I am calling it below.
+        group_info_ptr = ::getgrgid(gid);
+        if (group_info_ptr)
+        {
+            group_name.assign(group_info_ptr->gr_name);
+            return group_name.c_str();
+        }
+    }
+    group_name.clear();
+    return NULL;
+}
+
+bool
 HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec)
 {
     Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);

Modified: lldb/trunk/source/Host/windows/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/Host.cpp?rev=216210&r1=216209&r2=216210&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/Host.cpp (original)
+++ lldb/trunk/source/Host/windows/Host.cpp Thu Aug 21 15:02:17 2014
@@ -235,19 +235,6 @@ Host::DynamicLibraryGetSymbol(void *opaq
     return NULL;
 }
 
-const char *
-Host::GetUserName (uint32_t uid, std::string &user_name)
-{
-    return NULL;
-}
-
-const char *
-Host::GetGroupName (uint32_t gid, std::string &group_name)
-{
-    llvm_unreachable("Windows does not support group name");
-    return NULL;
-}
-
 uint32_t
 Host::GetUserID ()
 {

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp?rev=216210&r1=216209&r2=216210&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp Thu Aug 21 15:02:17 2014
@@ -1538,19 +1538,21 @@ GDBRemoteCommunicationServer::Handle_qsP
 GDBRemoteCommunication::PacketResult
 GDBRemoteCommunicationServer::Handle_qUserName (StringExtractorGDBRemote &packet)
 {
+#if !defined(LLDB_DISABLE_POSIX)
     // Packet format: "qUserName:%i" where %i is the uid
     packet.SetFilePos(::strlen ("qUserName:"));
     uint32_t uid = packet.GetU32 (UINT32_MAX);
     if (uid != UINT32_MAX)
     {
         std::string name;
-        if (Host::GetUserName (uid, name))
+        if (HostInfo::LookupUserName(uid, name))
         {
             StreamString response;
             response.PutCStringAsRawHex8 (name.c_str());
             return SendPacketNoLock (response.GetData(), response.GetSize());
         }
     }
+#endif
     return SendErrorResponse (5);
 
 }
@@ -1558,19 +1560,21 @@ GDBRemoteCommunicationServer::Handle_qUs
 GDBRemoteCommunication::PacketResult
 GDBRemoteCommunicationServer::Handle_qGroupName (StringExtractorGDBRemote &packet)
 {
+#if !defined(LLDB_DISABLE_POSIX)
     // Packet format: "qGroupName:%i" where %i is the gid
     packet.SetFilePos(::strlen ("qGroupName:"));
     uint32_t gid = packet.GetU32 (UINT32_MAX);
     if (gid != UINT32_MAX)
     {
         std::string name;
-        if (Host::GetGroupName (gid, name))
+        if (HostInfo::LookupGroupName(gid, name))
         {
             StreamString response;
             response.PutCStringAsRawHex8 (name.c_str());
             return SendPacketNoLock (response.GetData(), response.GetSize());
         }
     }
+#endif
     return SendErrorResponse (6);
 }
 

Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=216210&r1=216209&r2=216210&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Thu Aug 21 15:02:17 2014
@@ -776,30 +776,34 @@ Platform::SetRemoteWorkingDirectory(cons
 const char *
 Platform::GetUserName (uint32_t uid)
 {
+#if !defined(LLDB_DISABLE_POSIX)
     const char *user_name = GetCachedUserName(uid);
     if (user_name)
         return user_name;
     if (IsHost())
     {
         std::string name;
-        if (Host::GetUserName(uid, name))
+        if (HostInfo::LookupUserName(uid, name))
             return SetCachedUserName (uid, name.c_str(), name.size());
     }
+#endif
     return NULL;
 }
 
 const char *
 Platform::GetGroupName (uint32_t gid)
 {
+#if !defined(LLDB_DISABLE_POSIX)
     const char *group_name = GetCachedGroupName(gid);
     if (group_name)
         return group_name;
     if (IsHost())
     {
         std::string name;
-        if (Host::GetGroupName(gid, name))
+        if (HostInfo::LookupGroupName(gid, name))
             return SetCachedGroupName (gid, name.c_str(), name.size());
     }
+#endif
     return NULL;
 }
 





More information about the lldb-commits mailing list