Tuesday, July 3, 2007

Au - Debug with gdb

I thought I have got the idea on debugging in linux platform -- mainly using gdb, cscope in emacs. Emacs is an IDE or NOT IDE, doesn't matter, but in emacs, source code browse (open file in c-mode or c++ mode), gdb and cscope can work together to make the magic happen. Here are some tips when running gdb:

- use cscope to find the function you want to trace, then open the souce code in C/C++ mode.
- C-x [space] to set break point. (c-mode and gdb)
- "f" will bring me to where the code runs at. (gdb)
- trace the memory variables (gdb)

x/160xb 0xb7f690c8
| |\ |
| | \ |
| | \ |
| | \ |
N F U Address
Here N: repeat times,
F: display format: x for hex, s for string.
U: unit size: b for bytes, h is two bytes, w for four bytes.

(gdb) x/160xb 0xb7f690c8
0xb7f690c8: 0x8e 0x93 0xa6 0x34 0x18 0x0f 0x0f 0x17
0xb7f690d0: 0x2e 0xac 0x96 0x8e 0x8f 0x9b 0xd6 0x1e
0xb7f690d8: 0x12 0x0f 0x15 0x25 0xb9 0x99 0x8f 0x90
0xb7f690e0: 0x9b 0xca 0x1f 0x13 0x10 0x17 0x2a 0xb1
0xb7f690e8: 0x98 0x90 0x92 0x9f 0x46 0x1c 0x12 0x13
0xb7f690f0: 0x1c 0x47 0xa1 0x94 0x91 0x99 0xbb 0x25
0xb7f690f8: 0x16 0x13 0x19 0x31 0xaa 0x96 0x92 0x98
0xb7f69100: 0xb1 0x29 0x18 0x14 0x1a 0x32 0xaa 0x97
0xb7f69108: 0x93 0x9b 0xbd 0x25 0x17 0x15 0x1e 0x4d
0xb7f69110: 0xa1 0x95 0x96 0xa2 0x45 0x1d 0x16 0x19
0xb7f69118: 0x2b 0xb2 0x9a 0x95 0x9c 0xc4 0x24 0x18
0xb7f69120: 0x18 0x25 0xc3 0x9d 0x96 0x9c 0xba 0x28
0xb7f69128: 0x19 0x19 0x26 0xc3 0x9d 0x98 0x9d 0xc4
0xb7f69130: 0x26 0x1a 0x1b 0x2d 0xb4 0x9c 0x99 0xa4
0xb7f69138: 0x4c 0x1f 0x1a 0x1f 0x4a 0xa6 0x9a 0x9d
0xb7f69140: 0xb9 0x2b 0x1c 0x1d 0x2f 0xb2 0x9d 0x9c
0xb7f69148: 0xac 0x38 0x1e 0x1d 0x2b 0xbe 0x9f 0x9c
0xb7f69150: 0xaa 0x3e 0x20 0x1d 0x2b 0xbf 0xa0 0x9d
0xb7f69158: 0xad 0x3a 0x20 0x1f 0x30 0xb7 0x9f 0x9f
0xb7f69160: 0xb8 0x2f 0x1f 0x23 0x43 0xac 0x9f 0xa7