Linux下GCC的DEBUG和优化以及编译过程_第1页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、linux下gcc的debug和优化,以及编译过程int main(vo) int* p = 0; return a(p); int a(int *p) int y = *p; return y; rootlocalhost debug -c unlimit rootlocalhost debug gcc -wall g null.c rootlocalhost debug ./a.out segmentation fault (core mped) rootlocalhost debug null.c a.out core.21982 rootlocalhost debug yum -y i

2、nstall gdb rootlocalhost debug gdb a.out core.21982 . . . (gdb) print p no symbol table is loaded. use the command. (gdb) print p $1 = (int *) 0x0 (gdb) backace 0 0x08048389 in a (p=0x0) at null.c:10 1 0x08048377 in main () at null.c:6 (gdb) quit (gdb) 其次:优化实例(这里主要采纳的是-o03和no-loops方式) rootlocalhost

3、opm test.c ilude stdio.h double powern(double d, unsigned n) double x = 1.0; unsigned j; for(j=1;j j+) x *=d; return x; int main(void) double m = 0.0; unsigned i; for(i=1;i =100000000;i+ ) sum += powern(i,i%5); printf( sum = %gn ,sum); return 0; rootlocalhost opm gcc -wall -o0 test.c -o o0 /优化等级为0-不

4、优化 rootlocalhost opm ./o0 sum = 5e+30 real 0m2.815s user 0m2.799s sys 0m0.013s rootlocalhost opm gcc -wall -o1 test.c -o o1 /优化等级为1 rootlocalhost opm time ./o1 sum = 5e+30 real 0m1.849s user 0m1.843s sys 0m0.006s rootlocalhost opm gcc -wall -o2 test.c -o o2 /优化等级为2 rootlocalhost opm time ./o2 sum =

5、5e+30 real 0m1.923s user 0m1.910s sys 0m0.011s rootlocalhost opm gcc -wall -o3 test.c -o o3 /优化等级为1 rootlocalhost opm time ./o3 sum = 5e+30 real 0m1.460s user 0m1.453s sys 0m0.006s rootlocalhost opm gcc -wall -o3 -funroll-loops test.c -o o4 /加入noloop优化 rootlocalhost opm time ./o4 sum = 5e+30 real 0m

6、1.322s user 0m1.308s sys 0m0.014s 第三:优化协助发觉debug rootlocalhost o vim uninit.c int sign(int x) int s; if (x 0) s = 1; else if (x 0) s = -1; return s; rootlocalhost o gcc -wall -c uninit.c rootlocalhost o gcc -wall -o1 -c uninit.c uninit.c: in function 'sign': uninit.c:3: warning: 's'

7、may be u uninitialized in this function rootlocalhost o gcc -wall -o2 -c uninit.c uninit.c: in function 'sign': uninit.c:3: warning: 's' may be used uninitialized in this function rootlocalhost o gcc -wall -o3 -c uninit.c uninit.c: in function 'sign': uninit.c:3: warning: 

8、9;s' may be used uninitialized in this function 编译过程描述实例 rootlocalhost hello vim hello.c include stdio.h int main(void) printf( hello world!n return 0; 第四:最后列举下编译的过程实例 1、 预处理器阶段(p hello.c hello.i) rootlocalhost hello cpp hello.c hello.i 2、 编译器阶段(gcc -wall -s hello.i) rootlocalhost hello gcc -wal

9、l -s hello.i 3、 汇编器阶段(as hello.s -o hello.o) rootlocalhost hello as hello.s -o hello.o 4、 衔接器阶段(gcc hello.o) rootlocalhost hello gcc hello.o rootlocalhost hello ./a.out hello world! rootlocalhost hello file a.out /检测可执行文件的信息 a.out: elf 32-bit lsb eable, intel 80386, version 1 (sysv), for gnu/linux 2.6.9, dynamically linked (uses shared libs), for gnu/linux 2.6.9, not stripped rootlocalhost hello l a.out /检查用到的库文件 lin

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论