UC3M

Telematic/Audiovisual Syst./Communication Syst. Engineering

Systems Architecture

September 2017 - January 2018

14.3.  The debugging option

The executable generated by the compiler contains information about a set of symbols that uses. The nm command shows these symbols. Read the manual page and use this command to show these symbols on the screen. What is the difference in the symbols when using the -a? option?

Detecting execution errors in a C program that has compiled with no problems is the most costly part. The debugger is a program capable of executing a program line by line showing at the same time the source code and the variable values. But in order to do that, the debugger needs the executable to include information about in which files is the source code. This information is not needed for the regular execution of the program, and therefore, to include it, the -g option is used. Compile again the program, but this time using the -g option.

$ gcc -g -Wall -o main_en main_en.c

Generate two executables using different values for the -o option. One including the information for debugging, and another one without it. Check with the ls command that they have different sizes. Next use the nm command with the options -al to show the symbols. What is the difference between both executables?

You may capture the output of the nm command in two files and compare them, either using the editor (you may open two separated windows) or using the diff command (read the manual page). Check for the appearance of the name of the file containing the source code.