[Lldb-commits] [lldb] c5aa63d - [lldb/Host] Add missing proc states
Jordan Rupprecht via lldb-commits
lldb-commits at lists.llvm.org
Wed Sep 2 08:52:56 PDT 2020
Author: Jordan Rupprecht
Date: 2020-09-02T08:24:06-07:00
New Revision: c5aa63dd560b9cf5825c1e4da2a9ee53dbd772f3
URL: https://github.com/llvm/llvm-project/commit/c5aa63dd560b9cf5825c1e4da2a9ee53dbd772f3
DIFF: https://github.com/llvm/llvm-project/commit/c5aa63dd560b9cf5825c1e4da2a9ee53dbd772f3.diff
LOG: [lldb/Host] Add missing proc states
The /proc/<pid>/status parsing is missing a few cases:
- Idle
- Parked
- Dead
If we encounter an unknown proc state, this leads to an msan warning. In reality, we only check that the state != Zombie, so it doesn't really matter that we handle all cases, but handle them anyway (current list: [1]). Also explicitly set it to unknown if we encounter an unknown state. There will still be an msan warning if the proc entry has no `State:` line, but that should not happen.
Use a StringSwitch to make the handling of proc states a little more compact.
[1] https://github.com/torvalds/linux/blob/master/fs/proc/array.c
Reviewed By: labath
Differential Revision: https://reviews.llvm.org/D86818
Added:
Modified:
lldb/source/Host/linux/Host.cpp
Removed:
################################################################################
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index 45973f5d214b..520a00df35f6 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/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 @@ using namespace lldb_private;
namespace {
enum class ProcessState {
Unknown,
+ Dead,
DiskSleep,
+ Idle,
Paging,
+ Parked,
Running,
Sleeping,
TracedOrStopped,
@@ -50,12 +54,14 @@ class ProcessLaunchInfo;
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 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo &ProcessInfo,
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();
More information about the lldb-commits
mailing list