Below is the problem statement. At the bottom is my actual question if you end up just skimming the problem statement.
edit
I forgot to mention: I'm linking with --no-strip-discarded --discard-none
. One of the object files (pre-link) gets matched by grep
when I search for the type in question, but I'm not finding that string after dumping info from the object file with nm
, objdump
, and readelf
.
I'm looking at some C code that uses an idiom along the lines of:
// somecode.h
typedef struct {
// ...
volatile unsigned char *member1;
} Type1_t;
typedef struct {
unsigned int member1:16;
unsigned int member2:32;
unsigned int member3:16;
} Type2_t;
// somecode.c
// ...
void someFunction( Type1_t *type1Ptr ) {
// ...
doSomething( ((Type2_t*)type1Ptr->member1)->accessType2Member );
}
Please ignore any objections you might have to the coding style, that isn't my question.
In this case, no instance of Type2_t
is ever instantiated, so as best I can tell the compiler determined it wasn't necessary to emit debugging information about the type.
I'm attempting to monitor the behavior of code using this casted data to track down a problem, but the best I've managed to do is get gdb to print the array in question as an array of bytes. I can set a watch on the array with:
watch {char[12]}type1Ptr->member1
... but in addition to not actually displaying member1, member2, & member3
, the pretty-printer for char arrays prints it out as a sequence of the form \000\032\021
... etc (a note on this: I'm in solaris, and gdb 7.2 in Solaris has issues with libiconv, which gdb uses for code page translations. I'm stuck with ISO-8859-1 for now. I'm unsure if that's why it doesn't just print it as a sequence of hex characters), so I end up either having to print the contents with display
or some other mechanism, then interpret the contents in my head.
What I'm looking for:
gcc
emit all debug symbols, even if the type in question only shows up when doing a cast?
gdb
somehow so the type is defined?gdb
have any facility for doing more complex casts than just casting to currently defined types? As an example, is there a way to do something like the following(gdb) print {struct { unsigned int:16 member1; unsigned int:32 member2;
unsigned int:16 member3;} }( type1Ptr->member1 )
It looks like this question/answer takes care of the 2nd question, and sort of alleviates the need for #3.