+ -
当前位置:首页 → 问答吧 → 20101104-[经典]一篇很不错的ARM体系结构的讲义资料,需要的就赶快下载.txt

20101104-[经典]一篇很不错的ARM体系结构的讲义资料,需要的就赶快下载.txt

时间:2010-11-14

来源:互联网

测试代码:

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 11\n");
11.
12. exit(1);
13.
14. printf("\ntest generic function 31\n");
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 11\n");
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对应的汇编代码内容发生了变化,这个是为什么呢 ?

作者: vfdff   发布时间: 2010-11-14

run之前,exit在libc里,只知道原型,只能反汇编出调用exit的代码,
run之后,exit已经在进程地址空间内,不仅知道原型,也知道实体。

作者: xhy   发布时间: 2010-11-14

那为什么printf不是这么处理的 ?

(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则没有定义呢 ?

作者: vfdff   发布时间: 2010-11-14

因为printf被优化成puts了

作者: xhy   发布时间: 2010-11-14

热门下载

更多