summaryrefslogtreecommitdiffstats
path: root/pintos-progos/misc/gdb-macros
diff options
context:
space:
mode:
Diffstat (limited to 'pintos-progos/misc/gdb-macros')
-rw-r--r--pintos-progos/misc/gdb-macros140
1 files changed, 140 insertions, 0 deletions
diff --git a/pintos-progos/misc/gdb-macros b/pintos-progos/misc/gdb-macros
new file mode 100644
index 0000000..a0b68c3
--- /dev/null
+++ b/pintos-progos/misc/gdb-macros
@@ -0,0 +1,140 @@
1#
2# A set of useful macros that can help debug Pintos.
3#
4# Include with "source" cmd in gdb.
5# Use "help user-defined" for help.
6#
7# Author: Godmar Back <gback@cs.vt.edu>, Feb 2006
8#
9# $Id: gdb-macros,v 1.1 2006-04-07 18:29:34 blp Exp $
10#
11
12# for internal use
13define offsetof
14 set $rc = (char*)&((struct $arg0 *)0)->$arg1 - (char*)0
15end
16
17define list_entry
18 offsetof $arg1 $arg2
19 set $rc = ((struct $arg1 *) ((uint8_t *) ($arg0) - $rc))
20end
21
22# dump a Pintos list
23define dumplist
24 set $list = $arg0
25 set $e = $list->head.next
26 set $i = 0
27 while $e != &(($arg0).tail)
28 list_entry $e $arg1 $arg2
29 set $l = $rc
30 printf "pintos-debug: dumplist #%d: %p ", $i++, $l
31 output *$l
32 set $e = $e->next
33 printf "\n"
34 end
35end
36
37document dumplist
38 Dump the content of a Pintos list,
39 invoke as dumplist name_of_list name_of_struct name_of_elem_in_list_struct
40end
41
42# print a thread's backtrace, given a pointer to the struct thread *
43define btthread
44 if $arg0 == ($esp - ((unsigned)$esp % 4096))
45 bt
46 else
47 set $saveEIP = $eip
48 set $saveESP = $esp
49 set $saveEBP = $ebp
50
51 set $esp = ((struct thread *)$arg0)->stack
52 set $ebp = ((void**)$esp)[2]
53 set $eip = ((void**)$esp)[4]
54
55 bt
56
57 set $eip = $saveEIP
58 set $esp = $saveESP
59 set $ebp = $saveEBP
60 end
61end
62document btthread
63 Show the backtrace of a thread,
64 invoke as btthread pointer_to_struct_thread
65end
66
67# print backtraces associated with all threads in a list
68define btthreadlist
69 set $list = $arg0
70 set $e = $list->head.next
71 while $e != &(($arg0).tail)
72 list_entry $e thread $arg1
73 printf "pintos-debug: dumping backtrace of thread '%s' @%p\n", \
74 ((struct thread*)$rc)->name, $rc
75 btthread $rc
76 set $e = $e->next
77 printf "\n"
78 end
79end
80document btthreadlist
81 Given a list of threads, print each thread's backtrace
82 invoke as btthreadlist name_of_list name_of_elem_in_list_struct
83end
84
85# print backtraces of all threads (based on 'all_list' all threads list)
86define btthreadall
87 btthreadlist all_list allelem
88end
89document btthreadall
90 Print backtraces of all threads
91end
92
93# print a correct backtrace by adjusting $eip
94# this works best right at intr0e_stub
95define btpagefault
96 set $saveeip = $eip
97 set $eip = ((void**)$esp)[1]
98 backtrace
99 set $eip = $saveeip
100end
101document btpagefault
102 Print a backtrace of the current thread after a pagefault
103end
104
105# invoked whenever the program stops
106define hook-stop
107 # stopped at stub #0E = #14 (page fault exception handler stub)
108 if ($eip == intr0e_stub)
109 set $savedeip = ((void**)$esp)[1]
110 # if this was in user mode, the OS should handle it
111 # either handle the page fault or terminate the process
112 if ($savedeip < 0xC0000000)
113 printf "pintos-debug: a page fault exception occurred in user mode\n"
114 printf "pintos-debug: hit 'c' to continue, or 's' to step to intr_handler\n"
115 else
116 # if this was in kernel mode, a stack trace might be useful
117 printf "pintos-debug: a page fault occurred in kernel mode\n"
118 btpagefault
119 end
120 end
121end
122
123# load symbols for a Pintos user program
124define loadusersymbols
125 shell objdump -h $arg0 | awk '/.text/ { print "add-symbol-file $arg0 0x"$4 }' > .loadsymbols
126 source .loadsymbols
127 shell rm -f .loadsymbols
128end
129document loadusersymbols
130 Load the symbols contained in a user program's executable.
131 Example:
132 loadusersymbols tests/userprog/exec-multiple
133end
134
135define debugpintos
136 target remote localhost:1234
137end
138document debugpintos
139 Attach debugger to pintos process
140end