[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-06-03 Thread Fred Grim via lldb-commits

feg208 wrote:

@clayborg This pr is ready for re-review

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-28 Thread Fred Grim via lldb-commits

feg208 wrote:

@clayborg This pr is ready for re-review

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Fred Grim via lldb-commits

feg208 wrote:

@clayborg I rolled up those requested changes. That'll make a nicer interface

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Fred Grim via lldb-commits


@@ -195,48 +195,66 @@ class ProcessInstanceInfo : public ProcessInfo {
 return m_process_session_id != LLDB_INVALID_PROCESS_ID;
   }
 
-  struct timespec GetUserTime() const { return m_user_time; }
+  struct timespec GetUserTime() const { return m_user_time.value(); }
 
   void SetUserTime(struct timespec utime) { m_user_time = utime; }
 
   bool UserTimeIsValid() const {
-return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+return m_user_time.has_value() &&
+   (m_user_time->tv_sec > 0 || m_user_time->tv_usec > 0);
   }
 
-  struct timespec GetSystemTime() const { return m_system_time; }
+  struct timespec GetSystemTime() const { return m_system_time.value(); }
 
   void SetSystemTime(struct timespec stime) { m_system_time = stime; }
 
   bool SystemTimeIsValid() const {
-return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+return m_system_time.has_value() &&
+   (m_system_time->tv_sec > 0 || m_system_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeUserTime() const {
-return m_cumulative_user_time;
+return m_cumulative_user_time.value();
   }
 
   void SetCumulativeUserTime(struct timespec cutime) {
 m_cumulative_user_time = cutime;
   }
 
   bool CumulativeUserTimeIsValid() const {
-return m_cumulative_user_time.tv_sec > 0 ||
-   m_cumulative_user_time.tv_usec > 0;
+return m_cumulative_user_time.has_value() &&
+   (m_cumulative_user_time->tv_sec > 0 ||
+m_cumulative_user_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeSystemTime() const {
-return m_cumulative_system_time;
+return m_cumulative_system_time.value();
   }
 
   void SetCumulativeSystemTime(struct timespec cstime) {
 m_cumulative_system_time = cstime;
   }
 
   bool CumulativeSystemTimeIsValid() const {
-return m_cumulative_system_time.tv_sec > 0 ||
-   m_cumulative_system_time.tv_usec > 0;
+return m_cumulative_system_time.has_value() &&
+   (m_cumulative_system_time->tv_sec > 0 ||
+m_cumulative_system_time->tv_usec > 0);
   }
 
+  int8_t GetPriorityValue() const { return m_priority_value.value(); }
+
+  void SetPriorityValue(int8_t priority_value) {
+m_priority_value = priority_value;
+  }
+
+  bool PriorityValueIsValid() const;

feg208 wrote:

done

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Fred Grim via lldb-commits


@@ -195,48 +195,66 @@ class ProcessInstanceInfo : public ProcessInfo {
 return m_process_session_id != LLDB_INVALID_PROCESS_ID;
   }
 
-  struct timespec GetUserTime() const { return m_user_time; }
+  struct timespec GetUserTime() const { return m_user_time.value(); }
 
   void SetUserTime(struct timespec utime) { m_user_time = utime; }
 
   bool UserTimeIsValid() const {
-return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+return m_user_time.has_value() &&
+   (m_user_time->tv_sec > 0 || m_user_time->tv_usec > 0);
   }
 
-  struct timespec GetSystemTime() const { return m_system_time; }
+  struct timespec GetSystemTime() const { return m_system_time.value(); }
 
   void SetSystemTime(struct timespec stime) { m_system_time = stime; }
 
   bool SystemTimeIsValid() const {
-return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+return m_system_time.has_value() &&
+   (m_system_time->tv_sec > 0 || m_system_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeUserTime() const {
-return m_cumulative_user_time;
+return m_cumulative_user_time.value();
   }
 
   void SetCumulativeUserTime(struct timespec cutime) {
 m_cumulative_user_time = cutime;
   }
 
   bool CumulativeUserTimeIsValid() const {
-return m_cumulative_user_time.tv_sec > 0 ||
-   m_cumulative_user_time.tv_usec > 0;
+return m_cumulative_user_time.has_value() &&
+   (m_cumulative_user_time->tv_sec > 0 ||
+m_cumulative_user_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeSystemTime() const {
-return m_cumulative_system_time;
+return m_cumulative_system_time.value();
   }
 
   void SetCumulativeSystemTime(struct timespec cstime) {
 m_cumulative_system_time = cstime;
   }
 
   bool CumulativeSystemTimeIsValid() const {
-return m_cumulative_system_time.tv_sec > 0 ||
-   m_cumulative_system_time.tv_usec > 0;
+return m_cumulative_system_time.has_value() &&
+   (m_cumulative_system_time->tv_sec > 0 ||
+m_cumulative_system_time->tv_usec > 0);
   }
 
+  int8_t GetPriorityValue() const { return m_priority_value.value(); }

feg208 wrote:

done

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Fred Grim via lldb-commits


@@ -195,48 +195,66 @@ class ProcessInstanceInfo : public ProcessInfo {
 return m_process_session_id != LLDB_INVALID_PROCESS_ID;
   }
 
-  struct timespec GetUserTime() const { return m_user_time; }
+  struct timespec GetUserTime() const { return m_user_time.value(); }
 
   void SetUserTime(struct timespec utime) { m_user_time = utime; }
 
   bool UserTimeIsValid() const {
-return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+return m_user_time.has_value() &&
+   (m_user_time->tv_sec > 0 || m_user_time->tv_usec > 0);
   }
 
-  struct timespec GetSystemTime() const { return m_system_time; }
+  struct timespec GetSystemTime() const { return m_system_time.value(); }
 
   void SetSystemTime(struct timespec stime) { m_system_time = stime; }
 
   bool SystemTimeIsValid() const {
-return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+return m_system_time.has_value() &&
+   (m_system_time->tv_sec > 0 || m_system_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeUserTime() const {
-return m_cumulative_user_time;
+return m_cumulative_user_time.value();
   }
 
   void SetCumulativeUserTime(struct timespec cutime) {
 m_cumulative_user_time = cutime;
   }
 
   bool CumulativeUserTimeIsValid() const {
-return m_cumulative_user_time.tv_sec > 0 ||
-   m_cumulative_user_time.tv_usec > 0;
+return m_cumulative_user_time.has_value() &&
+   (m_cumulative_user_time->tv_sec > 0 ||
+m_cumulative_user_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeSystemTime() const {
-return m_cumulative_system_time;
+return m_cumulative_system_time.value();
   }
 
   void SetCumulativeSystemTime(struct timespec cstime) {
 m_cumulative_system_time = cstime;
   }
 
   bool CumulativeSystemTimeIsValid() const {
-return m_cumulative_system_time.tv_sec > 0 ||
-   m_cumulative_system_time.tv_usec > 0;
+return m_cumulative_system_time.has_value() &&
+   (m_cumulative_system_time->tv_sec > 0 ||
+m_cumulative_system_time->tv_usec > 0);
   }
 
+  int8_t GetPriorityValue() const { return m_priority_value.value(); }
+
+  void SetPriorityValue(int8_t priority_value) {
+m_priority_value = priority_value;
+  }
+
+  bool PriorityValueIsValid() const;
+
+  void SetIsZombie(bool is_zombie) { m_zombie = is_zombie; }
+
+  bool IsZombieValid() const { return m_zombie.has_value(); }
+
+  bool IsZombie() const { return m_zombie.value(); }

feg208 wrote:

done

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Fred Grim via lldb-commits


@@ -250,10 +268,12 @@ class ProcessInstanceInfo : public ProcessInfo {
   lldb::pid_t m_parent_pid = LLDB_INVALID_PROCESS_ID;
   lldb::pid_t m_process_group_id = LLDB_INVALID_PROCESS_ID;
   lldb::pid_t m_process_session_id = LLDB_INVALID_PROCESS_ID;
-  struct timespec m_user_time {};
-  struct timespec m_system_time {};
-  struct timespec m_cumulative_user_time {};
-  struct timespec m_cumulative_system_time {};
+  std::optional m_user_time = std::nullopt;
+  std::optional m_system_time = std::nullopt;
+  std::optional m_cumulative_user_time = std::nullopt;
+  std::optional m_cumulative_system_time = std::nullopt;
+  std::optional m_priority_value = std::nullopt;
+  std::optional m_zombie = std::nullopt;

feg208 wrote:

done

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Fred Grim via lldb-commits


@@ -250,10 +268,12 @@ class ProcessInstanceInfo : public ProcessInfo {
   lldb::pid_t m_parent_pid = LLDB_INVALID_PROCESS_ID;
   lldb::pid_t m_process_group_id = LLDB_INVALID_PROCESS_ID;
   lldb::pid_t m_process_session_id = LLDB_INVALID_PROCESS_ID;
-  struct timespec m_user_time {};
-  struct timespec m_system_time {};
-  struct timespec m_cumulative_user_time {};
-  struct timespec m_cumulative_system_time {};
+  std::optional m_user_time = std::nullopt;
+  std::optional m_system_time = std::nullopt;
+  std::optional m_cumulative_user_time = std::nullopt;
+  std::optional m_cumulative_system_time = std::nullopt;

feg208 wrote:

done

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Fred Grim via lldb-commits

https://github.com/feg208 edited https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Fred Grim via lldb-commits


@@ -147,96 +148,111 @@ class ProcessInstanceInfo : public ProcessInfo {
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
-  : ProcessInfo(name, arch, pid), m_euid(UINT32_MAX), m_egid(UINT32_MAX),
-m_parent_pid(LLDB_INVALID_PROCESS_ID) {}
+  : ProcessInfo(name, arch, pid) {}
 
   void Clear() {
 ProcessInfo::Clear();
-m_euid = UINT32_MAX;
-m_egid = UINT32_MAX;
-m_parent_pid = LLDB_INVALID_PROCESS_ID;
+m_euid = std::nullopt;
+m_egid = std::nullopt;
+m_parent_pid = std::nullopt;
   }
 
-  uint32_t GetEffectiveUserID() const { return m_euid; }
+  uint32_t GetEffectiveUserID() const { return m_euid.value(); }

feg208 wrote:

yeah. I of the same view

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Fred Grim via lldb-commits

https://github.com/feg208 updated 
https://github.com/llvm/llvm-project/pull/91544

>From 8f694b7ab4436c0540284cbbf280ad557a750920 Mon Sep 17 00:00:00 2001
From: Fred Grim 
Date: Wed, 8 May 2024 15:36:16 -0700
Subject: [PATCH] [lldb] Adds additional fields to ProcessInfo

To implement SaveCore for elf binaries we need to populate some
additional fields in the prpsinfo struct. Those fields are the nice
value of the process whose core is to be taken as well as a boolean
flag indicating whether or not that process is a zombie. This commit
adds those as well as tests to ensure that the values are consistent
with expectations
---
 lldb/include/lldb/Utility/ProcessInfo.h | 24 ++-
 lldb/source/Host/linux/Host.cpp | 32 ++---
 lldb/source/Utility/ProcessInfo.cpp |  7 +++---
 lldb/unittests/Host/linux/HostTest.cpp  | 21 
 4 files changed, 67 insertions(+), 17 deletions(-)

diff --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index 54ac000dc7fc2..78ade4bbb1ee6 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -15,6 +15,7 @@
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/NameMatches.h"
 #include "lldb/Utility/StructuredData.h"
+#include 
 #include 
 
 namespace lldb_private {
@@ -147,8 +148,7 @@ class ProcessInstanceInfo : public ProcessInfo {
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
-  : ProcessInfo(name, arch, pid), m_euid(UINT32_MAX), m_egid(UINT32_MAX),
-m_parent_pid(LLDB_INVALID_PROCESS_ID) {}
+  : ProcessInfo(name, arch, pid) {}
 
   void Clear() {
 ProcessInfo::Clear();
@@ -237,6 +237,16 @@ class ProcessInstanceInfo : public ProcessInfo {
m_cumulative_system_time.tv_usec > 0;
   }
 
+  std::optional GetPriorityValue() const { return m_priority_value; }
+
+  void SetPriorityValue(int8_t priority_value) {
+m_priority_value = priority_value;
+  }
+
+  void SetIsZombie(bool is_zombie) { m_zombie = is_zombie; }
+
+  std::optional IsZombie() const { return m_zombie; }
+
   void Dump(Stream , UserIDResolver ) const;
 
   static void DumpTableHeader(Stream , bool show_args, bool verbose);
@@ -250,10 +260,12 @@ class ProcessInstanceInfo : public ProcessInfo {
   lldb::pid_t m_parent_pid = LLDB_INVALID_PROCESS_ID;
   lldb::pid_t m_process_group_id = LLDB_INVALID_PROCESS_ID;
   lldb::pid_t m_process_session_id = LLDB_INVALID_PROCESS_ID;
-  struct timespec m_user_time {};
-  struct timespec m_system_time {};
-  struct timespec m_cumulative_user_time {};
-  struct timespec m_cumulative_system_time {};
+  struct timespec m_user_time;
+  struct timespec m_system_time;
+  struct timespec m_cumulative_user_time;
+  struct timespec m_cumulative_system_time;
+  std::optional m_priority_value = std::nullopt;
+  std::optional m_zombie = std::nullopt;
 };
 
 typedef std::vector ProcessInstanceInfoList;
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index c6490f2fc9e2f..5545f9ef4d70e 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 
,
   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",
- _fields.pid, stat_fields.comm, _fields.state,
- _fields.ppid, _fields.pgrp, _fields.session,
- _fields.tty_nr, _fields.tpgid, _fields.flags,
- _fields.minflt, _fields.cminflt, _fields.majflt,
- _fields.cmajflt, _fields.utime, _fields.stime,
- _fields.cutime, _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",
+  _fields.pid, stat_fields.comm, _fields.state,
+  _fields.ppid, _fields.pgrp, _fields.session,
+  _fields.tty_nr, _fields.tpgid, _fields.flags,
+  _fields.minflt, _fields.cminflt, _fields.majflt,
+  _fields.cmajflt, _fields.utime, _fields.stime,
+  _fields.cutime, _fields.cstime,
+  _fields.realtime_priority, _fields.priority) < 0) {
 return false;
   }
 
@@ -115,6 +124,11 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
 return ts;

[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Greg Clayton via lldb-commits


@@ -250,10 +268,12 @@ class ProcessInstanceInfo : public ProcessInfo {
   lldb::pid_t m_parent_pid = LLDB_INVALID_PROCESS_ID;
   lldb::pid_t m_process_group_id = LLDB_INVALID_PROCESS_ID;
   lldb::pid_t m_process_session_id = LLDB_INVALID_PROCESS_ID;
-  struct timespec m_user_time {};
-  struct timespec m_system_time {};
-  struct timespec m_cumulative_user_time {};
-  struct timespec m_cumulative_system_time {};
+  std::optional m_user_time = std::nullopt;
+  std::optional m_system_time = std::nullopt;
+  std::optional m_cumulative_user_time = std::nullopt;
+  std::optional m_cumulative_system_time = std::nullopt;
+  std::optional m_priority_value = std::nullopt;
+  std::optional m_zombie = std::nullopt;

clayborg wrote:

If we are going to make these optional, then the accessors should return 
optionals

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Greg Clayton via lldb-commits


@@ -195,48 +195,66 @@ class ProcessInstanceInfo : public ProcessInfo {
 return m_process_session_id != LLDB_INVALID_PROCESS_ID;
   }
 
-  struct timespec GetUserTime() const { return m_user_time; }
+  struct timespec GetUserTime() const { return m_user_time.value(); }
 
   void SetUserTime(struct timespec utime) { m_user_time = utime; }
 
   bool UserTimeIsValid() const {
-return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+return m_user_time.has_value() &&
+   (m_user_time->tv_sec > 0 || m_user_time->tv_usec > 0);
   }
 
-  struct timespec GetSystemTime() const { return m_system_time; }
+  struct timespec GetSystemTime() const { return m_system_time.value(); }
 
   void SetSystemTime(struct timespec stime) { m_system_time = stime; }
 
   bool SystemTimeIsValid() const {
-return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+return m_system_time.has_value() &&
+   (m_system_time->tv_sec > 0 || m_system_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeUserTime() const {
-return m_cumulative_user_time;
+return m_cumulative_user_time.value();
   }
 
   void SetCumulativeUserTime(struct timespec cutime) {
 m_cumulative_user_time = cutime;
   }
 
   bool CumulativeUserTimeIsValid() const {
-return m_cumulative_user_time.tv_sec > 0 ||
-   m_cumulative_user_time.tv_usec > 0;
+return m_cumulative_user_time.has_value() &&
+   (m_cumulative_user_time->tv_sec > 0 ||
+m_cumulative_user_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeSystemTime() const {
-return m_cumulative_system_time;
+return m_cumulative_system_time.value();
   }
 
   void SetCumulativeSystemTime(struct timespec cstime) {
 m_cumulative_system_time = cstime;
   }
 
   bool CumulativeSystemTimeIsValid() const {
-return m_cumulative_system_time.tv_sec > 0 ||
-   m_cumulative_system_time.tv_usec > 0;
+return m_cumulative_system_time.has_value() &&
+   (m_cumulative_system_time->tv_sec > 0 ||
+m_cumulative_system_time->tv_usec > 0);
   }
 
+  int8_t GetPriorityValue() const { return m_priority_value.value(); }
+
+  void SetPriorityValue(int8_t priority_value) {
+m_priority_value = priority_value;
+  }
+
+  bool PriorityValueIsValid() const;

clayborg wrote:

This should be removed as this is the point of using std::optionals. 

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Greg Clayton via lldb-commits


@@ -195,48 +195,66 @@ class ProcessInstanceInfo : public ProcessInfo {
 return m_process_session_id != LLDB_INVALID_PROCESS_ID;
   }
 
-  struct timespec GetUserTime() const { return m_user_time; }
+  struct timespec GetUserTime() const { return m_user_time.value(); }
 
   void SetUserTime(struct timespec utime) { m_user_time = utime; }
 
   bool UserTimeIsValid() const {
-return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+return m_user_time.has_value() &&
+   (m_user_time->tv_sec > 0 || m_user_time->tv_usec > 0);
   }
 
-  struct timespec GetSystemTime() const { return m_system_time; }
+  struct timespec GetSystemTime() const { return m_system_time.value(); }
 
   void SetSystemTime(struct timespec stime) { m_system_time = stime; }
 
   bool SystemTimeIsValid() const {
-return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+return m_system_time.has_value() &&
+   (m_system_time->tv_sec > 0 || m_system_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeUserTime() const {
-return m_cumulative_user_time;
+return m_cumulative_user_time.value();
   }
 
   void SetCumulativeUserTime(struct timespec cutime) {
 m_cumulative_user_time = cutime;
   }
 
   bool CumulativeUserTimeIsValid() const {
-return m_cumulative_user_time.tv_sec > 0 ||
-   m_cumulative_user_time.tv_usec > 0;
+return m_cumulative_user_time.has_value() &&
+   (m_cumulative_user_time->tv_sec > 0 ||
+m_cumulative_user_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeSystemTime() const {
-return m_cumulative_system_time;
+return m_cumulative_system_time.value();
   }
 
   void SetCumulativeSystemTime(struct timespec cstime) {
 m_cumulative_system_time = cstime;
   }
 
   bool CumulativeSystemTimeIsValid() const {
-return m_cumulative_system_time.tv_sec > 0 ||
-   m_cumulative_system_time.tv_usec > 0;
+return m_cumulative_system_time.has_value() &&
+   (m_cumulative_system_time->tv_sec > 0 ||
+m_cumulative_system_time->tv_usec > 0);
   }
 
+  int8_t GetPriorityValue() const { return m_priority_value.value(); }
+
+  void SetPriorityValue(int8_t priority_value) {
+m_priority_value = priority_value;
+  }
+
+  bool PriorityValueIsValid() const;
+
+  void SetIsZombie(bool is_zombie) { m_zombie = is_zombie; }
+
+  bool IsZombieValid() const { return m_zombie.has_value(); }
+
+  bool IsZombie() const { return m_zombie.value(); }

clayborg wrote:

If we are going to use optionals for m_zombie, then we don't need two 
functions, just return the optional:
```
std::optional GetIsZombie() const { return m_zombie; }
```
And callers will need to check if this has a value and set to a default value 
like:
```
bool is_zombie = proc_info.GetIsZombie().value_or(false);
```


https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Greg Clayton via lldb-commits


@@ -195,48 +195,66 @@ class ProcessInstanceInfo : public ProcessInfo {
 return m_process_session_id != LLDB_INVALID_PROCESS_ID;
   }
 
-  struct timespec GetUserTime() const { return m_user_time; }
+  struct timespec GetUserTime() const { return m_user_time.value(); }
 
   void SetUserTime(struct timespec utime) { m_user_time = utime; }
 
   bool UserTimeIsValid() const {
-return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+return m_user_time.has_value() &&
+   (m_user_time->tv_sec > 0 || m_user_time->tv_usec > 0);
   }
 
-  struct timespec GetSystemTime() const { return m_system_time; }
+  struct timespec GetSystemTime() const { return m_system_time.value(); }
 
   void SetSystemTime(struct timespec stime) { m_system_time = stime; }
 
   bool SystemTimeIsValid() const {
-return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+return m_system_time.has_value() &&
+   (m_system_time->tv_sec > 0 || m_system_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeUserTime() const {
-return m_cumulative_user_time;
+return m_cumulative_user_time.value();
   }
 
   void SetCumulativeUserTime(struct timespec cutime) {
 m_cumulative_user_time = cutime;
   }
 
   bool CumulativeUserTimeIsValid() const {
-return m_cumulative_user_time.tv_sec > 0 ||
-   m_cumulative_user_time.tv_usec > 0;
+return m_cumulative_user_time.has_value() &&
+   (m_cumulative_user_time->tv_sec > 0 ||
+m_cumulative_user_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeSystemTime() const {
-return m_cumulative_system_time;
+return m_cumulative_system_time.value();
   }
 
   void SetCumulativeSystemTime(struct timespec cstime) {
 m_cumulative_system_time = cstime;
   }
 
   bool CumulativeSystemTimeIsValid() const {
-return m_cumulative_system_time.tv_sec > 0 ||
-   m_cumulative_system_time.tv_usec > 0;
+return m_cumulative_system_time.has_value() &&
+   (m_cumulative_system_time->tv_sec > 0 ||
+m_cumulative_system_time->tv_usec > 0);
   }
 
+  int8_t GetPriorityValue() const { return m_priority_value.value(); }

clayborg wrote:

This function should return `std::optional` if we are going to use an 
optional value for `m_priority_value` as this is just a crash waiting to 
happen. Callers can provide figure out a good default value to use if this 
hasn't been set with code like:
```
int8_t priority = proc_info. GetPriorityValue().value_or(0);
```
But as it stands we are going to crash at some point if someone doesn't call 
`PriorityValueIsValid()` first. So lets either use std::optional and return 
std::optional, or just default to sane values without optionals.

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Greg Clayton via lldb-commits

https://github.com/clayborg requested changes to this pull request.

We should either truly use `std::optional` and return `std::optional` for 
all getters, or just not use them. This patch adds a `bool IsZombieValid()` 
which the user must know to call prior to calling `bool IsZombie()`, which is 
just a crash waiting to happen. So lets either use `std::optional` correclty, 
or remove it and use sane default values. I like the idea of using 
`std::optional` and suggested ways to provide default values with the 
`value_or(T)` calls clients can easily use.

So might suggest to revert any `struct timespec` optionals since we aren't 
using them at all, and use `std::optional` and return `std::optional` from the 
getter functions and have the clients use `value_or(T)` just for these two new 
functions.

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Greg Clayton via lldb-commits


@@ -195,48 +195,66 @@ class ProcessInstanceInfo : public ProcessInfo {
 return m_process_session_id != LLDB_INVALID_PROCESS_ID;
   }
 
-  struct timespec GetUserTime() const { return m_user_time; }
+  struct timespec GetUserTime() const { return m_user_time.value(); }
 
   void SetUserTime(struct timespec utime) { m_user_time = utime; }
 
   bool UserTimeIsValid() const {
-return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+return m_user_time.has_value() &&
+   (m_user_time->tv_sec > 0 || m_user_time->tv_usec > 0);
   }
 
-  struct timespec GetSystemTime() const { return m_system_time; }
+  struct timespec GetSystemTime() const { return m_system_time.value(); }
 
   void SetSystemTime(struct timespec stime) { m_system_time = stime; }
 
   bool SystemTimeIsValid() const {
-return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+return m_system_time.has_value() &&
+   (m_system_time->tv_sec > 0 || m_system_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeUserTime() const {
-return m_cumulative_user_time;
+return m_cumulative_user_time.value();
   }
 
   void SetCumulativeUserTime(struct timespec cutime) {
 m_cumulative_user_time = cutime;
   }
 
   bool CumulativeUserTimeIsValid() const {
-return m_cumulative_user_time.tv_sec > 0 ||
-   m_cumulative_user_time.tv_usec > 0;
+return m_cumulative_user_time.has_value() &&
+   (m_cumulative_user_time->tv_sec > 0 ||
+m_cumulative_user_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeSystemTime() const {
-return m_cumulative_system_time;
+return m_cumulative_system_time.value();
   }
 
   void SetCumulativeSystemTime(struct timespec cstime) {
 m_cumulative_system_time = cstime;
   }
 
   bool CumulativeSystemTimeIsValid() const {
-return m_cumulative_system_time.tv_sec > 0 ||
-   m_cumulative_system_time.tv_usec > 0;
+return m_cumulative_system_time.has_value() &&
+   (m_cumulative_system_time->tv_sec > 0 ||
+m_cumulative_system_time->tv_usec > 0);
   }
 
+  int8_t GetPriorityValue() const { return m_priority_value.value(); }
+
+  void SetPriorityValue(int8_t priority_value) {
+m_priority_value = priority_value;
+  }
+
+  bool PriorityValueIsValid() const;
+
+  void SetIsZombie(bool is_zombie) { m_zombie = is_zombie; }

clayborg wrote:

The setter here is fine

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Greg Clayton via lldb-commits


@@ -250,10 +268,12 @@ class ProcessInstanceInfo : public ProcessInfo {
   lldb::pid_t m_parent_pid = LLDB_INVALID_PROCESS_ID;
   lldb::pid_t m_process_group_id = LLDB_INVALID_PROCESS_ID;
   lldb::pid_t m_process_session_id = LLDB_INVALID_PROCESS_ID;
-  struct timespec m_user_time {};
-  struct timespec m_system_time {};
-  struct timespec m_cumulative_user_time {};
-  struct timespec m_cumulative_system_time {};
+  std::optional m_user_time = std::nullopt;
+  std::optional m_system_time = std::nullopt;
+  std::optional m_cumulative_user_time = std::nullopt;
+  std::optional m_cumulative_system_time = std::nullopt;

clayborg wrote:

Revert all `struct timespec` optionals because we aren't checking if they have 
values and we can crash when calling the accessors.

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Greg Clayton via lldb-commits

https://github.com/clayborg edited 
https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Greg Clayton via lldb-commits


@@ -147,96 +148,111 @@ class ProcessInstanceInfo : public ProcessInfo {
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
-  : ProcessInfo(name, arch, pid), m_euid(UINT32_MAX), m_egid(UINT32_MAX),
-m_parent_pid(LLDB_INVALID_PROCESS_ID) {}
+  : ProcessInfo(name, arch, pid) {}
 
   void Clear() {
 ProcessInfo::Clear();
-m_euid = UINT32_MAX;
-m_egid = UINT32_MAX;
-m_parent_pid = LLDB_INVALID_PROCESS_ID;
+m_euid = std::nullopt;
+m_egid = std::nullopt;
+m_parent_pid = std::nullopt;
   }
 
-  uint32_t GetEffectiveUserID() const { return m_euid; }
+  uint32_t GetEffectiveUserID() const { return m_euid.value(); }

clayborg wrote:

It is ok to not do all of the ivars at one, but for the `std::optional` stuff 
that remains, if we just call `.value()` and it hasn't been set we are going to 
throw an exception right? We either need to make these not optional, or return 
the optional when accessing and let the callers deal with the values no being 
available.

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Fred Grim via lldb-commits

feg208 wrote:


> A message like this that the PR is ready for re-review should be all you 
> need. Several folks left comments and they might be waiting for all of them 
> to be addressed before they take another look. 

Ok. @clayborg I think I have addressed your concerns but I'd love another look 
as you have time.

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

> Hello all. I am wondering what I can do to advance this patch? I think it is 
> required to support process save-core in linux for lldb. I'd love to move 
> this before adding static methods in ThreadEfCore.h to produce populated 
> prpsinfo and prstatus structs for inclusion in a generated corefile. Is there 
> someone else I should include on review here? @JDevlieghere? I am happy to 
> amend this in whatever way the community thinks works best for lldb.

A message like this that the PR is ready for re-review should be all you need. 
Several folks left comments and they might be waiting for all of them to be 
addressed before they take another look. If you don't hear back within a week, 
you can ping the patch to get reviewer's attention. 

There's some more info here: 
https://llvm.org/docs/CodeReview.html#lgtm-how-a-patch-is-accepted

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Fred Grim via lldb-commits

https://github.com/feg208 updated 
https://github.com/llvm/llvm-project/pull/91544

>From e7b1cf56dae4c93b871aeeeafc5b40752baf823e Mon Sep 17 00:00:00 2001
From: Fred Grim 
Date: Wed, 8 May 2024 15:36:16 -0700
Subject: [PATCH] [lldb] Adds additional fields to ProcessInfo

To implement SaveCore for elf binaries we need to populate some
additional fields in the prpsinfo struct. Those fields are the nice
value of the process whose core is to be taken as well as a boolean
flag indicating whether or not that process is a zombie. This commit
adds those as well as tests to ensure that the values are consistent
with expectations
---
 lldb/include/lldb/Utility/ProcessInfo.h | 52 +
 lldb/source/Host/linux/Host.cpp | 32 +++
 lldb/source/Utility/ProcessInfo.cpp | 11 --
 lldb/unittests/Host/linux/HostTest.cpp  | 21 ++
 4 files changed, 89 insertions(+), 27 deletions(-)

diff --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index 54ac000dc7fc2..6844211f05c74 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -15,6 +15,7 @@
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/NameMatches.h"
 #include "lldb/Utility/StructuredData.h"
+#include 
 #include 
 
 namespace lldb_private {
@@ -147,8 +148,7 @@ class ProcessInstanceInfo : public ProcessInfo {
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
-  : ProcessInfo(name, arch, pid), m_euid(UINT32_MAX), m_egid(UINT32_MAX),
-m_parent_pid(LLDB_INVALID_PROCESS_ID) {}
+  : ProcessInfo(name, arch, pid) {}
 
   void Clear() {
 ProcessInfo::Clear();
@@ -195,24 +195,26 @@ class ProcessInstanceInfo : public ProcessInfo {
 return m_process_session_id != LLDB_INVALID_PROCESS_ID;
   }
 
-  struct timespec GetUserTime() const { return m_user_time; }
+  struct timespec GetUserTime() const { return m_user_time.value(); }
 
   void SetUserTime(struct timespec utime) { m_user_time = utime; }
 
   bool UserTimeIsValid() const {
-return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+return m_user_time.has_value() &&
+   (m_user_time->tv_sec > 0 || m_user_time->tv_usec > 0);
   }
 
-  struct timespec GetSystemTime() const { return m_system_time; }
+  struct timespec GetSystemTime() const { return m_system_time.value(); }
 
   void SetSystemTime(struct timespec stime) { m_system_time = stime; }
 
   bool SystemTimeIsValid() const {
-return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+return m_system_time.has_value() &&
+   (m_system_time->tv_sec > 0 || m_system_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeUserTime() const {
-return m_cumulative_user_time;
+return m_cumulative_user_time.value();
   }
 
   void SetCumulativeUserTime(struct timespec cutime) {
@@ -220,12 +222,13 @@ class ProcessInstanceInfo : public ProcessInfo {
   }
 
   bool CumulativeUserTimeIsValid() const {
-return m_cumulative_user_time.tv_sec > 0 ||
-   m_cumulative_user_time.tv_usec > 0;
+return m_cumulative_user_time.has_value() &&
+   (m_cumulative_user_time->tv_sec > 0 ||
+m_cumulative_user_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeSystemTime() const {
-return m_cumulative_system_time;
+return m_cumulative_system_time.value();
   }
 
   void SetCumulativeSystemTime(struct timespec cstime) {
@@ -233,10 +236,25 @@ class ProcessInstanceInfo : public ProcessInfo {
   }
 
   bool CumulativeSystemTimeIsValid() const {
-return m_cumulative_system_time.tv_sec > 0 ||
-   m_cumulative_system_time.tv_usec > 0;
+return m_cumulative_system_time.has_value() &&
+   (m_cumulative_system_time->tv_sec > 0 ||
+m_cumulative_system_time->tv_usec > 0);
   }
 
+  int8_t GetPriorityValue() const { return m_priority_value.value(); }
+
+  void SetPriorityValue(int8_t priority_value) {
+m_priority_value = priority_value;
+  }
+
+  bool PriorityValueIsValid() const;
+
+  void SetIsZombie(bool is_zombie) { m_zombie = is_zombie; }
+
+  bool IsZombieValid() const { return m_zombie.has_value(); }
+
+  bool IsZombie() const { return m_zombie.value(); }
+
   void Dump(Stream , UserIDResolver ) const;
 
   static void DumpTableHeader(Stream , bool show_args, bool verbose);
@@ -250,10 +268,12 @@ class ProcessInstanceInfo : public ProcessInfo {
   lldb::pid_t m_parent_pid = LLDB_INVALID_PROCESS_ID;
   lldb::pid_t m_process_group_id = LLDB_INVALID_PROCESS_ID;
   lldb::pid_t m_process_session_id = LLDB_INVALID_PROCESS_ID;
-  struct timespec m_user_time {};
-  struct timespec m_system_time {};
-  struct timespec m_cumulative_user_time {};
-  struct timespec m_cumulative_system_time {};
+  std::optional m_user_time = std::nullopt;
+  std::optional m_system_time = std::nullopt;
+  std::optional m_cumulative_user_time = std::nullopt;
+  

[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-20 Thread Fred Grim via lldb-commits

feg208 wrote:

Hello all. I am wondering what I can do to advance this patch? I think it is 
required to support process save-core in linux for lldb. I'd love to move this 
before adding static methods in ThreadEfCore.h to produce populated prpsinfo 
and prstatus structs for inclusion in a generated corefile. Is there someone 
else I should include on review here? @JDevlieghere? I am happy to amend this 
in whatever way the community thinks works best for lldb.

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-15 Thread Fred Grim via lldb-commits

https://github.com/feg208 updated 
https://github.com/llvm/llvm-project/pull/91544

>From 8b9ffe9bfb20c5c911c1c08ef966b4ac1ac587a0 Mon Sep 17 00:00:00 2001
From: Fred Grim 
Date: Wed, 8 May 2024 15:36:16 -0700
Subject: [PATCH] [lldb] Adds additional fields to ProcessInfo

To implement SaveCore for elf binaries we need to populate some
additional fields in the prpsinfo struct. Those fields are the nice
value of the process whose core is to be taken as well as a boolean
flag indicating whether or not that process is a zombie. This commit
adds those as well as tests to ensure that the values are consistent
with expectations
---
 lldb/include/lldb/Utility/ProcessInfo.h | 52 +
 lldb/source/Host/linux/Host.cpp | 32 +++
 lldb/source/Utility/ProcessInfo.cpp | 11 --
 lldb/unittests/Host/linux/HostTest.cpp  | 21 ++
 4 files changed, 89 insertions(+), 27 deletions(-)

diff --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index 54ac000dc7fc2..6844211f05c74 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -15,6 +15,7 @@
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/NameMatches.h"
 #include "lldb/Utility/StructuredData.h"
+#include 
 #include 
 
 namespace lldb_private {
@@ -147,8 +148,7 @@ class ProcessInstanceInfo : public ProcessInfo {
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
-  : ProcessInfo(name, arch, pid), m_euid(UINT32_MAX), m_egid(UINT32_MAX),
-m_parent_pid(LLDB_INVALID_PROCESS_ID) {}
+  : ProcessInfo(name, arch, pid) {}
 
   void Clear() {
 ProcessInfo::Clear();
@@ -195,24 +195,26 @@ class ProcessInstanceInfo : public ProcessInfo {
 return m_process_session_id != LLDB_INVALID_PROCESS_ID;
   }
 
-  struct timespec GetUserTime() const { return m_user_time; }
+  struct timespec GetUserTime() const { return m_user_time.value(); }
 
   void SetUserTime(struct timespec utime) { m_user_time = utime; }
 
   bool UserTimeIsValid() const {
-return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+return m_user_time.has_value() &&
+   (m_user_time->tv_sec > 0 || m_user_time->tv_usec > 0);
   }
 
-  struct timespec GetSystemTime() const { return m_system_time; }
+  struct timespec GetSystemTime() const { return m_system_time.value(); }
 
   void SetSystemTime(struct timespec stime) { m_system_time = stime; }
 
   bool SystemTimeIsValid() const {
-return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+return m_system_time.has_value() &&
+   (m_system_time->tv_sec > 0 || m_system_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeUserTime() const {
-return m_cumulative_user_time;
+return m_cumulative_user_time.value();
   }
 
   void SetCumulativeUserTime(struct timespec cutime) {
@@ -220,12 +222,13 @@ class ProcessInstanceInfo : public ProcessInfo {
   }
 
   bool CumulativeUserTimeIsValid() const {
-return m_cumulative_user_time.tv_sec > 0 ||
-   m_cumulative_user_time.tv_usec > 0;
+return m_cumulative_user_time.has_value() &&
+   (m_cumulative_user_time->tv_sec > 0 ||
+m_cumulative_user_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeSystemTime() const {
-return m_cumulative_system_time;
+return m_cumulative_system_time.value();
   }
 
   void SetCumulativeSystemTime(struct timespec cstime) {
@@ -233,10 +236,25 @@ class ProcessInstanceInfo : public ProcessInfo {
   }
 
   bool CumulativeSystemTimeIsValid() const {
-return m_cumulative_system_time.tv_sec > 0 ||
-   m_cumulative_system_time.tv_usec > 0;
+return m_cumulative_system_time.has_value() &&
+   (m_cumulative_system_time->tv_sec > 0 ||
+m_cumulative_system_time->tv_usec > 0);
   }
 
+  int8_t GetPriorityValue() const { return m_priority_value.value(); }
+
+  void SetPriorityValue(int8_t priority_value) {
+m_priority_value = priority_value;
+  }
+
+  bool PriorityValueIsValid() const;
+
+  void SetIsZombie(bool is_zombie) { m_zombie = is_zombie; }
+
+  bool IsZombieValid() const { return m_zombie.has_value(); }
+
+  bool IsZombie() const { return m_zombie.value(); }
+
   void Dump(Stream , UserIDResolver ) const;
 
   static void DumpTableHeader(Stream , bool show_args, bool verbose);
@@ -250,10 +268,12 @@ class ProcessInstanceInfo : public ProcessInfo {
   lldb::pid_t m_parent_pid = LLDB_INVALID_PROCESS_ID;
   lldb::pid_t m_process_group_id = LLDB_INVALID_PROCESS_ID;
   lldb::pid_t m_process_session_id = LLDB_INVALID_PROCESS_ID;
-  struct timespec m_user_time {};
-  struct timespec m_system_time {};
-  struct timespec m_cumulative_user_time {};
-  struct timespec m_cumulative_system_time {};
+  std::optional m_user_time = std::nullopt;
+  std::optional m_system_time = std::nullopt;
+  std::optional m_cumulative_user_time = std::nullopt;
+  

[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-15 Thread Fred Grim via lldb-commits


@@ -147,96 +148,111 @@ class ProcessInstanceInfo : public ProcessInfo {
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
-  : ProcessInfo(name, arch, pid), m_euid(UINT32_MAX), m_egid(UINT32_MAX),
-m_parent_pid(LLDB_INVALID_PROCESS_ID) {}
+  : ProcessInfo(name, arch, pid) {}
 
   void Clear() {
 ProcessInfo::Clear();
-m_euid = UINT32_MAX;
-m_egid = UINT32_MAX;
-m_parent_pid = LLDB_INVALID_PROCESS_ID;
+m_euid = std::nullopt;
+m_egid = std::nullopt;
+m_parent_pid = std::nullopt;
   }
 
-  uint32_t GetEffectiveUserID() const { return m_euid; }
+  uint32_t GetEffectiveUserID() const { return m_euid.value(); }

feg208 wrote:

@clayborg I made the changes referenced above (i.e. backed out the optionals 
for the pid/uid/gid fields). Is this a dealbreaker for you? Or do you think we 
can revisit at a later time?

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-15 Thread Fred Grim via lldb-commits

https://github.com/feg208 updated 
https://github.com/llvm/llvm-project/pull/91544

>From b35ded1c20bb67df941bb7c54aece789a18cde99 Mon Sep 17 00:00:00 2001
From: Fred Grim 
Date: Wed, 8 May 2024 15:36:16 -0700
Subject: [PATCH] [lldb] Adds additional fields to ProcessInfo

To implement SaveCore for elf binaries we need to populate some
additional fields in the prpsinfo struct. Those fields are the nice
value of the process whose core is to be taken as well as a boolean
flag indicating whether or not that process is a zombie. This commit
adds those as well as tests to ensure that the values are consistent
with expectations
---
 lldb/include/lldb/Utility/ProcessInfo.h | 64 -
 lldb/source/Host/linux/Host.cpp | 32 +
 lldb/source/Utility/ProcessInfo.cpp | 11 +++--
 lldb/unittests/Host/linux/HostTest.cpp  | 21 
 4 files changed, 94 insertions(+), 34 deletions(-)

diff --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index 54ac000dc7fc2..363a81d4e874f 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -15,6 +15,7 @@
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/NameMatches.h"
 #include "lldb/Utility/StructuredData.h"
+#include 
 #include 
 
 namespace lldb_private {
@@ -147,8 +148,7 @@ class ProcessInstanceInfo : public ProcessInfo {
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
-  : ProcessInfo(name, arch, pid), m_euid(UINT32_MAX), m_egid(UINT32_MAX),
-m_parent_pid(LLDB_INVALID_PROCESS_ID) {}
+  : ProcessInfo(name, arch, pid) {}
 
   void Clear() {
 ProcessInfo::Clear();
@@ -173,19 +173,17 @@ class ProcessInstanceInfo : public ProcessInfo {
 
   void SetParentProcessID(lldb::pid_t pid) { m_parent_pid = pid; }
 
-  bool ParentProcessIDIsValid() const {
-return m_parent_pid != LLDB_INVALID_PROCESS_ID;
-  }
+  bool ParentProcessIDIsValid() const { return m_parent_pid != 
LLDB_INVALID_PROCESS_ID; }
 
   lldb::pid_t GetProcessGroupID() const { return m_process_group_id; }
 
   void SetProcessGroupID(lldb::pid_t pgrp) { m_process_group_id = pgrp; }
 
-  bool ProcessGroupIDIsValid() const {
-return m_process_group_id != LLDB_INVALID_PROCESS_ID;
-  }
+  bool ProcessGroupIDIsValid() const { return m_process_group_id != 
LLDB_INVALID_PROCESS_ID; }
 
-  lldb::pid_t GetProcessSessionID() const { return m_process_session_id; }
+  lldb::pid_t GetProcessSessionID() const {
+return m_process_session_id;
+  }
 
   void SetProcessSessionID(lldb::pid_t session) {
 m_process_session_id = session;
@@ -195,24 +193,26 @@ class ProcessInstanceInfo : public ProcessInfo {
 return m_process_session_id != LLDB_INVALID_PROCESS_ID;
   }
 
-  struct timespec GetUserTime() const { return m_user_time; }
+  struct timespec GetUserTime() const { return m_user_time.value(); }
 
   void SetUserTime(struct timespec utime) { m_user_time = utime; }
 
   bool UserTimeIsValid() const {
-return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+return m_user_time.has_value() &&
+   (m_user_time->tv_sec > 0 || m_user_time->tv_usec > 0);
   }
 
-  struct timespec GetSystemTime() const { return m_system_time; }
+  struct timespec GetSystemTime() const { return m_system_time.value(); }
 
   void SetSystemTime(struct timespec stime) { m_system_time = stime; }
 
   bool SystemTimeIsValid() const {
-return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+return m_system_time.has_value() &&
+   (m_system_time->tv_sec > 0 || m_system_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeUserTime() const {
-return m_cumulative_user_time;
+return m_cumulative_user_time.value();
   }
 
   void SetCumulativeUserTime(struct timespec cutime) {
@@ -220,12 +220,13 @@ class ProcessInstanceInfo : public ProcessInfo {
   }
 
   bool CumulativeUserTimeIsValid() const {
-return m_cumulative_user_time.tv_sec > 0 ||
-   m_cumulative_user_time.tv_usec > 0;
+return m_cumulative_user_time.has_value() &&
+   (m_cumulative_user_time->tv_sec > 0 ||
+m_cumulative_user_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeSystemTime() const {
-return m_cumulative_system_time;
+return m_cumulative_system_time.value();
   }
 
   void SetCumulativeSystemTime(struct timespec cstime) {
@@ -233,10 +234,25 @@ class ProcessInstanceInfo : public ProcessInfo {
   }
 
   bool CumulativeSystemTimeIsValid() const {
-return m_cumulative_system_time.tv_sec > 0 ||
-   m_cumulative_system_time.tv_usec > 0;
+return m_cumulative_system_time.has_value() &&
+   (m_cumulative_system_time->tv_sec > 0 ||
+m_cumulative_system_time->tv_usec > 0);
+  }
+
+  int8_t GetPriorityValue() const { return m_priority_value.value(); }
+
+  void SetPriorityValue(int8_t priority_value) {
+m_priority_value = 

[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-13 Thread Fred Grim via lldb-commits

https://github.com/feg208 updated 
https://github.com/llvm/llvm-project/pull/91544

>From dbb4b4126754be15ffd9d12d9997e4969f7ba5cf Mon Sep 17 00:00:00 2001
From: Fred Grim 
Date: Wed, 8 May 2024 15:36:16 -0700
Subject: [PATCH] [lldb] Adds additional fields to ProcessInfo

To implement SaveCore for elf binaries we need to populate some
additional fields in the prpsinfo struct. Those fields are the nice
value of the process whose core is to be taken as well as a boolean
flag indicating whether or not that process is a zombie. This commit
adds those as well as tests to ensure that the values are consistent
with expectations
---
 lldb/include/lldb/Utility/ProcessInfo.h | 94 +++--
 lldb/source/Host/linux/Host.cpp | 32 ++---
 lldb/source/Utility/ProcessInfo.cpp | 11 ++-
 lldb/unittests/Host/linux/HostTest.cpp  | 21 ++
 4 files changed, 109 insertions(+), 49 deletions(-)

diff --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index 54ac000dc7fc2..995873a6869e0 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -15,6 +15,7 @@
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/NameMatches.h"
 #include "lldb/Utility/StructuredData.h"
+#include 
 #include 
 
 namespace lldb_private {
@@ -147,72 +148,71 @@ class ProcessInstanceInfo : public ProcessInfo {
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
-  : ProcessInfo(name, arch, pid), m_euid(UINT32_MAX), m_egid(UINT32_MAX),
-m_parent_pid(LLDB_INVALID_PROCESS_ID) {}
+  : ProcessInfo(name, arch, pid) {}
 
   void Clear() {
 ProcessInfo::Clear();
-m_euid = UINT32_MAX;
-m_egid = UINT32_MAX;
-m_parent_pid = LLDB_INVALID_PROCESS_ID;
+m_euid = std::nullopt;
+m_egid = std::nullopt;
+m_parent_pid = std::nullopt;
   }
 
-  uint32_t GetEffectiveUserID() const { return m_euid; }
+  uint32_t GetEffectiveUserID() const { return m_euid.value(); }
 
-  uint32_t GetEffectiveGroupID() const { return m_egid; }
+  uint32_t GetEffectiveGroupID() const { return m_egid.value(); }
 
-  bool EffectiveUserIDIsValid() const { return m_euid != UINT32_MAX; }
+  bool EffectiveUserIDIsValid() const { return m_euid.has_value(); }
 
-  bool EffectiveGroupIDIsValid() const { return m_egid != UINT32_MAX; }
+  bool EffectiveGroupIDIsValid() const { return m_egid.has_value(); }
 
   void SetEffectiveUserID(uint32_t uid) { m_euid = uid; }
 
   void SetEffectiveGroupID(uint32_t gid) { m_egid = gid; }
 
-  lldb::pid_t GetParentProcessID() const { return m_parent_pid; }
+  lldb::pid_t GetParentProcessID() const { return m_parent_pid.value(); }
 
   void SetParentProcessID(lldb::pid_t pid) { m_parent_pid = pid; }
 
-  bool ParentProcessIDIsValid() const {
-return m_parent_pid != LLDB_INVALID_PROCESS_ID;
-  }
+  bool ParentProcessIDIsValid() const { return m_parent_pid.has_value(); }
 
-  lldb::pid_t GetProcessGroupID() const { return m_process_group_id; }
+  lldb::pid_t GetProcessGroupID() const { return m_process_group_id.value(); }
 
   void SetProcessGroupID(lldb::pid_t pgrp) { m_process_group_id = pgrp; }
 
-  bool ProcessGroupIDIsValid() const {
-return m_process_group_id != LLDB_INVALID_PROCESS_ID;
-  }
+  bool ProcessGroupIDIsValid() const { return m_process_group_id.has_value(); }
 
-  lldb::pid_t GetProcessSessionID() const { return m_process_session_id; }
+  lldb::pid_t GetProcessSessionID() const {
+return m_process_session_id.value();
+  }
 
   void SetProcessSessionID(lldb::pid_t session) {
 m_process_session_id = session;
   }
 
   bool ProcessSessionIDIsValid() const {
-return m_process_session_id != LLDB_INVALID_PROCESS_ID;
+return m_process_session_id.has_value();
   }
 
-  struct timespec GetUserTime() const { return m_user_time; }
+  struct timespec GetUserTime() const { return m_user_time.value(); }
 
   void SetUserTime(struct timespec utime) { m_user_time = utime; }
 
   bool UserTimeIsValid() const {
-return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+return m_user_time.has_value() &&
+   (m_user_time->tv_sec > 0 || m_user_time->tv_usec > 0);
   }
 
-  struct timespec GetSystemTime() const { return m_system_time; }
+  struct timespec GetSystemTime() const { return m_system_time.value(); }
 
   void SetSystemTime(struct timespec stime) { m_system_time = stime; }
 
   bool SystemTimeIsValid() const {
-return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+return m_system_time.has_value() &&
+   (m_system_time->tv_sec > 0 || m_system_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeUserTime() const {
-return m_cumulative_user_time;
+return m_cumulative_user_time.value();
   }
 
   void SetCumulativeUserTime(struct timespec cutime) {
@@ -220,12 +220,13 @@ class ProcessInstanceInfo : public ProcessInfo {
   }
 
   bool CumulativeUserTimeIsValid() const {

[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-13 Thread Fred Grim via lldb-commits


@@ -147,96 +148,111 @@ class ProcessInstanceInfo : public ProcessInfo {
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
-  : ProcessInfo(name, arch, pid), m_euid(UINT32_MAX), m_egid(UINT32_MAX),
-m_parent_pid(LLDB_INVALID_PROCESS_ID) {}
+  : ProcessInfo(name, arch, pid) {}
 
   void Clear() {
 ProcessInfo::Clear();
-m_euid = UINT32_MAX;
-m_egid = UINT32_MAX;
-m_parent_pid = LLDB_INVALID_PROCESS_ID;
+m_euid = std::nullopt;
+m_egid = std::nullopt;
+m_parent_pid = std::nullopt;
   }
 
-  uint32_t GetEffectiveUserID() const { return m_euid; }
+  uint32_t GetEffectiveUserID() const { return m_euid.value(); }

feg208 wrote:

Maybe a better approach is to keep the optionals in the members that are 
particular to ProcessInstanceInfo (i.e. the time fields, priority, and the 
zombie fields) and revert the pid fields and the pid and uid/gid fields to the 
previous and punt that to a later pr. How does that sound? 

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-13 Thread Will Hawkins via lldb-commits

hawkinsw wrote:

> > Sorry for the nits! I am not smart enough to contribute on the technical 
> > merits, so I am trying to find some way to help!
> 
> Ehhh grammar is not where I shine. I rolled them up

Not at all! I thought the comments were really excellent and helpful! I just 
wanted to help if I could!

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-13 Thread Fred Grim via lldb-commits


@@ -147,96 +148,111 @@ class ProcessInstanceInfo : public ProcessInfo {
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
-  : ProcessInfo(name, arch, pid), m_euid(UINT32_MAX), m_egid(UINT32_MAX),
-m_parent_pid(LLDB_INVALID_PROCESS_ID) {}
+  : ProcessInfo(name, arch, pid) {}
 
   void Clear() {
 ProcessInfo::Clear();
-m_euid = UINT32_MAX;
-m_egid = UINT32_MAX;
-m_parent_pid = LLDB_INVALID_PROCESS_ID;
+m_euid = std::nullopt;
+m_egid = std::nullopt;
+m_parent_pid = std::nullopt;
   }
 
-  uint32_t GetEffectiveUserID() const { return m_euid; }
+  uint32_t GetEffectiveUserID() const { return m_euid.value(); }

feg208 wrote:

I don't have particularly strong feelings here but we should keep it consistent 
between this class and the parent class which has GetUID and GetGID neither of 
which returns a std::optional. Given the risk of std::bad_optional_access 
getting thrown thoughout I am coming to the notion that maybe we shouldn't use 
optionals here? If we have optionals I guess we are mandating that the paired 
IsValid must exist and must always be called. That seems like it'll create 
challenges. Can we go back to using invalid values like UINT32_MAX and maybe 
alter the interface to use optionals in a subsequent pr? This way we could 
debate the merits of this approach independent of adding a niceness field. 

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-13 Thread Fred Grim via lldb-commits

feg208 wrote:

> Sorry for the nits! I am not smart enough to contribute on the technical 
> merits, so I am trying to find some way to help!

Ehhh grammar is not where I shine. I rolled them up

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-13 Thread Fred Grim via lldb-commits


@@ -70,6 +71,12 @@ struct StatFields {
   long unsigned stime;
   long cutime;
   long cstime;
+  // in proc_pid_stat(5) this field is specified as priority

feg208 wrote:

done

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-13 Thread Fred Grim via lldb-commits


@@ -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

feg208 wrote:

done

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-13 Thread Fred Grim via lldb-commits


@@ -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

feg208 wrote:

done

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-13 Thread Fred Grim via lldb-commits


@@ -115,13 +124,19 @@ static bool GetStatusInfo(::pid_t Pid, 
ProcessInstanceInfo ,
 return ts;
   };
 
+  // priority (nice) values run from 19 to -20 inclusive (in linux). In the

feg208 wrote:

done

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-13 Thread Fred Grim via lldb-commits


@@ -115,13 +124,19 @@ static bool GetStatusInfo(::pid_t Pid, 
ProcessInstanceInfo ,
 return ts;
   };
 
+  // priority (nice) values run from 19 to -20 inclusive (in linux). In the
+  // prpsinfo struct pr_nice is a char

feg208 wrote:

done

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-13 Thread Fred Grim via lldb-commits


@@ -86,4 +89,22 @@ TEST_F(HostTest, GetProcessInfo) {
   ProcessInstanceInfo::timespec next_user_time = Info.GetUserTime();
   ASSERT_TRUE(user_time.tv_sec <= next_user_time.tv_sec ||
   user_time.tv_usec <= next_user_time.tv_usec);
+
+  struct rlimit rlim;
+  EXPECT_EQ(getrlimit(RLIMIT_NICE, ), 0);
+  // getpriority can return -1 so we zero errno first
+  errno = 0;
+  int prio = getpriority(PRIO_PROCESS, PRIO_PROCESS);
+  ASSERT_TRUE((prio < 0 && errno == 0) || prio >= 0);
+  ASSERT_EQ(Info.GetPriorityValue(), prio);
+  // If we can't raise our nice level then this test can't be performed

feg208 wrote:

done

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-13 Thread Fred Grim via lldb-commits

https://github.com/feg208 updated 
https://github.com/llvm/llvm-project/pull/91544

>From d01efd10f8a4b7d908acaa3237541bf6a83b4c7c Mon Sep 17 00:00:00 2001
From: Fred Grim 
Date: Wed, 8 May 2024 15:36:16 -0700
Subject: [PATCH] [lldb] Adds additional fields to ProcessInfo

To implement SaveCore for elf binaries we need to populate some
additional fields in the prpsinfo struct. Those fields are the nice
value of the process whose core is to be taken as well as a boolean
flag indicating whether or not that process is a zombie. This commit
adds those as well as tests to ensure that the values are consistent
with expectations
---
 lldb/include/lldb/Utility/ProcessInfo.h | 94 +++--
 lldb/source/Host/linux/Host.cpp | 32 ++---
 lldb/source/Utility/ProcessInfo.cpp | 11 ++-
 lldb/unittests/Host/linux/HostTest.cpp  | 21 ++
 4 files changed, 109 insertions(+), 49 deletions(-)

diff --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index 54ac000dc7fc2..995873a6869e0 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -15,6 +15,7 @@
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/NameMatches.h"
 #include "lldb/Utility/StructuredData.h"
+#include 
 #include 
 
 namespace lldb_private {
@@ -147,72 +148,71 @@ class ProcessInstanceInfo : public ProcessInfo {
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
-  : ProcessInfo(name, arch, pid), m_euid(UINT32_MAX), m_egid(UINT32_MAX),
-m_parent_pid(LLDB_INVALID_PROCESS_ID) {}
+  : ProcessInfo(name, arch, pid) {}
 
   void Clear() {
 ProcessInfo::Clear();
-m_euid = UINT32_MAX;
-m_egid = UINT32_MAX;
-m_parent_pid = LLDB_INVALID_PROCESS_ID;
+m_euid = std::nullopt;
+m_egid = std::nullopt;
+m_parent_pid = std::nullopt;
   }
 
-  uint32_t GetEffectiveUserID() const { return m_euid; }
+  uint32_t GetEffectiveUserID() const { return m_euid.value(); }
 
-  uint32_t GetEffectiveGroupID() const { return m_egid; }
+  uint32_t GetEffectiveGroupID() const { return m_egid.value(); }
 
-  bool EffectiveUserIDIsValid() const { return m_euid != UINT32_MAX; }
+  bool EffectiveUserIDIsValid() const { return m_euid.has_value(); }
 
-  bool EffectiveGroupIDIsValid() const { return m_egid != UINT32_MAX; }
+  bool EffectiveGroupIDIsValid() const { return m_egid.has_value(); }
 
   void SetEffectiveUserID(uint32_t uid) { m_euid = uid; }
 
   void SetEffectiveGroupID(uint32_t gid) { m_egid = gid; }
 
-  lldb::pid_t GetParentProcessID() const { return m_parent_pid; }
+  lldb::pid_t GetParentProcessID() const { return m_parent_pid.value(); }
 
   void SetParentProcessID(lldb::pid_t pid) { m_parent_pid = pid; }
 
-  bool ParentProcessIDIsValid() const {
-return m_parent_pid != LLDB_INVALID_PROCESS_ID;
-  }
+  bool ParentProcessIDIsValid() const { return m_parent_pid.has_value(); }
 
-  lldb::pid_t GetProcessGroupID() const { return m_process_group_id; }
+  lldb::pid_t GetProcessGroupID() const { return m_process_group_id.value(); }
 
   void SetProcessGroupID(lldb::pid_t pgrp) { m_process_group_id = pgrp; }
 
-  bool ProcessGroupIDIsValid() const {
-return m_process_group_id != LLDB_INVALID_PROCESS_ID;
-  }
+  bool ProcessGroupIDIsValid() const { return m_process_group_id.has_value(); }
 
-  lldb::pid_t GetProcessSessionID() const { return m_process_session_id; }
+  lldb::pid_t GetProcessSessionID() const {
+return m_process_session_id.value();
+  }
 
   void SetProcessSessionID(lldb::pid_t session) {
 m_process_session_id = session;
   }
 
   bool ProcessSessionIDIsValid() const {
-return m_process_session_id != LLDB_INVALID_PROCESS_ID;
+return m_process_session_id.has_value();
   }
 
-  struct timespec GetUserTime() const { return m_user_time; }
+  struct timespec GetUserTime() const { return m_user_time.value(); }
 
   void SetUserTime(struct timespec utime) { m_user_time = utime; }
 
   bool UserTimeIsValid() const {
-return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+return m_user_time.has_value() &&
+   (m_user_time->tv_sec > 0 || m_user_time->tv_usec > 0);
   }
 
-  struct timespec GetSystemTime() const { return m_system_time; }
+  struct timespec GetSystemTime() const { return m_system_time.value(); }
 
   void SetSystemTime(struct timespec stime) { m_system_time = stime; }
 
   bool SystemTimeIsValid() const {
-return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+return m_system_time.has_value() &&
+   (m_system_time->tv_sec > 0 || m_system_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeUserTime() const {
-return m_cumulative_user_time;
+return m_cumulative_user_time.value();
   }
 
   void SetCumulativeUserTime(struct timespec cutime) {
@@ -220,12 +220,13 @@ class ProcessInstanceInfo : public ProcessInfo {
   }
 
   bool CumulativeUserTimeIsValid() const {

[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-10 Thread Fred Grim via lldb-commits


@@ -144,6 +144,19 @@ class ProcessInstanceInfo : public ProcessInfo {
 long int tv_usec = 0;
   };
 
+  enum class ProcessState {
+Unknown,
+Dead,
+DiskSleep,
+Idle,
+Paging,
+Parked,
+Running,
+Sleeping,
+TracedOrStopped,
+Zombie,
+  };
+

feg208 wrote:

moved back

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-10 Thread Will Hawkins via lldb-commits


@@ -70,6 +71,12 @@ struct StatFields {
   long unsigned stime;
   long cutime;
   long cstime;
+  // in proc_pid_stat(5) this field is specified as priority

hawkinsw wrote:

```suggestion
  // In proc_pid_stat(5) this field is specified as priority
```

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-10 Thread Will Hawkins via lldb-commits


@@ -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

hawkinsw wrote:

```suggestion
  // naming here.
```

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-10 Thread Will Hawkins via lldb-commits


@@ -115,13 +124,19 @@ static bool GetStatusInfo(::pid_t Pid, 
ProcessInstanceInfo ,
 return ts;
   };
 
+  // priority (nice) values run from 19 to -20 inclusive (in linux). In the
+  // prpsinfo struct pr_nice is a char

hawkinsw wrote:

```suggestion
  // prpsinfo struct pr_nice is a char.
```

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-10 Thread Will Hawkins via lldb-commits


@@ -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

hawkinsw wrote:

```suggestion
  // nomenclature in ProcessInstanceInfo, we adopt the documented
```

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-10 Thread Will Hawkins via lldb-commits


@@ -115,13 +124,19 @@ static bool GetStatusInfo(::pid_t Pid, 
ProcessInstanceInfo ,
 return ts;
   };
 
+  // priority (nice) values run from 19 to -20 inclusive (in linux). In the

hawkinsw wrote:

```suggestion
  // Priority (nice) values run from 19 to -20 inclusive (in Linux). In the
```

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-10 Thread Will Hawkins via lldb-commits


@@ -86,4 +89,22 @@ TEST_F(HostTest, GetProcessInfo) {
   ProcessInstanceInfo::timespec next_user_time = Info.GetUserTime();
   ASSERT_TRUE(user_time.tv_sec <= next_user_time.tv_sec ||
   user_time.tv_usec <= next_user_time.tv_usec);
+
+  struct rlimit rlim;
+  EXPECT_EQ(getrlimit(RLIMIT_NICE, ), 0);
+  // getpriority can return -1 so we zero errno first
+  errno = 0;
+  int prio = getpriority(PRIO_PROCESS, PRIO_PROCESS);
+  ASSERT_TRUE((prio < 0 && errno == 0) || prio >= 0);
+  ASSERT_EQ(Info.GetPriorityValue(), prio);
+  // If we can't raise our nice level then this test can't be performed

hawkinsw wrote:

```suggestion
  // If we can't raise our nice level then this test can't be performed.
```

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-10 Thread Will Hawkins via lldb-commits

https://github.com/hawkinsw commented:

Sorry for the nits! I am not smart enough to contribute on the technical 
merits, so I am trying to find some way to help!

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-10 Thread Will Hawkins via lldb-commits

https://github.com/hawkinsw edited 
https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-10 Thread Greg Clayton via lldb-commits


@@ -147,96 +148,111 @@ class ProcessInstanceInfo : public ProcessInfo {
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
-  : ProcessInfo(name, arch, pid), m_euid(UINT32_MAX), m_egid(UINT32_MAX),
-m_parent_pid(LLDB_INVALID_PROCESS_ID) {}
+  : ProcessInfo(name, arch, pid) {}
 
   void Clear() {
 ProcessInfo::Clear();
-m_euid = UINT32_MAX;
-m_egid = UINT32_MAX;
-m_parent_pid = LLDB_INVALID_PROCESS_ID;
+m_euid = std::nullopt;
+m_egid = std::nullopt;
+m_parent_pid = std::nullopt;
   }
 
-  uint32_t GetEffectiveUserID() const { return m_euid; }
+  uint32_t GetEffectiveUserID() const { return m_euid.value(); }

clayborg wrote:

can we actually return `std::optional` here? Otherwise if someone 
calls this and `m_euid` doesn't have a value, then it will throw a 
`std::bad_optional_access` exception.

There is a `std::optional::value_or(T)`, but that will defeat the reason for 
adding a std::optional in the first place. So I see two options:
```
uint32_t GetEffectiveUserID(uint32_t default_value = 0) const { return 
m_euid.value_or(default_value); }
```
or
```
std::optional GetEffectiveUserID() const { return m_euid; }
```
I would prefer the latter, but now sure now many locations this will affect.

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-10 Thread Fred Grim via lldb-commits


@@ -91,14 +87,16 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
   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",
- _fields.pid, stat_fields.comm, _fields.state,
- _fields.ppid, _fields.pgrp, _fields.session,
- _fields.tty_nr, _fields.tpgid, _fields.flags,
- _fields.minflt, _fields.cminflt, _fields.majflt,
- _fields.cmajflt, _fields.utime, _fields.stime,
- _fields.cutime, _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",
+  _fields.pid, stat_fields.comm, _fields.state,
+  _fields.ppid, _fields.pgrp, _fields.session,
+  _fields.tty_nr, _fields.tpgid, _fields.flags,
+  _fields.minflt, _fields.cminflt, _fields.majflt,
+  _fields.cmajflt, _fields.utime, _fields.stime,
+  _fields.cutime, _fields.cstime,
+  _fields.realtime_priority, _fields.priority) < 0) {

feg208 wrote:

from proc_pid_stat(5)
```
(18) priority  %ld
 (Explanation for Linux 2.6) For processes running a 
real-time scheduling policy (policy below; see sched_setscheduler(2)), this is 
the negated scheduling priority, minus one; that is, a number in the range -2 
to -100, corresponding to  real-time
 priorities  1  to  99.   For processes running under a 
non-real-time scheduling policy, this is the raw nice value (setpriority(2)) as 
represented in the kernel.  The kernel stores nice values as numbers in the 
range 0 (high) to 39 (low), corre‐
 sponding to the user-visible nice range of -20 to 19.

 Before Linux 2.6, this was a scaled value based on the 
scheduler weighting given to this process.
```
so yes

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-10 Thread Fred Grim via lldb-commits

https://github.com/feg208 updated 
https://github.com/llvm/llvm-project/pull/91544

>From dbf56b2ebe93d2f3ef6e41bceb7359f6e10ae38d Mon Sep 17 00:00:00 2001
From: Fred Grim 
Date: Wed, 8 May 2024 15:36:16 -0700
Subject: [PATCH] [lldb] Adds additional fields to ProcessInfo

To implement SaveCore for elf binaries we need to populate some
additional fields in the prpsinfo struct. Those fields are the nice
value of the process whose core is to be taken as well as a boolean
flag indicating whether or not that process is a zombie. This commit
adds those as well as tests to ensure that the values are consistent
with expectations
---
 lldb/include/lldb/Utility/ProcessInfo.h | 94 +++--
 lldb/source/Host/linux/Host.cpp | 32 ++---
 lldb/source/Utility/ProcessInfo.cpp | 11 ++-
 lldb/unittests/Host/linux/HostTest.cpp  | 21 ++
 4 files changed, 109 insertions(+), 49 deletions(-)

diff --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index 54ac000dc7fc2..995873a6869e0 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -15,6 +15,7 @@
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/NameMatches.h"
 #include "lldb/Utility/StructuredData.h"
+#include 
 #include 
 
 namespace lldb_private {
@@ -147,72 +148,71 @@ class ProcessInstanceInfo : public ProcessInfo {
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
-  : ProcessInfo(name, arch, pid), m_euid(UINT32_MAX), m_egid(UINT32_MAX),
-m_parent_pid(LLDB_INVALID_PROCESS_ID) {}
+  : ProcessInfo(name, arch, pid) {}
 
   void Clear() {
 ProcessInfo::Clear();
-m_euid = UINT32_MAX;
-m_egid = UINT32_MAX;
-m_parent_pid = LLDB_INVALID_PROCESS_ID;
+m_euid = std::nullopt;
+m_egid = std::nullopt;
+m_parent_pid = std::nullopt;
   }
 
-  uint32_t GetEffectiveUserID() const { return m_euid; }
+  uint32_t GetEffectiveUserID() const { return m_euid.value(); }
 
-  uint32_t GetEffectiveGroupID() const { return m_egid; }
+  uint32_t GetEffectiveGroupID() const { return m_egid.value(); }
 
-  bool EffectiveUserIDIsValid() const { return m_euid != UINT32_MAX; }
+  bool EffectiveUserIDIsValid() const { return m_euid.has_value(); }
 
-  bool EffectiveGroupIDIsValid() const { return m_egid != UINT32_MAX; }
+  bool EffectiveGroupIDIsValid() const { return m_egid.has_value(); }
 
   void SetEffectiveUserID(uint32_t uid) { m_euid = uid; }
 
   void SetEffectiveGroupID(uint32_t gid) { m_egid = gid; }
 
-  lldb::pid_t GetParentProcessID() const { return m_parent_pid; }
+  lldb::pid_t GetParentProcessID() const { return m_parent_pid.value(); }
 
   void SetParentProcessID(lldb::pid_t pid) { m_parent_pid = pid; }
 
-  bool ParentProcessIDIsValid() const {
-return m_parent_pid != LLDB_INVALID_PROCESS_ID;
-  }
+  bool ParentProcessIDIsValid() const { return m_parent_pid.has_value(); }
 
-  lldb::pid_t GetProcessGroupID() const { return m_process_group_id; }
+  lldb::pid_t GetProcessGroupID() const { return m_process_group_id.value(); }
 
   void SetProcessGroupID(lldb::pid_t pgrp) { m_process_group_id = pgrp; }
 
-  bool ProcessGroupIDIsValid() const {
-return m_process_group_id != LLDB_INVALID_PROCESS_ID;
-  }
+  bool ProcessGroupIDIsValid() const { return m_process_group_id.has_value(); }
 
-  lldb::pid_t GetProcessSessionID() const { return m_process_session_id; }
+  lldb::pid_t GetProcessSessionID() const {
+return m_process_session_id.value();
+  }
 
   void SetProcessSessionID(lldb::pid_t session) {
 m_process_session_id = session;
   }
 
   bool ProcessSessionIDIsValid() const {
-return m_process_session_id != LLDB_INVALID_PROCESS_ID;
+return m_process_session_id.has_value();
   }
 
-  struct timespec GetUserTime() const { return m_user_time; }
+  struct timespec GetUserTime() const { return m_user_time.value(); }
 
   void SetUserTime(struct timespec utime) { m_user_time = utime; }
 
   bool UserTimeIsValid() const {
-return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+return m_user_time.has_value() &&
+   (m_user_time->tv_sec > 0 || m_user_time->tv_usec > 0);
   }
 
-  struct timespec GetSystemTime() const { return m_system_time; }
+  struct timespec GetSystemTime() const { return m_system_time.value(); }
 
   void SetSystemTime(struct timespec stime) { m_system_time = stime; }
 
   bool SystemTimeIsValid() const {
-return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+return m_system_time.has_value() &&
+   (m_system_time->tv_sec > 0 || m_system_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeUserTime() const {
-return m_cumulative_user_time;
+return m_cumulative_user_time.value();
   }
 
   void SetCumulativeUserTime(struct timespec cutime) {
@@ -220,12 +220,13 @@ class ProcessInstanceInfo : public ProcessInfo {
   }
 
   bool CumulativeUserTimeIsValid() const {

[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-10 Thread Fred Grim via lldb-commits


@@ -254,6 +280,8 @@ class ProcessInstanceInfo : public ProcessInfo {
   struct timespec m_system_time {};
   struct timespec m_cumulative_user_time {};
   struct timespec m_cumulative_system_time {};
+  std::optional m_priority_value = std::nullopt;
+  bool m_zombie = false;

feg208 wrote:

done

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-10 Thread Greg Clayton via lldb-commits


@@ -144,6 +144,19 @@ class ProcessInstanceInfo : public ProcessInfo {
 long int tv_usec = 0;
   };
 
+  enum class ProcessState {
+Unknown,
+Dead,
+DiskSleep,
+Idle,
+Paging,
+Parked,
+Running,
+Sleeping,
+TracedOrStopped,
+Zombie,
+  };
+

clayborg wrote:

There doesn't seem to be a reason for this to be here, so if we can move it 
back, that would be great. Ideally this file would be OS agnostic, but it 
started out a bit unix specific in the first place.

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-10 Thread Greg Clayton via lldb-commits


@@ -12,6 +12,9 @@
 #include "lldb/Utility/ProcessInfo.h"
 #include "gtest/gtest.h"
 
+#include 
+#include 

clayborg wrote:

This is fine if this is a host test, so nothing needs to be done. We are 
expecting linux + posix here which is fine.

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-10 Thread Greg Clayton via lldb-commits


@@ -254,6 +280,8 @@ class ProcessInstanceInfo : public ProcessInfo {
   struct timespec m_system_time {};
   struct timespec m_cumulative_user_time {};
   struct timespec m_cumulative_system_time {};
+  std::optional m_priority_value = std::nullopt;
+  bool m_zombie = false;

clayborg wrote:

making this optional as well would be good. If it isn't set, it means we don't 
know, but if it is set to true/false we do know. Again, almost all members of 
this structure could benefit from being std::optional

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-10 Thread Greg Clayton via lldb-commits


@@ -91,14 +87,16 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
   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",
- _fields.pid, stat_fields.comm, _fields.state,
- _fields.ppid, _fields.pgrp, _fields.session,
- _fields.tty_nr, _fields.tpgid, _fields.flags,
- _fields.minflt, _fields.cminflt, _fields.majflt,
- _fields.cmajflt, _fields.utime, _fields.stime,
- _fields.cutime, _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",
+  _fields.pid, stat_fields.comm, _fields.state,
+  _fields.ppid, _fields.pgrp, _fields.session,
+  _fields.tty_nr, _fields.tpgid, _fields.flags,
+  _fields.minflt, _fields.cminflt, _fields.majflt,
+  _fields.cmajflt, _fields.utime, _fields.stime,
+  _fields.cutime, _fields.cstime,
+  _fields.realtime_priority, _fields.priority) < 0) {

clayborg wrote:

are the priority fields always in this data? Just want to make sure that this 
`sscanf` call won't fail on some certain versions of linux/unix?

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-10 Thread Ed Maste via lldb-commits


@@ -12,6 +12,9 @@
 #include "lldb/Utility/ProcessInfo.h"
 #include "gtest/gtest.h"
 
+#include 
+#include 

emaste wrote:

Much of this file would work just fine on FreeBSD as well so that might make 
sense, although I'm not sure what the best structure would be -- maybe much of 
this file should move to a new lldb/unittests/Host/posix/HostTest.cpp, leaving 
anything Linux-specific here?

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-09 Thread Fred Grim via lldb-commits


@@ -237,6 +250,16 @@ class ProcessInstanceInfo : public ProcessInfo {
m_cumulative_system_time.tv_usec > 0;
   }
 
+  int8_t GetNiceValue() const { return m_nice_value; }

feg208 wrote:

prpsinfo has pr_nice field to be populated 
https://github.com/llvm/llvm-project/blob/main/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h#L99

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-09 Thread Fred Grim via lldb-commits


@@ -237,6 +250,16 @@ class ProcessInstanceInfo : public ProcessInfo {
m_cumulative_system_time.tv_usec > 0;
   }
 
+  int8_t GetNiceValue() const { return m_nice_value; }

feg208 wrote:

Done. Agreed. I also added a note in the linux specific code. In linuxland 
priority implies a realtime priority while nice is nice

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-09 Thread Fred Grim via lldb-commits


@@ -237,6 +250,16 @@ class ProcessInstanceInfo : public ProcessInfo {
m_cumulative_system_time.tv_usec > 0;
   }
 
+  int8_t GetNiceValue() const { return m_nice_value; }
+
+  void SetNiceValue(int8_t nice_value) { m_nice_value = nice_value; }
+
+  bool NiceValueIsValid() const;
+
+  void SetIsZombie() { m_zombie = true; }

feg208 wrote:

There is now

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-09 Thread Fred Grim via lldb-commits


@@ -17,6 +17,7 @@
 
 #include 
 #include 
+#include 

feg208 wrote:

removed

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-09 Thread Fred Grim via lldb-commits


@@ -117,6 +118,10 @@ bool ProcessInfo::IsScriptedProcess() const {
   return m_scripted_metadata_sp && *m_scripted_metadata_sp;
 }
 
+bool ProcessInstanceInfo::NiceValueIsValid() const {
+  return m_nice_value >= PRIO_MIN && m_nice_value <= PRIO_MAX;

feg208 wrote:

I removed this and just made the check to be a value stored in the optional

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-09 Thread Fred Grim via lldb-commits

https://github.com/feg208 updated 
https://github.com/llvm/llvm-project/pull/91544

>From 18b0d55d1c4e04842e531c7f7e304998f2b2ad4e Mon Sep 17 00:00:00 2001
From: Fred Grim 
Date: Wed, 8 May 2024 15:36:16 -0700
Subject: [PATCH] [lldb] Adds additional fields to ProcessInfo

To implement SaveCore for elf binaries we need to populate some
additional fields in the prpsinfo struct. Those fields are the nice
value of the process whose core is to be taken as well as a boolean
flag indicating whether or not that process is a zombie. This commit
adds those as well as tests to ensure that the values are consistent
with expectations
---
 lldb/include/lldb/Utility/ProcessInfo.h | 28 +++
 lldb/source/Host/linux/Host.cpp | 45 ++---
 lldb/source/Utility/ProcessInfo.cpp |  4 +++
 lldb/unittests/Host/linux/HostTest.cpp  | 20 +++
 4 files changed, 77 insertions(+), 20 deletions(-)

diff --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index 54ac000dc7fc..240f78d1c4e4 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -15,6 +15,7 @@
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/NameMatches.h"
 #include "lldb/Utility/StructuredData.h"
+#include 
 #include 
 
 namespace lldb_private {
@@ -144,6 +145,19 @@ class ProcessInstanceInfo : public ProcessInfo {
 long int tv_usec = 0;
   };
 
+  enum class ProcessState {
+Unknown,
+Dead,
+DiskSleep,
+Idle,
+Paging,
+Parked,
+Running,
+Sleeping,
+TracedOrStopped,
+Zombie,
+  };
+
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
@@ -237,6 +251,18 @@ class ProcessInstanceInfo : public ProcessInfo {
m_cumulative_system_time.tv_usec > 0;
   }
 
+  int8_t GetPriorityValue() const { return m_priority_value.value(); }
+
+  void SetPriorityValue(int8_t priority_value) {
+m_priority_value = priority_value;
+  }
+
+  bool PriorityValueIsValid() const;
+
+  void SetIsZombie(bool is_zombie = true) { m_zombie = is_zombie; }
+
+  bool IsZombie() const { return m_zombie; }
+
   void Dump(Stream , UserIDResolver ) const;
 
   static void DumpTableHeader(Stream , bool show_args, bool verbose);
@@ -254,6 +280,8 @@ class ProcessInstanceInfo : public ProcessInfo {
   struct timespec m_system_time {};
   struct timespec m_cumulative_user_time {};
   struct timespec m_cumulative_system_time {};
+  std::optional m_priority_value = std::nullopt;
+  bool m_zombie = false;
 };
 
 typedef std::vector ProcessInstanceInfoList;
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index c6490f2fc9e2..186323393c14 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -37,18 +37,8 @@ using namespace lldb;
 using namespace lldb_private;
 
 namespace {
-enum class ProcessState {
-  Unknown,
-  Dead,
-  DiskSleep,
-  Idle,
-  Paging,
-  Parked,
-  Running,
-  Sleeping,
-  TracedOrStopped,
-  Zombie,
-};
+
+using ProcessState = typename ProcessInstanceInfo::ProcessState;
 
 constexpr int task_comm_len = 16;
 
@@ -70,6 +60,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 +87,16 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
   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",
- _fields.pid, stat_fields.comm, _fields.state,
- _fields.ppid, _fields.pgrp, _fields.session,
- _fields.tty_nr, _fields.tpgid, _fields.flags,
- _fields.minflt, _fields.cminflt, _fields.majflt,
- _fields.cmajflt, _fields.utime, _fields.stime,
- _fields.cutime, _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",
+  _fields.pid, stat_fields.comm, _fields.state,
+  _fields.ppid, _fields.pgrp, _fields.session,
+  _fields.tty_nr, _fields.tpgid, _fields.flags,
+  _fields.minflt, _fields.cminflt, _fields.majflt,
+  _fields.cmajflt, _fields.utime, _fields.stime,
+  _fields.cutime, _fields.cstime,
+  _fields.realtime_priority, _fields.priority) < 0) {
 return false;
   }
 
@@ -115,6 +113,11 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
 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 = 

[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-09 Thread Ed Maste via lldb-commits


@@ -237,6 +250,16 @@ class ProcessInstanceInfo : public ProcessInfo {
m_cumulative_system_time.tv_usec > 0;
   }
 
+  int8_t GetNiceValue() const { return m_nice_value; }

emaste wrote:

nice and priority are not synonymous though, nice is one input into the 
process's priority. I'm not sure which we actually want in this context.

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-09 Thread Fred Grim via lldb-commits


@@ -12,6 +12,9 @@
 #include "lldb/Utility/ProcessInfo.h"
 #include "gtest/gtest.h"
 
+#include 
+#include 

feg208 wrote:

yeah. The cmake file enforces a linux-only build as well. However as @jimingham 
pointed out someone could plausibly move this into a non-linux build. Maybe I 
should place guards here and below? The functionality is in POSIX I think and 
my understanding is that windows would conform to POSIX to some degree. But to 
be honest I know very little about what happens on the windows side of the 
fence.

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-09 Thread Fred Grim via lldb-commits


@@ -254,6 +277,8 @@ class ProcessInstanceInfo : public ProcessInfo {
   struct timespec m_system_time {};
   struct timespec m_cumulative_user_time {};
   struct timespec m_cumulative_system_time {};
+  int8_t m_nice_value = INT8_MAX;

feg208 wrote:

yeah. I'll make this change. Especially here since priority can be in a range 
that has zero near the center

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-09 Thread Fred Grim via lldb-commits


@@ -144,6 +144,19 @@ class ProcessInstanceInfo : public ProcessInfo {
 long int tv_usec = 0;
   };
 
+  enum class ProcessState {
+Unknown,
+Dead,
+DiskSleep,
+Idle,
+Paging,
+Parked,
+Running,
+Sleeping,
+TracedOrStopped,
+Zombie,
+  };
+

feg208 wrote:

yeah. So if you look at the definition of ELFLinuxPrPsInfo there is a char 
member `pr_state` that will be something like T or Z or whatever. So we'd need 
these available to set that assuming we didn't want OS specific codes in there 
which are very linux specific (I found the mapping in the linux kernel code). 
Maybe we should move it back though? I mean for the purpose of generating a 
core the state is always going to be TraceOrStopped in any case.

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-08 Thread Greg Clayton via lldb-commits

https://github.com/clayborg edited 
https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-08 Thread Greg Clayton via lldb-commits


@@ -12,6 +12,9 @@
 #include "lldb/Utility/ProcessInfo.h"
 #include "gtest/gtest.h"
 
+#include 
+#include 

clayborg wrote:

it is ok to include this header file here because this is a linux specific host 
test.

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-08 Thread Greg Clayton via lldb-commits


@@ -17,6 +17,7 @@
 
 #include 
 #include 
+#include 

clayborg wrote:

Not every OS will have this header file, so I am not sure we can/should be 
importing this header. Windows build will most likely fail and any non unix 
based OS as well.

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-08 Thread Greg Clayton via lldb-commits


@@ -144,6 +144,19 @@ class ProcessInstanceInfo : public ProcessInfo {
 long int tv_usec = 0;
   };
 
+  enum class ProcessState {
+Unknown,
+Dead,
+DiskSleep,
+Idle,
+Paging,
+Parked,
+Running,
+Sleeping,
+TracedOrStopped,
+Zombie,
+  };
+

clayborg wrote:

This isn't used in this header file. Any reason this was moved here?

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-08 Thread Greg Clayton via lldb-commits


@@ -254,6 +277,8 @@ class ProcessInstanceInfo : public ProcessInfo {
   struct timespec m_system_time {};
   struct timespec m_cumulative_user_time {};
   struct timespec m_cumulative_system_time {};
+  int8_t m_nice_value = INT8_MAX;

clayborg wrote:

maybe make this a `std::optional`? It would be nice to know when/if 
things in `ProcessInstanceInfo` are set to value values or just defaulted. it 
might be nice to make many things in this class be std::optional as well so we 
know when we have a valid value and when we don't

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-08 Thread Greg Clayton via lldb-commits

https://github.com/clayborg requested changes to this pull request.

So `ProcessInstanceInfo` is already very OS specific, so I can't object to 
adding more OS specific information to this structure. It would be nice to 
abstract OS specific things into a dictionary so allow OS specific things to be 
added with OS specific key/value pairs, but since it is already very unix 
centric these changes are ok. We have to be careful to not include OS specific 
header files like `` as they won't be available on windows or 
other non linux OS versions. See inline comments for details.

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-08 Thread Greg Clayton via lldb-commits


@@ -117,6 +118,10 @@ bool ProcessInfo::IsScriptedProcess() const {
   return m_scripted_metadata_sp && *m_scripted_metadata_sp;
 }
 
+bool ProcessInstanceInfo::NiceValueIsValid() const {
+  return m_nice_value >= PRIO_MIN && m_nice_value <= PRIO_MAX;

clayborg wrote:

`PRIO_MIN` and `PRIO_MAX` come from linux/unix header and won't be available on 
other systems. I am also wondering if the `PRIO_MIN` and `PRIO_MAX` will differ 
from one linux OS to another? Probably best to not rely on these defines from 
OS specific header files, so I would suggest either manually defining them in 
this file or not checking the values.

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-08 Thread Greg Clayton via lldb-commits

https://github.com/clayborg edited 
https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-08 Thread Alex Langford via lldb-commits


@@ -237,6 +250,16 @@ class ProcessInstanceInfo : public ProcessInfo {
m_cumulative_system_time.tv_usec > 0;
   }
 
+  int8_t GetNiceValue() const { return m_nice_value; }
+
+  void SetNiceValue(int8_t nice_value) { m_nice_value = nice_value; }
+
+  bool NiceValueIsValid() const;
+
+  void SetIsZombie() { m_zombie = true; }

bulbazord wrote:

Is there a way to unset it being a zombie?

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-08 Thread Alex Langford via lldb-commits


@@ -237,6 +250,16 @@ class ProcessInstanceInfo : public ProcessInfo {
m_cumulative_system_time.tv_usec > 0;
   }
 
+  int8_t GetNiceValue() const { return m_nice_value; }

bulbazord wrote:

Suggestion: `nice` -> `priority_level` or something similar. The unix world 
uses the words `nice` and `niceness` but Windows and other platforms do not. 
It's also not a very obvious word if you lack the domain expertise.

https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-08 Thread via lldb-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 1aeb64c8ec7b96b2301929d8a325a6e1d9ddaa2f 
8355e9f14b898572d81721118e6a842d63652a33 -- 
lldb/include/lldb/Utility/ProcessInfo.h lldb/source/Host/linux/Host.cpp 
lldb/source/Utility/ProcessInfo.cpp lldb/unittests/Host/linux/HostTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index ddaa93c6d5..fb0fca2ccc 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -250,23 +250,15 @@ public:
m_cumulative_system_time.tv_usec > 0;
   }
 
-  int8_t GetNiceValue() const {
-return m_nice_value;
-  }
+  int8_t GetNiceValue() const { return m_nice_value; }
 
-  void SetNiceValue(int8_t nice_value) {
-m_nice_value = nice_value;
-  }
+  void SetNiceValue(int8_t nice_value) { m_nice_value = nice_value; }
 
   bool NiceValueIsValid() const;
 
-  void SetIsZombie() {
-m_zombie = true;
-  }
+  void SetIsZombie() { m_zombie = true; }
 
-  bool IsZombie() const {
-return m_zombie;
-  }
+  bool IsZombie() const { return m_zombie; }
 
   void Dump(Stream , UserIDResolver ) const;
 
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index c12bd259c5..ba2323990a 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -83,15 +83,16 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
   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 %ld 
%ld",
- _fields.pid, stat_fields.comm, _fields.state,
- _fields.ppid, _fields.pgrp, _fields.session,
- _fields.tty_nr, _fields.tpgid, _fields.flags,
- _fields.minflt, _fields.cminflt, _fields.majflt,
- _fields.cmajflt, _fields.utime, _fields.stime,
- _fields.cutime, _fields.cstime, _fields.priority,
- _fields.nice) < 0) {
+  if (sscanf(
+  Rest.data(),
+  "%d %s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld",
+  _fields.pid, stat_fields.comm, _fields.state,
+  _fields.ppid, _fields.pgrp, _fields.session,
+  _fields.tty_nr, _fields.tpgid, _fields.flags,
+  _fields.minflt, _fields.cminflt, _fields.majflt,
+  _fields.cmajflt, _fields.utime, _fields.stime,
+  _fields.cutime, _fields.cstime, _fields.priority,
+  _fields.nice) < 0) {
 return false;
   }
 
@@ -110,9 +111,8 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
 
   // nice values run from 19 to -20 inclusive (in linux). In the prpsinfo 
struct
   // pr_nice is a char
-  auto nice_value = static_cast(
-(stat_fields.nice < 0 ? 0x80 : 0x00) | (stat_fields.nice & 0x7f)
-  );
+  auto nice_value = static_cast((stat_fields.nice < 0 ? 0x80 : 0x00) |
+(stat_fields.nice & 0x7f));
 
   ProcessInfo.SetParentProcessID(stat_fields.ppid);
   ProcessInfo.SetProcessGroupID(stat_fields.pgrp);
diff --git a/lldb/source/Utility/ProcessInfo.cpp 
b/lldb/source/Utility/ProcessInfo.cpp
index de9992ec12..5add5fc8a8 100644
--- a/lldb/source/Utility/ProcessInfo.cpp
+++ b/lldb/source/Utility/ProcessInfo.cpp
@@ -15,9 +15,9 @@
 #include "lldb/Utility/UserIDResolver.h"
 #include "llvm/ADT/SmallString.h"
 
-#include 
 #include 
 #include 
+#include 
 
 using namespace lldb;
 using namespace lldb_private;
diff --git a/lldb/unittests/Host/linux/HostTest.cpp 
b/lldb/unittests/Host/linux/HostTest.cpp
index 310e6fe3e6..c1cc2d5277 100644
--- a/lldb/unittests/Host/linux/HostTest.cpp
+++ b/lldb/unittests/Host/linux/HostTest.cpp
@@ -12,8 +12,8 @@
 #include "lldb/Utility/ProcessInfo.h"
 #include "gtest/gtest.h"
 
-#include 
 #include 
+#include 
 #include 
 
 using namespace lldb_private;

``




https://github.com/llvm/llvm-project/pull/91544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-08 Thread Fred Grim via lldb-commits

https://github.com/feg208 updated 
https://github.com/llvm/llvm-project/pull/91544

>From 57e47b53682d43d2b1febba721688c6931c43291 Mon Sep 17 00:00:00 2001
From: Fred Grim 
Date: Wed, 8 May 2024 15:36:16 -0700
Subject: [PATCH] [lldb] Adds additional fields to ProcessInfo

To implement SaveCore for elf binaries we need to populate some
additional fields in the prpsinfo struct. Those fields are the nice
value of the process whose core is to be taken as well as a boolean
flag indicating whether or not that process is a zombie. This commit
adds those as well as tests to ensure that the values are consistent
with expectations
---
 lldb/include/lldb/Utility/ProcessInfo.h | 25 +++
 lldb/source/Host/linux/Host.cpp | 41 +
 lldb/source/Utility/ProcessInfo.cpp |  5 +++
 lldb/unittests/Host/linux/HostTest.cpp  | 20 
 4 files changed, 71 insertions(+), 20 deletions(-)

diff --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index 54ac000dc7fc2..fb0fca2cccbe3 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -144,6 +144,19 @@ class ProcessInstanceInfo : public ProcessInfo {
 long int tv_usec = 0;
   };
 
+  enum class ProcessState {
+Unknown,
+Dead,
+DiskSleep,
+Idle,
+Paging,
+Parked,
+Running,
+Sleeping,
+TracedOrStopped,
+Zombie,
+  };
+
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
@@ -237,6 +250,16 @@ class ProcessInstanceInfo : public ProcessInfo {
m_cumulative_system_time.tv_usec > 0;
   }
 
+  int8_t GetNiceValue() const { return m_nice_value; }
+
+  void SetNiceValue(int8_t nice_value) { m_nice_value = nice_value; }
+
+  bool NiceValueIsValid() const;
+
+  void SetIsZombie() { m_zombie = true; }
+
+  bool IsZombie() const { return m_zombie; }
+
   void Dump(Stream , UserIDResolver ) const;
 
   static void DumpTableHeader(Stream , bool show_args, bool verbose);
@@ -254,6 +277,8 @@ class ProcessInstanceInfo : public ProcessInfo {
   struct timespec m_system_time {};
   struct timespec m_cumulative_user_time {};
   struct timespec m_cumulative_system_time {};
+  int8_t m_nice_value = INT8_MAX;
+  bool m_zombie = false;
 };
 
 typedef std::vector ProcessInstanceInfoList;
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index c6490f2fc9e2f..ba2323990adac 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -37,18 +37,8 @@ using namespace lldb;
 using namespace lldb_private;
 
 namespace {
-enum class ProcessState {
-  Unknown,
-  Dead,
-  DiskSleep,
-  Idle,
-  Paging,
-  Parked,
-  Running,
-  Sleeping,
-  TracedOrStopped,
-  Zombie,
-};
+
+using ProcessState = typename ProcessInstanceInfo::ProcessState;
 
 constexpr int task_comm_len = 16;
 
@@ -70,6 +60,8 @@ struct StatFields {
   long unsigned stime;
   long cutime;
   long cstime;
+  long priority;
+  long nice;
   //  other things. We don't need them below
 };
 }
@@ -91,14 +83,16 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
   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",
- _fields.pid, stat_fields.comm, _fields.state,
- _fields.ppid, _fields.pgrp, _fields.session,
- _fields.tty_nr, _fields.tpgid, _fields.flags,
- _fields.minflt, _fields.cminflt, _fields.majflt,
- _fields.cmajflt, _fields.utime, _fields.stime,
- _fields.cutime, _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",
+  _fields.pid, stat_fields.comm, _fields.state,
+  _fields.ppid, _fields.pgrp, _fields.session,
+  _fields.tty_nr, _fields.tpgid, _fields.flags,
+  _fields.minflt, _fields.cminflt, _fields.majflt,
+  _fields.cmajflt, _fields.utime, _fields.stime,
+  _fields.cutime, _fields.cstime, _fields.priority,
+  _fields.nice) < 0) {
 return false;
   }
 
@@ -115,6 +109,11 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
 return ts;
   };
 
+  // nice values run from 19 to -20 inclusive (in linux). In the prpsinfo 
struct
+  // pr_nice is a char
+  auto nice_value = static_cast((stat_fields.nice < 0 ? 0x80 : 0x00) |
+(stat_fields.nice & 0x7f));
+
   ProcessInfo.SetParentProcessID(stat_fields.ppid);
   ProcessInfo.SetProcessGroupID(stat_fields.pgrp);
   ProcessInfo.SetProcessSessionID(stat_fields.session);
@@ -122,6 +121,7 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
   ProcessInfo.SetSystemTime(convert(stat_fields.stime));
   ProcessInfo.SetCumulativeUserTime(convert(stat_fields.cutime));
   

[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-08 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Fred Grim (feg208)


Changes

To implement SaveCore for elf binaries we need to populate some additional 
fields in the prpsinfo struct. Those fields are the nice value of the process 
whose core is to be taken as well as a boolean flag indicating whether or not 
that process is a zombie. This commit adds those as well as tests to ensure 
that the values are consistent with expectations

---
Full diff: https://github.com/llvm/llvm-project/pull/91544.diff


4 Files Affected:

- (modified) lldb/include/lldb/Utility/ProcessInfo.h (+33) 
- (modified) lldb/source/Host/linux/Host.cpp (+15-14) 
- (modified) lldb/source/Utility/ProcessInfo.cpp (+5) 
- (modified) lldb/unittests/Host/linux/HostTest.cpp (+21) 


``diff
diff --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index 54ac000dc7fc2..ddaa93c6d5c91 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -144,6 +144,19 @@ class ProcessInstanceInfo : public ProcessInfo {
 long int tv_usec = 0;
   };
 
+  enum class ProcessState {
+Unknown,
+Dead,
+DiskSleep,
+Idle,
+Paging,
+Parked,
+Running,
+Sleeping,
+TracedOrStopped,
+Zombie,
+  };
+
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
@@ -237,6 +250,24 @@ class ProcessInstanceInfo : public ProcessInfo {
m_cumulative_system_time.tv_usec > 0;
   }
 
+  int8_t GetNiceValue() const {
+return m_nice_value;
+  }
+
+  void SetNiceValue(int8_t nice_value) {
+m_nice_value = nice_value;
+  }
+
+  bool NiceValueIsValid() const;
+
+  void SetIsZombie() {
+m_zombie = true;
+  }
+
+  bool IsZombie() const {
+return m_zombie;
+  }
+
   void Dump(Stream , UserIDResolver ) const;
 
   static void DumpTableHeader(Stream , bool show_args, bool verbose);
@@ -254,6 +285,8 @@ class ProcessInstanceInfo : public ProcessInfo {
   struct timespec m_system_time {};
   struct timespec m_cumulative_user_time {};
   struct timespec m_cumulative_system_time {};
+  int8_t m_nice_value = INT8_MAX;
+  bool m_zombie = false;
 };
 
 typedef std::vector ProcessInstanceInfoList;
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index c6490f2fc9e2f..c12bd259c5a7d 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -37,18 +37,8 @@ using namespace lldb;
 using namespace lldb_private;
 
 namespace {
-enum class ProcessState {
-  Unknown,
-  Dead,
-  DiskSleep,
-  Idle,
-  Paging,
-  Parked,
-  Running,
-  Sleeping,
-  TracedOrStopped,
-  Zombie,
-};
+
+using ProcessState = typename ProcessInstanceInfo::ProcessState;
 
 constexpr int task_comm_len = 16;
 
@@ -70,6 +60,8 @@ struct StatFields {
   long unsigned stime;
   long cutime;
   long cstime;
+  long priority;
+  long nice;
   //  other things. We don't need them below
 };
 }
@@ -92,13 +84,14 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
 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",
+ "%d %s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu %ld %ld %ld 
%ld",
  _fields.pid, stat_fields.comm, _fields.state,
  _fields.ppid, _fields.pgrp, _fields.session,
  _fields.tty_nr, _fields.tpgid, _fields.flags,
  _fields.minflt, _fields.cminflt, _fields.majflt,
  _fields.cmajflt, _fields.utime, _fields.stime,
- _fields.cutime, _fields.cstime) < 0) {
+ _fields.cutime, _fields.cstime, _fields.priority,
+ _fields.nice) < 0) {
 return false;
   }
 
@@ -115,6 +108,12 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
 return ts;
   };
 
+  // nice values run from 19 to -20 inclusive (in linux). In the prpsinfo 
struct
+  // pr_nice is a char
+  auto nice_value = static_cast(
+(stat_fields.nice < 0 ? 0x80 : 0x00) | (stat_fields.nice & 0x7f)
+  );
+
   ProcessInfo.SetParentProcessID(stat_fields.ppid);
   ProcessInfo.SetProcessGroupID(stat_fields.pgrp);
   ProcessInfo.SetProcessSessionID(stat_fields.session);
@@ -122,6 +121,7 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
   ProcessInfo.SetSystemTime(convert(stat_fields.stime));
   ProcessInfo.SetCumulativeUserTime(convert(stat_fields.cutime));
   ProcessInfo.SetCumulativeSystemTime(convert(stat_fields.cstime));
+  ProcessInfo.SetNiceValue(nice_value);
   switch (stat_fields.state) {
   case 'R':
 State = ProcessState::Running;
@@ -134,6 +134,7 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
 break;
   case 'Z':
 State = ProcessState::Zombie;
+ProcessInfo.SetIsZombie();
 break;
   case 'X':
 State = ProcessState::Dead;
diff --git a/lldb/source/Utility/ProcessInfo.cpp 
b/lldb/source/Utility/ProcessInfo.cpp
index 

[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-05-08 Thread Fred Grim via lldb-commits

https://github.com/feg208 created 
https://github.com/llvm/llvm-project/pull/91544

To implement SaveCore for elf binaries we need to populate some additional 
fields in the prpsinfo struct. Those fields are the nice value of the process 
whose core is to be taken as well as a boolean flag indicating whether or not 
that process is a zombie. This commit adds those as well as tests to ensure 
that the values are consistent with expectations

>From 8355e9f14b898572d81721118e6a842d63652a33 Mon Sep 17 00:00:00 2001
From: Fred Grim 
Date: Wed, 8 May 2024 15:36:16 -0700
Subject: [PATCH] [lldb] Adds additional fields to ProcessInfo

To implement SaveCore for elf binaries we need to populate some
additional fields in the prpsinfo struct. Those fields are the nice
value of the process whose core is to be taken as well as a boolean
flag indicating whether or not that process is a zombie. This commit
adds those as well as tests to ensure that the values are consistent
with expectations
---
 lldb/include/lldb/Utility/ProcessInfo.h | 33 +
 lldb/source/Host/linux/Host.cpp | 29 +++---
 lldb/source/Utility/ProcessInfo.cpp |  5 
 lldb/unittests/Host/linux/HostTest.cpp  | 21 
 4 files changed, 74 insertions(+), 14 deletions(-)

diff --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index 54ac000dc7fc2..ddaa93c6d5c91 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -144,6 +144,19 @@ class ProcessInstanceInfo : public ProcessInfo {
 long int tv_usec = 0;
   };
 
+  enum class ProcessState {
+Unknown,
+Dead,
+DiskSleep,
+Idle,
+Paging,
+Parked,
+Running,
+Sleeping,
+TracedOrStopped,
+Zombie,
+  };
+
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
@@ -237,6 +250,24 @@ class ProcessInstanceInfo : public ProcessInfo {
m_cumulative_system_time.tv_usec > 0;
   }
 
+  int8_t GetNiceValue() const {
+return m_nice_value;
+  }
+
+  void SetNiceValue(int8_t nice_value) {
+m_nice_value = nice_value;
+  }
+
+  bool NiceValueIsValid() const;
+
+  void SetIsZombie() {
+m_zombie = true;
+  }
+
+  bool IsZombie() const {
+return m_zombie;
+  }
+
   void Dump(Stream , UserIDResolver ) const;
 
   static void DumpTableHeader(Stream , bool show_args, bool verbose);
@@ -254,6 +285,8 @@ class ProcessInstanceInfo : public ProcessInfo {
   struct timespec m_system_time {};
   struct timespec m_cumulative_user_time {};
   struct timespec m_cumulative_system_time {};
+  int8_t m_nice_value = INT8_MAX;
+  bool m_zombie = false;
 };
 
 typedef std::vector ProcessInstanceInfoList;
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index c6490f2fc9e2f..c12bd259c5a7d 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -37,18 +37,8 @@ using namespace lldb;
 using namespace lldb_private;
 
 namespace {
-enum class ProcessState {
-  Unknown,
-  Dead,
-  DiskSleep,
-  Idle,
-  Paging,
-  Parked,
-  Running,
-  Sleeping,
-  TracedOrStopped,
-  Zombie,
-};
+
+using ProcessState = typename ProcessInstanceInfo::ProcessState;
 
 constexpr int task_comm_len = 16;
 
@@ -70,6 +60,8 @@ struct StatFields {
   long unsigned stime;
   long cutime;
   long cstime;
+  long priority;
+  long nice;
   //  other things. We don't need them below
 };
 }
@@ -92,13 +84,14 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
 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",
+ "%d %s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu %ld %ld %ld 
%ld",
  _fields.pid, stat_fields.comm, _fields.state,
  _fields.ppid, _fields.pgrp, _fields.session,
  _fields.tty_nr, _fields.tpgid, _fields.flags,
  _fields.minflt, _fields.cminflt, _fields.majflt,
  _fields.cmajflt, _fields.utime, _fields.stime,
- _fields.cutime, _fields.cstime) < 0) {
+ _fields.cutime, _fields.cstime, _fields.priority,
+ _fields.nice) < 0) {
 return false;
   }
 
@@ -115,6 +108,12 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
 return ts;
   };
 
+  // nice values run from 19 to -20 inclusive (in linux). In the prpsinfo 
struct
+  // pr_nice is a char
+  auto nice_value = static_cast(
+(stat_fields.nice < 0 ? 0x80 : 0x00) | (stat_fields.nice & 0x7f)
+  );
+
   ProcessInfo.SetParentProcessID(stat_fields.ppid);
   ProcessInfo.SetProcessGroupID(stat_fields.pgrp);
   ProcessInfo.SetProcessSessionID(stat_fields.session);
@@ -122,6 +121,7 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
   ProcessInfo.SetSystemTime(convert(stat_fields.stime));