Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* gdb registers multiple definition of symbols : patch to fix this
@ 2007-07-31 12:02 Kalpana Ramamurthy
  2007-07-31 17:16 ` Daniel Jacobowitz
  0 siblings, 1 reply; 4+ messages in thread
From: Kalpana Ramamurthy @ 2007-07-31 12:02 UTC (permalink / raw)
  To: gdb; +Cc: kalpana.balaji

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-08-01 11:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-31 12:02 gdb registers multiple definition of symbols : patch to fix this Kalpana Ramamurthy
2007-07-31 17:16 ` Daniel Jacobowitz
2007-08-01  4:45   ` gdb registers multiple definition of symbols : patch to fixthis Kalpana Ramamurthy
2007-08-01 11:21     ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox