c++/2066: gdb fails to resolve symbols of forward-declared classes

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

>Number:         2066
>Category:       c++
>Synopsis:       gdb fails to resolve symbols of forward-declared classes
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          patch
>Submitter-Id:   net
>Arrival-Date:   Sat Jan 07 21:58:01 GMT 2006
>Originator:     thor@math.tu-berlin.de
>Release:        6.4
If a class appears as a member of a larger class, and the inner class is forward declared somewhere in the file such that the forward-typedef is found first in the symbol table, gdb fails to resolve the members of the inner class.
Hard. Requires a careful layout of the object file, but see the patch that fixes the problem.

Setup at least three files plus headers, forward class A in the first file, define class B with inner class A in the second, define class A in the third. Link in proper order such that the forward is first in the symbol file. Then open the debugee with gdb, try to print the value of any inner member of class A.
Replace valops.c, lines 2258 ff. by the following:

  /* FIX THOR : Must convert the base type to the
  ** proper real base type with check_typedef.
  for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--) {
    struct type *t = check_typedef (TYPE_BASECLASS (type, i));
    if (check_field_in (t, name))
      return 1;

  return 0;

More information about the Gdb-prs mailing list