1 # dump dalvik backtrace 2 define dbt 3 if $argc == 1 4 set $FP = $arg0 5 else 6 set $FP = $r5 7 end 8 9 set $frame = 0 10 set $savedPC = 0 11 while $FP 12 set $stackSave = $FP - sizeof(StackSaveArea) 13 set $savedPC = ((StackSaveArea *)$stackSave)->savedPc 14 set $method = ((StackSaveArea *)$stackSave)->method 15 printf "#%d\n", $frame 16 printf " FP = %#x\n", $FP 17 printf " stack save = %#x\n", $stackSave 18 printf " Curr pc = %#x\n", ((StackSaveArea *) $stackSave)->xtra.currentPc 19 printf " FP prev = %#x\n", ((StackSaveArea *) $stackSave)->prevFrame 20 if $method != 0 21 printf " returnAddr: 0x%x\n", \ 22 ((StackSaveArea *)$stackSave)->returnAddr 23 printf " class = %s\n", ((Method *) $method)->clazz->descriptor 24 printf " method = %s (%#08x)\n", ((Method *) $method)->name, $method 25 printf " signature = %s\n", ((Method *) $method)->shorty 26 printf " bytecode offset = 0x%x\n", (short *) (((StackSaveArea *) $stackSave)->xtra.currentPc) - (short *) (((Method *) $method)->insns) 27 set $regSize = ((Method *) $method)->registersSize 28 set $insSize = ((Method *) $method)->insSize 29 set $index = 0 30 while $index < $regSize 31 printf " v%d = %d", $index, ((int *)$FP)[$index] 32 if $regSize - $index <= $insSize 33 printf " (in%d)\n", $insSize - $regSize + $index 34 else 35 printf " (local%d)\n", $index 36 end 37 set $index = $index + 1 38 end 39 else 40 printf " break frame\n" 41 end 42 set $FP = (int) ((StackSaveArea *)$stackSave)->prevFrame 43 set $frame = $frame + 1 44 end 45 end 46 47 document dbt 48 Unwind Dalvik stack frames. Argument 0 is the frame address of the top 49 frame. If omitted r5 will be used as the default (as the case in the 50 interpreter and JIT'ed code). 51 end 52 53 # ART debugging. ART uses SIGSEGV signals for internal purposes. To allow 54 # gdb to debug programs using ART we need to treat this signal specially. We 55 # also set a breakpoint in a libart.so function to stop when the program 56 # hits an unexpected breakpoint 57 set $art_debug_enabled = 0 58 define art-on 59 if $art_debug_enabled == 0 60 # deal with SIGSEGV signals 61 handle SIGSEGV noprint nostop pass 62 63 # set a breakpoint and record its number 64 set breakpoint pending on 65 break art_sigsegv_fault 66 set $art_bpnum = $bpnum 67 commands $art_bpnum 68 silent 69 printf "Caught SIGSEGV in user program\n" 70 end 71 set breakpoint pending auto 72 73 printf "ART debugging mode is enabled.\n" 74 printf "If you are debugging a native only process, you need to\n" 75 printf "re-enable normal SIGSEGV handling using this command:\n" 76 printf " handle SIGSEGV print stop\n" 77 set $art_debug_enabled = 1 78 else 79 printf "ART debugging mode is already enabled.\n" 80 end 81 end 82 83 document art-on 84 Enter ART debugging mode. In ART debugging mode, SIGSEGV signals are ignored 85 by gdb unless they are not handled by ART itself. A breakpoint is 86 set to stop the program when an unexpected SIGSEGV signal is 87 encountered. 88 89 To switch ART debugging mode off, use "art-off" 90 end 91 92 define art-off 93 if $art_debug_enabled == 1 94 # restore SIGSEGV to its default 95 handle SIGSEGV print stop pass 96 97 # delete our breakpoint 98 delete $art_bpnum 99 100 set $art_debug_enabled = 0 101 printf "ART debugging mode is disabled.\n" 102 end 103 end 104 105 document art-off 106 Leave ART debugging mode. Signal handling is restored to default settings. 107 108 Use the command "art-on" to enable ART debugging mode. 109 end 110