cdebugginggccdwarf

Source column numbers in DWARF line table


For any element in a C/C++ source file, I would like to be able to determine the corresponding memory location within its compiled executable. Compiling with debug, and using the resulting DWARF information goes a long way towards this, but falls just short of my goal. GCC seems to generate the DWARF .debug_line information with only line numbers, leaving column numbers as 0! It seems odd to me that the DWARF specification allows for column numbers to be specified, but GCC does not seem to generate them.

Is there something I am missing - perhaps some configuration or command line parameter to let GCC know that I would like columns in my debug info? Or perhaps there is an entirely different way to accomplish my goal?

Here is a simple bit of code to demonstrates the lack of column numbers in DWARF:

int f(int x)
{
    x = 0; x++;
    return x;
}

Compile this with:

gcc -g -c test.c

Then view DWARF information with:

dwarfdump -l test.o

Here's the output:

.debug_line: line number info for a single cu
Source lines (from CU-DIE at .debug_info offset 0x0000000b):

<pc>        [row,col] NS BB ET PE EB IS= DI= uri: "filepath"
NS new statement, BB new basic block, ET end of text sequence
PE prologue end, EB epilogue begin
IA=val ISA number, DI=val discriminator value
0x00000000  [   2, 0] NS uri: "test.c"
0x00000007  [   3, 0] NS
0x00000012  [   4, 0] NS
0x00000015  [   5, 0] NS
0x00000017  [   5, 0] NS ET

Solution

  • GCC does not emit column numbers in DWARF. It could be done, but nobody has supplied a patch to do it. If you're interested, GCC's DWARF generation code is (nearly) all in gcc/dwarf2out.c.