为什么exit函数在run前后会发生变化?
测试代码:
- 1. #include <malloc.h>
- 2. #include <stdio.h>
- 3. #include <stdlib.h>
- 4. #include <string.h>
- 5. #include <asm/page.h>
- 6. #include <sys/mman.h>
- 7.
- 8. int main(int argc,char** argv)
- 9. {
- 10. printf("ntest generic function 11n");
- 11.
- 12. exit(1);
- 13.
- 14. printf("ntest generic function 31n");
- 15.
- 16. return 0;
- 17. }
复制代码(gdb) b main
Breakpoint 1 at 0x804847d: file hook1.c, line 10.
(gdb) disas exit
Dump of assembler code for function exit@plt:
0x080483b0 <exit@plt+0>: jmp *0x804a00c
0x080483b6 <exit@plt+6>: push $0x18
0x080483bb <exit@plt+11>: 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 11n");
Current language: auto
The current source language is "auto; currently c++".
(gdb) disas exit
Dump of assembler code for function exit:
0xb7d59140 <exit+0>: push %ebx
0xb7d59141 <exit+1>: call 0xb7d418de <_Unwind_Find_FDE+114>
0xb7d59146 <exit+6>: add $0x12deae,%ebx
0xb7d5914c <exit+12>: sub $0x18,%esp
0xb7d5914f <exit+15>: movl $0x1,0x8(%esp)
0xb7d59157 <exit+23>: lea 0x330(%ebx),%eax
0xb7d5915d <exit+29>: mov %eax,0x4(%esp)
0xb7d59161 <exit+33>: mov 0x20(%esp),%eax
0xb7d59165 <exit+37>: mov %eax,(%esp)
0xb7d59168 <exit+40>: call 0xb7d59050
End of assembler dump.
(gdb)
在执行(gdb) r前后可以发现,exit对应的汇编代码内容发生了变化,这个是为什么呢 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
路过,看看
请问您是怎么发现printf被转换成了puts的呢 ?
回复 3# vfdff
在我的系统上(ubuntu 10.04),printf()被GCC转换成puts()了。
exit/puts都有类似的变化了,这恐怕与动态链接时修改PLT/GOT有关,GDB这里聪明了一把。
更深入地,得DX来解惑了
不过我发现在使用cygwin时没有这个问题,难道cygwin没有libc库这种处理方法吗?而是直接进行连接
(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则没有定义呢 ?