Debugging information is put into .o files by compilers. The level and format of information is controlled by compiler options. Use the -g option with the Intel® C++ or Fortran (ifort) Compiler, for example:
% icc -g hello.c
...
% icpc -g hello.cpp
...
With the GNU* Compiler Collection (GCC, versions earlier than 3.x), use the -gdwarf-2 option:
% gcc -gdwarf-2 hello.c
...
% g++ -gdwarf-2 hello.cpp
...
See your compiler's reference page for more details.
The debugging information is propagated into the a.out (executable) or .so (shared library) by the link command.
The debugging information can cause .o files to be very large, causing long link times, but even so it can also be incomplete.
If you are debugging optimized code, refer to the Debugging Optimized Code section of this manual and the appropriate compiler documentation for information about -g and related extended debug options and their relationship to optimization.