diff options
Diffstat (limited to 'pintos-progos/misc/gdb-macros')
| -rw-r--r-- | pintos-progos/misc/gdb-macros | 140 |
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 | ||
| 13 | define offsetof | ||
| 14 | set $rc = (char*)&((struct $arg0 *)0)->$arg1 - (char*)0 | ||
| 15 | end | ||
| 16 | |||
| 17 | define list_entry | ||
| 18 | offsetof $arg1 $arg2 | ||
| 19 | set $rc = ((struct $arg1 *) ((uint8_t *) ($arg0) - $rc)) | ||
| 20 | end | ||
| 21 | |||
| 22 | # dump a Pintos list | ||
| 23 | define 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 | ||
| 35 | end | ||
| 36 | |||
| 37 | document 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 | ||
| 40 | end | ||
| 41 | |||
| 42 | # print a thread's backtrace, given a pointer to the struct thread * | ||
| 43 | define 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 | ||
| 61 | end | ||
| 62 | document btthread | ||
| 63 | Show the backtrace of a thread, | ||
| 64 | invoke as btthread pointer_to_struct_thread | ||
| 65 | end | ||
| 66 | |||
| 67 | # print backtraces associated with all threads in a list | ||
| 68 | define 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 | ||
| 79 | end | ||
| 80 | document 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 | ||
| 83 | end | ||
| 84 | |||
| 85 | # print backtraces of all threads (based on 'all_list' all threads list) | ||
| 86 | define btthreadall | ||
| 87 | btthreadlist all_list allelem | ||
| 88 | end | ||
| 89 | document btthreadall | ||
| 90 | Print backtraces of all threads | ||
| 91 | end | ||
| 92 | |||
| 93 | # print a correct backtrace by adjusting $eip | ||
| 94 | # this works best right at intr0e_stub | ||
| 95 | define btpagefault | ||
| 96 | set $saveeip = $eip | ||
| 97 | set $eip = ((void**)$esp)[1] | ||
| 98 | backtrace | ||
| 99 | set $eip = $saveeip | ||
| 100 | end | ||
| 101 | document btpagefault | ||
| 102 | Print a backtrace of the current thread after a pagefault | ||
| 103 | end | ||
| 104 | |||
| 105 | # invoked whenever the program stops | ||
| 106 | define 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 | ||
| 121 | end | ||
| 122 | |||
| 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 | ||
| 126 | source .loadsymbols | ||
| 127 | shell rm -f .loadsymbols | ||
| 128 | end | ||
| 129 | document loadusersymbols | ||
| 130 | Load the symbols contained in a user program's executable. | ||
| 131 | Example: | ||
| 132 | loadusersymbols tests/userprog/exec-multiple | ||
| 133 | end | ||
| 134 | |||
| 135 | define debugpintos | ||
| 136 | target remote localhost:1234 | ||
| 137 | end | ||
| 138 | document debugpintos | ||
| 139 | Attach debugger to pintos process | ||
| 140 | end | ||
