Chinaunix首页 | 论坛 | 博客
  • 博客访问: 133781
  • 博文数量: 18
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 174
  • 用 户 组: 普通用户
  • 注册时间: 2014-09-30 10:35
文章分类

全部博文(18)

文章存档

2016年(1)

2015年(13)

2014年(4)

我的朋友

分类: LINUX

2015-10-15 00:52:48

今天用gdb调试程序打印变量值的时候出现<optimized out>情况,百度了下发现是由于编译优化导致,查看了下程序gcc的编译参数带上了 -O2参数用于优化编译,将其修改为-O0不进行编译优化后,调试就比较顺畅了。

顺便把gcc的几个优化选项说明也记录下加深理解
/>

少优化->多优化:

O0 -->> O1 -->> O2 -->>--Os-->> O3

-O0表示没有优化,-O1为缺省值,-O3优化级别最高,-Os相当于-O2.5。是使用了所有-O2的优化选项,但又不缩减代码尺寸的方法。
-O
-O1
Optimize. Optimizing compilation takes somewhat more time, and a lot more memory for a large function.
With -O, the compiler tries to reduce code size and execution time, without performing any optimizations that take a great deal of compilation time.
-O turns on the following optimization flags:
          -fdefer-pop 
          -fmerge-constants 
          -fthread-jumps 
          -floop-optimize 
          -fif-conversion 
          -fif-conversion2 
          -fdelayed-branch 
          -fguess-branch-probability 
          -fcprop-registers
     
-O also turns on -fomit-frame-pointer on machines where doing so does not interfere with debugging. 
-O2
Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. The compiler does not perform loop unrolling or function inlining when you specify -O2. As compared to -O, this option increases both compilation time and the performance of the generated code.

-O2 turns on all optimization flags specified by -O. It also turns on the following optimization flags:
          -fforce-mem 
          -foptimize-sibling-calls 
          -fstrength-reduce 
          -fcse-follow-jumps  -fcse-skip-blocks 
          -frerun-cse-after-loop  -frerun-loop-opt 
          -fgcse  -fgcse-lm  -fgcse-sm  -fgcse-las 
          -fdelete-null-pointer-checks 
          -fexpensive-optimizations 
          -fregmove 
          -fschedule-insns  -fschedule-insns2 
          -fsched-interblock  -fsched-spec 
          -fcaller-saves 
          -fpeephole2 
          -freorder-blocks  -freorder-functions 
          -fstrict-aliasing 
          -funit-at-a-time 
          -falign-functions  -falign-jumps 
          -falign-loops  -falign-labels 
          -fcrossjumping
     
Please note the warning under -fgcse about invoking -O2 on programs that use computed gotos. 
-O3
Optimize yet more. -O3 turns on all optimizations specified by -O2 and also turns on the -finline-functions, -fweb, -frename-registers and -funswitch-loops options.
-O0
Do not optimize. This is the default. 
-Os
Optimize for size. -Os enables all -O2 optimizations that do not typically increase code size. It also performs further optimizations designed to reduce code size.
-Os disables the following optimization flags:

          -falign-functions  -falign-jumps  -falign-loops 
          -falign-labels  -freorder-blocks  -fprefetch-loop-arrays
     
If you use multiple -O options, with or without level numbers, the last such option is the one that is effective.

阅读(12886) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~