]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
2002-11-13 David Carlton <carlton@math.stanford.edu>
authorDavid Carlton <carlton@bactrian.org>
Thu, 14 Nov 2002 00:07:54 +0000 (00:07 +0000)
committerDavid Carlton <carlton@bactrian.org>
Thu, 14 Nov 2002 00:07:54 +0000 (00:07 +0000)
* buildsym.c (finish_block): Initialize block_scope (block) in
C++ function blocks.
* dwarf2read.c: Delete variable current_namespace.
(psymtab_to_symtab_1): Rename current_namespace to
processing_current_namespace.
(read_namespace): Ditto.
* buildsym.h: New variable processing_current_namespace.
* block.h: Declarations for block_scope and block_set_scope.
* block.c (block_scope): New function.
(block_set_scope): New function.
* cp-support.h (struct namespace_info): Add 'scope' member.
* buildsym.c (finish_block): Replace BLOCK_USING by
block_set_using.
(end_symtab): Ditto.
* block.h: Declaration for block_set_using.
* block.c (block_set_using): New function.
(block_initialize_namespace): New function.
* symtab.c (lookup_symbol_aux_using): Replace BLOCK_USING by
block_using.
* buildsym.c (finish_block): Set BLOCK_NAMESPACE to NULL, not
BLOCK_USING.
* jv-lang.c (get_java_class_symtab): Ditto.
* block.h: Declaration for block_using.
* block.c (block_using): New function.
* Makefile.in (block.o): New rule; also add block.c to SFILES and
block.o to COMMON_OBS.
* block.c: New file.
* symtab.c (contained_in): Move to block.c.
(block_function): Ditto.
* block.h (struct block): Have the language-specific stuff contain
a struct namespace_info.
(BLOCK_NAMESPACE): New macro.
(BLOCK_USING): Delete.
* linespec.c (decode_variable): Add comment before
decode_variable.
* cp-support.h (struct namespace_info): New struct.

gdb/ChangeLog
gdb/Makefile.in
gdb/block.c [new file with mode: 0644]
gdb/block.h
gdb/buildsym.c
gdb/buildsym.h
gdb/cp-support.h
gdb/dwarf2read.c
gdb/jv-lang.c
gdb/linespec.c
gdb/symtab.c

index 0ab11b051c63d18e99e7eb4521015d2893163e0f..82304c269578717bef03e64894f8891dbf89efb5 100644 (file)
@@ -1,3 +1,42 @@
+2002-11-13  David Carlton  <carlton@math.stanford.edu>
+
+       * buildsym.c (finish_block): Initialize block_scope (block) in
+       C++ function blocks.
+       * dwarf2read.c: Delete variable current_namespace.
+       (psymtab_to_symtab_1): Rename current_namespace to
+       processing_current_namespace.
+       (read_namespace): Ditto.
+       * buildsym.h: New variable processing_current_namespace.
+       * block.h: Declarations for block_scope and block_set_scope.
+       * block.c (block_scope): New function.
+       (block_set_scope): New function.
+       * cp-support.h (struct namespace_info): Add 'scope' member.
+       * buildsym.c (finish_block): Replace BLOCK_USING by
+       block_set_using.
+       (end_symtab): Ditto.
+       * block.h: Declaration for block_set_using.
+       * block.c (block_set_using): New function.
+       (block_initialize_namespace): New function.
+       * symtab.c (lookup_symbol_aux_using): Replace BLOCK_USING by
+       block_using.
+       * buildsym.c (finish_block): Set BLOCK_NAMESPACE to NULL, not
+       BLOCK_USING.
+       * jv-lang.c (get_java_class_symtab): Ditto.
+       * block.h: Declaration for block_using.
+       * block.c (block_using): New function.
+       * Makefile.in (block.o): New rule; also add block.c to SFILES and
+       block.o to COMMON_OBS.
+       * block.c: New file.
+       * symtab.c (contained_in): Move to block.c.
+       (block_function): Ditto.
+       * block.h (struct block): Have the language-specific stuff contain
+       a struct namespace_info.
+       (BLOCK_NAMESPACE): New macro.
+       (BLOCK_USING): Delete.
+       * linespec.c (decode_variable): Add comment before
+       decode_variable.
+       * cp-support.h (struct namespace_info): New struct.
+
 2002-11-06  David Carlton  <carlton@math.stanford.edu>
 
        * linespec.c: Delete declaration of operator_chars.
