diff options
author | Josh Gao | 2017-08-18 17:37:26 -0500 |
---|---|---|
committer | Josh Gao | 2017-08-18 18:16:58 -0500 |
commit | fd13bf0dcd374e98a3acd8e3d3672221aef94c7c (patch) | |
tree | 0b26dc2667b938e0c522307d80707b9eae88eb3b /debuggerd/crash_dump.cpp | |
parent | de6b44aa0ec047aacf277ce797574b50f406d589 (diff) | |
download | platform-system-core-fd13bf0dcd374e98a3acd8e3d3672221aef94c7c.tar.gz platform-system-core-fd13bf0dcd374e98a3acd8e3d3672221aef94c7c.tar.xz platform-system-core-fd13bf0dcd374e98a3acd8e3d3672221aef94c7c.zip |
crash_dump: print the identity of tracers.
Instead of printing a useless "ptrace attach failed: strerror(EPERM)"
message, print the name and pid of a competing tracer when we fail to
attach because a process is already being ptraced.
Bug: http://b/31531918
Test: debuggerd_test32, debuggerd_test64 on aosp_angler
Test: strace -p `pidof surfaceflinger`; debuggerd -b surfaceflinger
Change-Id: Ifd3f80fe03de30ff38c0e0068560a7b12875f29d
Diffstat (limited to 'debuggerd/crash_dump.cpp')
-rw-r--r-- | debuggerd/crash_dump.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/debuggerd/crash_dump.cpp b/debuggerd/crash_dump.cpp index 4b1e51dde..cd1da50f5 100644 --- a/debuggerd/crash_dump.cpp +++ b/debuggerd/crash_dump.cpp | |||
@@ -79,9 +79,27 @@ static bool pid_contains_tid(int pid_proc_fd, pid_t tid) { | |||
79 | return fstatat(pid_proc_fd, task_path.c_str(), &st, 0) == 0; | 79 | return fstatat(pid_proc_fd, task_path.c_str(), &st, 0) == 0; |
80 | } | 80 | } |
81 | 81 | ||
82 | static pid_t get_tracer(pid_t tracee) { | ||
83 | // Check to see if the thread is being ptraced by another process. | ||
84 | android::procinfo::ProcessInfo process_info; | ||
85 | if (android::procinfo::GetProcessInfo(tracee, &process_info)) { | ||
86 | return process_info.tracer; | ||
87 | } | ||
88 | return -1; | ||
89 | } | ||
90 | |||
82 | // Attach to a thread, and verify that it's still a member of the given process | 91 | // Attach to a thread, and verify that it's still a member of the given process |
83 | static bool ptrace_seize_thread(int pid_proc_fd, pid_t tid, std::string* error) { | 92 | static bool ptrace_seize_thread(int pid_proc_fd, pid_t tid, std::string* error) { |
84 | if (ptrace(PTRACE_SEIZE, tid, 0, 0) != 0) { | 93 | if (ptrace(PTRACE_SEIZE, tid, 0, 0) != 0) { |
94 | if (errno == EPERM) { | ||
95 | pid_t tracer = get_tracer(tid); | ||
96 | if (tracer != -1) { | ||
97 | *error = StringPrintf("failed to attach to thread %d, already traced by %d (%s)", tid, | ||
98 | tracer, get_process_name(tracer).c_str()); | ||
99 | return false; | ||
100 | } | ||
101 | } | ||
102 | |||
85 | *error = StringPrintf("failed to attach to thread %d: %s", tid, strerror(errno)); | 103 | *error = StringPrintf("failed to attach to thread %d: %s", tid, strerror(errno)); |
86 | return false; | 104 | return false; |
87 | } | 105 | } |