Apparently gdb cannot find the symbols associated with local variable-length arrays.
Is it a gcc problem or a gdb problem? (Or maybe it's just my problem...).
Take the following program "main.c"
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char **argv ) {
int n;
n = random() & 0xf;
int array[n];
int *array_pt = array;
int i;
for (i=0; i<n; i++) {
array[i] = random()&0xffff;
}
return(0);
}
Compile as:
gcc -c -O0 -g -ggdb -Wall main.c -o main.o
gcc main.o -o main
If I now run it under gdb, I find that symbol "array_pt" is known, but "array" isn't.
(gdb) p array
No symbol "array" in current context.
(gdb) p array_pt
$1 = (int *) 0x7fff5fbff6f0
I circumvent the problem by using a pointer, as in the example, but... is this normal?
After @Michael's suggestion I'm including relevant output of dwarfdump
0x000000d5: TAG_variable [5]
AT_name( "array.1" )
AT_decl_file( "/.../main.c" )
AT_decl_line( 7 )
AT_type( {0x00000152} ( int[]* ) )
AT_location( fbreg -56 )
0x00000104: TAG_variable [5]
AT_name( "array_pt" )
AT_decl_file( "/.../main.c" )
AT_decl_line( 8 )
AT_type( {0x0000015a} ( int* ) )
AT_location( fbreg -72 )
p array
beforearray
has been initialized. Set a breakpoint at say, the for loop, and verify it's still happening.dwarfdump
to verify symbol information exists in the object files / dSYM bundles.-std=c99
?