From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5970 invoked by alias); 21 Oct 2008 04:44:00 -0000 Received: (qmail 5959 invoked by uid 22791); 21 Oct 2008 04:43:58 -0000 X-Spam-Check-By: sourceware.org Received: from nwd2mail10.analog.com (HELO nwd2mail10.analog.com) (137.71.25.55) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 21 Oct 2008 04:43:18 +0000 X-IronPort-AV: E=Sophos;i="4.33,455,1220241600"; d="diff'?scan'208";a="76911102" Received: from nwd2mhb1.analog.com ([137.71.5.12]) by nwd2mail10.analog.com with ESMTP; 21 Oct 2008 00:43:16 -0400 Received: from nwd2exm4.ad.analog.com (nwd2exm4.ad.analog.com [10.64.53.123]) by nwd2mhb1.analog.com (8.9.3 (PHNE_28810+JAGae91741)/8.9.3) with ESMTP id AAA28045 for ; Tue, 21 Oct 2008 00:43:16 -0400 (EDT) Received: from chinexm1.ad.analog.com ([10.99.27.42]) by nwd2exm4.ad.analog.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 21 Oct 2008 00:43:16 -0400 Received: from [10.99.29.118] ([10.99.29.118]) by chinexm1.ad.analog.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 21 Oct 2008 12:43:14 +0800 Message-ID: <48FD5DE1.9090105@analog.com> Date: Tue, 21 Oct 2008 04:44:00 -0000 From: Jie Zhang User-Agent: Mozilla-Thunderbird 2.0.0.17 (X11/20081018) MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: [PATCH] Fix a bug of addrmap Content-Type: multipart/mixed; boundary="------------030200090507050803050806" X-IsSubscribed: yes 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: 2008-10/txt/msg00503.txt.bz2 This is a multi-part message in MIME format. --------------030200090507050803050806 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1158 Hi, I encountered a problem when trying CVS HEAD gdb with gcc-4.1, which has no .debug_ranges support. Below is the test case: $ cat main.c int main () { return 0; } extern void __attribute__ ((__section__ (".init.text"))) foo_init (void); void foo_init () { return; } $ cat foo.c int foo () { return 0; } $ gcc-4.1 -o test main.c foo.c -g CVS HEAD gdb cannot show the source line of foo. $ gdb test GNU gdb (GDB) 6.8.50.20081020-cvs [snip] (gdb) b foo Breakpoint 1 at 0x400458 while gdb-6.8 can $ gdb test GNU gdb 6.8 [snip] (gdb) b foo Breakpoint 1 at 0x400458: file foo.c, line 3. Since gcc-4.1 does not generate .debug_ranges, gdb tries to create addrmap from low_pc and high_pc. When creating mutable addrmap, the address range of main.c is treated as contiguous, e.g. [0x400448, 0x40053e], while foo.c is e.g. [0x400454, 0x40045f], which is embedded in the former. In current gdb, the value of the start and end transitions for foo.c are initialized as same as the value of the start one for main.c. Then later in addrmap_mutable_set_empty, those transitions are removed. This patch should fix this case. Is it OK? Regards, Jie --------------030200090507050803050806 Content-Type: text/x-patch; name="gdb-addrmap-embedded-range.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="gdb-addrmap-embedded-range.diff" Content-length: 2480 * addrmap.c (force_transition): Add new argument start. (addrmap_mutable_set_empty): Establish the end transition before the start transition. Index: addrmap.c =================================================================== RCS file: /cvs/src/src/gdb/addrmap.c,v retrieving revision 1.4 diff -u -p -r1.4 addrmap.c --- addrmap.c 1 Jan 2008 22:53:09 -0000 1.4 +++ addrmap.c 21 Oct 2008 03:42:19 -0000 @@ -291,18 +291,27 @@ addrmap_splay_tree_insert (struct addrma /* Without changing the mapping of any address, ensure that there is a tree node at ADDR, even if it would represent a "transition" from - one value to the same value. */ + one value to the same value. If START is non-zero, this is the + start transition of the address range. Otherwise, it's the end + transition. */ static void -force_transition (struct addrmap_mutable *this, CORE_ADDR addr) +force_transition (struct addrmap_mutable *this, CORE_ADDR addr, int start) { splay_tree_node n = addrmap_splay_tree_lookup (this, addr); if (! n) { - n = addrmap_splay_tree_predecessor (this, addr); - addrmap_splay_tree_insert (this, addr, - n ? addrmap_node_value (n) : NULL); + void *value; + + if (start) + value = NULL; + else + { + n = addrmap_splay_tree_predecessor (this, addr); + value = n ? addrmap_node_value (n) : NULL; + } + addrmap_splay_tree_insert (this, addr, value); } } @@ -328,10 +337,16 @@ addrmap_mutable_set_empty (struct addrma - First pass: change all NULL regions to OBJ. - Second pass: remove any unnecessary transitions. */ - /* Establish transitions at the start and end. */ - force_transition (map, start); + /* Establish transitions at the start and end. The end transition + is established first such that its value will be initialized as + same as the value of its predecessor. The value of the start + transition will always be initialized to NULL. With this + establishing order, the value of these transitions will be set + properly later even if the given address range is embedded in + another address range. */ if (end_inclusive < CORE_ADDR_MAX) - force_transition (map, end_inclusive + 1); + force_transition (map, end_inclusive + 1, 0); + force_transition (map, start, 1); /* Walk the area, changing all NULL regions to OBJ. */ for (n = addrmap_splay_tree_lookup (map, start), gdb_assert (n); --------------030200090507050803050806--