[Lldb-commits] [lldb] r369906 - ProcessInstanceInfo: Fix dumping of invalid user ids

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Mon Aug 26 06:03:22 PDT 2019


Author: labath
Date: Mon Aug 26 06:03:21 2019
New Revision: 369906

URL: http://llvm.org/viewvc/llvm-project?rev=369906&view=rev
Log:
ProcessInstanceInfo: Fix dumping of invalid user ids

Don't attempt to print invalid user ids. Previously, these would come
out as UINT32_MAX, or as an assertion failure.

Modified:
    lldb/trunk/source/Utility/ProcessInfo.cpp
    lldb/trunk/unittests/Target/ProcessInstanceInfoTest.cpp

Modified: lldb/trunk/source/Utility/ProcessInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/ProcessInfo.cpp?rev=369906&r1=369905&r2=369906&view=diff
==============================================================================
--- lldb/trunk/source/Utility/ProcessInfo.cpp (original)
+++ lldb/trunk/source/Utility/ProcessInfo.cpp Mon Aug 26 06:03:21 2019
@@ -189,24 +189,39 @@ void ProcessInstanceInfo::DumpAsTableRow
     if (m_arch.IsValid())
       m_arch.DumpTriple(arch_strm);
 
-    auto print = [&](UserIDResolver::id_t id,
-                     llvm::Optional<llvm::StringRef> (UserIDResolver::*get)(
+    auto print = [&](bool (ProcessInstanceInfo::*isValid)() const,
+                     uint32_t (ProcessInstanceInfo::*getID)() const,
+                     llvm::Optional<llvm::StringRef> (UserIDResolver::*getName)(
                          UserIDResolver::id_t id)) {
-      if (auto name = (resolver.*get)(id))
-        s.Format("{0,-10} ", *name);
+      const char *format = "{0,-10} ";
+      if (!(this->*isValid)()) {
+        s.Format(format, "");
+        return;
+      }
+      uint32_t id = (this->*getID)();
+      if (auto name = (resolver.*getName)(id))
+        s.Format(format, *name);
       else
-        s.Format("{0,-10} ", id);
+        s.Format(format, id);
     };
     if (verbose) {
-      print(m_uid, &UserIDResolver::GetUserName);
-      print(m_gid, &UserIDResolver::GetGroupName);
-      print(m_euid, &UserIDResolver::GetUserName);
-      print(m_egid, &UserIDResolver::GetGroupName);
+      print(&ProcessInstanceInfo::UserIDIsValid,
+            &ProcessInstanceInfo::GetUserID, &UserIDResolver::GetUserName);
+      print(&ProcessInstanceInfo::GroupIDIsValid,
+            &ProcessInstanceInfo::GetGroupID, &UserIDResolver::GetGroupName);
+      print(&ProcessInstanceInfo::EffectiveUserIDIsValid,
+            &ProcessInstanceInfo::GetEffectiveUserID,
+            &UserIDResolver::GetUserName);
+      print(&ProcessInstanceInfo::EffectiveGroupIDIsValid,
+            &ProcessInstanceInfo::GetEffectiveGroupID,
+            &UserIDResolver::GetGroupName);
 
       s.Printf("%-24s ", arch_strm.GetData());
     } else {
-      print(m_euid, &UserIDResolver::GetUserName);
-      s.Printf(" %-24s ", arch_strm.GetData());
+      print(&ProcessInstanceInfo::EffectiveUserIDIsValid,
+            &ProcessInstanceInfo::GetEffectiveUserID,
+            &UserIDResolver::GetUserName);
+      s.Printf("%-24s ", arch_strm.GetData());
     }
 
     if (verbose || show_args) {

Modified: lldb/trunk/unittests/Target/ProcessInstanceInfoTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Target/ProcessInstanceInfoTest.cpp?rev=369906&r1=369905&r2=369906&view=diff
==============================================================================
--- lldb/trunk/unittests/Target/ProcessInstanceInfoTest.cpp (original)
+++ lldb/trunk/unittests/Target/ProcessInstanceInfoTest.cpp Mon Aug 26 06:03:21 2019
@@ -73,3 +73,21 @@ TEST(ProcessInstanceInfo, DumpTable) {
 )",
       s.GetData());
 }
+
+TEST(ProcessInstanceInfo, DumpTable_invalidUID) {
+  ProcessInstanceInfo info("a.out", ArchSpec("x86_64-pc-linux"), 47);
+
+  DummyUserIDResolver resolver;
+  StreamString s;
+
+  const bool show_args = false;
+  const bool verbose = false;
+  ProcessInstanceInfo::DumpTableHeader(s, show_args, verbose);
+  info.DumpAsTableRow(s, resolver, show_args, verbose);
+  EXPECT_STREQ(
+      R"(PID    PARENT USER       TRIPLE                   NAME
+====== ====== ========== ======================== ============================
+47     0                 x86_64-pc-linux          a.out
+)",
+      s.GetData());
+}




More information about the lldb-commits mailing list