https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81932

            Bug ID: 81932
           Summary: Template arguments of type unsigned generate incorrect
                    debugging information
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: psmith at gnu dot org
  Target Milestone: ---

I've upgraded from GCC 6.2/binutils 2.27 to GCC 7.2/binutils 2.29 (compiled
myself), running on GNU/Linux on x86_64.  Everything is fine except that GDB
(I've tried both 7.11 and 8.0) can no longer correctly print objects of one of
my templated classes, which I have created a Python printer for.

My template is complex but it's basically:

  template<typename T, unsigned int LEAF_SIZE_POW = 6>
  class TreeVector
  {
    ...
      class Tree
      {
    ...
      private:
          uint const _depth;
      };
    ...
      Tree* tree;
      uint64 _maxIndex;
    ...
  };

When I compile with GCC 6.2, I'm able to see the type of my object via GDB
Python macros:

  (gdb) ptype tv
  type = class TreeVector<Pod, 2u> [with T = Pod] {
    private:
      TreeVector<T, 2u>::Tree *tree;
      volatile uint64 _maxIndex;
    ...

  (gdb) ptype tv.tree
  type = class TreeVector<Pod, 2u>::Tree {
    private:
      const uint _depth;
    ...

  (gdb) python
  >class tv(gdb.Function):
  >    def __init__(self):
  >        gdb.Function.__init__(self, "tv")
  >    def invoke(self, vector):
  >        gdb.write("vector: %s\n" % (str(vector.type)))
  >        gdb.write("tree: %s\n" % (str(vector['tree'].type)))
  >        gdb.write("depth: %d\n" % (vector['tree']['_depth']))
  >        tt = gdb.lookup_type("TreeVector<Pod, 2u>::Tree")
  >        return 0
  >tv()
  >^D

  (gdb) p $tv(tv)
  vector: TreeVector<Pod, 2u>
  tree: TreeVector<Pod, 2u>::Tree *
  depth: 3
  $1 = 0

Note here how the value for the second template argument is "2u" and everything
works.

Now I compile this same code with GCC 7.2/binutils 2.29 and use the same GDB,
and my results are different:

  (gdb) ptype tv
  type = class TreeVector<Pod, 2> [with T = Pod] {
    private:
      TreeVector<T, 2>::Tree *tree;
      volatile uint64 _maxIndex;
    ...

  (gdb) ptype tv.tree
  type = class TreeVector<Pod, 2>::Tree {
    private:
      const uint _depth;
    ...

  (gdb) p $tv(tv)
  vector: TreeVector<Pod, 2>
  tree: TreeVector<Pod, 2>::Tree *
  warning: RTTI symbol not found for class 'TreeVector<Pod, 2u>::Tree'
  depth: 3
  Python Exception <class 'gdb.error'> No type named TreeVector<Pod,
2u>::Tree.: 
  Error occurred in Python convenience function: No type named TreeVector<Pod,
2u>::Tree.

Note how the value in the template is just "2", not "2u".  But, when GDB shows
the RTTI warning it's still looking for the "2u" in the type.  However that
type definitely doesn't exist (we get an error trying to look it up).

If I change my template to use "int" instead of "unsigned int", then everything
works in both versions of GCC (removing the now-invalid gdb.lookup_type call):

  (gdb) ptype tv
  type = class TreeVector<Pod, 2> [with T = Pod] {
    ...

  (gdb) p $tv(tv)
  vector: TreeVector<Pod, 2>
  tree: TreeVector<Pod, 2>::Tree *
  depth: 3
  $1 = 0

Reply via email to