Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: gdb@sourceware.org
Subject: Re: Ada testsuite failures
Date: Wed, 03 Jan 2007 14:04:00 -0000	[thread overview]
Message-ID: <20070103140514.GA19241@adacore.com> (raw)
In-Reply-To: <20070102164044.GA14566@nevyn.them.org>

[-- Attachment #1: Type: text/plain, Size: 2761 bytes --]

> (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

[-- Attachment #2: nochild.diff --]
[-- Type: text/plain, Size: 1450 bytes --]

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;

[-- Attachment #3: nofield.c --]
[-- Type: text/plain, Size: 1169 bytes --]

/* 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;
}


[-- Attachment #4: nofield.exp --]
[-- Type: text/plain, Size: 1594 bytes --]

# 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"


  parent reply	other threads:[~2007-01-03 14:04 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-31 19:46 Daniel Jacobowitz
2007-01-02  7:37 ` Joel Brobecker
2007-01-02 14:42   ` Daniel Jacobowitz
2007-01-02 16:31     ` Joel Brobecker
2007-01-02 11:38 ` Joel Brobecker
2007-01-02 14:39   ` Daniel Jacobowitz
2007-01-02 16:30     ` Joel Brobecker
2007-01-02 16:32       ` Joel Brobecker
2007-01-02 16:40         ` Daniel Jacobowitz
2007-01-02 16:50           ` Joel Brobecker
2007-01-03 14:04           ` Joel Brobecker [this message]
2007-01-03 14:05             ` Joel Brobecker
2007-01-03 22:21             ` Jim Blandy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070103140514.GA19241@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox