diff options
Diffstat (limited to 'lldb/source/Host/linux/Host.cpp')
| -rw-r--r-- | lldb/source/Host/linux/Host.cpp | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp index c6490f2fc9e2..5545f9ef4d70 100644 --- a/lldb/source/Host/linux/Host.cpp +++ b/lldb/source/Host/linux/Host.cpp @@ -37,6 +37,7 @@ using namespace lldb; using namespace lldb_private; namespace { + enum class ProcessState { Unknown, Dead, @@ -70,6 +71,12 @@ struct StatFields { long unsigned stime; long cutime; long cstime; + // In proc_pid_stat(5) this field is specified as priority + // but documented as realtime priority. To keep with the adopted + // nomenclature in ProcessInstanceInfo, we adopt the documented + // naming here. + long realtime_priority; + long priority; // .... other things. We don't need them below }; } @@ -91,14 +98,16 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo &ProcessInfo, if (Rest.empty()) return false; StatFields stat_fields; - if (sscanf(Rest.data(), - "%d %s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu %ld %ld", - &stat_fields.pid, stat_fields.comm, &stat_fields.state, - &stat_fields.ppid, &stat_fields.pgrp, &stat_fields.session, - &stat_fields.tty_nr, &stat_fields.tpgid, &stat_fields.flags, - &stat_fields.minflt, &stat_fields.cminflt, &stat_fields.majflt, - &stat_fields.cmajflt, &stat_fields.utime, &stat_fields.stime, - &stat_fields.cutime, &stat_fields.cstime) < 0) { + if (sscanf( + Rest.data(), + "%d %s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld", + &stat_fields.pid, stat_fields.comm, &stat_fields.state, + &stat_fields.ppid, &stat_fields.pgrp, &stat_fields.session, + &stat_fields.tty_nr, &stat_fields.tpgid, &stat_fields.flags, + &stat_fields.minflt, &stat_fields.cminflt, &stat_fields.majflt, + &stat_fields.cmajflt, &stat_fields.utime, &stat_fields.stime, + &stat_fields.cutime, &stat_fields.cstime, + &stat_fields.realtime_priority, &stat_fields.priority) < 0) { return false; } @@ -115,6 +124,11 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo &ProcessInfo, return ts; }; + // Priority (nice) values run from 19 to -20 inclusive (in linux). In the + // prpsinfo struct pr_nice is a char. + auto priority_value = static_cast<int8_t>( + (stat_fields.priority < 0 ? 0x80 : 0x00) | (stat_fields.priority & 0x7f)); + ProcessInfo.SetParentProcessID(stat_fields.ppid); ProcessInfo.SetProcessGroupID(stat_fields.pgrp); ProcessInfo.SetProcessSessionID(stat_fields.session); @@ -122,6 +136,7 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo &ProcessInfo, ProcessInfo.SetSystemTime(convert(stat_fields.stime)); ProcessInfo.SetCumulativeUserTime(convert(stat_fields.cutime)); ProcessInfo.SetCumulativeSystemTime(convert(stat_fields.cstime)); + ProcessInfo.SetPriorityValue(priority_value); switch (stat_fields.state) { case 'R': State = ProcessState::Running; @@ -156,6 +171,7 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo &ProcessInfo, State = ProcessState::Unknown; break; } + ProcessInfo.SetIsZombie(State == ProcessState::Zombie); if (State == ProcessState::Unknown) { LLDB_LOG(log, "Unknown process state {0}", stat_fields.state); |
