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