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]

Re: using directive patch


Hi,

the patch did not apply for HEAD - the current GIT snapshot should be updated.
Fixed a real crash on missing imported `DW_AT_name', fixed a possible crash on
missing `DW_AT_import'.

Unfortunately it cannot work right as there is a GCC Bug I submitted now for
`using namespace' inside blocks:
	http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37410
I expect that after fixing this GCC Bug the testcase included below (*1) will
fail due to the line `using_directives = NULL;' in finish_block() - IMO it
should restore (not reset) the original using-directives context.  Due to the
GCC Bug the GDB Bug is not reproducible.

There is also still missing the renaming support.


Thanks,
Jan


(*1):
At `break2' try to print `aaa'.
------------------------------------------------------------------------------
#include <stdio.h>

namespace A1
  {
    int aaa = 1;
  };
namespace A2
  {
    int bbb = 2;
  };

int
main (void)
{
  int x;
  using namespace A1;
  x = 0;

  {
    using namespace A2;
    int block_create;

    block_create = bbb; /* break1 */
    printf ("%d\n", bbb);
  }

  printf ("%d\n", aaa); /* break2 */

  return 0;
}
------------------------------------------------------------------------------
--- ./gdb/block.c	2008-09-07 10:12:55.000000000 +0200
+++ ./gdb/block.c	2008-09-07 20:22:44.000000000 +0200
@@ -207,24 +207,16 @@ block_set_scope (struct block *block, co
 }
 
 /* This returns the first using directives associated to BLOCK, if
-   any.  */
-
-/* FIXME: carlton/2003-04-23: This uses the fact that we currently
-   only have using directives in static blocks, because we only
-   generate using directives from anonymous namespaces.  Eventually,
-   when we support using directives everywhere, we'll want to replace
-   this by some iterator functions.  */
+   any.  Each BLOCK_NAMESPACE()->USING already contains all the namespaces
+   imported at that code point - even those from its parent blocks.  */
 
 struct using_direct *
 block_using (const struct block *block)
 {
-  const struct block *static_block = block_static_block (block);
-
-  if (static_block == NULL
-      || BLOCK_NAMESPACE (static_block) == NULL)
+  if (block == NULL || BLOCK_NAMESPACE (block) == NULL)
     return NULL;
   else
-    return BLOCK_NAMESPACE (static_block)->using;
+    return BLOCK_NAMESPACE (block)->using;
 }
 
 /* Set BLOCK's using member to USING; if needed, allocate memory via
--- ./gdb/buildsym.c	2008-08-21 20:40:34.000000000 +0200
+++ ./gdb/buildsym.c	2008-09-07 20:10:29.000000000 +0200
@@ -384,6 +384,10 @@ finish_block (struct symbol *symbol, str
       opblock = pblock;
     }
 
+  block_set_using (block, using_directives, &objfile->objfile_obstack);
+  
+  using_directives = NULL;
+
   record_pending_block (objfile, block, opblock);
 
   return block;
@@ -1202,10 +1206,12 @@ push_context (int desc, CORE_ADDR valu)
   new->params = param_symbols;
   new->old_blocks = pending_blocks;
   new->start_addr = valu;
+  new->using_directives = using_directives;
   new->name = NULL;
 
   local_symbols = NULL;
   param_symbols = NULL;
+  using_directives = NULL;
 
   return new;
 }
--- ./gdb/buildsym.h	2008-04-07 21:29:55.000000000 +0200
+++ ./gdb/buildsym.h	2008-09-07 17:25:56.000000000 +0200
@@ -125,6 +125,10 @@ EXTERN struct pending *local_symbols;
 
 EXTERN struct pending *param_symbols;
 
+/* using directives local to lexical context */
+
+EXTERN struct using_direct *using_directives;
+
 /* Stack representing unclosed lexical contexts (that will become
    blocks, eventually).  */
 
@@ -138,6 +142,10 @@ struct context_stack
 
     struct pending *params;
 
+    /* Pending using directives at the time we entered */
+
+    struct using_direct *using_directives;
+
     /* Pointer into blocklist as of entry */
 
     struct pending_block *old_blocks;
