Re: teaching gdb about new types?

Doug Evans
2011-05-10T23:42:34Z

On Fri, Apr 29, 2011 at 8:02 PM, Richard Silverman <res@qoxp.net> wrote:
> On Fri, 29 Apr 2011, Paul Koning wrote:
>
>> If you're worried about types rather than line numbers, I would think that
>> all you'd need is a symbol table that has the right type definitions in it.
>>  If you know what they are supposed to be, you can supply such a symbol
>> table easily enough.
>>
>>        paul
>
> I tried that -- I created a little file:
>
> ----------------------------------------
> #include <pthreads.h>
>
> pthread_cond_t p;
> pthread_mutex_t m;
> ----------------------------------------
>
> ... and built an object from it.  However, I can't find a way to get gdb to
> use it while debugging an existing program, that is, to add the type
> definitions in that object to its existing set.  The commands "symbol-file"
> and "add-symbol-file" seem likely candidates, but they don't appear to do
> it.

I've used add-symbol-file to accomplish exactly this kind of thing.
Can you elaborate on what didn't work?

Here's a quick example to illustrate.

bash$ cat foo.c
#include <pthread.h>
pthread_cond_t p;
pthread_mutex_t m;
bash$ gcc -g -c foo.c
bash$ gdb hello.x
[...]
(gdb) pty pthread_cond_t
No symbol "pthread_cond_t" in current context.
(gdb) add-symbol-file foo.o 0
add symbol table from file "foo.o" at
.text_addr = 0x0
(y or n) y
(gdb) pty pthread_cond_t
type = union {
struct {
int __lock;
unsigned int __futex;
long long unsigned int __total_seq;
long long unsigned int __wakeup_seq;
long long unsigned int __woken_seq;
void *__mutex;
unsigned int __nwaiters;
unsigned int __broadcast_seq;
} __data;
char __size[48];
long long int __align;
}
(gdb)