Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/i386/gdbscripts gdb script for backtracing an i386 ...



details:   https://anonhg.NetBSD.org/src/rev/ad4e7e275f97
branches:  trunk
changeset: 487458:ad4e7e275f97
user:      jhawk <jhawk%NetBSD.org@localhost>
date:      Thu Jun 08 03:15:40 2000 +0000

description:
gdb script for backtracing an i386 kernel stack.
Useful when "where" in gdb fails to cross trap()s,
e.g. port-i386/10313

diffstat:

 sys/arch/i386/gdbscripts/stack |  99 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 99 insertions(+), 0 deletions(-)

diffs (104 lines):

diff -r ff4be6f0e727 -r ad4e7e275f97 sys/arch/i386/gdbscripts/stack
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/i386/gdbscripts/stack    Thu Jun 08 03:15:40 2000 +0000
@@ -0,0 +1,99 @@
+# $NetBSD: stack,v 1.1 2000/06/08 03:15:40 jhawk Exp $
+
+# Copyright (c) 2000 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by John A. Hawkinson.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. All advertising materials mentioning features or use of this software
+#    must display the following acknowledgement:
+#        This product includes software developed by the NetBSD
+#        Foundation, Inc. and its contributors.
+# 4. Neither the name of The NetBSD Foundation nor the names of its
+#    contributors may be used to endorse or promote products derived
+#    from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+
+# Follow an i386 kernel stack trace.
+# This code makes presumptions about the way frames look, consistent
+# with arch/i386/i386/db_trace.c. It also steals algorithms from there.
+
+# Output looks like:
+#
+#  0xc03049cb <cpu_reboot+99>(0x100,0x0,0xc04fd728,0x0,0x6)
+#            at 0xc01bc97d <panic+197> (frame at 0xc5633bd0)
+#
+# In this case, the initial hex number and offset should be disregarded,
+# and it should be interprted as if it were:
+#
+#  cpu_reboot(0x100,0x0,0xc04fd728,0x0,0x6)
+#            at 0xc01bc97d <panic+197> (frame at 0xc5633bd0)
+#
+# due to limitations of gdb scripting.
+
+define stack
+  set $frame=$arg0
+  set $retaddr=$arg1
+
+  while ($frame != 0)
+    set $callpc = $retaddr
+    set $retaddr = *(long*)($frame+4)
+
+    set $inst=*(long*)$retaddr
+    if (($inst & 0xff) == 0x59)
+# (popl %ecx)
+       set $narg=1
+    else if (($inst & 0xffff) == 0xc483)
+# (addl %n, %esp)
+          set $narg = (($inst >> 16) & 0xff) / 4
+         else
+          set $narg = 5
+    end
+
+    set $argp = $frame+8
+    printf "  "
+    output/a $callpc
+    printf "("
+    while ($narg != 0)
+      printf "0x%lx", *(long*)$argp
+      set $argp = $argp+4
+      set $narg = $narg-1
+      if ($narg != 0)
+       printf ","
+      end
+    end
+    printf ")\n             at "
+    output/a $retaddr
+    printf " (frame at %#x)\n", $frame
+
+    set $frame=*(long*)($frame+0)
+  end
+end
+
+document stack
+  ==> (gdb) stack FP IP
+  print a backtrace of all stack frames, starting at frame pointer FP,
+  and instruction pointer IP. For the default trace, run:
+  "stack $ebp $eip"
+end
\ No newline at end of file



Home | Main Index | Thread Index | Old Index