summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Gao2018-06-14 17:03:12 -0500
committerJosh Gao2018-06-14 17:40:06 -0500
commit24113ae6415a2fdde38e71eec75458e0c697ad2f (patch)
tree0c8feceb7a0e2693e6e624d359737ce7a6407004 /debuggerd
parente5aa7ee753f88903b0506b542b629bbd54ef5092 (diff)
downloadplatform-system-core-24113ae6415a2fdde38e71eec75458e0c697ad2f.tar.gz
platform-system-core-24113ae6415a2fdde38e71eec75458e0c697ad2f.tar.xz
platform-system-core-24113ae6415a2fdde38e71eec75458e0c697ad2f.zip
debuggerd: add support for Java traces.
Test: `debuggerd -j $(pidof com.android.settings)` Change-Id: I051c9b6d313e5350416b3d0743c3fc75f43fbd0c
Diffstat (limited to 'debuggerd')
-rw-r--r--debuggerd/debuggerd.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/debuggerd/debuggerd.cpp b/debuggerd/debuggerd.cpp
index b016e23ee..360ea95b3 100644
--- a/debuggerd/debuggerd.cpp
+++ b/debuggerd/debuggerd.cpp
@@ -20,6 +20,7 @@
20#include <string.h> 20#include <string.h>
21 21
22#include <limits> 22#include <limits>
23#include <string_view>
23#include <thread> 24#include <thread>
24 25
25#include <android-base/file.h> 26#include <android-base/file.h>
@@ -33,9 +34,10 @@
33using android::base::unique_fd; 34using android::base::unique_fd;
34 35
35static void usage(int exit_code) { 36static void usage(int exit_code) {
36 fprintf(stderr, "usage: debuggerd [-b] PID\n"); 37 fprintf(stderr, "usage: debuggerd [-bj] PID\n");
37 fprintf(stderr, "\n"); 38 fprintf(stderr, "\n");
38 fprintf(stderr, "-b, --backtrace just a backtrace rather than a full tombstone\n"); 39 fprintf(stderr, "-b, --backtrace just a backtrace rather than a full tombstone\n");
40 fprintf(stderr, "-j collect java traces\n");
39 _exit(exit_code); 41 _exit(exit_code);
40} 42}
41 43
@@ -58,8 +60,19 @@ static std::thread spawn_redirect_thread(unique_fd fd) {
58int main(int argc, char* argv[]) { 60int main(int argc, char* argv[]) {
59 if (argc <= 1) usage(0); 61 if (argc <= 1) usage(0);
60 if (argc > 3) usage(1); 62 if (argc > 3) usage(1);
61 if (argc == 3 && strcmp(argv[1], "-b") != 0 && strcmp(argv[1], "--backtrace") != 0) usage(1); 63
62 bool backtrace_only = argc == 3; 64 DebuggerdDumpType dump_type = kDebuggerdTombstone;
65
66 if (argc == 3) {
67 std::string_view flag = argv[1];
68 if (flag == "-b" || flag == "--backtrace") {
69 dump_type = kDebuggerdNativeBacktrace;
70 } else if (flag == "-j") {
71 dump_type = kDebuggerdJavaBacktrace;
72 } else {
73 usage(1);
74 }
75 }
63 76
64 pid_t pid; 77 pid_t pid;
65 if (!android::base::ParseInt(argv[argc - 1], &pid, 1, std::numeric_limits<pid_t>::max())) { 78 if (!android::base::ParseInt(argv[argc - 1], &pid, 1, std::numeric_limits<pid_t>::max())) {
@@ -90,8 +103,7 @@ int main(int argc, char* argv[]) {
90 } 103 }
91 104
92 std::thread redirect_thread = spawn_redirect_thread(std::move(piperead)); 105 std::thread redirect_thread = spawn_redirect_thread(std::move(piperead));
93 if (!debuggerd_trigger_dump(pid, backtrace_only ? kDebuggerdNativeBacktrace : kDebuggerdTombstone, 106 if (!debuggerd_trigger_dump(pid, dump_type, 0, std::move(pipewrite))) {
94 0, std::move(pipewrite))) {
95 redirect_thread.join(); 107 redirect_thread.join();
96 errx(1, "failed to dump process %d", pid); 108 errx(1, "failed to dump process %d", pid);
97 } 109 }