Annotation of wikisrc/users/haad/ddb_howto.mdwn, revision 1.2

1.1       wiki        1: [[!meta title="NetBSD Developer Cheatsheet"]]
                      2: 
                      3: [[!toc]]
                      4: 
                      5: 
                      6: This article is going to be a collection of random notes which I have found during my development in kernel. I have found that there are some hints which every developer knows, but there is no documentation where newbie can learn them.
                      7: 
                      8: 
                      9: ## Finding where the bug is
                     10: 
                     11: When you get a crash in the kernel you want to translate the address from the backtrace to the line in the source code:
                     12: 
                     13: Stopped in pid 496.1 (gdb) at netbsd:breakpoint+0x5: leave
                     14: 
                     15: First, you need to find the address of the breakpoint function in the running kernel image with the nm(1) command:
                     16: 
                     17: nm netbsd | grep breakpoint
                     18: 
                     19: Then add 0x5 to the address, and use addr2line(1) to get the exact line in the kernel source code where you get the crash:
                     20: 
                     21: addr2line -g netbsd {sum address}
                     22: 
                     23: In gdb(1), this can be achieved with the command info line *(function_name)+0x5.
                     24: 
                     25: ## What to do if ddb backtrace doesn't work
                     26: 
                     27: The DDB backtrace command usually doesn't work when the EIP register was set to NULL, e.g. via a bad function pointer. In this case we can get part of the backtrace by using a different approach.
                     28: 
                     29: db> show all reg
                     30: 
                     31: eip 0 cs 0 eflags 0 esp 0xcb741b70
                     32: 
                     33: We need to find which address was set in the ESP register (this is the stack pointer register on i386). When we have our address we need to use
                     34: 
                     35: x /Lx 0xcb741b70,20
                     36: 
                     37: to print the first 20 addresses from the stack. To easily find the address of the last function you need to look for an address with 0xc0 at the start.
                     38: 
                     39: The command x /I c06428fc will then translate the function address to it's name with the symbol table lookup.
1.2     ! gson       40: 
        !            41: ## What to do if gdb cannot backtrace through trap()
1.1       wiki       42: 
                     43: Use ('source') .../sys/arch/i386/gdbscripts/stack gdb script and run 'stack'. See also PR 10313.
1.2     ! gson       44: 
        !            45: ## How to rebuild /boot
1.1       wiki       46: 
                     47: (This example assumes you are running NetBSD-i386)
                     48: 
                     49:     * Make sure you have the tools built
                     50:     * sys/arch/i386/stand/boot and enter $TOOLDIR/bin/nbmake-i386

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb