c++/2065: Unable to locate constructors with forward-declared classes

thor@math.tu-berlin.de thor@math.tu-berlin.de
Sat Jan 7 21:48:00 GMT 2006

>Number:         2065
>Category:       c++
>Synopsis:       Unable to locate constructors with forward-declared classes
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          patch
>Submitter-Id:   net
>Arrival-Date:   Sat Jan 07 21:48:01 GMT 2006
>Originator:     thor@math.tu-berlin.de
>Release:        6.4
gdb fails to resolve the address of class constructors correctly if the class declaration (instead of its definition) is found first in the symbol file.
If a source file contains a forward declaration of a class, and this file is compiled first, then g++ inserts a "typedef" symbol into the debugging output. If now a breakpoint is set at the constructor of this class, this typedef is resolved instead of the full name, giving it an address of zero. If gdb is requested to list the constructor, it crashes with a segfault. Similarly, if a breakpoint is inserted at the constructor, setting the breakpoint fails because it is thought of to be at address zero. 

Thus, this bug is hard to reproduce because it depends on the layout of the object file whether the mentioned problem appears. See the fix below, though.
Replace gdb/symtab.c, lines 1789ff by the following:

	  if (SYMBOL_DOMAIN (sym) == domain
	      && (linkage_name != NULL
		  ? strcmp (SYMBOL_LINKAGE_NAME (sym), linkage_name) == 0 : 1)) { /* FIX THOR */
	    if (domain != VAR_DOMAIN || sym->aclass != LOC_TYPEDEF) /* Must *NOT* use type forwards here */
	      return sym;
	  } /* FIX THOR end */

This adds an additional test for forward declarations and avoids to return them as valid symbol resolutions.

More information about the Gdb-prs mailing list