From patchwork Fri Jul 20 04:27:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 28504 Received: (qmail 13177 invoked by alias); 20 Jul 2018 04:28:06 -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 13073 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, T_FILL_THIS_FORM_SHORT autolearn=ham version=3.3.2 spammy=7797, UD:coffread.c, coffread.c, coffreadc X-HELO: gateway30.websitewelcome.com Received: from gateway30.websitewelcome.com (HELO gateway30.websitewelcome.com) (50.116.127.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 20 Jul 2018 04:28:02 +0000 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 14E958456 for ; Thu, 19 Jul 2018 23:28:01 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id gN1CfPxMlbXuJgN1IfXPng; Thu, 19 Jul 2018 23:28:00 -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=UL5qrRlY+F7Cb0AAWIlVEG80P1vrN+UUigzTAh/iuEU=; b=UuOkc2N9/YPr2Yjez2LF5iYyhP etiSsReC+fy2+jx1JJCyYjUkm2FYb1rASNiGLflPeSy189CDk4Q4BBNhJjmABQ1sUzDKQ2s1Q2cpr v/knyDNj5pfI6cqZHYSwENURU; 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-Dd; Thu, 19 Jul 2018 23:27:50 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA v2 02/23] Move current_subfile to buildsym_compunit Date: Thu, 19 Jul 2018 22:27:26 -0600 Message-Id: <20180720042747.18473-3-tom@tromey.com> In-Reply-To: <20180720042747.18473-1-tom@tromey.com> References: <20180720042747.18473-1-tom@tromey.com> This moves the global current_subfile into buildsym_compunit. gdb/ChangeLog 2018-07-19 Tom Tromey * xcoffread.c (process_linenos): Update. * stabsread.c (define_symbol, read_type, read_enum_type): Update. * mdebugread.c (psymtab_to_symtab_1): Update. * dwarf2read.c (setup_type_unit_groups) (lnp_state_machine::handle_set_file, dwarf_record_line_p) (lnp_state_machine::record_line, dwarf_decode_lines): Update. * dbxread.c (process_one_symbol): Update. * coffread.c (coff_symtab_read, enter_linenos) (process_coff_symbol): Update. * buildsym.h (current_subfile): Don't declare. (get_current_subfile): Declare. * buildsym.c (struct buildsym_compunit) : New member. (start_subfile, free_buildsym_compunit, push_subfile) (prepare_for_building, start_symtab): Update. (get_current_subfile): New function. --- gdb/ChangeLog | 19 +++++++++++++++++++ gdb/buildsym.c | 25 ++++++++++++++++++------- gdb/buildsym.h | 6 ++++-- gdb/coffread.c | 8 ++++---- gdb/dbxread.c | 8 ++++---- gdb/dwarf2read.c | 26 +++++++++++++------------- gdb/mdebugread.c | 2 +- gdb/stabsread.c | 8 ++++---- gdb/xcoffread.c | 4 +++- 9 files changed, 70 insertions(+), 36 deletions(-) diff --git a/gdb/buildsym.c b/gdb/buildsym.c index aa7191d785b..620f252114d 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -214,6 +214,8 @@ struct buildsym_compunit /* The stack of contexts that are pushed by push_context and popped by pop_context. */ std::vector m_context_stack; + + struct subfile *m_current_subfile = nullptr; }; /* The work-in-progress of the compunit we are building. @@ -761,7 +763,7 @@ start_subfile (const char *name) if (FILENAME_CMP (subfile_name, name) == 0) { - current_subfile = subfile; + buildsym_compunit->m_current_subfile = subfile; if (subfile_name != subfile->name) xfree (subfile_name); return; @@ -779,7 +781,7 @@ start_subfile (const char *name) subfile->next = buildsym_compunit->subfiles; buildsym_compunit->subfiles = subfile; - current_subfile = subfile; + buildsym_compunit->m_current_subfile = subfile; subfile->name = xstrdup (name); @@ -839,7 +841,6 @@ free_buildsym_compunit (void) return; delete buildsym_compunit; buildsym_compunit = NULL; - current_subfile = NULL; } /* For stabs readers, the first N_SO symbol is assumed to be the @@ -895,8 +896,10 @@ void push_subfile () { gdb_assert (buildsym_compunit != nullptr); - gdb_assert (current_subfile != NULL && current_subfile->name != NULL); - buildsym_compunit->m_subfile_stack.push_back (current_subfile->name); + gdb_assert (buildsym_compunit->m_current_subfile != NULL); + gdb_assert (buildsym_compunit->m_current_subfile->name != NULL); + buildsym_compunit->m_subfile_stack.push_back + (buildsym_compunit->m_current_subfile->name); } const char * @@ -1029,7 +1032,6 @@ prepare_for_building () gdb_assert (file_symbols == NULL); gdb_assert (global_symbols == NULL); gdb_assert (pending_addrmap == NULL); - gdb_assert (current_subfile == NULL); gdb_assert (buildsym_compunit == nullptr); } @@ -1068,7 +1070,7 @@ start_symtab (struct objfile *objfile, const char *name, const char *comp_dir, start_subfile (name); /* Save this so that we don't have to go looking for it at the end of the subfiles list. */ - buildsym_compunit->main_subfile = current_subfile; + buildsym_compunit->main_subfile = buildsym_compunit->m_current_subfile; return buildsym_compunit->compunit_symtab; } @@ -1755,6 +1757,15 @@ get_context_stack_depth () return buildsym_compunit->m_context_stack.size (); } +/* See buildsym.h. */ + +struct subfile * +get_current_subfile () +{ + gdb_assert (buildsym_compunit != nullptr); + return buildsym_compunit->m_current_subfile; +} + /* Initialize anything that needs initializing when starting to read a diff --git a/gdb/buildsym.h b/gdb/buildsym.h index 32a2e1b7b7b..9a4856d234d 100644 --- a/gdb/buildsym.h +++ b/gdb/buildsym.h @@ -64,8 +64,6 @@ struct subfile struct symtab *symtab; }; -EXTERN struct subfile *current_subfile; - /* Record the symbols defined for each context in a list. We don't create a struct block for the context until we know how long to make it. */ @@ -274,6 +272,10 @@ extern struct context_stack *get_current_context_stack (); extern int get_context_stack_depth (); +/* Return the current subfile. */ + +extern struct subfile *get_current_subfile (); + #undef EXTERN #endif /* defined (BUILDSYM_H) */ diff --git a/gdb/coffread.c b/gdb/coffread.c index 718c3342066..758cd49b394 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -858,7 +858,7 @@ coff_symtab_read (minimal_symbol_reader &reader, language_unknown, since such a ``file name'' is not recognized. Override that with the minimal language to allow printing values in this symtab. */ - current_subfile->language = language_minimal; + get_current_subfile ()->language = language_minimal; complete_symtab ("_globals_", 0, 0); /* Done with all files, everything from here on out is globals. */ @@ -1128,7 +1128,7 @@ coff_symtab_read (minimal_symbol_reader &reader, of the closing '}', and for which we do not have any other statement-line-number. */ if (fcn_last_line == 1) - record_line (current_subfile, fcn_first_line, + record_line (get_current_subfile (), fcn_first_line, gdbarch_addr_bits_remove (gdbarch, fcn_first_line_addr)); else @@ -1504,7 +1504,7 @@ enter_linenos (long file_offset, int first_line, CORE_ADDR addr = lptr.l_addr.l_paddr; addr += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); - record_line (current_subfile, + record_line (get_current_subfile (), first_line + L_LNNO32 (&lptr), gdbarch_addr_bits_remove (gdbarch, addr)); } @@ -1627,7 +1627,7 @@ process_coff_symbol (struct coff_symbol *cs, name = cs->c_name; name = EXTERNAL_NAME (name, objfile->obfd); - SYMBOL_SET_LANGUAGE (sym, current_subfile->language, + SYMBOL_SET_LANGUAGE (sym, get_current_subfile ()->language, &objfile->objfile_obstack); SYMBOL_SET_NAMES (sym, name, strlen (name), 1, objfile); diff --git a/gdb/dbxread.c b/gdb/dbxread.c index ad3f2a91bf6..b5cec28ae48 100644 --- a/gdb/dbxread.c +++ b/gdb/dbxread.c @@ -2508,7 +2508,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, { CORE_ADDR addr = last_function_start + valu; - record_line (current_subfile, 0, + record_line (get_current_subfile (), 0, gdbarch_addr_bits_remove (gdbarch, addr)); } @@ -2642,7 +2642,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, name. Patch things up. */ if (previous_stab_code == (unsigned char) N_SO) { - patch_subfile_names (current_subfile, name); + patch_subfile_names (get_current_subfile (), name); break; /* Ignore repeated SOs. */ } end_symtab (valu, SECT_OFF_TEXT (objfile)); @@ -2712,12 +2712,12 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, CORE_ADDR addr = processing_gcc_compilation == 2 ? last_function_start : valu; - record_line (current_subfile, desc, + record_line (get_current_subfile (), desc, gdbarch_addr_bits_remove (gdbarch, addr)); sline_found_in_function = 1; } else - record_line (current_subfile, desc, + record_line (get_current_subfile (), desc, gdbarch_addr_bits_remove (gdbarch, valu)); break; diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 859419e9d4b..62c87e635e6 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -11574,18 +11574,18 @@ setup_type_unit_groups (struct die_info *die, struct dwarf2_cu *cu) dwarf2_start_subfile (fe.name, fe.include_dir (cu->line_header)); - if (current_subfile->symtab == NULL) + if (get_current_subfile ()->symtab == NULL) { /* NOTE: start_subfile will recognize when it's been passed a file it has already seen. So we can't assume there's a simple mapping from cu->line_header->file_names to subfiles, plus cu->line_header->file_names may contain dups. */ - current_subfile->symtab - = allocate_symtab (cust, current_subfile->name); + get_current_subfile ()->symtab + = allocate_symtab (cust, get_current_subfile ()->name); } - fe.symtab = current_subfile->symtab; + fe.symtab = get_current_subfile ()->symtab; tu_group->symtabs[i] = fe.symtab; } } @@ -20461,7 +20461,7 @@ lnp_state_machine::handle_set_file (file_name_index file) { const char *dir = fe->include_dir (m_line_header); - m_last_subfile = current_subfile; + m_last_subfile = get_current_subfile (); m_line_has_non_zero_discriminator = m_discriminator != 0; dwarf2_start_subfile (fe->name, dir); } @@ -20526,7 +20526,7 @@ dwarf_record_line_p (unsigned int line, unsigned int last_line, int line_has_non_zero_discriminator, struct subfile *last_subfile) { - if (current_subfile != last_subfile) + if (get_current_subfile () != last_subfile) return 1; if (line != last_line) return 1; @@ -20607,7 +20607,7 @@ lnp_state_machine::record_line (bool end_sequence) fe->included_p = 1; if (m_record_lines_p && m_is_stmt) { - if (m_last_subfile != current_subfile || end_sequence) + if (m_last_subfile != get_current_subfile () || end_sequence) { dwarf_finish_line (m_gdbarch, m_last_subfile, m_address, m_record_line_callback); @@ -20619,11 +20619,11 @@ lnp_state_machine::record_line (bool end_sequence) m_line_has_non_zero_discriminator, m_last_subfile)) { - dwarf_record_line_1 (m_gdbarch, current_subfile, + dwarf_record_line_1 (m_gdbarch, get_current_subfile (), m_line, m_address, m_record_line_callback); } - m_last_subfile = current_subfile; + m_last_subfile = get_current_subfile (); m_last_line = m_line; } } @@ -20954,12 +20954,12 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir, dwarf2_start_subfile (fe.name, fe.include_dir (lh)); - if (current_subfile->symtab == NULL) + if (get_current_subfile ()->symtab == NULL) { - current_subfile->symtab - = allocate_symtab (cust, current_subfile->name); + get_current_subfile ()->symtab + = allocate_symtab (cust, get_current_subfile ()->name); } - fe.symtab = current_subfile->symtab; + fe.symtab = get_current_subfile ()->symtab; } } } diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index 8b1db999773..a22cf84aa36 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -4056,7 +4056,7 @@ psymtab_to_symtab_1 (struct objfile *objfile, /* Handle encoded stab line number. */ valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); - record_line (current_subfile, sh.index, + record_line (get_current_subfile (), sh.index, gdbarch_addr_bits_remove (gdbarch, valu)); } } diff --git a/gdb/stabsread.c b/gdb/stabsread.c index 50ca0e414f1..ad7b459d722 100644 --- a/gdb/stabsread.c +++ b/gdb/stabsread.c @@ -695,7 +695,7 @@ define_symbol (CORE_ADDR valu, const char *string, int desc, int type, SYMBOL_LINE (sym) = 0; /* unknown */ } - SYMBOL_SET_LANGUAGE (sym, current_subfile->language, + SYMBOL_SET_LANGUAGE (sym, get_current_subfile ()->language, &objfile->objfile_obstack); if (is_cplus_marker (string[0])) @@ -1296,7 +1296,7 @@ define_symbol (CORE_ADDR valu, const char *string, int desc, int type, */ /* Pascal accepts names for pointer types. */ - if (current_subfile->language == language_pascal) + if (get_current_subfile ()->language == language_pascal) { TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_LINKAGE_NAME (sym); } @@ -1638,7 +1638,7 @@ again: return error_type (pp, objfile); } type_name = NULL; - if (current_subfile->language == language_cplus) + if (get_current_subfile ()->language == language_cplus) { char *name = (char *) alloca (p - *pp + 1); @@ -3678,7 +3678,7 @@ read_enum_type (const char **pp, struct type *type, sym = allocate_symbol (objfile); SYMBOL_SET_LINKAGE_NAME (sym, name); - SYMBOL_SET_LANGUAGE (sym, current_subfile->language, + SYMBOL_SET_LANGUAGE (sym, get_current_subfile ()->language, &objfile->objfile_obstack); SYMBOL_ACLASS_INDEX (sym) = LOC_CONST; SYMBOL_DOMAIN (sym) = VAR_DOMAIN; diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index 785de290a66..98efa969c38 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -713,6 +713,7 @@ process_linenos (CORE_ADDR start, CORE_ADDR end) /* Line numbers are not necessarily ordered. xlc compilation will put static function to the end. */ + struct subfile *current_subfile = get_current_subfile (); lineTb = arrange_linetable (lv); if (lv == lineTb) { @@ -775,8 +776,9 @@ process_linenos (CORE_ADDR start, CORE_ADDR end) if (fakename == NULL) fakename = " ?"; start_subfile (fakename); - xfree (current_subfile->name); + xfree (get_current_subfile ()->name); } + struct subfile *current_subfile = get_current_subfile (); current_subfile->name = xstrdup (inclTable[ii].name); #endif