This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
gdb registers multiple definition of symbols : patch to fix this
- From: "Kalpana Ramamurthy" <kal_pana at hotmail dot com>
- To: gdb at sourceware dot org
- Cc: kalpana dot balaji at symphonysv dot com
- Date: Tue, 31 Jul 2007 11:53:23 +0000
- Subject: gdb registers multiple definition of symbols : patch to fix this
- Bcc:
Hello,
My code is written for 64 bit support. I have upgraded the compiler to 3.4.6
which was previously 3.2.2. I think the default debug information generated
is dwarf-2 (the code was compiled with -ggdb option). I have a class
definition containing about 10 fields. But when I say "ptype cGroupCache",
it shows me only 1 field !. This happened to a some of the other classes too
that I tested. But in those cases, when I start gdb with --readnow option, I
see all the fields. But for this particular class, --readnow option doesn't
help either.
Why this patch is required with the code is compiled with gcc 3.4.6 is
something that I still don't
know.
Currently to workaround this problem, I patched the symtab.c code with the
following algorithm in the function lookup_symbol_aux_symtabs().
1. Browse across all the definitions of the symbol
2. For each definition found, get the number of fields
3. If the number is greater thatn the number of fields of the last saved
defintion, save the definition.
4. At the end of the browsing, return the saved definition (if it exists).
Please note that though this patch fixes the problem, its only a workaround.
The root cause is still
unknown. Why is gdb registering multiple definitions of the symbol ? And
even if that's necessary,
why is it not picking the correct definition ?
Code snippet that was patched :
***************************************************
/* Add declarations for sym1, block1, s1 and maxfields */
struct symbol * sym, *sym1;
const struct block *block, *block1 ;
struct symtab *s, *s1 ;
int maxfields = -1;
/* Initialize sym1 to NULL */
sym1 = NULL ;
ALL_SYMTABS (objfile, s)
{
bv = BLOCKVECTOR (s)
block = BLOCKVECTOR_BLOCK (bv, block_index) ;
sym = lookup_block_symbol (block, name, linkage_name, domain);
/* PATCH begins */
if (sym)
{
int fields = 0 ;
if (sym->type && sym->type->main_type)
{
fields = sym->type->main_type->nfields;
}
if (fields >= maxfields)
{
maxfields = fields ;
sym1 = sym ;
block1 = block ;
s1 = s ;
}
}
if (sym1)
{
block_found = block1 ;
if (symtab != NULL)
*symtab = s1 ;
sym = fixup_symbol_section (sym1, objfile) ;
return (sym1) ;
}
}
*******************************************************
_________________________________________________________________
Catch all the cricketing action right here. Live score, match reports,
photos et al. http://content.msn.co.in/Sports/Cricket/Default.aspx