index aca653773af6ba48dfacbc314e5fc0173388cef1..266dd97742c493ee33b217e74709575f82e2aa0a 100644 (file)
@@ -531,7 +531,7 @@ TARGET_FLAGS_TO_PASS = \
 
 SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \
        ax-general.c ax-gdb.c \
-       bcache.c blockframe.c breakpoint.c buildsym.c builtin-regs.c \
+       bcache.c block.c blockframe.c breakpoint.c buildsym.c builtin-regs.c \
        c-exp.y c-lang.c c-typeprint.c c-valprint.c \
        charset.c cli-out.c coffread.c complaints.c completer.c corefile.c \
        cp-abi.c cp-support.c cp-valprint.c \
@@ -830,7 +830,7 @@ TAGFILES_NO_SRCDIR = $(SFILES) $(HFILES_NO_SRCDIR) $(ALLDEPFILES) \
        $(SUBDIR_CLI_SRCS)
 TAGFILES_WITH_SRCDIR = $(HFILES_WITH_SRCDIR)
 
-COMMON_OBS = version.o blockframe.o breakpoint.o findvar.o regcache.o \
+COMMON_OBS = version.o block.o blockframe.o breakpoint.o findvar.o regcache.o \
        charset.o dictionary.o disasm.o \
        charset.o disasm.o \
        source.o values.o eval.o valops.o valarith.o valprint.o printcmd.o \
@@ -1533,6 +1533,7 @@ ax-gdb.o: ax-gdb.c $(defs_h) $(symtab_h) $(symfile_h) $(gdbtypes_h) \
        $(target_h) $(ax_h) $(ax_gdb_h) $(gdb_string_h) $(block_h)
 ax-general.o: ax-general.c $(defs_h) $(ax_h) $(value_h) $(gdb_string_h)
 bcache.o: bcache.c $(defs_h) $(gdb_obstack_h) $(bcache_h) $(gdb_string_h)
+block.o: block.c $(defs_h) $(block_h) $(gdb_obstack_h) $(cp_support_h)
 blockframe.o: blockframe.c $(defs_h) $(symtab_h) $(bfd_h) $(symfile_h) \
        $(objfiles_h) $(frame_h) $(gdbcore_h) $(value_h) $(target_h) \
        $(inferior_h) $(annotate_h) $(regcache_h) $(gdb_assert_h) \
diff --git a/gdb/block.c b/gdb/block.c
new file mode 100644 (file)
index 0000000..f7161ae
--- /dev/null
@@ -0,0 +1,123 @@
+/* Block support for the GNU debugger, GDB.
+
+   Copyright 2002 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   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.  */
+
+#include "defs.h"
+#include "block.h"
+#include "gdb_obstack.h"
+#include "cp-support.h"
+
+static void block_initialize_namespace (struct block *block,
+                                       struct obstack *obstack);
+
+/* Return the symbol for the function which contains a specified
+   lexical block, described by a struct block BL.  */
+
+struct symbol *
+block_function (struct block *bl)
+{
+  while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)
+    bl = BLOCK_SUPERBLOCK (bl);
+
+  return BLOCK_FUNCTION (bl);
+}
+
+/* Return Nonzero if block A is lexically nested within block B,
+   or if A and B have the same pc range.
+   Return zero otherwise. */
+
+int
+contained_in (struct block *a, struct block *b)
+{
+  if (!a || !b)
+    return 0;
+  return BLOCK_START (a) >= BLOCK_START (b) && BLOCK_END (a) <= BLOCK_END (b);
+}
+
+/* Now come some functions designed to deal with C++ namespace issues.
+   The accessors are safe to use even in the non-C++ case.  */
+
+/* This returns the using directives associated to BLOCK (but _not_
+   its parents), if any.  */
+
+struct using_direct_node *
+block_using (const struct block *block)
+{
+  if (BLOCK_NAMESPACE (block) == NULL)
+    return NULL;
+  else
+    return BLOCK_NAMESPACE (block)->using;
+}
+
+/* Set block_using (BLOCK) to USING; if needed, allocate memory via
+   OBSTACK.  */
+
+void
+block_set_using (struct block *block, struct using_direct_node *using,
+                struct obstack *obstack)
+{
+  block_initialize_namespace (block, obstack);
+
+  BLOCK_NAMESPACE (block)->using = using;
+}
+
+/* This returns the namespace that BLOCK is enclosed in, or "" if it
+   isn't enclosed in a namespace at all.  This travels the chain of
+   superblocks looking for a scope, if necessary.  */
+
+const char *
+block_scope (struct block *block)
+{
+  for (; block != NULL; block = BLOCK_SUPERBLOCK (block))
+    {
+      if (BLOCK_NAMESPACE (block) != NULL
+         && BLOCK_NAMESPACE (block)->scope != NULL)
+       return BLOCK_NAMESPACE (block)->scope;
+    }
+
+  return "";
+}
+
+/* Set block_scope (BLOCK) to SCOPE; if needed, allocate memory via
+   OBSTACK.  (It won't make a copy of SCOPE, however, so that already
+   has to be allocated correctly.)  */
+
+void
+block_set_scope (struct block *block, const char *scope,
+                struct obstack *obstack)
+{
+  block_initialize_namespace (block, obstack);
+
+  BLOCK_NAMESPACE (block)->scope = scope;
+}
+
+/* If BLOCK_NAMESPACE (block) is NULL, allocate it via OBSTACK and
+   ititialize its members to zero.  */
+
+static void
+block_initialize_namespace (struct block *block, struct obstack *obstack)
+{
+  if (BLOCK_NAMESPACE (block) == NULL)
+    {
+      BLOCK_NAMESPACE (block)
+       = obstack_alloc (obstack, sizeof (struct namespace_info));
+      BLOCK_NAMESPACE (block)->using = NULL;
+    }
+}
index b2498636c51a1a7e4163381c05f3c56944c1014c..9ad53af7826a75db75e37c881027ef04a9a510ec 100644 (file)
@@ -50,7 +50,9 @@
 
 struct symbol;
 struct dictionary;
