Annotation of wikisrc/users/haad/ddb_howto.mdwn, revision 1.4
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:
1.3 sevan 13: Stopped in pid 496.1 (gdb) at netbsd:breakpoint+0x5: leave
1.1 wiki 14:
1.3 sevan 15: First, you need to find the address of the breakpoint function in the running kernel image with the [[!template id=man name="nm" section="1"]] command:
1.1 wiki 16:
1.3 sevan 17: nm netbsd | grep breakpoint
1.1 wiki 18:
1.3 sevan 19: Then add `0x5` to the address, and use [[!template id=man name="addr2line" section="1"]] to get the exact line in the kernel source code where you get the crash:
1.1 wiki 20:
1.4 ! sevan 21: addr2line -e netbsd {sum address}
1.1 wiki 22:
1.3 sevan 23: In [[!template id=man name="gdb" section="1"]], this can be achieved with the command `info line *(function_name)+0x5`.
1.1 wiki 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:
1.3 sevan 29: db> show all reg
1.1 wiki 30:
1.3 sevan 31: eip 0 cs 0 eflags 0 esp 0xcb741b70
1.1 wiki 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:
1.3 sevan 35: x /Lx 0xcb741b70,20
1.1 wiki 36:
1.3 sevan 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.
1.1 wiki 38:
1.3 sevan 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:
1.3 sevan 43: Use `source .../sys/arch/i386/gdbscripts/stack` gdb script and run `stack`. See also [PR 10313](http://gnats.netbsd.org/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