Skip to content

[sanitizer] VReport thread status for failed PTRACE_ATTACH #111901

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

Conversation

vitalybuka
Copy link
Collaborator

Such threads can cause false leak reports,
but often it's hard to diagnose the reason of
failed PTRACE_ATTACH. Maybe we can find
a clue from /proc/*/task/*/status

@llvmbot
Copy link
Member

llvmbot commented Oct 10, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Vitaly Buka (vitalybuka)

Changes

Such threads can cause false leak reports,
but often it's hard to diagnose the reason of
failed PTRACE_ATTACH. Maybe we can find
a clue from /proc/*/task/*/status


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

1 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp (+8)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
index d9f803a276dadc..a42f6ab1241796 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
@@ -148,6 +148,14 @@ bool ThreadSuspender::SuspendThread(tid_t tid) {
     // Log this event and move on.
     VReport(1, "Could not attach to thread %zu (errno %d).\n", (uptr)tid,
             pterrno);
+    if (common_flags()->verbosity >= 2) {
+      InternalScopedString path;
+      path.AppendF("/proc/%d/task/%llu/status", pid_, tid);
+      InternalMmapVector<char> buffer;
+      ReadFileToVector(path.data(), &buffer);
+      buffer.push_back(0);
+      VReport(2, "%s: %s\n", path.data(), buffer.data());
+    }
     return false;
   } else {
     VReport(2, "Attached to thread %zu.\n", (uptr)tid);

Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
@vitalybuka vitalybuka changed the base branch from users/vitalybuka/spr/main.sanitizer-vreport-thread-status-for-failed-ptrace_attach to main October 10, 2024 20:39
vitalybuka added a commit that referenced this pull request Oct 10, 2024
@vitalybuka vitalybuka merged commit af7fa27 into main Oct 10, 2024
7 of 9 checks passed
@vitalybuka vitalybuka deleted the users/vitalybuka/spr/sanitizer-vreport-thread-status-for-failed-ptrace_attach branch October 10, 2024 21:53
DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
Such threads can cause false leak reports,
but often it's hard to diagnose the reason of
failed PTRACE_ATTACH. Maybe we can find
a clue from `/proc/*/task/*/status`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants