From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8534 invoked by alias); 2 Jul 2008 17:00:17 -0000 Received: (qmail 8521 invoked by uid 22791); 2 Jul 2008 17:00:16 -0000 X-Spam-Check-By: sourceware.org Received: from mms2.broadcom.com (HELO mms2.broadcom.com) (216.31.210.18) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 02 Jul 2008 16:59:17 +0000 Received: from [10.11.16.99] by mms2.broadcom.com with ESMTP (Broadcom SMTP Relay (Email Firewall v6.3.2)); Wed, 02 Jul 2008 09:59:02 -0700 X-Server-Uuid: D3C04415-6FA8-4F2C-93C1-920E106A2031 Received: by mail-irva-10.broadcom.com (Postfix, from userid 47) id 0D9542B2; Wed, 2 Jul 2008 09:59:02 -0700 (PDT) Received: from mail-irva-8.broadcom.com (mail-irva-8 [10.11.18.52]) by mail-irva-10.broadcom.com (Postfix) with ESMTP id E76652B0 for ; Wed, 2 Jul 2008 09:59:01 -0700 (PDT) Received: from mail-irva-13.broadcom.com (mail-irva-13.broadcom.com [10.11.16.103]) by mail-irva-8.broadcom.com (MOS 3.7.5a-GA) with ESMTP id GZE40840; Wed, 2 Jul 2008 09:59:00 -0700 (PDT) Received: from NT-IRVA-0752.brcm.ad.broadcom.com (nt-irva-0752 [10.8.194.67]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id 5B8D374CFE for ; Wed, 2 Jul 2008 09:59:00 -0700 ( PDT) Content-class: urn:content-classes:message MIME-Version: 1.0 Subject: Bug handling zero sized symbols in minsyms.c Date: Wed, 02 Jul 2008 17:00:00 -0000 Message-ID: From: "Robert Norton" To: gdb@sourceware.org X-WSS-ID: 64756C5C3D075946093-01-01 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2008-07/txt/msg00014.txt.bz2 Hi, In minsyms.c:lookup_minimal_symbol_by_pc_section() there is some code which attempts to prefer symbols with sizes over those with zero size. This is quite useful[1]. Unfortunately the present code will only work if there is at most one zero-sized symbol. The fix is around line 503: if (MSYMBOL_SIZE (&msymbol[hi]) =3D=3D 0 && best_zero_sized =3D=3D -1) { best_zero_sized =3D hi; hi--;=20=20=20=20=20=20=20=20=20=20 continue;=20=20=20=20=20=20 } SHOULD be: if (MSYMBOL_SIZE (&msymbol[hi]) =3D=3D 0) { if (best_zero_sized =3D=3D -1) best_zero_sized =3D hi; hi--; continue; } We keep the highest zero-sized symbol as the best but continue to iterate backwards until we hit a non-zero-sized symbol or run out of symbols. It's pretty clear that this is what was originally intended. I can get copyright assigment for this if required although it seems pretty trivial... Cheers, Robert [1] In particular it is useful when debugging assembly functions which have internal labels for loops etc. Without this fix we sometimes get back a minsym corresponding to an internal label (e.g. a loop) when really what we wanted was the function symbol. This messes up prologue analysis and some other things. For example in our GDB port the assembly file: .global main main: nop test2: nop test3: nop .size main,.-main .type main,@function results in: (gdb) info sym test2 main + 8 in section .text (gdb) info sym test3 test3 in section .text <----------------- !!! (gdb) disas main Dump of assembler code for function main: 0x00000270 : NOP 0x00000278 : NOP 0x00000280 : NOP <----------------- !!! End of assembler dump. and in a patched version: (gdb) info sym test2 main + 8 in section .text (gdb) info sym test3 main + 16 in section .text (gdb) disas main Dump of assembler code for function main: 0x00000270 : NOP 0x00000278 : NOP 0x00000280 : NOP End of assembler dump. RCS file: /cvs/dev/tools/src/binutils/gdb/minsyms.c,v retrieving revision 1.3 diff -u -r1.3 minsyms.c --- minsyms.c 4 Jan 2008 18:33:25 -0000 1.3 +++ minsyms.c 2 Jul 2008 16:36:02 -0000 @@ -503,10 +503,10 @@ symbol isn't an object or function (e.g. a label), or it may just mean that the size was not specified. */ - if (MSYMBOL_SIZE (&msymbol[hi]) =3D=3D 0 - && best_zero_sized =3D=3D -1) + if (MSYMBOL_SIZE (&msymbol[hi]) =3D=3D 0) { - best_zero_sized =3D hi; + if (best_zero_sized =3D=3D -1) + best_zero_sized =3D hi; hi--; continue; }