Able properly intermix the assembly and high-level source code
|
135 |
---|
(gdb) where
#4 0x080718f4 in main ()
(gdb) print &select
We will focus more on stack tracebacks, problem determination facilities, and using a debugger in other chapters. For now, we will concentrate on the steps needed to create an assembly listing and how to correlate an offset with a line of code.
4.5.2 Generating Assembly Listings
{
int a = 5;
printf( “%s %d\n”, s, c );
|
Compiling Chap. 4 |
---|
This produces the executable file as_listing. For gcc, specifying the -S flag causes the compilation to stop before the assembling phase and dump out the generated assembly code. By default, if -o is not used to specify an output filename, gcc converts the input source filename extension (such as .c) to .s. To be able to properly intermix the assembly and high-level source code, it is also required to use the -g flag to produce debug symbols and line number information. For the code in as_listing.c, to produce an assembly output, run the following command:
gcc as_listing.c -S -g
For the most part, the reason for examining an assembly listing is to determine how the compiler interpreted the high-level language and what assembly language resulted. When first looking at an assembly listing, it can be quite intimidating. It’s important to understand that there is a lot of information in this file that is only of use to a system’s assembler. Generally, much of this data can be ignored as often only a very specific area of the code will be desired and referred to by a function name and an offset in a stack dump or stack traceback for example. With this information and the assembly listing in hand,