This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[jankratochvil-misc] Fix visibility of _static_ variables in C++constructors


https://bugzilla.redhat.com/show_bug.cgi?id=445912
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33044

2008-10-06  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dwarf2read.c (unsigned_int_compar): New function.
	(read_func_scope): New variable die_children, initialize it.
	Process all DIEs of DW_AT_abstract_origin not referenced by any of the
	children of this DIE die.

2008-10-06  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.cp/abstract-origin.exp, gdb.cp/abstract-origin.cc: New test.
---
 gdb/dwarf2read.c                         |   87 +++++++++++++++++++++++++++++-
 gdb/testsuite/gdb.cp/abstract-origin.cc  |   42 ++++++++++++++
 gdb/testsuite/gdb.cp/abstract-origin.exp |   40 ++++++++++++++
 3 files changed, 167 insertions(+), 2 deletions(-)
 create mode 100644 gdb/testsuite/gdb.cp/abstract-origin.cc
 create mode 100644 gdb/testsuite/gdb.cp/abstract-origin.exp

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index a6584c4..3bed85f 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -3032,6 +3032,15 @@ add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
   cu->last_fn = thisfn;
 }
 
+static int
+unsigned_int_compar (const void *ap, const void *bp)
+{
+  unsigned int a = *(unsigned int *) ap;
+  unsigned int b = *(unsigned int *) bp;
+
+  return (a > b) - (b > a);
+}
+
 static void
 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
 {
@@ -3044,6 +3053,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
   char *name;
   CORE_ADDR baseaddr;
   struct block *block;
+  unsigned die_children;
 
   baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
 
@@ -3080,14 +3090,87 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
 
   cu->list_in_scope = &local_symbols;
 
-  if (die->child != NULL)
+  child_die = die->child;
+  die_children = 0;
+  while (child_die && child_die->tag)
     {
+      process_die (child_die, cu);
+      child_die = sibling_die (child_die);
+      die_children++;
+    }
+
+  attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
+  if (attr)
+    {
+      /* For the list of CHILD_DIEs.  */
+      unsigned *offsets;
+      unsigned *offsets_end, *offsetp;
+      struct die_info *origin_die, *origin_child_die;
+      struct cleanup *cleanups;
+
+      origin_die = follow_die_ref (die, attr, &cu);
+      if (die->tag != origin_die->tag)
+	complaint (&symfile_complaints,
+		   _("DIE 0x%x and its abstract origin 0x%x have different "
+		     "tags"),
+		   die->offset, origin_die->offset);
+
+      offsets = xmalloc (sizeof (*offsets) * die_children);
+      cleanups = make_cleanup (xfree, offsets);
+
+      offsets_end = offsets;
       child_die = die->child;
       while (child_die && child_die->tag)
 	{
-	  process_die (child_die, cu);
+	  attr = dwarf2_attr (child_die, DW_AT_abstract_origin, cu);
+	  if (!attr)
+	    complaint (&symfile_complaints,
+		       _("Child DIE 0x%x of DIE 0x%x has missing "
+			 "DW_AT_abstract_origin"),
+		       child_die->offset, die->offset);
+	  else
+	    {
+	      struct die_info *child_origin_die;
+
+	      child_origin_die = follow_die_ref (child_die, attr, &cu);
+	      if (child_die->tag != child_origin_die->tag)
+		complaint (&symfile_complaints,
+			   _("Child DIE 0x%x and its abstract origin 0x%x have "
+			     "different tags"),
+			   child_die->offset, child_origin_die->offset);
+	      *offsets_end++ = child_origin_die->offset;
+	    }
 	  child_die = sibling_die (child_die);
 	}
+      qsort (offsets, offsets_end - offsets, sizeof (*offsets),
+	     unsigned_int_compar);
+      /* Disabled as excessively expensive - check if we may ever complain.  */
+      if (0)
+	{
+	  for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
+	    if (offsetp[-1] == *offsetp)
+	      complaint (&symfile_complaints,
+			 _("Child DIEs of DIE 0x%x duplicitly abstract-origin "
+			   "referenced DIE 0x%x"),
+			 die->offset, *offsetp);
+	}
+
+      offsetp = offsets;
+      origin_child_die = origin_die->child;
+      while (origin_child_die && origin_child_die->tag)
+      	{
+	  /* Is origin_child_die referenced by any of the DIE children?  */
+	  while (offsetp < offsets_end && *offsetp < origin_child_die->offset)
+	    offsetp++;
+	  if (offsetp >= offsets_end || *offsetp > origin_child_die->offset)
+	    {
+	      /* Found that origin_child_die is really not referenced.  */
+	      process_die (origin_child_die, cu);
+	    }
+	  origin_child_die = sibling_die (origin_child_die);
+	}
+
+      do_cleanups (cleanups);
     }
 
   new = pop_context ();
diff --git a/gdb/testsuite/gdb.cp/abstract-origin.cc b/gdb/testsuite/gdb.cp/abstract-origin.cc
new file mode 100644
index 0000000..e2de3fb
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/abstract-origin.cc
@@ -0,0 +1,42 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2008 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 3 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, see <http://www.gnu.org/licenses/>.
+   */
+
+extern void f (int *);
+
+class A
+{
+public:
+  A(int i);
+};
+
+A::A(int i)
+{
+  static int *problem = new int(i);
+  f (problem);				/* break-here */
+}
+
+void f (int *)
+{
+}
+
+int
+main (void)
+{
+  A a(42);
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.cp/abstract-origin.exp b/gdb/testsuite/gdb.cp/abstract-origin.exp
new file mode 100644
index 0000000..92cc23c
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/abstract-origin.exp
@@ -0,0 +1,40 @@
+# Copyright 2008 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 3 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, see <http://www.gnu.org/licenses/>.
+
+set testfile abstract-origin
+set srcfile ${testfile}.cc
+set binfile ${objdir}/${subdir}/${testfile}
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
+    untested "Couldn't compile test program"
+    return -1
+}
+
+# Get things started.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+if ![runto_main] {
+    untested abstract-origin
+    return -1
+}
+
+gdb_breakpoint [gdb_get_line_number "break-here"]
+gdb_continue_to_breakpoint "break-here"
+
+# The Bug was: No symbol "problem" in current context.
+gdb_test "p problem" " = \\(int \\*\\) 0x.*"
-- 
1.6.0.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]