Home | History | Annotate | Download | only in gdb
      1 #
      2 # Copyright (C) 2014 The Android Open Source Project
      3 #
      4 # Licensed under the Apache License, Version 2.0 (the "License");
      5 # you may not use this file except in compliance with the License.
      6 # You may obtain a copy of the License at
      7 #
      8 #      http://www.apache.org/licenses/LICENSE-2.0
      9 #
     10 # Unless required by applicable law or agreed to in writing, software
     11 # distributed under the License is distributed on an "AS IS" BASIS,
     12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 # See the License for the specific language governing permissions and
     14 # limitations under the License.
     15 
     16 # ART debugging.  ART uses SIGSEGV signals for internal purposes.  To allow
     17 # gdb to debug programs using ART we need to treat this signal specially.  We
     18 # also set a breakpoint in a libart.so function to stop when the program
     19 # hits an unexpected breakpoint
     20 set $art_debug_enabled = 0
     21 define art-on
     22     if $art_debug_enabled == 0
     23         # deal with SIGSEGV signals
     24         handle SIGSEGV noprint nostop pass
     25 
     26         # set a breakpoint and record its number
     27         set breakpoint pending on
     28         break art_sigsegv_fault
     29         set $art_bpnum = $bpnum
     30         commands $art_bpnum
     31         silent
     32         printf "Caught SIGSEGV in user program\n"
     33         end
     34         set breakpoint pending auto
     35 
     36         printf "ART debugging mode is enabled.\n"
     37         printf "If you are debugging a native only process, you need to\n"
     38         printf "re-enable normal SIGSEGV handling using this command:\n"
     39         printf "  handle SIGSEGV print stop\n"
     40         set $art_debug_enabled = 1
     41     else
     42         printf "ART debugging mode is already enabled.\n"
     43     end
     44 end
     45 
     46 document art-on
     47     Enter ART debugging mode. In ART debugging mode, SIGSEGV signals are ignored
     48     by gdb unless they are not handled by ART itself.  A breakpoint is
     49     set to stop the program when an unexpected SIGSEGV signal is
     50     encountered.
     51 
     52     To switch ART debugging mode off, use "art-off"
     53 end
     54 
     55 define art-off
     56     if $art_debug_enabled == 1
     57         # restore SIGSEGV to its default
     58         handle SIGSEGV print stop pass
     59 
     60         # delete our breakpoint
     61         delete $art_bpnum
     62 
     63         set $art_debug_enabled = 0
     64         printf "ART debugging mode is disabled.\n"
     65     end
     66 end
     67 
     68 document art-off
     69     Leave ART debugging mode.  Signal handling is restored to default settings.
     70 
     71     Use the command "art-on" to enable ART debugging mode.
     72 end
     73