+struct namespace_info;
 struct using_direct_node;
+struct obstack;
 
 struct block
 {
@@ -83,12 +85,11 @@ struct block
   {
     struct
     {
-      /* Contains information about what using directives or other
-        similar features are added by this block.  This should always
-        be NULL for global blocks: if there are using directives that
-        affect an entire file, put it in the static block.  */
+      /* Contains information about namespace-related info relevant to
+        this block: using directives and the current namespace
+        scope.  */
       
-      struct using_direct_node *using;
+      struct namespace_info *namespace;
     }
     cplus_specific;
   }
@@ -112,7 +113,7 @@ struct block
 #define BLOCK_FUNCTION(bl)     (bl)->function
 #define BLOCK_SUPERBLOCK(bl)   (bl)->superblock
 #define BLOCK_DICT(bl)         (bl)->dict
-#define BLOCK_USING(bl)                (bl)->language_specific.cplus_specific.using
+#define BLOCK_NAMESPACE(bl)    (bl)->language_specific.cplus_specific.namespace
 #define BLOCK_GCC_COMPILED(bl) (bl)->gcc_compile_flag
 
 struct blockvector
@@ -136,3 +137,13 @@ extern struct symbol *block_function (struct block *);
 
 extern int contained_in (struct block *, struct block *);
 
+extern struct using_direct_node *block_using (const struct block *);
+
+extern void block_set_using (struct block *block,
+                            struct using_direct_node *using,
+                            struct obstack *obstack);
+
+extern const char *block_scope (struct block *block);
+
+extern void block_set_scope (struct block *block, const char *scope,
+                            struct obstack *obstack);
index 789c6c658871e12ee0997c344a7d3fffe5b7d67e..6a0433fe16b00c6d0439cebfb5cbf067945676db 100644 (file)
@@ -344,7 +344,7 @@ finish_block (struct symbol *symbol, struct pending **listhead,
   BLOCK_END (block) = end;
   /* Superblock filled in when containing block is made */
   BLOCK_SUPERBLOCK (block) = NULL;
-  BLOCK_USING (block) = NULL;
+  BLOCK_NAMESPACE (block) = NULL;
 
   BLOCK_GCC_COMPILED (block) = processing_gcc_compilation;
 
@@ -448,18 +448,41 @@ finish_block (struct symbol *symbol, struct pending **listhead,
          const char *name = SYMBOL_CPLUS_DEMANGLED_NAME (symbol);
          const char *next;
 
+         if (processing_has_namespace_info)
+           block_set_scope (block, processing_current_namespace,
+                            &objfile->symbol_obstack);
+         else
+           {
+             const char *current, *next;
+             
+             for (current = name, next = cp_find_first_component (current);
+                  *next == ':';
+                  /* The '+ 2' is to skip the '::'.  */
+                  current = next,
+                    next = cp_find_first_component (current + 2))
+               ;
+             if (current == name)
+               block_set_scope (block, "", &objfile->symbol_obstack);
+             else
+               block_set_scope (block,
+                                obsavestring (name, current - name,
+                                              &objfile->symbol_obstack),
+                                &objfile->symbol_obstack);
+           }
+         
          for (next = cp_find_first_component (name);
               *next == ':';
               /* The '+ 2' is to skip the '::'.  */
               next = cp_find_first_component (next + 2))
            {
-             BLOCK_USING (block)
-               = cp_add_using_obstack (name, 0, next - name,
-                                       BLOCK_USING (block),
-                                       &objfile->symbol_obstack);
+             block_set_using (block,
+                              cp_add_using_obstack (name, 0, next - name,
+                                                    block_using (block),
+                                                    &objfile->symbol_obstack),
+                              &objfile->symbol_obstack);
            }
 
-         /* FIMXE: carlton/2002-10-09: Until I understand the
+         /* FIXME: carlton/2002-10-09: Until I understand the
             possible pitfalls of demangled names a lot better, I want
             to make sure I'm not running into surprises.  */
          gdb_assert (*next == '\0');
@@ -1025,9 +1048,10 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
       blockvector = make_blockvector (objfile);
       if (using_list != NULL)
        {
-         BLOCK_USING (BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK))
-           = copy_usings_to_obstack (using_list,
-                                     &objfile->symbol_obstack);
+         block_set_using (BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK),
+                          copy_usings_to_obstack (using_list,
+                                                  &objfile->symbol_obstack),
+                          &objfile->symbol_obstack);
          using_list = NULL;
        }
     }
