[Lldb-commits] [PATCH] D86818: [lldb/Host] Add missing proc states

Jordan Rupprecht via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Sep 2 08:53:00 PDT 2020


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc5aa63dd560b: [lldb/Host] Add missing proc states (authored by rupprecht).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86818/new/

https://reviews.llvm.org/D86818

Files:
  lldb/source/Host/linux/Host.cpp


Index: lldb/source/Host/linux/Host.cpp
===================================================================
--- lldb/source/Host/linux/Host.cpp
+++ lldb/source/Host/linux/Host.cpp
@@ -16,6 +16,7 @@
 #include <sys/utsname.h>
 #include <unistd.h>
 
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/Object/ELF.h"
 #include "llvm/Support/ScopedPrinter.h"
 
@@ -35,8 +36,11 @@
 namespace {
 enum class ProcessState {
   Unknown,
+  Dead,
   DiskSleep,
+  Idle,
   Paging,
+  Parked,
   Running,
   Sleeping,
   TracedOrStopped,
@@ -50,12 +54,14 @@
 
 static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo &ProcessInfo,
                           ProcessState &State, ::pid_t &TracerPid) {
+  Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
+
   auto BufferOrError = getProcFile(Pid, "status");
   if (!BufferOrError)
     return false;
 
   llvm::StringRef Rest = BufferOrError.get()->getBuffer();
-  while(!Rest.empty()) {
+  while (!Rest.empty()) {
     llvm::StringRef Line;
     std::tie(Line, Rest) = Rest.split('\n');
 
@@ -84,26 +90,19 @@
       Line.ltrim().consumeInteger(10, PPid);
       ProcessInfo.SetParentProcessID(PPid);
     } else if (Line.consume_front("State:")) {
-      char S = Line.ltrim().front();
-      switch (S) {
-      case 'R':
-        State = ProcessState::Running;
-        break;
-      case 'S':
-        State = ProcessState::Sleeping;
-        break;
-      case 'D':
-        State = ProcessState::DiskSleep;
-        break;
-      case 'Z':
-        State = ProcessState::Zombie;
-        break;
-      case 'T':
-        State = ProcessState::TracedOrStopped;
-        break;
-      case 'W':
-        State = ProcessState::Paging;
-        break;
+      State = llvm::StringSwitch<ProcessState>(Line.ltrim().take_front(1))
+                  .Case("D", ProcessState::DiskSleep)
+                  .Case("I", ProcessState::Idle)
+                  .Case("R", ProcessState::Running)
+                  .Case("S", ProcessState::Sleeping)
+                  .CaseLower("T", ProcessState::TracedOrStopped)
+                  .Case("W", ProcessState::Paging)
+                  .Case("P", ProcessState::Parked)
+                  .Case("X", ProcessState::Dead)
+                  .Case("Z", ProcessState::Zombie)
+                  .Default(ProcessState::Unknown);
+      if (State == ProcessState::Unknown) {
+        LLDB_LOG(log, "Unknown process state {0}", Line);
       }
     } else if (Line.consume_front("TracerPid:")) {
       Line = Line.ltrim();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86818.289471.patch
Type: text/x-patch
Size: 2504 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200902/3cc9cc79/attachment-0001.bin>


More information about the lldb-commits mailing list