2 # A set of useful macros that can help debug Pintos.
4 # Include with "source" cmd in gdb.
5 # Use "help user-defined" for help.
7 # Author: Godmar Back <gback@cs.vt.edu>, Feb 2006
9 # $Id: gdb-macros,v 1.1 2006-04-07 18:29:34 blp Exp $
14 set $rc = (char*)&((struct $arg0 *)0)->$arg1 - (char*)0
19 set $rc = ((struct $arg1 *) ((uint8_t *) ($arg0) - $rc))
25 set $e = $list->head.next
27 while $e != &(($arg0).tail)
28 list_entry $e $arg1 $arg2
30 printf "pintos-debug: dumplist #%d: %p ", $i++, $l
38 Dump the content of a Pintos list,
39 invoke as dumplist name_of_list name_of_struct name_of_elem_in_list_struct
42 # print a thread's backtrace, given a pointer to the struct thread *
44 if $arg0 == ($esp - ((unsigned)$esp % 4096))
51 set $esp = ((struct thread *)$arg0)->stack
52 set $ebp = ((void**)$esp)[2]
53 set $eip = ((void**)$esp)[4]
63 Show the backtrace of a thread,
64 invoke as btthread pointer_to_struct_thread
67 # print backtraces associated with all threads in a list
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
81 Given a list of threads, print each thread's backtrace
82 invoke as btthreadlist name_of_list name_of_elem_in_list_struct
85 # print backtraces of all threads (based on 'all_list' all threads list)
87 btthreadlist all_list allelem
90 Print backtraces of all threads
93 # print a correct backtrace by adjusting $eip
94 # this works best right at intr0e_stub
97 set $eip = ((void**)$esp)[1]
102 Print a backtrace of the current thread after a pagefault
105 # invoked whenever the program stops
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"
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"
123 # load symbols for a Pintos user program
124 define loadusersymbols
125 shell objdump -h $arg0 | awk '/.text/ { print "add-symbol-file $arg0 0x"$4 }' > .loadsymbols
127 shell rm -f .loadsymbols
129 document loadusersymbols
130 Load the symbols contained in a user program's executable.
132 loadusersymbols tests/userprog/exec-multiple
136 target remote localhost:1234
139 Attach debugger to pintos process