Ada testsuite failures

Joel Brobecker brobecker@adacore.com
Wed Jan 3 14:04:00 GMT 2007


> (gdb) ptype bar.empty
> No definition of "bar.empty" in current context.

Thanks for sending me your objfiles. I know what's going on, now.
Once I understood the source of this issue, it was actually fairly
simple to reproduce the problem with a C program. Consider:

    struct empty {};
    struct not_empty { long long a; };
    
    int
    main (void)
    {
      struct empty e = {};
      struct not_empty n = { 1 };
    
      n.a = (long long) &e;
    
      return 0;
    }

The heart of the problem is that struct empty is a struct that does
not have any children. We have some guards in dwarf2read.c for both
partial symbols and full symbols readers that make GDB ignore the
DW_TAG_structure DIEs for type empty:

    add_partial_symbol (...)
    {
        case DW_TAG_structure_type:
          /* Skip aggregate types without children, these are external
             references.  */
          /* NOTE: carlton/2003-10-07: See comment in new_symbol about
             static vs. global.  */
 !!!->    if (pdi->has_children == 0)
            return;
          add_psymbol_to_list (actual_name, strlen (actual_name),

Same for full symbols:

    process_structure_scope (...)
    {
    [...]
      if (die->child != NULL && ! die_is_declaration (die, cu))
        new_symbol (die, die->type, cu);

What saves us with our version of GNAT Pro is that the compiler
also creates a DW_TAG_typedef DIE associated to this struct.
This is this DIE that allows GDB to create a symbol for this type.

With the C example above, where the language allows me to control
whether typedefs are emitted or not, I can reproduce with the compiler
I use the same problem as yours.

The guards cited above have been there since version 1.1 of dwarf2read.c.
I don't know how relevant they are now - presumably today's compilers
would rather use a declaration attribute rather than empty structs.
Strictly speaking, the guard as implemented is wrong. So I propose to
simply remove it.

2006-02-03  Joel Brobecker  <brobecker@adacore.com>

        * dwarf2read.c (add_partial_symbol): Update copyright year.
        Do not skip struct, union and enum types with no children.

2006-02-03  Joel Brobecker  <brobecker@adacore.com>

        * gdb.base/nofield.c: New file.
        * gdb.base/nofield.exp: New testcase.

Tested on x86_64-linux. No regression. Nofield.exp has two FAILs before
the patch, and is all PASS after.

OK to apply?

(It should fix the problem you are seeing, but I am unable to verify
this, because I can't run your program on my machine. It was compiled
with the shared version of the GNAT runtime (libgnat-4.0.so). Next
time I'll make sure to ask to add -bargs -static. Can you verify that
your FAIL is gone with this patch? - Thank you!)

-- 
Joel
-------------- next part --------------
Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.207
diff -u -p -r1.207 dwarf2read.c
--- dwarf2read.c	27 Dec 2006 22:38:57 -0000	1.207
+++ dwarf2read.c	3 Jan 2007 13:58:37 -0000
@@ -1,7 +1,7 @@
 /* DWARF 2 debugging format support for GDB.
 
    Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-                 2002, 2003, 2004, 2005, 2006
+                 2002, 2003, 2004, 2005, 2006, 2007
    Free Software Foundation, Inc.
 
    Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
@@ -1979,12 +1979,8 @@ add_partial_symbol (struct partial_die_i
     case DW_TAG_structure_type:
     case DW_TAG_union_type:
     case DW_TAG_enumeration_type:
-      /* Skip aggregate types without children, these are external
-         references.  */
       /* NOTE: carlton/2003-10-07: See comment in new_symbol about
 	 static vs. global.  */
-      if (pdi->has_children == 0)
-	return;
       add_psymbol_to_list (actual_name, strlen (actual_name),
 			   STRUCT_DOMAIN, LOC_TYPEDEF,
 			   (cu->language == language_cplus
@@ -4017,7 +4013,7 @@ process_structure_scope (struct die_info
       child_die = sibling_die (child_die);
     }
 
-  if (die->child != NULL && ! die_is_declaration (die, cu))
+  if (!die_is_declaration (die, cu))
     new_symbol (die, die->type, cu);
 
   processing_current_prefix = previous_prefix;
-------------- next part --------------
/* This testcase is part of GDB, the GNU debugger.

   Copyright 2007 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
 
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

   Please email any bugs, comments, and/or additions to this file to:
   bug-gdb@prep.ai.mit.edu  */

struct empty {};
union empty_union {};

struct not_empty
{
  long long e;
  long long u;
};

int
main (void)
{
  struct empty e = {};
  union empty_union u;
  struct not_empty n = {1, 2};

  n.e = (long long) &e;
  n.u = (long long) &u;

  return 0;
}

-------------- next part --------------
# Copyright 2007 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA

if $tracelevel {
    strace $tracelevel
}

set testfile "nofield"
set srcfile ${testfile}.c
set binfile ${objdir}/${subdir}/${testfile}
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
    untested "Couldn't compile ${srcfile}"
    return -1
}

set eol "\[\r\n\]+"
set sp "\[ \t\]*"

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}

gdb_test "ptype struct not_empty" \
         "type = struct not_empty {$eol${sp}long long int e;$eol${sp}long long int u;$eol}" \
         "ptype struct not_empty"

gdb_test "ptype struct empty" \
         "type = struct empty {$eol$sp<no data fields>$eol}" \
         "ptype struct empty"

gdb_test "ptype union empty_union" \
         "type = union empty_union {$eol$sp<no data fields>$eol}" \
         "ptype union empty_union"



More information about the Gdb mailing list