From patchwork Fri Jul 20 04:27:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 28505 Received: (qmail 13261 invoked by alias); 20 Jul 2018 04:28:07 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 13144 invoked by uid 89); 20 Jul 2018 04:28:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=forever, coffread.c, coffreadc, UD:coffread.c X-HELO: gateway22.websitewelcome.com Received: from gateway22.websitewelcome.com (HELO gateway22.websitewelcome.com) (192.185.46.225) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 20 Jul 2018 04:28:01 +0000 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 1F8B5A05B for ; Thu, 19 Jul 2018 23:28:00 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id gN1CfPxKXbXuJgN1HfXPgT; Thu, 19 Jul 2018 23:27:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=kTyyNfwB2d2Bkbj6kFa1RWEBS9moNYGtRHrXqhwhuqc=; b=T34oiqDoLN+7ILmW6OvD0FHzwV Dkv8EI7xXc0QCceBlo59Vk768dhwjBlv8qRE2lF2HYKOET8R/Oe6ODoIXQgDU/J4+0ddBEI7xMSGC Vm0Jt1C1D9MfA9P2+5+MWkCRS; Received: from 75-166-85-72.hlrn.qwest.net ([75.166.85.72]:39336 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fgN1C-003pgz-2I; Thu, 19 Jul 2018 23:27:50 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA v2 01/23] Move the context stack to buildsym_compunit Date: Thu, 19 Jul 2018 22:27:25 -0600 Message-Id: <20180720042747.18473-2-tom@tromey.com> In-Reply-To: <20180720042747.18473-1-tom@tromey.com> References: <20180720042747.18473-1-tom@tromey.com> This moves the context stack globals to be members of buildsym_compunit, changing the type to a std::vector in the process. Because the callers expect the context stack object to be valid after being popped, at Simon's suggestion I've changed pop_context to return the object rather than the pointer. gdb/ChangeLog 2018-07-19 Tom Tromey * coffread.c (coff_symtab_read): Update. * xcoffread.c (read_xcoff_symtab): Update. * dwarf2read.c (new_symbol): Update. (read_func_scope, read_lexical_block_scope): Update. * dbxread.c (process_one_symbol): Update. * buildsym.h (context_stack, context_stack_depth): Don't declare. (outermost_context_p): Remove macro. (outermost_context_p, get_current_context_stack) (get_context_stack_depth): Declare. (pop_context): Return struct context_stack. * buildsym.c (struct buildsym_compunit) m_context_stack; }; /* The work-in-progress of the compunit we are building. @@ -257,10 +261,6 @@ struct pending_block static struct pending_block *pending_blocks; -/* Currently allocated size of context stack. */ - -static int context_stack_size; - static void free_buildsym_compunit (void); static int compare_line_numbers (const void *ln1p, const void *ln2p); @@ -275,7 +275,6 @@ static void free_pending_blocks (); needed, and realloc'd down to the size actually used, when completed. */ -#define INITIAL_CONTEXT_STACK_SIZE 10 #define INITIAL_LINE_VECTOR_LENGTH 1000 @@ -1025,8 +1024,6 @@ prepare_for_building () { local_symbols = NULL; - context_stack_depth = 0; - /* These should have been reset either by successful completion of building a symtab, or by the scoped_free_pendings destructor. */ gdb_assert (file_symbols == NULL); @@ -1215,15 +1212,15 @@ end_symtab_get_static_block (CORE_ADDR end_addr, int expandable, int required) /* Finish the lexical context of the last function in the file; pop the context stack. */ - if (context_stack_depth > 0) + if (!buildsym_compunit->m_context_stack.empty ()) { - struct context_stack *cstk = pop_context (); + struct context_stack cstk = pop_context (); /* Make a block for the local symbols within. */ - finish_block (cstk->name, &local_symbols, cstk->old_blocks, NULL, - cstk->start_addr, end_addr); + finish_block (cstk.name, &local_symbols, cstk.old_blocks, NULL, + cstk.start_addr, end_addr); - if (context_stack_depth > 0) + if (!buildsym_compunit->m_context_stack.empty ()) { /* This is said to happen with SCO. The old coffread.c code simply emptied the context stack, so we do the @@ -1231,7 +1228,7 @@ end_symtab_get_static_block (CORE_ADDR end_addr, int expandable, int required) believed to happen in most cases (even for coffread.c); it used to be an abort(). */ complaint (_("Context stack not empty in end_symtab")); - context_stack_depth = 0; + buildsym_compunit->m_context_stack.clear (); } } @@ -1575,11 +1572,8 @@ augment_type_symtab (void) struct compunit_symtab *cust = buildsym_compunit->compunit_symtab; const struct blockvector *blockvector = COMPUNIT_BLOCKVECTOR (cust); - if (context_stack_depth > 0) - { - complaint (_("Context stack not empty in augment_type_symtab")); - context_stack_depth = 0; - } + if (!buildsym_compunit->m_context_stack.empty ()) + complaint (_("Context stack not empty in augment_type_symtab")); if (pending_blocks != NULL) complaint (_("Blocks in a type symtab")); if (buildsym_compunit->m_pending_macros != NULL) @@ -1619,17 +1613,11 @@ augment_type_symtab (void) struct context_stack * push_context (int desc, CORE_ADDR valu) { - struct context_stack *newobj; + gdb_assert (buildsym_compunit != nullptr); - if (context_stack_depth == context_stack_size) - { - context_stack_size *= 2; - context_stack = (struct context_stack *) - xrealloc ((char *) context_stack, - (context_stack_size * sizeof (struct context_stack))); - } + buildsym_compunit->m_context_stack.emplace_back (); + struct context_stack *newobj = &buildsym_compunit->m_context_stack.back (); - newobj = &context_stack[context_stack_depth++]; newobj->depth = desc; newobj->locals = local_symbols; newobj->old_blocks = pending_blocks; @@ -1647,11 +1635,14 @@ push_context (int desc, CORE_ADDR valu) /* Pop a context block. Returns the address of the context block just popped. */ -struct context_stack * -pop_context (void) +struct context_stack +pop_context () { - gdb_assert (context_stack_depth > 0); - return (&context_stack[--context_stack_depth]); + gdb_assert (buildsym_compunit != nullptr); + gdb_assert (!buildsym_compunit->m_context_stack.empty ()); + struct context_stack result = buildsym_compunit->m_context_stack.back (); + buildsym_compunit->m_context_stack.pop_back (); + return result; } @@ -1735,6 +1726,35 @@ get_global_using_directives () return &buildsym_compunit->m_global_using_directives; } +/* See buildsym.h. */ + +bool +outermost_context_p () +{ + gdb_assert (buildsym_compunit != nullptr); + return buildsym_compunit->m_context_stack.empty (); +} + +/* See buildsym.h. */ + +struct context_stack * +get_current_context_stack () +{ + gdb_assert (buildsym_compunit != nullptr); + if (buildsym_compunit->m_context_stack.empty ()) + return nullptr; + return &buildsym_compunit->m_context_stack.back (); +} + +/* See buildsym.h. */ + +int +get_context_stack_depth () +{ + gdb_assert (buildsym_compunit != nullptr); + return buildsym_compunit->m_context_stack.size (); +} + /* Initialize anything that needs initializing when starting to read a @@ -1746,14 +1766,6 @@ buildsym_init () { pending_addrmap_interesting = 0; - /* Context stack is initially empty. Allocate first one with room - for a few levels; reuse it forever afterward. */ - if (context_stack == NULL) - { - context_stack_size = INITIAL_CONTEXT_STACK_SIZE; - context_stack = XNEWVEC (struct context_stack, context_stack_size); - } - /* Ensure the scoped_free_pendings destructor was called after the last time. */ gdb_assert (free_pendings == NULL); diff --git a/gdb/buildsym.h b/gdb/buildsym.h index efb35c907b6..32a2e1b7b7b 100644 --- a/gdb/buildsym.h +++ b/gdb/buildsym.h @@ -133,15 +133,6 @@ struct context_stack }; -EXTERN struct context_stack *context_stack; - -/* Index of first unused entry in context stack. */ - -EXTERN int context_stack_depth; - -/* Non-zero if the context stack is empty. */ -#define outermost_context_p() (context_stack_depth == 0) - /* The type of the record_line function. */ typedef void (record_line_ftype) (struct subfile *subfile, int line, CORE_ADDR pc); @@ -201,7 +192,7 @@ extern void buildsym_init (); extern struct context_stack *push_context (int desc, CORE_ADDR valu); -extern struct context_stack *pop_context (void); +extern struct context_stack pop_context (); extern record_line_ftype record_line; @@ -270,6 +261,19 @@ extern void set_local_using_directives (struct using_direct *new_local); extern struct using_direct **get_global_using_directives (); +/* True if the context stack is empty. */ + +extern bool outermost_context_p (); + +/* Return the top of the context stack, or nullptr if there is an + entry. */ + +extern struct context_stack *get_current_context_stack (); + +/* Return the context stack depth. */ + +extern int get_context_stack_depth (); + #undef EXTERN #endif /* defined (BUILDSYM_H) */ diff --git a/gdb/coffread.c b/gdb/coffread.c index ff55542031d..718c3342066 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -1100,7 +1100,7 @@ coff_symtab_read (minimal_symbol_reader &reader, break; } - newobj = pop_context (); + struct context_stack cstk = pop_context (); /* Stack must be empty now. */ if (!outermost_context_p () || newobj == NULL) { @@ -1135,8 +1135,8 @@ coff_symtab_read (minimal_symbol_reader &reader, enter_linenos (fcn_line_ptr, fcn_first_line, fcn_last_line, objfile); - finish_block (newobj->name, &local_symbols, newobj->old_blocks, - NULL, newobj->start_addr, + finish_block (cstk.name, &local_symbols, cstk.old_blocks, + NULL, cstk.start_addr, fcn_cs_saved.c_value + fcn_aux_saved.x_sym.x_misc.x_fsize + ANOFFSET (objfile->section_offsets, @@ -1163,8 +1163,8 @@ coff_symtab_read (minimal_symbol_reader &reader, break; } - newobj = pop_context (); - if (depth-- != newobj->depth) + struct context_stack cstk = pop_context (); + if (depth-- != cstk.depth) { complaint (_("Mismatched .eb symbol ignored " "starting at symnum %d"), @@ -1177,11 +1177,11 @@ coff_symtab_read (minimal_symbol_reader &reader, cs->c_value + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); /* Make a block for the local symbols within. */ - finish_block (0, &local_symbols, newobj->old_blocks, NULL, - newobj->start_addr, tmpaddr); + finish_block (0, &local_symbols, cstk.old_blocks, NULL, + cstk.start_addr, tmpaddr); } /* Now pop locals of block just finished. */ - local_symbols = newobj->locals; + local_symbols = cstk.locals; } break; diff --git a/gdb/dbxread.c b/gdb/dbxread.c index 996da278e24..ad3f2a91bf6 100644 --- a/gdb/dbxread.c +++ b/gdb/dbxread.c @@ -2448,6 +2448,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, { struct gdbarch *gdbarch = get_objfile_arch (objfile); struct context_stack *newobj; + struct context_stack cstk; /* This remembers the address of the start of a function. It is used because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries are relative to the current function's start address. On systems @@ -2512,16 +2513,16 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, } within_function = 0; - newobj = pop_context (); + cstk = pop_context (); /* Make a block for the local symbols within. */ - block = finish_block (newobj->name, &local_symbols, - newobj->old_blocks, NULL, - newobj->start_addr, newobj->start_addr + valu); + block = finish_block (cstk.name, &local_symbols, + cstk.old_blocks, NULL, + cstk.start_addr, cstk.start_addr + valu); /* For C++, set the block's scope. */ - if (SYMBOL_LANGUAGE (newobj->name) == language_cplus) - cp_set_block_scope (newobj->name, block, &objfile->objfile_obstack); + if (SYMBOL_LANGUAGE (cstk.name) == language_cplus) + cp_set_block_scope (cstk.name, block, &objfile->objfile_obstack); /* May be switching to an assembler file which may not be using block relative stabs, so reset the offset. */ @@ -2568,8 +2569,8 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, break; } - newobj = pop_context (); - if (desc != newobj->depth) + cstk = pop_context (); + if (desc != cstk.depth) lbrac_mismatch_complaint (symnum); if (local_symbols != NULL) @@ -2581,9 +2582,9 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, complaint (_("misplaced N_LBRAC entry; discarding local " "symbols which have no enclosing block")); } - local_symbols = newobj->locals; + local_symbols = cstk.locals; - if (context_stack_depth > 1) + if (get_context_stack_depth () > 1) { /* This is not the outermost LBRAC...RBRAC pair in the function, its local symbols preceded it, and are the ones @@ -2596,14 +2597,14 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, /* Muzzle a compiler bug that makes end < start. ??? Which compilers? Is this ever harmful?. */ - if (newobj->start_addr > valu) + if (cstk.start_addr > valu) { complaint (_("block start larger than block end")); - newobj->start_addr = valu; + cstk.start_addr = valu; } /* Make a block for the local symbols within. */ - finish_block (0, &local_symbols, newobj->old_blocks, NULL, - newobj->start_addr, valu); + finish_block (0, &local_symbols, cstk.old_blocks, NULL, + cstk.start_addr, valu); } } else @@ -2876,7 +2877,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, within_function = 1; - if (context_stack_depth > 1) + if (get_context_stack_depth () > 1) { complaint (_("unmatched N_LBRAC before symtab pos %d"), symnum); @@ -2887,15 +2888,15 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, { struct block *block; - newobj = pop_context (); + cstk = pop_context (); /* Make a block for the local symbols within. */ - block = finish_block (newobj->name, &local_symbols, - newobj->old_blocks, NULL, - newobj->start_addr, valu); + block = finish_block (cstk.name, &local_symbols, + cstk.old_blocks, NULL, + cstk.start_addr, valu); /* For C++, set the block's scope. */ - if (SYMBOL_LANGUAGE (newobj->name) == language_cplus) - cp_set_block_scope (newobj->name, block, + if (SYMBOL_LANGUAGE (cstk.name) == language_cplus) + cp_set_block_scope (cstk.name, block, &objfile->objfile_obstack); } diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index b7933de49cf..859419e9d4b 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -13683,10 +13683,10 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) } } - newobj = pop_context (); + struct context_stack cstk = pop_context (); /* Make a block for the local symbols within. */ - block = finish_block (newobj->name, &local_symbols, newobj->old_blocks, - newobj->static_link, lowpc, highpc); + block = finish_block (cstk.name, &local_symbols, cstk.old_blocks, + cstk.static_link, lowpc, highpc); /* For C++, set the block's scope. */ if ((cu->language == language_cplus @@ -13700,7 +13700,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) /* If we have address ranges, record them. */ dwarf2_record_block_ranges (die, block, baseaddr, cu); - gdbarch_make_symbol_special (gdbarch, newobj->name, objfile); + gdbarch_make_symbol_special (gdbarch, cstk.name, objfile); /* Attach template arguments to function. */ if (!template_args.empty ()) @@ -13720,8 +13720,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 = newobj->locals; - set_local_using_directives (newobj->local_using_directives); + local_symbols = cstk.locals; + set_local_using_directives (cstk.local_using_directives); /* If we've finished processing a top-level function, subsequent symbols go in the file symbol list. */ @@ -13737,7 +13737,6 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) { struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile; struct gdbarch *gdbarch = get_objfile_arch (objfile); - struct context_stack *newobj; CORE_ADDR lowpc, highpc; struct die_info *child_die; CORE_ADDR baseaddr; @@ -13777,13 +13776,13 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) } } inherit_abstract_dies (die, cu); - newobj = pop_context (); + struct context_stack cstk = pop_context (); if (local_symbols != NULL || (*get_local_using_directives ()) != NULL) { struct block *block - = finish_block (0, &local_symbols, newobj->old_blocks, NULL, - newobj->start_addr, highpc); + = finish_block (0, &local_symbols, cstk.old_blocks, NULL, + cstk.start_addr, highpc); /* Note that recording ranges after traversing children, as we do here, means that recording a parent's ranges entails @@ -13797,8 +13796,8 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) to do. */ dwarf2_record_block_ranges (die, block, baseaddr, cu); } - local_symbols = newobj->locals; - set_local_using_directives (newobj->local_using_directives); + local_symbols = cstk.locals; + set_local_using_directives (cstk.local_using_directives); } /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */ @@ -21348,26 +21347,28 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, } break; case DW_TAG_formal_parameter: - /* If we are inside a function, mark this as an argument. If - not, we might be looking at an argument to an inlined function - when we do not have enough information to show inlined frames; - pretend it's a local variable in that case so that the user can - still see it. */ - if (!outermost_context_p () - && context_stack[context_stack_depth - 1].name != NULL) - SYMBOL_IS_ARGUMENT (sym) = 1; - attr = dwarf2_attr (die, DW_AT_location, cu); - if (attr) - { - var_decode_location (attr, sym, cu); - } - attr = dwarf2_attr (die, DW_AT_const_value, cu); - if (attr) - { - dwarf2_const_value (attr, sym, cu); - } + { + /* If we are inside a function, mark this as an argument. If + not, we might be looking at an argument to an inlined function + when we do not have enough information to show inlined frames; + pretend it's a local variable in that case so that the user can + still see it. */ + struct context_stack *curr = get_current_context_stack (); + if (curr != nullptr && curr->name != nullptr) + SYMBOL_IS_ARGUMENT (sym) = 1; + attr = dwarf2_attr (die, DW_AT_location, cu); + if (attr) + { + var_decode_location (attr, sym, cu); + } + attr = dwarf2_attr (die, DW_AT_const_value, cu); + if (attr) + { + dwarf2_const_value (attr, sym, cu); + } - list_to_add = cu->list_in_scope; + list_to_add = cu->list_in_scope; + } break; case DW_TAG_unspecified_parameters: /* From varargs functions; gdb doesn't seem to have any diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index 7f4e63e6412..785de290a66 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -1397,17 +1397,17 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst) within_function = 0; break; } - newobj = pop_context (); + struct context_stack cstk = pop_context (); /* Stack must be empty now. */ - if (!outermost_context_p () || newobj == NULL) + if (!outermost_context_p ()) { ef_complaint (cs->c_symnum); within_function = 0; break; } - finish_block (newobj->name, &local_symbols, newobj->old_blocks, - NULL, newobj->start_addr, + finish_block (cstk.name, &local_symbols, cstk.old_blocks, + NULL, cstk.start_addr, (fcn_cs_saved.c_value + fcn_aux_saved.x_sym.x_misc.x_fsize + ANOFFSET (objfile->section_offsets, @@ -1488,8 +1488,8 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst) eb_complaint (cs->c_symnum); break; } - newobj = pop_context (); - if (depth-- != newobj->depth) + struct context_stack cstk = pop_context (); + if (depth-- != cstk.depth) { eb_complaint (cs->c_symnum); break; @@ -1497,14 +1497,14 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst) if (local_symbols && !outermost_context_p ()) { /* Make a block for the local symbols within. */ - finish_block (newobj->name, &local_symbols, - newobj->old_blocks, NULL, - newobj->start_addr, + finish_block (cstk.name, &local_symbols, + cstk.old_blocks, NULL, + cstk.start_addr, (cs->c_value + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)))); } - local_symbols = newobj->locals; + local_symbols = cstk.locals; } break;