--- ./gdb/cp-namespace.c	2008-08-21 20:40:34.000000000 +0200
+++ ./gdb/cp-namespace.c	2008-09-07 17:26:15.000000000 +0200
@@ -35,11 +35,6 @@
 
 static struct using_direct *using_list;
 
-static struct using_direct *cp_add_using (const char *name,
-					  unsigned int inner_len,
-					  unsigned int outer_len,
-					  struct using_direct *next);
-
 static struct using_direct *cp_copy_usings (struct using_direct *using,
 					    struct obstack *obstack);
 
@@ -237,7 +232,7 @@ cp_is_anonymous (const char *namespace)
    using xmalloc.  It copies the strings, so NAME can be a temporary
    string.  */
 
-static struct using_direct *
+struct using_direct *
 cp_add_using (const char *name,
 	      unsigned int inner_len,
 	      unsigned int outer_len,
--- ./gdb/cp-support.h	2008-08-21 20:40:34.000000000 +0200
+++ ./gdb/cp-support.h	2008-09-07 17:12:50.000000000 +0200
@@ -80,6 +80,11 @@ extern void cp_add_using_directive (cons
 				    unsigned int outer_length,
 				    unsigned int inner_length);
 
+extern struct using_direct *cp_add_using (const char *name,
+					  unsigned int inner_len,
+					  unsigned int outer_len,
+					  struct using_direct *next);
+
 extern void cp_initialize_namespace (void);
 
 extern void cp_finalize_namespace (struct block *static_block,
--- ./gdb/dwarf2read.c	2008-09-02 00:21:45.000000000 +0200
+++ ./gdb/dwarf2read.c	2008-09-07 17:51:01.000000000 +0200
@@ -937,6 +937,8 @@ static void read_common_block (struct di
 
 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
 
+static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
+
 static const char *namespace_name (struct die_info *die,
 				   int *is_anonymous, struct dwarf2_cu *);
 
@@ -2756,14 +2758,12 @@ process_die (struct die_info *die, struc
       break;
     case DW_TAG_imported_declaration:
     case DW_TAG_imported_module:
-      /* FIXME: carlton/2002-10-16: Eventually, we should use the
-	 information contained in these.  DW_TAG_imported_declaration
-	 dies shouldn't have children; DW_TAG_imported_module dies
-	 shouldn't in the C++ case, but conceivably could in the
-	 Fortran case.  */
       processing_has_namespace_info = 1;
-      complaint (&symfile_complaints, _("unsupported tag: '%s'"),
-		 dwarf_tag_name (die->tag));
+      if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
+				 || cu->language != language_fortran))
+	complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
+		   dwarf_tag_name (die->tag));
+      read_import_statement (die, cu);
       break;
     default:
       new_symbol (die, NULL, cu);
@@ -2809,6 +2809,37 @@ dwarf2_full_name (struct die_info *die, 
   return name;
 }
 
+/* Read the import statement specified by the given die and record it.  */ 
+
+static void
+read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
+{
+  struct attribute *import_attr;
+  struct die_info *imported_die;
+  char *imported_name;
+  
+  import_attr = dwarf2_attr (die, DW_AT_import, cu);
+  if (import_attr == NULL)
+    {
+      complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
+		 dwarf_tag_name (die->tag));
+      return;
+    }
+
+  imported_die = follow_die_ref (die, import_attr, &cu);
+  imported_name = dwarf2_name (imported_die, cu);
+  if (imported_name == NULL)
+    {
+      /* C++ imports from std:: DW_TAG_base_type with no DW_AT_name - why?  */
+      return;
+    }
+
+  /* FIXME: dwarf2_name (die); for the local name after import.  */
+  
+  using_directives = cp_add_using (imported_name, strlen (imported_name), 0,
+                                   using_directives);
+}
+
 static void
 initialize_cu_func_list (struct dwarf2_cu *cu)
 {
@@ -3043,6 +3074,7 @@ read_func_scope (struct die_info *die, s
      back to building a containing block's symbol lists.  */
   local_symbols = new->locals;
   param_symbols = new->params;
+  using_directives = new->using_directives;
 
   /* If we've finished processing a top-level function, subsequent
      symbols go in the file symbol list.  */

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