Linuxでexit()関数がどのように機能するかを調べるための小さなプログラムを作成しました。
#include <unistd.h>
int main()
{
exit(0);
}
そして、gccでプログラムをコンパイルしました。
gcc -o example -g -static example.c
gdbでブレークポイントを設定すると、これらの行が表示されます。
Dump of assembler code for function exit:
0x080495a0 <+0>: sub $0x1c,%esp
0x080495a3 <+3>: mov 0x20(%esp),%eax
0x080495a7 <+7>: movl $0x1,0x8(%esp)
0x080495af <+15>: movl $0x80d602c,0x4(%esp)
0x080495b7 <+23>: mov %eax,(%esp)
0x080495ba <+26>: call 0x80494b0 <__run_exit_handlers>
End of assembler dump.
(gdb) b 0x080495a3
Function "0x080495a3" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (0x080495a3) pending.
(gdb) run
Starting program: /home/jack/Documents/overflow/example
[Inferior 1 (process 2299) exited normally]
プログラムはブレークポイントで停止しません。なんで?-staticを使用してプログラムをコンパイルしますが、ライブラリがメモリにロードされるまでブレークポイントが保留されるのはなぜですか?