index 3b8c16fa19f22938aeed4266a59d0cd2a11e4597..6229e060e0079fd881f84aacc19079d9ef21219e 100644 (file)
@@ -99,6 +99,13 @@ EXTERN unsigned char processing_hp_compilation;
 
 EXTERN unsigned char processing_has_namespace_info;
 
+/* If processing_has_namespace_info is nonzero, this string should
+   contain the name of the current namespace.  Other people shouldn't
+   have to copy it when referring to it, so don't free its previous
+   contents when setting this to a new value.  */
+
+EXTERN const char *processing_current_namespace;
+
 /* Count symbols as they are processed, for error messages.  */
 
 EXTERN unsigned int symnum;
index bb89c6fe26f7ed097f4d095fecc24489b5c47aa3..70963040f0ab77435eab3c657d95bac0354440b9 100644 (file)
@@ -67,6 +67,16 @@ struct using_direct_node
   struct using_direct_node *next;
 };
 
+/* This is used by struct block to store namespace-related info for
+   C++ files, namely using declarations and the current namespace in
+   scope.  */
+
+struct namespace_info
+{
+  struct using_direct_node *using;
+  const char *scope;
+};
+
 extern struct
 using_direct_node *cp_add_using_obstack (const char *name,
                                         unsigned short outer_length,
index b24d51c6278f75b11e9655a56b9f59f9611ff055..2963e0bcaffbd9a61209f58ad8541800fd698a63 100644 (file)
@@ -388,13 +388,6 @@ static struct partial_die_info zeroed_partial_die;
    in buildsym.c.  */
 static struct pending **list_in_scope = &file_symbols;
 
-/* If we're debugging C++ code, this string should contain the name of
-   the current namespace.  Other people shouldn't have to copy it when
-   referring to it, so don't free its previous contents when setting
-   this to a new value.  */
-
-static const char *current_namespace;
-
 /* FIXME: decode_locdesc sets these variables to describe the location
    to the caller.  These ought to be a structure or something.   If
    none of the flags are set, the object lives at the address returned
@@ -1632,7 +1625,7 @@ psymtab_to_symtab_1 (struct partial_symtab *pst)
   info_ptr = dwarf_info_buffer + offset;
 
   /* We're in the global namespace.  */
-  current_namespace = "";
+  processing_current_namespace = "";
 
   obstack_init (&dwarf2_tmp_obstack);
   back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
@@ -2992,7 +2985,7 @@ static void
 read_namespace (struct die_info *die, struct objfile *objfile,
                const struct comp_unit_head *cu_header)
 {
-  const char *previous_namespace = current_namespace;
+  const char *previous_namespace = processing_current_namespace;
   const char *name = NULL;
   int is_anonymous;
   struct die_info *current_die;
@@ -3015,18 +3008,19 @@ read_namespace (struct die_info *die, struct objfile *objfile,
 
   /* Now build the name of the current namespace.  */
 
-  current_namespace = obconcat (&objfile->symbol_obstack,
-                               previous_namespace,
-                               previous_namespace[0] == '\0' ? "" : "::",
-                               name);
+  processing_current_namespace = obconcat (&objfile->symbol_obstack,
+                                          previous_namespace,
+                                          previous_namespace[0] == '\0'
+                                          ? "" : "::",
+                                          name);
 
   /* If it's an anonymous namespace that we're seeing for the first
      time, add a using directive.  */
 
   if (is_anonymous && dwarf_attr (die, DW_AT_extension) == NULL)
-    add_using_directive (current_namespace,
+    add_using_directive (processing_current_namespace,
                         strlen (previous_namespace),
-                        strlen (current_namespace));
+                        strlen (processing_current_namespace));
   
   
   if (die->has_children)
@@ -3040,7 +3034,7 @@ read_namespace (struct die_info *die, struct objfile *objfile,
        }
     }
 
-  current_namespace = previous_namespace;
+  processing_current_namespace = previous_namespace;
 }
 
 /* Extract all information from a DW_TAG_pointer_type DIE and add to
index c0daf07286fec17444b9579d4a8e463871a87ae4..4f60a4af6c5ec58c87f87a37519e9645607944b3 100644 (file)
@@ -117,7 +117,7 @@ get_java_class_symtab (void)
       BLOCK_SUPERBLOCK (bl) = NULL;
       BLOCK_DICT (bl) = dict_create_linear (&objfile->symbol_obstack,
                                            NULL);
-      BLOCK_USING (bl) = NULL;
+      BLOCK_NAMESPACE (bl) = NULL;
       BLOCK_GCC_COMPILED (bl) = 0;
       BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = bl;
 
index c4e37c93f87602ef7acd045d97c2d9f25502ce6d..df1d1b36d5793a9d580d8fb81f1eb9a3efd33df6 100644 (file)
@@ -1481,6 +1481,9 @@ decode_dollar (char **argptr, int funfirstline, struct symtab *default_symtab,
 
 \f
 
+/* Decode a linespec that's a variable.  If FILE_SYMTAB is non-NULL,
+   look in that file's static variables first.  */
+
 static struct symtabs_and_lines
 decode_variable (char **argptr, int funfirstline, char ***canonical,
                 int is_quoted, char *paren_pointer,
index c814ec959563dbe5905c6f978fbb276916ffe275..73c3b215629c1755d5765c18ffd3f1c3d79740c8 100644 (file)
@@ -1180,7 +1180,7 @@ static struct symbol *lookup_symbol_aux_using (const char *name,
 
   while (block != NULL)
     {
-      using = cp_copy_usings (BLOCK_USING (block), using);
+      using = cp_copy_usings (block_using (block), using);
       block = BLOCK_SUPERBLOCK (block);
     }
 
@@ -1777,18 +1777,6 @@ find_active_alias (struct symbol *sym, CORE_ADDR addr)
 }
 \f
 
-/* Return the symbol for the function which contains a specified
-   lexical block, described by a struct block BL.  */
-
-struct symbol *
-block_function (struct block *bl)
-{
-  while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)
-    bl = BLOCK_SUPERBLOCK (bl);
-
-  return BLOCK_FUNCTION (bl);
-}
-
 /* Find the symtab associated with PC and SECTION.  Look through the
    psymtabs and read in another symtab if necessary. */
 
@@ -3379,18 +3367,6 @@ rbreak_command (char *regexp, int from_tty)
 }
 \f
 
-/* Return Nonzero if block a is lexically nested within block b,
-   or if a and b have the same pc range.
-   Return zero otherwise. */
-int
-contained_in (struct block *a, struct block *b)
-{
-  if (!a || !b)
-    return 0;
-  return BLOCK_START (a) >= BLOCK_START (b) && BLOCK_END (a) <= BLOCK_END (b);
-}
-\f
-
 /* Helper routine for make_symbol_completion_list.  */
 
 static int return_val_size;