From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8109 invoked by alias); 9 Sep 2008 17:29:05 -0000 Received: (qmail 8100 invoked by uid 22791); 9 Sep 2008 17:29:05 -0000 X-Spam-Check-By: sourceware.org Received: from main.gmane.org (HELO ciao.gmane.org) (80.91.229.2) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 09 Sep 2008 17:28:13 +0000 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Kd70Y-0006tx-C2 for gdb-patches@sources.redhat.com; Tue, 09 Sep 2008 17:28:06 +0000 Received: from enigma.qnx.com ([209.226.137.106]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 09 Sep 2008 17:28:06 +0000 Received: from aristovski by enigma.qnx.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 09 Sep 2008 17:28:06 +0000 To: gdb-patches@sources.redhat.com From: Aleksandar Ristovski Subject: [patch] Fix SIGSEGV in gdb when printing ctor of non-virtual class Date: Tue, 09 Sep 2008 17:29:00 -0000 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------010308090606010502060206" User-Agent: Thunderbird 2.0.0.16 (Windows/20080708) 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-09/txt/msg00190.txt.bz2 This is a multi-part message in MIME format. --------------010308090606010502060206 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 554 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. --------------010308090606010502060206 Content-Type: text/plain; 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 { --------------010308090606010502060206 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}" } } --------------010308090606010502060206 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; } --------------010308090606010502060206--