红联Linux门户
Linux帮助

为什么exit函数在run前后会发生变化?

发布时间:2010-11-14 11:29:58来源:红联作者:vfdff
测试代码:[code]#include
#include
#include
#include
#include
#include

int main(int argc,char** argv)
{
printf("\ntest generic function 11\n");

exit(1);

printf("\ntest generic function 31\n");

return 0;
}[/code](gdb) b main
Breakpoint 1 at 0x804847d: file hook1.c, line 10.
(gdb) disas exit
Dump of assembler code for function exit@plt:
0x080483b0 : jmp *0x804a00c
0x080483b6 : push $0x18
0x080483bb : jmp 0x8048370
End of assembler dump.

(gdb) r
Starting program: /home/zyd/projects/test
Missing separate debuginfo for /lib/ld-linux.so.2
Try: zypper install -C "debuginfo(build-id)=d7706cbaa0ca09319cb645eac789cb8399078797"
Missing separate debuginfo for /usr/lib/libstdc++.so.6
Try: zypper install -C "debuginfo(build-id)=7a23cb3bcf4e7a44325f46051276e8e7872f0ec7"
Missing separate debuginfo for /lib/libm.so.6
Try: zypper install -C "debuginfo(build-id)=a488c775caa0433cb23f9764d683150f40872ef1"
Missing separate debuginfo for /lib/libgcc_s.so.1
Try: zypper install -C "debuginfo(build-id)=d7d12f7fa08cc56782efdf6ec887bb02452b3646"
Missing separate debuginfo for /lib/libc.so.6
Try: zypper install -C "debuginfo(build-id)=ee302691046515fe3766ae3b7d47afd3e3a8d063"

Breakpoint 1, main (argc=1, argv=0xbffff104) at hook1.c:10
10 printf("\ntest generic function 11\n");
Current language: auto
The current source language is "auto; currently c++".
(gdb) disas exit
Dump of assembler code for function exit:
0xb7d59140 : push %ebx
0xb7d59141 : call 0xb7d418de <_Unwind_Find_FDE+114>
0xb7d59146 : add $0x12deae,%ebx
0xb7d5914c : sub $0x18,%esp
0xb7d5914f : movl $0x1,0x8(%esp)
0xb7d59157 : lea 0x330(%ebx),%eax
0xb7d5915d : mov %eax,0x4(%esp)
0xb7d59161 : mov 0x20(%esp),%eax
0xb7d59165 : mov %eax,(%esp)
0xb7d59168 : call 0xb7d59050
End of assembler dump.

(gdb)

在执行(gdb) r前后可以发现,exit对应的汇编代码内容发生了变化,这个是为什么呢 ?
文章评论

共有 1 条评论

  1. vfdff 于 2010-11-14 12:24:10发表:

    (gdb) b main
    Breakpoint 1 at 0x8048487: file hook1.c, line 15.
    (gdb) b printf
    Function "printf" not defined.
    Make breakpoint pending on future shared library load? (y or [n]) y

    Breakpoint 2 (printf) pending.
    (gdb) b exit
    Breakpoint 3 at 0x80483b0
    (gdb)

    为什么对同样的库函数,exit就定义了,而printf则没有定义呢 ?