This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
Context cleanup
- From: Sami Wagiaalla <swagiaal at redhat dot com>
- To: Project Archer <archer at sourceware dot org>
- Date: Fri, 12 Sep 2008 11:50:57 -0400
- Subject: Context cleanup
This patch gits rid of three global variables in buildsym.h
(pending_blocks, local_symbols, param_symbols), and replaces their use
with one global context_stack object which already contains the same
variables. All references to the old global variables are replaced by
'current_context.{respective variable}'.
This promotes code reuse, helps us avoid creating global context
variables which need to be represented in the context object anyways.
Eg: using_directives in my "using directive patch"... there might be
more variables to come.
As for automatically restoring the context in pop_context, or using the
top of the stack for current context, I may or may not do that in a
separate patch. The problem is that when context is poped code keeps
referring to the old and current context so the refactor is not straight
forward.
2008-09-12 Sami Wagiaalla <swagiaal@redhat.com>
* buildsym.h: Deleted global variable pending_blocks, local_symbols,
param_symbols.
Created global struct current_context.
* buildsym.c: Use current_context instead of global variables.
* dwarf2read.c: Ditto.
* mdebugread.c: Ditto.
* stabsread.c: Ditto.
* dbxread.c: Ditto.
* coffread.c: Ditto.
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index 1945c22..282d761 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -222,7 +222,7 @@ free_pending_blocks (void)
{
/* The links are made in the objfile_obstack, so we only need to
reset PENDING_BLOCKS. */
- pending_blocks = NULL;
+ current_context.old_blocks = NULL;
}
/* Take one of the lists of symbols and make a block from it. Keep
@@ -342,7 +342,7 @@ finish_block (struct symbol *symbol, struct pending **listhead,
start of this scope that don't have superblocks yet. */
opblock = NULL;
- for (pblock = pending_blocks;
+ for (pblock = current_context.old_blocks;
pblock && pblock != old_blocks;
pblock = pblock->next)
{
@@ -413,8 +413,8 @@ record_pending_block (struct objfile *objfile, struct block *block,
}
else
{
- pblock->next = pending_blocks;
- pending_blocks = pblock;
+ pblock->next = current_context.old_blocks;
+ current_context.old_blocks = pblock;
}
}
@@ -459,7 +459,7 @@ make_blockvector (struct objfile *objfile)
/* Count the length of the list of blocks. */
- for (next = pending_blocks, i = 0; next; next = next->next, i++)
+ for (next = current_context.old_blocks, i = 0; next; next = next->next, i++)
{;
}
@@ -475,7 +475,7 @@ make_blockvector (struct objfile *objfile)
sure this is true. */
BLOCKVECTOR_NBLOCKS (blockvector) = i;
- for (next = pending_blocks; next; next = next->next)
+ for (next = current_context.old_blocks; next; next = next->next)
{
BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
}
@@ -935,7 +935,7 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
{
cstk = pop_context ();
/* Make a block for the local symbols within. */
- finish_block (cstk->name, &local_symbols, cstk->old_blocks,
+ finish_block (cstk->name, &(current_context.locals), cstk->old_blocks,
cstk->start_addr, end_addr, objfile);
if (context_stack_depth > 0)
@@ -953,7 +953,7 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
/* Reordered executables may have out of order pending blocks; if
OBJF_REORDERED is true, then sort the pending blocks. */
- if ((objfile->flags & OBJF_REORDERED) && pending_blocks)
+ if ((objfile->flags & OBJF_REORDERED) && current_context.old_blocks)
{
/* FIXME! Remove this horrid bubble sort and use merge sort!!! */
int swapped;
@@ -961,7 +961,7 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
{
struct pending_block *pb, *pbnext;
- pb = pending_blocks;
+ pb = current_context.old_blocks;
pbnext = pb->next;
swapped = 0;
@@ -996,7 +996,7 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
cleanup_undefined_types ();
finish_global_stabs (objfile);
- if (pending_blocks == NULL
+ if (current_context.old_blocks == NULL
&& file_symbols == NULL
&& global_symbols == NULL
&& have_line_numbers == 0
@@ -1198,14 +1198,14 @@ push_context (int desc, CORE_ADDR valu)
new = &context_stack[context_stack_depth++];
new->depth = desc;
- new->locals = local_symbols;
- new->params = param_symbols;
- new->old_blocks = pending_blocks;
+ new->locals = current_context.locals;
+ new->params = current_context.params;
+ new->old_blocks = current_context.old_blocks;
new->start_addr = valu;
new->name = NULL;
- local_symbols = NULL;
- param_symbols = NULL;
+ current_context.locals = NULL;
+ current_context.params = NULL;
return new;
}
@@ -1286,7 +1286,7 @@ buildsym_init (void)
free_pendings = NULL;
file_symbols = NULL;
global_symbols = NULL;
- pending_blocks = NULL;
+ current_context.old_blocks = NULL;
pending_macros = NULL;
/* We shouldn't have any address map at this point. */
diff --git a/gdb/buildsym.h b/gdb/buildsym.h
index 294bc41..2f0c849 100644
--- a/gdb/buildsym.h
+++ b/gdb/buildsym.h
@@ -117,14 +117,6 @@ EXTERN struct pending *file_symbols;
EXTERN struct pending *global_symbols;
-/* everything local to lexical context */
-
-EXTERN struct pending *local_symbols;
-
-/* func params local to lexical context */
-
-EXTERN struct pending *param_symbols;
-
/* Stack representing unclosed lexical contexts (that will become
blocks, eventually). */
@@ -170,6 +162,8 @@ EXTERN int context_stack_depth;
EXTERN int context_stack_size;
+EXTERN struct context_stack current_context;
+
/* Non-zero if the context stack is empty. */
#define outermost_context_p() (context_stack_depth == 0)
@@ -187,14 +181,6 @@ struct pending_block
struct block *block;
};
-/* Pointer to the head of a linked list of symbol blocks which have
- already been finalized (lexical contexts already closed) and which
- are just waiting to be built into a blockvector when finalizing the
- associated symtab. */
-
-EXTERN struct pending_block *pending_blocks;
-
-
struct subfile_stack
{
struct subfile_stack *next;
diff --git a/gdb/coffread.c b/gdb/coffread.c
index de81d47..c184d04 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -1024,7 +1024,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
enter_linenos (fcn_line_ptr, fcn_first_line, fcn_last_line,
objfile);
- finish_block (new->name, &local_symbols, new->old_blocks,
+ finish_block (new->name, ¤t_context.locals, new->old_blocks,
new->start_addr,
fcn_cs_saved.c_value
+ fcn_aux_saved.x_sym.x_misc.x_fsize
@@ -1060,16 +1060,16 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
symnum);
break;
}
- if (local_symbols && context_stack_depth > 0)
+ if (current_context.locals && context_stack_depth > 0)
{
tmpaddr =
cs->c_value + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
/* Make a block for the local symbols within. */
- finish_block (0, &local_symbols, new->old_blocks,
+ finish_block (0, ¤t_context.locals, new->old_blocks,
new->start_addr, tmpaddr, objfile);
}
/* Now pop locals of block just finished. */
- local_symbols = new->locals;
+ current_context.locals = new->locals;
}
break;
@@ -1514,7 +1514,7 @@ process_coff_symbol (struct coff_symbol *cs,
case C_AUTO:
SYMBOL_CLASS (sym) = LOC_LOCAL;
- add_symbol_to_list (sym, &local_symbols);
+ add_symbol_to_list (sym, ¤t_context.locals);
break;
case C_THUMBEXT:
@@ -1535,7 +1535,7 @@ process_coff_symbol (struct coff_symbol *cs,
if (within_function)
{
/* Static symbol of local scope */
- add_symbol_to_list (sym, &local_symbols);
+ add_symbol_to_list (sym, ¤t_context.locals);
}
else
{
@@ -1551,7 +1551,7 @@ process_coff_symbol (struct coff_symbol *cs,
SYMBOL_CLASS (sym) = LOC_REGISTER;
SYMBOL_VALUE (sym) = gdbarch_sdb_reg_to_regnum
(current_gdbarch, cs->c_value);
- add_symbol_to_list (sym, &local_symbols);
+ add_symbol_to_list (sym, ¤t_context.locals);
break;
case C_THUMBLABEL:
@@ -1561,7 +1561,7 @@ process_coff_symbol (struct coff_symbol *cs,
case C_ARG:
SYMBOL_CLASS (sym) = LOC_ARG;
SYMBOL_IS_ARGUMENT (sym) = 1;
- add_symbol_to_list (sym, &local_symbols);
+ add_symbol_to_list (sym, ¤t_context.locals);
break;
case C_REGPARM:
@@ -1569,7 +1569,7 @@ process_coff_symbol (struct coff_symbol *cs,
SYMBOL_IS_ARGUMENT (sym) = 1;
SYMBOL_VALUE (sym) = gdbarch_sdb_reg_to_regnum
(current_gdbarch, cs->c_value);
- add_symbol_to_list (sym, &local_symbols);
+ add_symbol_to_list (sym, ¤t_context.locals);
break;
case C_TPDEF:
@@ -2012,7 +2012,7 @@ coff_read_enum_type (int index, int length, int lastsym,
type = coff_alloc_type (index);
if (within_function)
- symlist = &local_symbols;
+ symlist = ¤t_context.locals;
else
symlist = &file_symbols;
osyms = *symlist;
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 25ec313..174ede3 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -2758,7 +2758,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
new = pop_context ();
/* Make a block for the local symbols within. */
- block = finish_block (new->name, &local_symbols, new->old_blocks,
+ block = finish_block (new->name, ¤t_context.locals, new->old_blocks,
new->start_addr, new->start_addr + valu,
objfile);
@@ -2829,7 +2829,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
if (desc != new->depth)
lbrac_mismatch_complaint (symnum);
- if (local_symbols != NULL)
+ if (current_context.locals != NULL)
{
/* GCC development snapshots from March to December of
2000 would output N_LSYM entries after N_LBRAC
@@ -2839,7 +2839,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
misplaced N_LBRAC entry; discarding local symbols which have \
no enclosing block"));
}
- local_symbols = new->locals;
+ current_context.locals = new->locals;
if (context_stack_depth > 1)
{
@@ -2849,7 +2849,7 @@ no enclosing block"));
for them (but don't bother if the block contains no
symbols. Should we complain on blocks without symbols?
I can't think of any useful purpose for them). */
- if (local_symbols != NULL)
+ if (current_context.locals != NULL)
{
/* Muzzle a compiler bug that makes end < start.
@@ -2861,7 +2861,7 @@ no enclosing block"));
new->start_addr = valu;
}
/* Make a block for the local symbols within. */
- finish_block (0, &local_symbols, new->old_blocks,
+ finish_block (0, ¤t_context.locals, new->old_blocks,
new->start_addr, valu, objfile);
}
}
@@ -3159,7 +3159,7 @@ no enclosing block"));
new = pop_context ();
/* Make a block for the local symbols within. */
- block = finish_block (new->name, &local_symbols,
+ block = finish_block (new->name, ¤t_context.locals,
new->old_blocks, new->start_addr,
valu, objfile);
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 1b68e2a..3e8c6eb 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -3011,7 +3011,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
frame-base has-a location expression. */
dwarf2_symbol_mark_computed (attr, new->name, cu);
- cu->list_in_scope = &local_symbols;
+ cu->list_in_scope = &(current_context.locals);
if (die->child != NULL)
{
@@ -3025,7 +3025,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
new = pop_context ();
/* Make a block for the local symbols within. */
- block = finish_block (new->name, &local_symbols, new->old_blocks,
+ block = finish_block (new->name, ¤t_context.locals, new->old_blocks,
lowpc, highpc, objfile);
/* For C++, set the block's scope. */
@@ -3041,8 +3041,8 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
a function declares a class that has methods). This means that
when we finish processing a function scope, we may need to go
back to building a containing block's symbol lists. */
- local_symbols = new->locals;
- param_symbols = new->params;
+ current_context.locals = new->locals;
+ current_context.params = new->params;
/* If we've finished processing a top-level function, subsequent
symbols go in the file symbol list. */
@@ -3086,10 +3086,10 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
}
new = pop_context ();
- if (local_symbols != NULL)
+ if (current_context.locals != NULL)
{
struct block *block
- = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
+ = finish_block (0, ¤t_context.locals, new->old_blocks, new->start_addr,
highpc, objfile);
/* Note that recording ranges after traversing children, as we
@@ -3104,7 +3104,7 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
to do. */
dwarf2_record_block_ranges (die, block, baseaddr, cu);
}
- local_symbols = new->locals;
+ current_context.locals = new->locals;
}
/* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index ede6fce..343f874 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -3945,7 +3945,7 @@ psymtab_to_symtab_1 (struct partial_symtab *pst, char *filename)
SYMBOL_TYPE (s) = mdebug_type_void;
SYMBOL_VALUE (s) = (long) e;
e->pdr.framereg = -1;
- add_symbol_to_list (s, &local_symbols);
+ add_symbol_to_list (s, ¤t_context.locals);
}
}
else if (sh.st == stLabel)
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index 45e7cee..fe89edf 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -802,7 +802,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
SYMBOL_CLASS (sym) = LOC_LABEL;
SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
SYMBOL_VALUE_ADDRESS (sym) = valu;
- add_symbol_to_list (sym, &local_symbols);
+ add_symbol_to_list (sym, ¤t_context.locals);
break;
case 'f':
@@ -914,7 +914,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
SYMBOL_CLASS (sym) = LOC_LOCAL;
SYMBOL_VALUE (sym) = valu;
SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
- add_symbol_to_list (sym, &local_symbols);
+ add_symbol_to_list (sym, ¤t_context.locals);
break;
case 'p':
@@ -935,7 +935,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
SYMBOL_VALUE (sym) = valu;
SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
SYMBOL_IS_ARGUMENT (sym) = 1;
- add_symbol_to_list (sym, &local_symbols);
+ add_symbol_to_list (sym, ¤t_context.locals);
if (gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG)
{
@@ -993,7 +993,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
/* Known safe, though useless */
}
SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
- add_symbol_to_list (sym, &local_symbols);
+ add_symbol_to_list (sym, ¤t_context.locals);
break;
case 'r':
@@ -1034,12 +1034,12 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
but this case is considered pathological and causes a warning
from a decent compiler. */
- if (local_symbols
- && local_symbols->nsyms > 0
+ if (current_context.locals
+ && current_context.locals->nsyms > 0
&& gdbarch_stabs_argument_has_addr (gdbarch, SYMBOL_TYPE (sym)))
{
struct symbol *prev_sym;
- prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
+ prev_sym = current_context.locals->symbol[current_context.locals->nsyms - 1];
if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
|| SYMBOL_CLASS (prev_sym) == LOC_ARG)
&& strcmp (SYMBOL_LINKAGE_NAME (prev_sym),
@@ -1054,7 +1054,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
break;
}
}
- add_symbol_to_list (sym, &local_symbols);
+ add_symbol_to_list (sym, ¤t_context.locals);
}
else
add_symbol_to_list (sym, &file_symbols);
@@ -1266,7 +1266,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
}
}
SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
- add_symbol_to_list (sym, &local_symbols);
+ add_symbol_to_list (sym, ¤t_context.locals);
break;
case 'v':
@@ -1276,7 +1276,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
SYMBOL_IS_ARGUMENT (sym) = 1;
SYMBOL_VALUE (sym) = valu;
SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
- add_symbol_to_list (sym, &local_symbols);
+ add_symbol_to_list (sym, ¤t_context.locals);
break;
case 'a':
@@ -1296,7 +1296,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
/* Known safe, though useless */
}
SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
- add_symbol_to_list (sym, &local_symbols);
+ add_symbol_to_list (sym, ¤t_context.locals);
break;
case 'X':
@@ -1308,7 +1308,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
SYMBOL_CLASS (sym) = LOC_LOCAL;
SYMBOL_VALUE (sym) = valu;
SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
- add_symbol_to_list (sym, &local_symbols);
+ add_symbol_to_list (sym, ¤t_context.locals);
break;
default:
@@ -4119,8 +4119,8 @@ common_block_start (char *name, struct objfile *objfile)
complaint (&symfile_complaints,
_("Invalid symbol data: common block within common block"));
}
- common_block = local_symbols;
- common_block_i = local_symbols ? local_symbols->nsyms : 0;
+ common_block = current_context.locals;
+ common_block_i = current_context.locals ? current_context.locals->nsyms : 0;
common_block_name = obsavestring (name, strlen (name),
&objfile->objfile_obstack);
}
@@ -4157,7 +4157,7 @@ common_block_end (struct objfile *objfile)
/* Now we copy all the symbols which have been defined since the BCOMM. */
/* Copy all the struct pendings before common_block. */
- for (next = local_symbols;
+ for (next = current_context.locals;
next != NULL && next != common_block;
next = next->next)
{