From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 485 invoked by alias); 4 Feb 2011 17:56:31 -0000 Received: (qmail 476 invoked by uid 22791); 4 Feb 2011 17:56:29 -0000 X-SWARE-Spam-Status: No, hits=-5.7 required=5.0 tests=AWL,BAYES_00,FSL_RU_URL,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_BJ,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 04 Feb 2011 17:56:23 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p14HuLww020080 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 4 Feb 2011 12:56:22 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p14HuLYv016133; Fri, 4 Feb 2011 12:56:21 -0500 Received: from opsy.redhat.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p14HuKo1015209; Fri, 4 Feb 2011 12:56:21 -0500 Received: by opsy.redhat.com (Postfix, from userid 500) id 6F2783784E1; Fri, 4 Feb 2011 10:56:20 -0700 (MST) From: Tom Tromey To: Vladimir Simonov Cc: gdb-patches@sourceware.org Subject: Re: gdb: Incorrect stack unwinding if compressed debug info is used References: <1296238472.3009.ezmlm@sourceware.org> <4D46D872.6080407@sw.ru> <4D4C383A.3000203@sw.ru> Date: Fri, 04 Feb 2011 17:56:00 -0000 In-Reply-To: <4D4C383A.3000203@sw.ru> (Vladimir Simonov's message of "Fri, 04 Feb 2011 20:32:42 +0300") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-02/txt/msg00082.txt.bz2 >>>>> "Vladimir" == Vladimir Simonov writes: Vladimir> I'd also suggest to remove dwarf2_read_section from Vladimir> fill_in_loclist_baton. Without it all works ok also. There is another caller of fill_in_loclist_baton, and it wasn't obvious to me that this change would be safe. Vladimir> But resulted code looks a bit hackish: I agree. Also, I audited all other uses of the 'size' field. I found one more where it was not obvious whether the use was safe. And, I found another area that could use a little cleanup. So, I came up with the appended. Let me know what you think. If you could try it, that would be helpful. I am running it through the test suite. I plan to commit it if it all passes. Tom 2011-02-04 Tom Tromey * dwarf2read.c (dwarf2_section_empty_p): New function. (dwarf2_read_section): Use dwarf2_section_empty_p. (dwarf2_section_size): New function. (dwarf2_get_section_info): Unconditionally read section. (dwarf2_read_index): Use dwarf2_section_empty_p. (partial_read_comp_unit_head): Use dwarf2_section_size. (dwarf2_symbol_mark_computed): Likewise. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 6a98d57..d7dd3d5 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -1509,6 +1509,14 @@ zlib_decompress_section (struct objfile *objfile, asection *sectp, #endif } +/* A helper function that decides whether a section is empty. */ + +static int +dwarf2_section_empty_p (struct dwarf2_section_info *info) +{ + return info->asection == NULL || info->size == 0; +} + /* Read the contents of the section SECTP from object file specified by OBJFILE, store info about the section into INFO. If the section is compressed, uncompress it before returning. */ @@ -1527,7 +1535,7 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) info->was_mmapped = 0; info->readin = 1; - if (info->asection == NULL || info->size == 0) + if (dwarf2_section_empty_p (info)) return; /* Check if the file has a 4-byte header indicating compression. */ @@ -1592,6 +1600,18 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) bfd_get_filename (abfd)); } +/* A helper function that returns the size of a section in a safe + way. */ + +static bfd_size_type +dwarf2_section_size (struct objfile *objfile, + struct dwarf2_section_info *info) +{ + if (!info->readin) + dwarf2_read_section (objfile, info); + return info->size; +} + /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and SECTION_NAME. */ @@ -1620,9 +1640,7 @@ dwarf2_get_section_info (struct objfile *objfile, const char *section_name, else gdb_assert_not_reached ("unexpected section"); - if (info->asection != NULL && info->size != 0 && info->buffer == NULL) - /* We haven't read this section in yet. Do it now. */ - dwarf2_read_section (objfile, info); + dwarf2_read_section (objfile, info); *sectp = info->asection; *bufp = info->buffer; @@ -2008,8 +2026,7 @@ dwarf2_read_index (struct objfile *objfile) offset_type types_list_elements = 0; int i; - if (dwarf2_per_objfile->gdb_index.asection == NULL - || dwarf2_per_objfile->gdb_index.size == 0) + if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index)) return 0; /* Older elfutils strip versions could keep the section in the main @@ -2823,7 +2840,9 @@ partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr, "(is %d, should be 2, 3, or 4) [in module %s]"), header->version, bfd_get_filename (abfd)); - if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size) + if (header->abbrev_offset + >= dwarf2_section_size (dwarf2_per_objfile->objfile, + &dwarf2_per_objfile->abbrev)) error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " "(offset 0x%lx + 6) [in module %s]"), (long) header->abbrev_offset, @@ -14365,7 +14384,8 @@ dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, /* ".debug_loc" may not exist at all, or the offset may be outside the section. If so, fall through to the complaint in the other branch. */ - && DW_UNSND (attr) < dwarf2_per_objfile->loc.size) + && DW_UNSND (attr) < dwarf2_section_size (dwarf2_per_objfile->objfile, + &dwarf2_per_objfile->loc)) { struct dwarf2_loclist_baton *baton;