Assembler Listings; Disassembling - Red Hat ENTERPRISE LINUX 3 - DEVELOPER TOOLS GUIDE Manual

Developer tools guide
Hide thumbs Also See for ENTERPRISE LINUX 3 - DEVELOPER TOOLS GUIDE:
Table of Contents

Advertisement

16
#1 0x15c in main () at hello.c:18
13. To exit the program and quit the debugger, type:
quit

3.5. Assembler Listings

The compiler normally turns a text based source file into a binary object file. It is possible however
to instruct it to just convert the source code into assembler and stop there. The
It also possible to instruct the compiler to produce an assembler listing as well as an object file. That
can be done as follows:
gcc -c -O2 -Wa,-al hello.c
tells GCC to compile or assemble source files, but not to link them.
-c
optimized code. These are both optional.
options which follows it on to the assembler. The
assembler listing.
This example shows a partial excerpt of an assembler listing for an x386-based target.
29
30 0027 90
31
32
33
34 0028 55
35 0029 89E5
36 002b 83EC08
37 002e 83E4F0
38 0031 83EC0C
39 0034 680E0000
39
00
40 0039 C7050000
40
00000300
40
0000
41 0043 E8FCFFFF
41
FF
42 0048 C7042404
Example 3-2. Assembly listing excerpt
It also possible to produce an assembler listing that intermixes the original input source code with
the assembler instructions produced by the compiler. This can help track down bugs, discover how
the compiler handles certain language constructs (such as function calls) and to learn more about
assembly language. To do this, just add an h to the assembler option like this:
gcc -c -g -O2 -Wa,-alh hello.c

3.6. Disassembling

The
tool can be used to to produce an disassembly of an object or executable file. It is used
objdump
like this:
objdump -d hello.o
Chapter 3. Developing with Red Hat Enterprise Linux Developer Tools
-Wa
.text
.p2align 2„3
.globl main
.type
main:
pushl
movl
subl
andl
subl
pushl
movl
call
movl
tells the compiler to pass the comma-separated list of
option is an assembler option to request an
-al
main,@function
%ebp
%esp, %ebp
$8, %esp
$-16, %esp
$12, %esp
$.LC1
$3, a
puts
$4, (%esp)
option does this.
-S
produces more fully
-O2

Advertisement

Table of Contents
loading

Table of Contents