GCC輸出帶C源代碼的彙編文件

GCC輸出帶C源代碼的彙編文件,一共有兩種方式(一樣也適合G++輸出呆CPP源代碼的彙編文件)。
測試代碼(hello.cpp)
  1. #include<iostream>
  2. usingnamespace std;
  3. intFactorialTail(int n,int sum)
  4. {
  5. if(n <0){return0;}
  6. elseif(n ==0){return1;}
  7. elseif(n ==1){return sum;}
  8. else{returnFactorialTail(n -1, n * sum);}
  9. }
  10. int main()
  11. {
  12. cout <<FactorialTail(5,1)<< endl;
  13. return0;
  14. }
 
第一種方式:
一、
  1. g++-S hello.cpp
  2. g++ -g -c hello.cpp
   生成.s彙編文件和.o文件:
_S.png
二、第一步中必需要使用第二條命令,第一條命令只是爲了顯示.s彙編文件
  1. objdump -S hello.o > hello_objdump.s
生成含有調試信息、CPP源代碼的彙編代碼
objdump.png
 

第二種方式:ios

使用GNU C Assembler的列表功能來完成,例如:測試

  1. g++-c -g -Wa,-adlhn hello.cpp > gnu.s

 

這個命令的說明以下: 
-Wa,option :把選項option傳遞給彙編器.若是option含有逗號,就在逗號處分割成多個選項.也就是Gas,至於Gas的命令參數,能夠查看相應的文檔,其中-a[cdghlns]參數的做用是打開列表功能。spa

這種方式能夠顯示足夠的信息,可是命令稍微複雜,參數比較多,不太容易選擇。命令行

Gas的命令行參數概要信息摘錄以下:調試

 1:  a: -a[cdghlns] enable listings 
 2:  alternate: --alternate enable alternate macro syntax 
 3:  D: -D for compatibility 
 4:  f: -f to work faster 
 5:  I: -I for .include search path 
 6:  K: -K for difference tables 
 7:  L: -L to retain local symbols 
 8:  listing: --listing-XXX to configure listing output 
 9:  M: -M or --mri to assemble in MRI compatibility mode 
10:  MD: --MD for dependency tracking 
11:  o: -o to name the object file 
12:  R: -R to join data and text sections 
13:  statistics: --statistics to see statistics about assembly 
14:  traditional-format: --traditional-format for compatible output 
15:  v: -v to announce version 
16:  W: -W, --no-warn, --warn, --fatal-warnings to control warnings 
17:  Z: -Z to make object file even after errors 

 

生成含有調試信息、CPP源代碼的彙編代碼:code

gun.png

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
相比而言,仍是第一種方式生成的文件更加的直觀明瞭。





附件列表

相關文章
相關標籤/搜索