Advanced Operating Systems COMP9242 2005/S2 |
UNSW
CRICOS Provider Number: 00098G |
Printer-Friendly
Version
|
Debugging in L4When developing an operating system on top of L4 you do not have the luxury of using a source level debugger such as gdb. There are still a number of techniques at your disposal to assist debugging, however. The Pistachio Kernel debuggerIf your operating system causes certain types of faults you are likely to be dropped into the L4 kernel debugger. You should also be able to break into the kernel debugger at any time with the escape (ESC) key (provided it is compiled into your kernel). The kernel debugger has many options that can be displayed by hitting the ? key. --- KD# breakin --- -- current ASID is 0, CPU 0 -- > help BS - back up to previous menu ? - this help message ESC - back to previous menu a - architecure specifics c - KDB configuration B - generic bootinfo SPC - show current user exception frame f - show floating point registers F - show exception frame K - dump kernel interface page s - search for an exception frame g - continue execution d - dump memory D - dump memory in other space 6 - Reset system q - show scheduling queue t - show thread control block T - shows thread control block (extended) 0 - sigma0 interaction # - statistics r - enable/disable/list tracepoints > The most useful functions you will use are (in no particular order) most likely SPC, F, K, g, d (and D), q, t (and T), r and 6. Take the time to learn to use them, they are a very handy and will save you many hours (or even days) of debugging. Debugging a stopOften when using L4 you will cause the kernel to enter the debugger for one reason or another. This example takes you through debugging an unhandled exception, eg. the output below:
The first thing you want to do is show the thread control block
(TCB) of the thread that cause the exception. The command
NB: Even though The first thing you need to do is work out which thread is
executing. the Once you have determined which thread is executing you want to
work out the code it is executing. The Now that we know the faulting address we now want to find out which line of code contains the fault. The first step is to find which executable file the fault is in. Dite helps us here:
Dite shows us in this case the the fault is in the
You can now use the searching facility in
In this case I am lucky and it is a small piece of function so tracking down the bug shouldn't be too hard. In large functions your skill at reading assembler code, (that was one of the recommended skills for this course remember), comes into play. Of course this should encourage to keep you functions small. More on objdumpObjdump is a very handy utility for working out exactly what is where in an executable so you can work out what exactly is going wrong. The two standard incantations for objdump are: % mips64-elf-objdump -dl my_elf.file | lessand % mips64-elf-objdump -lx my_elf.file | lessThe first command (-dl) disassesmbles the text segment and shows you all the instructions and at what address. Using this information you can find out things such as:
NB: In case it's not yet obvious, you will need to get up to speed on your MIPS assembly and not be afraid to get your hands dirty if you want to minimise the time you spend debugging. The second objdump command (-lx) is useful for when addresses appear inside an object file but outside of the text segment. This is especially useful when debugging ELF loading. The -lx option displays section and symbol information. Further options can be added to dump data segments etc. man objdump is your friend. Kernel Debugger TracingKernel debug tracing is a handy tool that can be used for many things:
Kernel debugger tracing has to be compiled into the kernel, select in make menuconfig under Debugger --> Trace Settings --> Enable Tracepoints. (This should be enabled already if you followed the instructions for m0 correctly. It may also be desirable to set the Debugger --> Enter kernel debugger on startup option if you need to enable tracing early on during boot. The simplest way to enable tracing from the kernel debugger is to use r to enter the tracing submenu, then E to enable all tracepoints. You can also ? from the tracing submenu to list all the options. It can be very handy to only trace certain kernel events. NOTE: If you enable the Fast IPC path you will not see any trace events for IPC messages delievered on the fastpath. There is no tracing for this case (otherwise it wouldn't be so fast!). A partial trace from the default tty_test application looks something like the following: 1 Available memory from 7dfff to 29f000 - 2MB 2 Found: 1 tty_test 3 Created tid: 40000000001 4 task: Hello world, I'm 0x40000000001! 5 --- KD# breakin --- 6 -- current ASID is 0, CPU 0 -- 7 > tracepoints 8 /tracepoints> enableall 9 /tracepoints> up 10 > go 11 wakeup timeout (curr=ffffffff80074000 wu=4000000000400000) Current time = 1006000 12 Unwind: tcb=0000040000000001 p=0000040000000001 s=WAIT_TIMEOUT (saved: p=0000000000000000 s=ABORTED) 13 task: count is 1 14 SYS_IPC: current: 0000040000000001, to_tid: 0000000000000000, from_tid: 0000040000000001, to: 0x2bd0 15 wakeup timeout (curr=ffffffff80074000 wu=4000000000400000) Current time = 2006000 16 Unwind: tcb=0000040000000001 p=0000040000000001 s=WAIT_TIMEOUT (saved: p=0000000000000000 s=ABORTED) 17 task: count is 2 18 SYS_IPC: current: 0000040000000001, to_tid: 0000000000000000, from_tid: 0000040000000001, to: 0x2bd0 Lines 1-4 are the end of the normal bootup for tty_test. At line 5 we break into the kernel debugger with ESC and enable all tracepoints. Line 11 we see the thread wakeup from its IPC timeout and the kernel perform an unwind on thread to return it with a timeout code. Line 13 is the printout from the thread. Line 14 is the IPC call from the thread with a timeout. The calling thread ID is 0000040000000001. The IPC destination TID is 0000000000000000 (no send phase). The from_tid is 0000040000000001 (L4_Myself, eg. wait for a timeout). The timout specified is 0x2bd0. This series of events then repeats. The run queuesq in the kernel debugger shows all the current L4 threads, in order of priority, and whether or not they are runnable. > showqueue [255]: (0000002700000001) (0000002900000001) [100]: (0000002a00000001) (0000040000000001) [ 0]: (0000000700000001) idle : ffffffff80074000 This dump shows 6 threads. 5 real threads and the idle thread. The two threads at priority 255 are sigma0 and the 1st thread in the root task. The two threads at priority 100 are the SOS kernel init thread (blocked on IPC forever), and the user-level tty_test thread. The thread at priority 0 is the in-kernel interrupt handler thread which delivers hardware interrupts to its pager. Threads with brackets around their thread ID, eg. (0000002a00000001) are currently blocked. Thread IDs without brackets are runnable. In the above example the only runnable thread is the idle thread. Other threads may become runnable due to a timeout, IPC or interrupt. Entering the kernel debuggerThe kernel debugger is a life-line to debug your code. Being able to enter the kernel debugger to examine the state at the right time can make hours of difference to debugging.
Examining Thread StateThere is a lot of information about a thread that you may want or need to find out. There are a number of ways to find thread state from within the kernel debugger. showtcbThe t command be used to dump a thread's TCB. This can be either the current thread (eg. during a debug enter, exception or whatever), or you can specify a thread ID. A sample TCB is shown here. Interesting fields are marked in bold and explained below. The explanation is only a rough guide and may be incomplete. The exact semantics can be checked in the L4 source. > showtcb tcb/tid/name [current]: current === TCB: 4000000000400000 === ID: 0000040000000001 = 0000000100000000/ffffffff802fc000 === PRIO: 0x64 ======== UIP: 000000000025c000 queues: Rswl wait : 0000000000000000:0000000000000000 space: ffffffff802f2000 USP: 0000000000252e58 tstate: RUNNING ready: 0000040000000001:0000040000000001 pdir : 0000000000000000 KSP: 4000000000400d08 sndhd : 0000000000000000 send : 0000000000000000:0000000000000000 pager: 0000002900000001 total quant: 0us, ts length : 10000us, curr ts: 10000us abs timeout: 0us, rel timeout: 0us sens prio: 100, delay: max=0us, curr=0us resources: 0000000000000000 [] partner: 0000000000000000, saved partner: 0000000000000000, saved state: ABORTED, scheduler: 0000002900000001
showtcbextThe T command be used to dump a thread's TCB and extended information as shown below. The first part is basically the same, interesting bits are highlighted and described below. > showtcbext tcb/tid/name [current]: 40000000001 === TCB: 4000000000400000 === ID: 0000040000000001 = 0000000100000000/ffffffff802fc000 === PRIO: 0x64 ======== UIP: 0000000200000808 queues: rsWl wait : 0000040000000001:0000040000000001 space: ffffffff802f2000 USP: 0000000000252dd8 tstate: WAIT_TO ready: 0000000000000000:0000000000000000 pdir : 0000000000000000 KSP: 4000000000400df8 sndhd : 0000000000000000 send : 0000000000000000:0000000000000000 pager: 0000002900000001 total quant: 0us, ts length : 10000us, curr ts: 10000us abs timeout: 1005424us, rel timeout: 829424us sens prio: 100, delay: max=0us, curr=0us resources: 0000000000000000 [] partner: 0000040000000001, saved partner: 0000000000000000, saved state: ABORTED, scheduler: 0000002900000001 user handle: 0000000000000000 cop flags: 00 preempt flags: 00 [~~~] exception handler: 0000000000000000 virtual sender: 0000002a00000001 intended receiver: 0000000000000000 xfer timeouts: snd (never) rcv (never) mr( 0): 2bd000000000000b 0000000000000001 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 mr( 8): 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 mr(16): 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 mr(24): 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 mr(32): 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 mr(40): 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 mr(48): 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 mr(56): 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 Message Tag: 11 untyped, 0 typed, label = 2bd000000000, flags = ---- br( 0): 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 br( 8): 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 br(16): 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 br(24): 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 br(32): 0000000000000000 Acceptor: 0000000000000000 (s) fpage : (NIL-FPAGE) The extended information also lists message and buffer register contents. This can be useful to debug the exact contents of IPC messages, especially when used in conjunction with kernel break-in on IPC send events. The IPC message tag is shown in a nice, easy to read format. The fpage acceptor for received fpages. Handy to debug why pagefaults re-occur, and whether fpages are being over-mapped. frameThe SPC (space bar) command be used to dump a thread's register set (eg. exception frame). Below is an example exception frame. > frame == Stack frame: ffffffff80074c20 == == STATUS: 40190e2 == CAUSE: 24 == EPC: ffffffff8006362c at = ffffffffffffff9a, v0 = ffffffff80072dd8, v1 = ffffffff800636e8, sp = ffffffff80074d40 a0 = 1b, a1 = 18, a2 = ffffffff8006cdb0, a3 = 0 t0 = 300000000, t1 = ffffffffbc800032, t2 = 1b, t3 = 2 t4 = 3, t5 = fffffffffffffffe, t6 = 5, t7 = 4000000000400038 s0 = ffffffff80074000, s1 = ffffffffffff00ff, s2 = ffffffff802a0000, s3 = ffffffff802a1ff8 s4 = ffffffff80075400, s5 = 606060606060606, s6 = 1305050606060606, s7 = e1d161718141513 t8 = ffffffffbc800032, t9 = 4, s8 = ffffffff800564b8, gp = 0 ra = ffffffff80063614, hi = 4, lo = 0 This dump shows the address of the stack frame, status and cause registers, EPC, and the general register file. Other stack frames can be inspected with the F command. You can find stack frames via the TCB and the s command. The STATUS and CAUSE registers are described in the processor manual (see chapter 5). The general registers are displayed with their typically used names. Name to number conversions can be found in sos/include/regdef.h (a hardcopy can be handy). The U4600 Hardware SwitchThe front panel of the U4600 box has two switches, a power button and another button. The other button is wired to interrupt pin 4 on the CPU. This generates an edge-triggered interrupt when you press this button. By default this interrupt is masked. This switch can be a very handy way to generate an event to enter your own OS debugger or display debugging information. Simply register a thread to handle interrupt 6 (4 + 2 software interrupts) and wait for an IPC. Rebooting the machine
Often when debugging your code you will want to reboot the
machine, however you may be working remotely, or otherwise not be
able to physically reboot the machine. The kernel debugger can do
this for you. First drop into the kernel debugger by hitting
If for some reason this doesn't work L4 may have gotten itself into an unexpected state and you will have to manually reboot the machine. Last modified: Fri Aug 6 11:58:42 EST 2004 |