Yukang's Page

## 获取挂掉程序的栈信息

2013-01-04

\$ gdb -p 5595 -batch -ex bt
0xb7fb4410 in __kernel_vsyscall ()
#0  0xb7fb4410 in __kernel_vsyscall ()
#1  0xb7dc2d50 in nanosleep () from /lib/tls/i686/cmov/libc.so.6
#2  0xb7dc2b87 in sleep () from /lib/tls/i686/cmov/libc.so.6
#3  0x0804874f in main () at print_stack.cc:64


Reddit上的一个得分最高的回复：

The ability to reason about code is probably the most important skill.
But it is sadly rare, and doesn't seem to be taught much, if at all.
Some things are simple, others take some more thought:

* Under what conditions will this branch get taken?
* What could cause this API to fail?
* Are all these parameters even valid?
* What sequence of events could lead to this situation?
* What assumptions does this code make?
* What side-effects does this code have?
* What contract is this code making (or breaking)?

The most talented engineer I know, when presented with a bug, does nothing but
read the code and think about the code and how it could fail.
Most of the time,  he just figures it out in his head and fixes it.
Sometimes he will insert some strategic printfs and narrow it down like that.
I don't think I have ever seen him use a debugger,
even on the most complex of problems.