From patchwork Thu Aug 21 08:22:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 2481 Received: (qmail 20232 invoked by alias); 21 Aug 2014 08:26:31 -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 20115 invoked by uid 89); 21 Aug 2014 08:26:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN autolearn=no version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 21 Aug 2014 08:26:29 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1XKNhS-0004Jd-BG from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Thu, 21 Aug 2014 01:26:26 -0700 Received: from SVR-ORW-FEM-05.mgc.mentorg.com ([147.34.97.43]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Thu, 21 Aug 2014 01:26:26 -0700 Received: from qiyao.dyndns.org.com (147.34.91.1) by svr-orw-fem-05.mgc.mentorg.com (147.34.97.43) with Microsoft SMTP Server id 14.2.247.3; Thu, 21 Aug 2014 01:26:25 -0700 From: Yao Qi To: Subject: [PATCH 2/3] Check data is GC'ed Date: Thu, 21 Aug 2014 16:22:17 +0800 Message-ID: <1408609338-17561-2-git-send-email-yao@codesourcery.com> In-Reply-To: <1408609338-17561-1-git-send-email-yao@codesourcery.com> References: <53D8A264.1050103@codesourcery.com> <1408609338-17561-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 X-IsSubscribed: yes We see the following fail on arm-none-eabi target, (gdb) print &var^M $1 = (int *) 0x0 <_ftext>^M (gdb) FAIL: gdb.dwarf2/dw2-var-zero-addr.exp: print &var Test dw2-var-zero-addr.exp is intended to test whether GDB can correctly know variable var is GC'ed by linker. Currently, the heuristic GDB is using is (see add_partial_symbol) && addr == 0 && !dwarf2_per_objfile->has_section_at_zero however, it doesn't work for bare metal targets, on which certain section is located at address zero. In this patch, we improve the heuristic that if the variable address is zero, and section at address zero is executable, we think the variable is GC'ed by linker, because there can't be a variable in an executable section. In order to know this, we replace flag has_section_at_zero with a pointer section_at_zero. gdb: 2014-08-20 Yao Qi * dwarf2read.c (struct dwarf2_per_objfile) : Remove. : New field. Callers update. (add_partial_symbol): Extend the condition to check whether the section at zero is executable. (new_symbol_full): Check whether the section at zero is executable. --- gdb/dwarf2read.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index cf2ce76..f5b6341 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -278,9 +278,8 @@ struct dwarf2_per_objfile original data was compressed using 'dwz -m'. */ struct dwz_file *dwz_file; - /* A flag indicating wether this objfile has a section loaded at a - VMA of 0. */ - int has_section_at_zero; + /* The section of this objfile loaded at a VMA of 0. */ + asection *section_at_zero; /* True if we are using the mapped index, or we are faking it for OBJF_READNOW's sake. */ @@ -2186,7 +2185,7 @@ dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames) if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) && bfd_section_vma (abfd, sectp) == 0) - dwarf2_per_objfile->has_section_at_zero = 1; + dwarf2_per_objfile->section_at_zero = sectp; } /* A helper function that decides whether a section is empty, @@ -6851,7 +6850,13 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) if (pdi->d.locdesc && addr == 0 - && !dwarf2_per_objfile->has_section_at_zero) + /* When the address is 0, if the object file doesn't have + section at zero or the section at zero is executable, + we think address 0 means the corresponding variable is + removed by linker, instead of there is a data at address + 0. */ + && (dwarf2_per_objfile->section_at_zero == NULL + || dwarf2_per_objfile->section_at_zero->flags & SEC_CODE)) { /* A global or static variable may also have been stripped out by the linker if unused, in which case its address @@ -7341,8 +7346,8 @@ dwarf2_read_symtab (struct partial_symtab *self, = objfile_data (objfile->separate_debug_objfile_backlink, dwarf2_objfile_data_key); - dwarf2_per_objfile->has_section_at_zero - = dpo_backlink->has_section_at_zero; + dwarf2_per_objfile->section_at_zero + = dpo_backlink->section_at_zero; } dwarf2_per_objfile->reading_partial_symbols = 0; @@ -11758,7 +11763,7 @@ dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, /* A not-uncommon case of bad debug info. Don't pollute the addrmap with bad data. */ if (range_beginning + baseaddr == 0 - && !dwarf2_per_objfile->has_section_at_zero) + && !dwarf2_per_objfile->section_at_zero) { complaint (&symfile_complaints, _(".debug_ranges entry has start address of zero" @@ -11871,7 +11876,7 @@ dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, labels are not in the output, so the relocs get a value of 0. If this is a discarded function, mark the pc bounds as invalid, so that GDB will ignore it. */ - if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) + if (low == 0 && !dwarf2_per_objfile->section_at_zero) return 0; *lowpc = low; @@ -12095,7 +12100,7 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block, /* A not-uncommon case of bad debug info. Don't pollute the addrmap with bad data. */ - if (start == 0 && !dwarf2_per_objfile->has_section_at_zero) + if (start == 0 && !dwarf2_per_objfile->section_at_zero) { complaint (&symfile_complaints, _(".debug_ranges entry has start address of zero" @@ -15668,7 +15673,7 @@ read_partial_die (const struct die_reader_specs *reader, labels are not in the output, so the relocs get a value of 0. If this is a discarded function, mark the pc bounds as invalid, so that GDB will ignore it. */ - if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero) + if (part_die->lowpc == 0 && !dwarf2_per_objfile->section_at_zero) { struct gdbarch *gdbarch = get_objfile_arch (objfile); @@ -17297,7 +17302,7 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir, pst = cu->per_cu->v.psymtab; if (address == 0 - && (!dwarf2_per_objfile->has_section_at_zero + && (!dwarf2_per_objfile->section_at_zero || (pst != NULL && pst->textlow > address))) { /* This line table is for a function which has been @@ -17870,7 +17875,8 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu, if (SYMBOL_CLASS (sym) == LOC_STATIC && SYMBOL_VALUE_ADDRESS (sym) == 0 - && !dwarf2_per_objfile->has_section_at_zero) + && (!dwarf2_per_objfile->section_at_zero + || (dwarf2_per_objfile->section_at_zero->flags & SEC_CODE))) { /* When a static variable is eliminated by the linker, the corresponding debug information is not stripped