stack revision 1.1
11.1Sjhawk# $NetBSD: stack,v 1.1 2000/06/08 03:15:40 jhawk Exp $ 21.1Sjhawk 31.1Sjhawk# Copyright (c) 2000 The NetBSD Foundation, Inc. 41.1Sjhawk# All rights reserved. 51.1Sjhawk# 61.1Sjhawk# This code is derived from software contributed to The NetBSD Foundation 71.1Sjhawk# by John A. Hawkinson. 81.1Sjhawk# 91.1Sjhawk# Redistribution and use in source and binary forms, with or without 101.1Sjhawk# modification, are permitted provided that the following conditions 111.1Sjhawk# are met: 121.1Sjhawk# 1. Redistributions of source code must retain the above copyright 131.1Sjhawk# notice, this list of conditions and the following disclaimer. 141.1Sjhawk# 2. Redistributions in binary form must reproduce the above copyright 151.1Sjhawk# notice, this list of conditions and the following disclaimer in the 161.1Sjhawk# documentation and/or other materials provided with the distribution. 171.1Sjhawk# 3. All advertising materials mentioning features or use of this software 181.1Sjhawk# must display the following acknowledgement: 191.1Sjhawk# This product includes software developed by the NetBSD 201.1Sjhawk# Foundation, Inc. and its contributors. 211.1Sjhawk# 4. Neither the name of The NetBSD Foundation nor the names of its 221.1Sjhawk# contributors may be used to endorse or promote products derived 231.1Sjhawk# from this software without specific prior written permission. 241.1Sjhawk# 251.1Sjhawk# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 261.1Sjhawk# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 271.1Sjhawk# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 281.1Sjhawk# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 291.1Sjhawk# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 301.1Sjhawk# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 311.1Sjhawk# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 321.1Sjhawk# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 331.1Sjhawk# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 341.1Sjhawk# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 351.1Sjhawk# POSSIBILITY OF SUCH DAMAGE. 361.1Sjhawk 371.1Sjhawk 381.1Sjhawk# Follow an i386 kernel stack trace. 391.1Sjhawk# This code makes presumptions about the way frames look, consistent 401.1Sjhawk# with arch/i386/i386/db_trace.c. It also steals algorithms from there. 411.1Sjhawk 421.1Sjhawk# Output looks like: 431.1Sjhawk# 441.1Sjhawk# 0xc03049cb <cpu_reboot+99>(0x100,0x0,0xc04fd728,0x0,0x6) 451.1Sjhawk# at 0xc01bc97d <panic+197> (frame at 0xc5633bd0) 461.1Sjhawk# 471.1Sjhawk# In this case, the initial hex number and offset should be disregarded, 481.1Sjhawk# and it should be interprted as if it were: 491.1Sjhawk# 501.1Sjhawk# cpu_reboot(0x100,0x0,0xc04fd728,0x0,0x6) 511.1Sjhawk# at 0xc01bc97d <panic+197> (frame at 0xc5633bd0) 521.1Sjhawk# 531.1Sjhawk# due to limitations of gdb scripting. 541.1Sjhawk 551.1Sjhawkdefine stack 561.1Sjhawk set $frame=$arg0 571.1Sjhawk set $retaddr=$arg1 581.1Sjhawk 591.1Sjhawk while ($frame != 0) 601.1Sjhawk set $callpc = $retaddr 611.1Sjhawk set $retaddr = *(long*)($frame+4) 621.1Sjhawk 631.1Sjhawk set $inst=*(long*)$retaddr 641.1Sjhawk if (($inst & 0xff) == 0x59) 651.1Sjhawk# (popl %ecx) 661.1Sjhawk set $narg=1 671.1Sjhawk else if (($inst & 0xffff) == 0xc483) 681.1Sjhawk# (addl %n, %esp) 691.1Sjhawk set $narg = (($inst >> 16) & 0xff) / 4 701.1Sjhawk else 711.1Sjhawk set $narg = 5 721.1Sjhawk end 731.1Sjhawk 741.1Sjhawk set $argp = $frame+8 751.1Sjhawk printf " " 761.1Sjhawk output/a $callpc 771.1Sjhawk printf "(" 781.1Sjhawk while ($narg != 0) 791.1Sjhawk printf "0x%lx", *(long*)$argp 801.1Sjhawk set $argp = $argp+4 811.1Sjhawk set $narg = $narg-1 821.1Sjhawk if ($narg != 0) 831.1Sjhawk printf "," 841.1Sjhawk end 851.1Sjhawk end 861.1Sjhawk printf ")\n at " 871.1Sjhawk output/a $retaddr 881.1Sjhawk printf " (frame at %#x)\n", $frame 891.1Sjhawk 901.1Sjhawk set $frame=*(long*)($frame+0) 911.1Sjhawk end 921.1Sjhawkend 931.1Sjhawk 941.1Sjhawkdocument stack 951.1Sjhawk ==> (gdb) stack FP IP 961.1Sjhawk print a backtrace of all stack frames, starting at frame pointer FP, 971.1Sjhawk and instruction pointer IP. For the default trace, run: 981.1Sjhawk "stack $ebp $eip" 991.1Sjhawkend