Home | History | Annotate | Line # | Download | only in gdbscripts
stack revision 1.2.8.2
      1  1.2.8.2  bouyer # $NetBSD: stack,v 1.2.8.2 2000/11/20 20:09:19 bouyer Exp $
      2  1.2.8.2  bouyer 
      3  1.2.8.2  bouyer # Copyright (c) 2000 The NetBSD Foundation, Inc.
      4  1.2.8.2  bouyer # All rights reserved.
      5  1.2.8.2  bouyer #
      6  1.2.8.2  bouyer # This code is derived from software contributed to The NetBSD Foundation
      7  1.2.8.2  bouyer # by John A. Hawkinson.
      8  1.2.8.2  bouyer #
      9  1.2.8.2  bouyer # Redistribution and use in source and binary forms, with or without
     10  1.2.8.2  bouyer # modification, are permitted provided that the following conditions
     11  1.2.8.2  bouyer # are met:
     12  1.2.8.2  bouyer # 1. Redistributions of source code must retain the above copyright
     13  1.2.8.2  bouyer #    notice, this list of conditions and the following disclaimer.
     14  1.2.8.2  bouyer # 2. Redistributions in binary form must reproduce the above copyright
     15  1.2.8.2  bouyer #    notice, this list of conditions and the following disclaimer in the
     16  1.2.8.2  bouyer #    documentation and/or other materials provided with the distribution.
     17  1.2.8.2  bouyer # 3. All advertising materials mentioning features or use of this software
     18  1.2.8.2  bouyer #    must display the following acknowledgement:
     19  1.2.8.2  bouyer #        This product includes software developed by the NetBSD
     20  1.2.8.2  bouyer #        Foundation, Inc. and its contributors.
     21  1.2.8.2  bouyer # 4. Neither the name of The NetBSD Foundation nor the names of its
     22  1.2.8.2  bouyer #    contributors may be used to endorse or promote products derived
     23  1.2.8.2  bouyer #    from this software without specific prior written permission.
     24  1.2.8.2  bouyer #
     25  1.2.8.2  bouyer # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     26  1.2.8.2  bouyer # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.2.8.2  bouyer # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.2.8.2  bouyer # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     29  1.2.8.2  bouyer # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.2.8.2  bouyer # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.2.8.2  bouyer # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.2.8.2  bouyer # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.2.8.2  bouyer # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.2.8.2  bouyer # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.2.8.2  bouyer # POSSIBILITY OF SUCH DAMAGE.
     36  1.2.8.2  bouyer 
     37  1.2.8.2  bouyer 
     38  1.2.8.2  bouyer # Follow an i386 kernel stack trace.
     39  1.2.8.2  bouyer # This code makes presumptions about the way frames look, consistent
     40  1.2.8.2  bouyer # with arch/i386/i386/db_trace.c. It also steals algorithms from there.
     41  1.2.8.2  bouyer 
     42  1.2.8.2  bouyer # Output looks like:
     43  1.2.8.2  bouyer #
     44  1.2.8.2  bouyer #  0xc03049cb <cpu_reboot+99>(0x100,0x0,0xc04fd728,0x0,0x6)
     45  1.2.8.2  bouyer #	      at 0xc01bc97d <panic+197> (frame at 0xc5633bd0)
     46  1.2.8.2  bouyer #
     47  1.2.8.2  bouyer # In this case, the initial hex number and offset should be disregarded,
     48  1.2.8.2  bouyer # and it should be interprted as if it were:
     49  1.2.8.2  bouyer #
     50  1.2.8.2  bouyer #  cpu_reboot(0x100,0x0,0xc04fd728,0x0,0x6)
     51  1.2.8.2  bouyer #	      at 0xc01bc97d <panic+197> (frame at 0xc5633bd0)
     52  1.2.8.2  bouyer #
     53  1.2.8.2  bouyer # due to limitations of gdb scripting.
     54  1.2.8.2  bouyer 
     55  1.2.8.2  bouyer define stacktrace
     56  1.2.8.2  bouyer   set $frame=$arg0
     57  1.2.8.2  bouyer   set $retaddr=$arg1
     58  1.2.8.2  bouyer 
     59  1.2.8.2  bouyer   while ($frame != 0)
     60  1.2.8.2  bouyer     set $callpc = $retaddr
     61  1.2.8.2  bouyer     set $retaddr = *(long*)($frame+sizeof(long*))
     62  1.2.8.2  bouyer 
     63  1.2.8.2  bouyer     set $inst=*(long*)$retaddr
     64  1.2.8.2  bouyer     if (($inst & 0xff) == 0x59)
     65  1.2.8.2  bouyer # (popl %ecx)
     66  1.2.8.2  bouyer 	set $narg=1
     67  1.2.8.2  bouyer     else if (($inst & 0xffff) == 0xc483)
     68  1.2.8.2  bouyer # (addl %n, %esp)
     69  1.2.8.2  bouyer 	   set $narg = (($inst >> 16) & 0xff) / 4
     70  1.2.8.2  bouyer          else
     71  1.2.8.2  bouyer 	   set $narg = 5
     72  1.2.8.2  bouyer     end
     73  1.2.8.2  bouyer 
     74  1.2.8.2  bouyer     set $argp = $frame+sizeof(long*)+sizeof(int)
     75  1.2.8.2  bouyer     printf "  "
     76  1.2.8.2  bouyer     output/a $callpc
     77  1.2.8.2  bouyer     printf "("
     78  1.2.8.2  bouyer     while ($narg != 0)
     79  1.2.8.2  bouyer       printf "0x%lx", *(long*)$argp
     80  1.2.8.2  bouyer       set $argp = $argp+sizeof(long*)
     81  1.2.8.2  bouyer       set $narg = $narg-1
     82  1.2.8.2  bouyer       if ($narg != 0)
     83  1.2.8.2  bouyer 	printf ","
     84  1.2.8.2  bouyer       end
     85  1.2.8.2  bouyer     end
     86  1.2.8.2  bouyer     printf ")\n             at "
     87  1.2.8.2  bouyer     output/a $retaddr
     88  1.2.8.2  bouyer     printf " (frame at %#x)\n", $frame
     89  1.2.8.2  bouyer 
     90  1.2.8.2  bouyer     set $frame=*(long*)$frame
     91  1.2.8.2  bouyer   end
     92  1.2.8.2  bouyer end
     93  1.2.8.2  bouyer 
     94  1.2.8.2  bouyer document stacktrace
     95  1.2.8.2  bouyer   ==> (gdb) stacktrace FP IP
     96  1.2.8.2  bouyer   print a backtrace of all stack frames, starting at frame pointer FP,
     97  1.2.8.2  bouyer   and instruction pointer IP.
     98  1.2.8.2  bouyer end
     99  1.2.8.2  bouyer 
    100  1.2.8.2  bouyer define stack
    101  1.2.8.2  bouyer   stacktrace $ebp $eip
    102  1.2.8.2  bouyer end
    103  1.2.8.2  bouyer 
    104  1.2.8.2  bouyer document stack
    105  1.2.8.2  bouyer   => (gdb) stack
    106  1.2.8.2  bouyer   Print a backtrace of all strack frames, starting at the current $ebp
    107  1.2.8.2  bouyer   and $eip.
    108  1.2.8.2  bouyer end
    109