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 a correct backtrace by adjusting $eip
86 # this works best right at intr0e_stub
89 set $eip = ((void**)$esp)[1]
94 Print a backtrace of the current thread after a pagefault
97 # invoked whenever the program stops
99 # stopped at stub #0E = #14 (page fault exception handler stub)
100 if ($eip == intr0e_stub)
101 set $savedeip = ((void**)$esp)[1]
102 # if this was in user mode, the OS should handle it
103 # either handle the page fault or terminate the process
104 if ($savedeip < 0xC0000000)
105 printf "pintos-debug: a page fault exception occurred in user mode\n"
106 printf "pintos-debug: hit 'c' to continue, or 's' to step to intr_handler\n"
108 # if this was in kernel mode, a stack trace might be useful
109 printf "pintos-debug: a page fault occurred in kernel mode\n"
116 target remote localhost:1234
119 Attach debugger to pintos process