Tuesday, April 04, 2006

Tips and Tricks using the GCC, CPP and Binutils

For the http://www.lug-salem.de/ I am preparing a short presentation for showing how to use the gcc and cpp and so for collecting information.

the version I am using is :
gcc (GCC) 4.0.3 20060304 (prerelease) (Debian 4.0.2-10)

the general idea is to specialize the information more and more, adding in more constants.
By dealing with the output of the preprocessor we can get a concise overview of the source code in one file. By looking at the assembler, we can see all types of information that is otherwise hard to find.

Here is the outline:
  1. preparation
    1. GNU/sourceforce/debian/cpan/google/redhat/
    2. documentation
    3. mailing list
    4. unpacking the project
    5. looking through the files available
    6. configuration and debugging m4, shell, sed, grep,test and friends
    7. aclocale, automake, autoconf
  2. modification of the makefiles,
    1. turning on the verbose mode and save temps in CFLAGS
CFLAGS = --verbose -save-temps
  1. CPP and various options
    1. checking how to run the C preprocessor... gcc -E
    2. Macro Bodies
    4. non executed blocks
  1. compilation with the gcc, what are the passes.
    1. CPP
    2. LEX
    3. PARSE
    4. AST
    5. RTL
    6. BACKEND
  2. What dump options are available
    1. CC1
    2. I files /usr/lib/gcc/i486-linux-gnu/4.0.3/cc1 -E -quiet -v -I. -I. -I.. -MD device.d -MF .deps/device.Tpo -MP -MT device.o -MQ device.o -DHAVE_CONFIG_H device.c -mtune=i686 -fworking-directory -O2 -fpch-preprocess -o device.i
    3. S files /usr/lib/gcc/i486-linux-gnu/4.0.3/cc1 -fpreprocessed device.i -quiet -dumpbase device.c -mtune=i686 -auxbase-strip device.o -g -O2 -version -o device.s
    4. tree files
    5. RTL
    6. flow graphs
    7. MAP FILES
  1. binutils
    1. NM, OBJDUMP, ReadElf for getting at the results
    1. Finding out the sizes of objects
    2. finding names of functions out of the addresses
    3. unmangling names
  2. using and scripting GDB for debugging and data collection
    1. stopping the command immediatly with a kill sig stop
    2. scripting the gdb
  3. Creating and Dealing with core dumps
    1. Ulimit
    2. debugging without debug information (map files and objdump)
    3. libbacktrace
    4. mapping OBJ files to ASM
  4. Doxygen and Co
  5. GraphViz
  6. Profiling, gprof, cache grid, memory profiles, strace, oprofile