From 187be4adee9642aa3d3409cd036a4345c84aae6b Mon Sep 17 00:00:00 2001 From: Dave Allison Date: Mon, 8 Sep 2014 16:33:24 -0700 Subject: [PATCH 1/2] Add support for debugging ART to the dalvik.gdb script. This adds two commands: art-on art-off To the gdbclient script for debugging ART-based executables in gdb. The default is 'art-on' Bug: 17409881 Change-Id: I90a1aed603e50853a40d5f5ec1c9b168dc17ddc7 (cherry picked from commit 22382a4774d7e7b34cc28082cbe76e58ce48a44b) --- scripts/gdb/dalvik.gdb | 59 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/scripts/gdb/dalvik.gdb b/scripts/gdb/dalvik.gdb index cab0951d7..6ee8d1d71 100644 --- a/scripts/gdb/dalvik.gdb +++ b/scripts/gdb/dalvik.gdb @@ -49,3 +49,62 @@ document dbt frame. If omitted r5 will be used as the default (as the case in the interpreter and JIT'ed code). end + +# ART debugging. ART uses SIGSEGV signals for internal purposes. To allow +# gdb to debug programs using ART we need to treat this signal specially. We +# also set a breakpoint in a libart.so function to stop when the program +# hits an unexpected breakpoint +set $art_debug_enabled = 0 +define art-on + if $art_debug_enabled == 0 + # deal with SIGSEGV signals + handle SIGSEGV noprint nostop pass + + # set a breakpoint and record its number + set breakpoint pending on + break art_sigsegv_fault + set $art_bpnum = $bpnum + commands $art_bpnum + silent + printf "Caught SIGSEGV in user program\n" + end + set breakpoint pending auto + + printf "ART debugging mode is enabled.\n" + set $art_debug_enabled = 1 + else + printf "ART debugging mode is already enabled.\n" + end +end + +document art-on + Enter ART debugging mode. In ART debugging mode, SIGSEGV signals are ignored + by gdb unless they are not handled by ART itself. A breakpoint is + set to stop the program when an unexpected SIGSEGV signal is + encountered. + + To switch ART debugging mode off, use "art-off" +end + +define art-off + if $art_debug_enabled == 1 + # restore SIGSEGV to its default + handle SIGSEGV print stop pass + + # delete our breakpoint + delete $art_bpnum + + set $art_debug_enabled = 0 + printf "ART debugging mode is disabled.\n" + end +end + +document art-off + Leave ART debugging mode. Signal handling is restored to default settings. + + Use the command "art-on" to enable ART debugging mode. +end + +# switch on ART debugging +art-on + From 5661570266848dc7da7131e26f02bdfec392a9a5 Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Fri, 3 Oct 2014 17:31:41 -0700 Subject: [PATCH 2/2] Do not call art-on macro by default. If you are debugging a native process, SIGSEGV gets ignored by default. The gdbclient bash function has been modified to only call the art-on macro when running gdbclient app_processXX. Also, print a warning in case someone is trying to debug a native process using app_process. Bug: 17815162 Change-Id: I0666e6713b0a03ee713be7827c5b671938f2c263 (cherry picked from commit 436b740b705c4316d3d5b73f04cdff9b8b8714e8) --- scripts/gdb/dalvik.gdb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/gdb/dalvik.gdb b/scripts/gdb/dalvik.gdb index 6ee8d1d71..6281661ef 100644 --- a/scripts/gdb/dalvik.gdb +++ b/scripts/gdb/dalvik.gdb @@ -71,6 +71,9 @@ define art-on set breakpoint pending auto printf "ART debugging mode is enabled.\n" + printf "If you are debugging a native only process, you need to\n" + printf "re-enable normal SIGSEGV handling using this command:\n" + printf " handle SIGSEGV print stop\n" set $art_debug_enabled = 1 else printf "ART debugging mode is already enabled.\n" @@ -104,7 +107,3 @@ document art-off Use the command "art-on" to enable ART debugging mode. end - -# switch on ART debugging -art-on -