From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2186 invoked by alias); 3 Sep 2005 02:02:49 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 1486 invoked by uid 22791); 3 Sep 2005 02:02:39 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Sat, 03 Sep 2005 02:02:39 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11/8.12.11) with ESMTP id j8322ShB022679 for ; Fri, 2 Sep 2005 22:02:28 -0400 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [172.16.52.156]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id j8322SV14264 for ; Fri, 2 Sep 2005 22:02:28 -0400 Received: from localhost.localdomain (vpn50-99.rdu.redhat.com [172.16.50.99]) by pobox.corp.redhat.com (8.12.8/8.12.8) with ESMTP id j8322SHW003941 for ; Fri, 2 Sep 2005 22:02:28 -0400 Received: from ironwood.lan (ironwood.lan [192.168.64.8]) by localhost.localdomain (8.12.11/8.12.10) with ESMTP id j8322MKm007426 for ; Fri, 2 Sep 2005 19:02:22 -0700 Date: Sat, 03 Sep 2005 02:02:00 -0000 From: Kevin Buettner To: gdb-patches@sources.redhat.com Subject: Re: [commit] mn10300: Register a dwarf2_reg_to_regnum function Message-ID: <20050902190222.5ab1edac@ironwood.lan> In-Reply-To: <200509030126.j831Q26V032052@elgar.sibelius.xs4all.nl> References: <20050902180915.07468bb1@ironwood.lan> <200509030126.j831Q26V032052@elgar.sibelius.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-SW-Source: 2005-09/txt/msg00020.txt.bz2 On Sat, 3 Sep 2005 03:26:02 +0200 (CEST) Mark Kettenis wrote: > > + if (dwarf2 < 0 > > + || dwarf2 >= (sizeof (dwarf2_to_gdb) / sizeof (dwarf2_to_gdb[0])) > > + || dwarf2_to_gdb[dwarf2] == -1) > > + internal_error (__FILE__, __LINE__, > > + "bogus register number in debug info: %d", dwarf2); > > + > > + return dwarf2_to_gdb[dwarf2]; > > +} > > Could you use ARRAY_SIZE here? Sure. (I should've spotted that myself...) > And that string should be i18n'd. or > perhaps it's better to use gdb_assert(); saves the translators some > work ;-). > > Hmm, isn't an internal error actually inappropriate here? The > condition could be triggered by bogus debug info, couldn't it? That > should be handled more graceful. I agree. It seems to me that a warning is more appropriate. But what should we do about the return value? There is no good choice since the value is bogus. I ended up just returning 0. (It should be safe...) For the time being, I've committed the patch below. I'm willing to change it again if we end up deciding that an internal error or assert is really more appropriate. * mn10300-tdep.c (mn10300_dwarf2_reg_to_regnum): Use ARRAY_SIZE. Change internal error to warning. Add i18n markup to warning string. Index: mn10300-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/mn10300-tdep.c,v retrieving revision 1.129 retrieving revision 1.131 diff -u -p -r1.129 -r1.131 --- mn10300-tdep.c 3 Sep 2005 01:12:21 -0000 1.129 +++ mn10300-tdep.c 3 Sep 2005 01:55:26 -0000 1.131 @@ -961,10 +961,12 @@ mn10300_dwarf2_reg_to_regnum (int dwarf2 }; if (dwarf2 < 0 - || dwarf2 >= (sizeof (dwarf2_to_gdb) / sizeof (dwarf2_to_gdb[0])) + || dwarf2 >= ARRAY_SIZE (dwarf2_to_gdb) || dwarf2_to_gdb[dwarf2] == -1) - internal_error (__FILE__, __LINE__, - "bogus register number in debug info: %d", dwarf2); + { + warning (_("Bogus register number in debug info: %d"), dwarf2); + return 0; + } return dwarf2_to_gdb[dwarf2]; }