Is there anyway using a C compiler such as GCC or clang to generate assembly output that has the C code mapped to the assembly output (so that it possible to see what block of assembly represent in C code) on a Linux system? I am trying to understand what the output of a piece of C code is with O3 enabled but I am having difficult time since my knowledge of assembly is lacking.
Asked
Active
Viewed 2,001 times
3
-
1This might be what you're looking for: http://stackoverflow.com/questions/1289881/using-gcc-to-produce-readable-assembly – Retired Ninja Sep 11 '14 at 07:21
-
use `-S` options with GCC, TCC, BCC – Grijesh Chauhan Sep 11 '14 at 07:22
-
2The quickest way is to use [godbolt](http://gcc.godbolt.org/#) it even uses color to link the C code to assembly. You will have to use `-x c` though but that is not too hard. Previously I would have linked you to [Online C++ compiler and evaluator](http://stackoverflow.com/questions/3916000/online-c-compiler-and-evaluator) but sadly was recently deleted. – Shafik Yaghmour Sep 11 '14 at 07:23
-
You can either go the `objdump` route, or you can tell gcc to generate a listings file (as described [here](http://www.delorie.com/djgpp/v2faq/faq8_20.html)). – Michael Sep 11 '14 at 07:28
1 Answers
0
Use -S
option with gcc
to generate the assembly file output.
gcc -S file.c
EDIT:
If you want to view both assembly
output and C
code side-by-side, use gdb -tui a.out
:
(gdb) layout split
The layout split command divides the window into two parts - one of them displaying the source code, the other one the corresponding assembly.

Shafik Yaghmour
- 154,301
- 39
- 440
- 740

manav m-n
- 11,136
- 23
- 74
- 97
-
The OP wants both C and assembly in the output. `-S` does not do that AFAIK. – Michael Sep 11 '14 at 07:25
-