diff options
author | David Carlton <carlton@bactrian.org> | 2002-11-14 00:07:54 +0000 |
---|---|---|
committer | David Carlton <carlton@bactrian.org> | 2002-11-14 00:07:54 +0000 |
commit | 248e20ab489d52d38f34f2014b6ee6fecc1b726c (patch) | |
tree | 09871bb618a9a2be344127ed6c5b2fde80a0af98 | |
parent | 7e7f7bd8c5c07d44500adc3542a1abe2f11e50e1 (diff) | |
download | gdb-248e20ab489d52d38f34f2014b6ee6fecc1b726c.zip gdb-248e20ab489d52d38f34f2014b6ee6fecc1b726c.tar.gz gdb-248e20ab489d52d38f34f2014b6ee6fecc1b726c.tar.bz2 |
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.
-rw-r--r-- | gdb/ChangeLog | 39 | ||||
-rw-r--r-- | gdb/Makefile.in | 5 | ||||
-rw-r--r-- | gdb/block.c | 123 | ||||
-rw-r--r-- | gdb/block.h | 23 | ||||
-rw-r--r-- | gdb/buildsym.c | 42 | ||||
-rw-r--r-- | gdb/buildsym.h | 7 | ||||
-rw-r--r-- | gdb/cp-support.h | 10 | ||||
-rw-r--r-- | gdb/dwarf2read.c | 26 | ||||
-rw-r--r-- | gdb/jv-lang.c | 2 | ||||
-rw-r--r-- | gdb/linespec.c | 3 | ||||
-rw-r--r-- | gdb/symtab.c | 26 |
11 files changed, 247 insertions, 59 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 0ab11b0..82304c2 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -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. diff --git a/gdb/Makefile.in b/gdb/Makefile.in index aca6537..266dd97 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -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 index 0000000..f7161ae --- /dev/null +++ b/gdb/block.c @@ -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; + } +} diff --git a/gdb/block.h b/gdb/block.h index b249863..9ad53af 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -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); diff --git a/gdb/buildsym.c b/gdb/buildsym.c index 789c6c6..6a0433f 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -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; } } diff --git a/gdb/buildsym.h b/gdb/buildsym.h index 3b8c16f..6229e06 100644 --- a/gdb/buildsym.h +++ b/gdb/buildsym.h @@ -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; diff --git a/gdb/cp-support.h b/gdb/cp-support.h index bb89c6f..7096304 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -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, diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index b24d51c..2963e0b 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -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 diff --git a/gdb/jv-lang.c b/gdb/jv-lang.c index c0daf07..4f60a4a 100644 --- a/gdb/jv-lang.c +++ b/gdb/jv-lang.c @@ -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; diff --git a/gdb/linespec.c b/gdb/linespec.c index c4e37c9..df1d1b36 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -1481,6 +1481,9 @@ decode_dollar (char **argptr, int funfirstline, struct symtab *default_symtab, +/* 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, diff --git a/gdb/symtab.c b/gdb/symtab.c index c814ec9..73c3b21 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -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) } -/* 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) } -/* 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); -} - - /* Helper routine for make_symbol_completion_list. */ static int return_val_size; |