Skip to content

[LLDB] Add IsCoreDumping to ProcessInstanceInfo #138580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 7, 2025

Conversation

Jlalond
Copy link
Contributor

@Jlalond Jlalond commented May 5, 2025

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. Which we acquire by reading it from /proc/pid/status

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

@Jlalond Jlalond requested review from DavidSpickett and labath May 5, 2025 20:35
@Jlalond Jlalond requested a review from JDevlieghere as a code owner May 5, 2025 20:35
@llvmbot llvmbot added the lldb label May 5, 2025
@llvmbot
Copy link
Member

llvmbot commented May 5, 2025

@llvm/pr-subscribers-lldb

Author: Jacob Lalonde (Jlalond)

Changes

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


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

3 Files Affected:

  • (modified) lldb/include/lldb/Utility/ProcessInfo.h (+6)
  • (modified) lldb/source/Host/linux/Host.cpp (+5)
  • (modified) lldb/unittests/Host/posix/HostTest.cpp (+3)
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..2e2d4fdd84097 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;
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

} else if (Line.consume_front("CoreDumping:")) {
uint32_t coredumping;
Line = Line.ltrim();
Line.consumeInteger(1, coredumping);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is calling:

    template <typename T> bool consumeInteger(unsigned Radix, T &Result) {
  • Radix of 1 means binary?
  • Parsing can fail, though now I look above and nothing else checks the return value, sigh...

This is new though, so can you make it check the return value and not set if it's false? The type is optional, so anyone making use of this is handling the "I don't know" state already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, I'll validate the return.

Copy link
Collaborator

@DavidSpickett DavidSpickett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you've checked the return value, this LGTM.

@Jlalond Jlalond merged commit 1ad57b5 into llvm:main May 7, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants