Skip to content

[lldb/telemetry] Report exit status only once #134078

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 1 commit into from
Apr 3, 2025
Merged

[lldb/telemetry] Report exit status only once #134078

merged 1 commit into from
Apr 3, 2025

Conversation

labath
Copy link
Collaborator

@labath labath commented Apr 2, 2025

SetExitStatus can be called the second time when we reap the debug server process. This shouldn't be interesting as at that point, we've already told everyone that the process has exited.

I believe/hope this will also help with sporadic shutdown crashes that have cropped up recently. They happen because the debug server is monitored from a detached thread, so this code can be called after main returns (and starts destroying everything). This isn't a real fix for that though, as the situation can still happen (it's just that it usually happens after the exit status has already been set). I think the real fix for that is to make sure these threads terminate before we start shutting everything down.

SetExitStatus can be called the second time when we reap the debug
server process. This shouldn't be interesting as at that point, we've
already told everyone that the process has exited.

I believe/hope this will also help with sporadic shutdown crashes that
have cropped up recently. They happen because the debug server is
monitored from a detached thread, so this code can be called after main
returns (and starts destroying everything). This isn't a real fix for
that though, as the situation can still happen (it's just that it
usually happens after the exit status has already been set). I think the
real fix for that is to make sure these threads terminate before we
start shutting everything down.
@labath labath requested a review from oontvoo April 2, 2025 12:44
@labath labath requested a review from JDevlieghere as a code owner April 2, 2025 12:44
@llvmbot llvmbot added the lldb label Apr 2, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 2, 2025

@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)

Changes

SetExitStatus can be called the second time when we reap the debug server process. This shouldn't be interesting as at that point, we've already told everyone that the process has exited.

I believe/hope this will also help with sporadic shutdown crashes that have cropped up recently. They happen because the debug server is monitored from a detached thread, so this code can be called after main returns (and starts destroying everything). This isn't a real fix for that though, as the situation can still happen (it's just that it usually happens after the exit status has already been set). I think the real fix for that is to make sure these threads terminate before we start shutting everything down.


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

1 Files Affected:

  • (modified) lldb/source/Target/Process.cpp (+14-14)
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 369933234ccca..7936cf28467b2 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -1067,6 +1067,20 @@ const char *Process::GetExitDescription() {
 bool Process::SetExitStatus(int status, llvm::StringRef exit_string) {
   // Use a mutex to protect setting the exit status.
   std::lock_guard<std::mutex> guard(m_exit_status_mutex);
+  Log *log(GetLog(LLDBLog::State | LLDBLog::Process));
+  LLDB_LOG(log, "(plugin = {0} status = {1} ({1:x8}), description=\"{2}\")",
+           GetPluginName(), status, exit_string);
+
+  // We were already in the exited state
+  if (m_private_state.GetValue() == eStateExited) {
+    LLDB_LOG(
+        log,
+        "(plugin = {0}) ignoring exit status because state was already set "
+        "to eStateExited",
+        GetPluginName());
+    return false;
+  }
+
   telemetry::ScopedDispatcher<telemetry::ProcessExitInfo> helper;
 
   UUID module_uuid;
@@ -1089,20 +1103,6 @@ bool Process::SetExitStatus(int status, llvm::StringRef exit_string) {
     info->pid = m_pid;
   });
 
-  Log *log(GetLog(LLDBLog::State | LLDBLog::Process));
-  LLDB_LOG(log, "(plugin = {0} status = {1} ({1:x8}), description=\"{2}\")",
-           GetPluginName(), status, exit_string);
-
-  // We were already in the exited state
-  if (m_private_state.GetValue() == eStateExited) {
-    LLDB_LOG(
-        log,
-        "(plugin = {0}) ignoring exit status because state was already set "
-        "to eStateExited",
-        GetPluginName());
-    return false;
-  }
-
   m_exit_status = status;
   if (!exit_string.empty())
     m_exit_string = exit_string.str();

@labath labath merged commit 662d385 into llvm:main Apr 3, 2025
12 checks passed
@labath labath deleted the exit branch April 3, 2025 09:59
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.

3 participants