https://github.com/Jlalond created 
https://github.com/llvm/llvm-project/pull/138580

This is the first useful patch in the series related to enabling `PTRACE_SEIZE` 
for processes Coredumping. In order to make the decision if we want to seize or 
attach, we need to expose that in processinfo.

We currently select a few entries from `/proc/pid/status`, and I now also 
extract CoreDumping.

Note that in status it is `CoreDumping` not `Coredumping`, so I kept with that, 
even if I prefer `Coredumping`

>From 03d5449b30f414e2a3f322f102101dc4b2c05c4f Mon Sep 17 00:00:00 2001
From: Jacob Lalonde <jalalo...@fb.com>
Date: Mon, 5 May 2025 11:33:05 -0700
Subject: [PATCH 1/2] Add IsCoredumping to ProcessInfo to use in the future of
 the ptrace_seize code

---
 lldb/include/lldb/Utility/ProcessInfo.h | 6 ++++++
 lldb/source/Host/linux/Host.cpp         | 5 +++++
 2 files changed, 11 insertions(+)

diff --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index 78ade4bbb1ee6..24041faad80bf 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -247,6 +247,11 @@ class ProcessInstanceInfo : public ProcessInfo {
 
   std::optional<bool> IsZombie() const { return m_zombie; }
 
+  // proc/../status specifies CoreDumping as the field
+  // so we match the case here.
+  void SetIsCoreDumping(bool is_coredumping) { m_coredumping = is_coredumping; 
}
+  std::optional<bool> IsCoreDumping() const { return m_coredumping; }
+
   void Dump(Stream &s, UserIDResolver &resolver) const;
 
   static void DumpTableHeader(Stream &s, bool show_args, bool verbose);
@@ -266,6 +271,7 @@ class ProcessInstanceInfo : public ProcessInfo {
   struct timespec m_cumulative_system_time;
   std::optional<int8_t> m_priority_value = std::nullopt;
   std::optional<bool> m_zombie = std::nullopt;
+  std::optional<bool> m_coredumping = std::nullopt;
 };
 
 typedef std::vector<ProcessInstanceInfo> ProcessInstanceInfoList;
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index 8b475a7ab5003..97e8024da6c07 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -213,6 +213,11 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
&ProcessInfo,
     } else if (Line.consume_front("Tgid:")) {
       Line = Line.ltrim();
       Line.consumeInteger(10, Tgid);
+    } else if (Line.consume_front("CoreDumping:")) {
+      uint32_t coredumping;
+      Line = Line.ltrim();
+      Line.consumeInteger(1, coredumping);
+      ProcessInfo.SetIsCoredumping(coredumping);
     }
   }
   return true;

>From 7e2b11ff8d63260d34ff63e9eeb2d519d887742c Mon Sep 17 00:00:00 2001
From: Jacob Lalonde <jalalo...@fb.com>
Date: Mon, 5 May 2025 13:18:31 -0700
Subject: [PATCH 2/2] Add test

---
 lldb/source/Host/linux/Host.cpp        | 2 +-
 lldb/unittests/Host/posix/HostTest.cpp | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index 97e8024da6c07..2e2d4fdd84097 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -217,7 +217,7 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
&ProcessInfo,
       uint32_t coredumping;
       Line = Line.ltrim();
       Line.consumeInteger(1, coredumping);
-      ProcessInfo.SetIsCoredumping(coredumping);
+      ProcessInfo.SetIsCoreDumping(coredumping);
     }
   }
   return true;
diff --git a/lldb/unittests/Host/posix/HostTest.cpp 
b/lldb/unittests/Host/posix/HostTest.cpp
index 5d50de3524d1e..082edccf4e774 100644
--- a/lldb/unittests/Host/posix/HostTest.cpp
+++ b/lldb/unittests/Host/posix/HostTest.cpp
@@ -115,5 +115,8 @@ TEST_F(HostTest, GetProcessInfoSetsPriority) {
   }
   ASSERT_TRUE(Info.IsZombie().has_value());
   ASSERT_FALSE(Info.IsZombie().value());
+
+  ASSERT_TRUE(Info.IsCoreDumping().has_value());
+  ASSERT_FALSE(Info.IsCoreDumping().value());
 }
 #endif

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to