[Lldb-commits] [PATCH] D86818: [lldb/Host] Add missing proc states
Jordan Rupprecht via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Fri Aug 28 14:52:01 PDT 2020
rupprecht created this revision.
Herald added subscribers: lldb-commits, danielkiss.
Herald added a project: LLDB.
rupprecht requested review of this revision.
Herald added a subscriber: JDevlieghere.
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
Repository:
rG LLVM Github Monorepo
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.288710.patch
Type: text/x-patch
Size: 2504 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200828/944e51b0/attachment.bin>
More information about the lldb-commits
mailing list