From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28453 invoked by alias); 2 Mar 2009 14:28:27 -0000 Received: (qmail 28443 invoked by uid 22791); 2 Mar 2009 14:28:25 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_43,J_CHICKENPOX_73,KAM_STOCKGEN,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from main.gmane.org (HELO ciao.gmane.org) (80.91.229.2) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 02 Mar 2009 14:28:15 +0000 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Le97s-0001dO-2t for gdb-patches@sources.redhat.com; Mon, 02 Mar 2009 14:28:12 +0000 Received: from entropy.qnx.com ([209.226.137.107]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 02 Mar 2009 14:28:12 +0000 Received: from aristovski by entropy.qnx.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 02 Mar 2009 14:28:12 +0000 To: gdb-patches@sources.redhat.com From: Aleksandar Ristovski Subject: Re: [patch] Fix SIGSEGV in gdb when printing ctor of non-virtual class Date: Mon, 02 Mar 2009 14:28:00 -0000 Message-ID: References: <48DD1C8A.7030206@qnx.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030104060203060408060506" User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) In-Reply-To: <48DD1C8A.7030206@qnx.com> 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: 2009-03/txt/msg00010.txt.bz2 This is a multi-part message in MIME format. --------------030104060203060408060506 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 940 An old patch. Gdb still SIGSEGV on this testcase, but I haven't got any replies. Any thoughts? Thanks, Aleksandar (re-attaching patch and testcase for your convenience). Aleksandar Ristovski wrote: > Ping? Does this patch make any sense? > > > Aleksandar Ristovski wrote: >> Hello, >> >> I run into a SIGSEGV crash in gdb when printing value of a non-virtual >> class' constructor (I got this from IDE asking for a wrong value). >> >> Example: >> >> (gdb) print n.Name >> >> where 'n' is an object of non-virtual class 'Name'. >> >> >> The attached tests demonstrate the problem and propose a fix. >> >> >> Thanks, >> >> Aleksandar Ristovski >> QNX Software Systems >> >> >> >> ChangeLog: >> >> * value.c (value_fn_field): Do not dereference if block does not >> exist. >> >> >> testsuite ChangeLog: >> >> * gdb.cp/cppeval.exp: New test. >> * gdb.cp/cppeval.cc: New test case to accompany cppeval.exp. >> > > --------------030104060203060408060506 Content-Type: text/x-patch; name="cppevalcrash20080909.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="cppevalcrash20080909.diff" Content-length: 1079 Index: gdb/value.c =================================================================== RCS file: /cvs/src/src/gdb/value.c,v retrieving revision 1.64 diff -u -p -r1.64 value.c --- gdb/value.c 11 Jun 2008 19:59:09 -0000 1.64 +++ gdb/value.c 9 Sep 2008 17:17:14 -0000 @@ -1415,8 +1415,8 @@ value_field (struct value *arg1, int fie */ struct value * -value_fn_field (struct value **arg1p, struct fn_field *f, int j, struct type *type, - int offset) +value_fn_field (struct value **arg1p, struct fn_field *f, int j, + struct type *type, int offset) { struct value *v; struct type *ftype = TYPE_FN_FIELD_TYPE (f, j); @@ -1440,7 +1440,16 @@ value_fn_field (struct value **arg1p, st v = allocate_value (ftype); if (sym) { - VALUE_ADDRESS (v) = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)); + /* Constructors of non-virtual classes will not have block. */ + struct block *block = SYMBOL_BLOCK_VALUE (sym); + + if (block) + VALUE_ADDRESS (v) = BLOCK_START (block); + else + { + release_value (v); + return NULL; + } } else { --------------030104060203060408060506 Content-Type: text/plain; name="cppeval.cc" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="cppeval.cc" Content-length: 299 #include #include #include /* NOTE: We intentionally don't make the classes virtual. */ class Name { public: Name(void) { myName = 0; } ~Name(void) { delete myName; } char* myName; }; int main(int argc, char *argv[]) { Name n; return EXIT_SUCCESS; } --------------030104060203060408060506 Content-Type: text/plain; name="cppeval.exp" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="cppeval.exp" Content-length: 1302 # This testcase is part of GDB, the GNU debugger. # Copyright 2008 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . set testfile "cppeval" set srcfile ${testfile}.cc set binfile ${objdir}/${subdir}/${testfile} if { [prepare_for_testing ${testfile}.exp ${testfile} "${srcfile}" {debug c++}] } { return -1 } runto_main # NOTE: the following test used to crash gdb if c is an object of a # class that inherits from non-virtual class Name. # # Print base constructor name. gdb_test_multiple "print n.Name" "print constructor of nonvirtual class" { -re "Cannot take address of method Name.*$gdb_prompt $" { pass "${testfile}" } default { fail "${testfile}" } } --------------030104060203060408060506--