Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Aleksandar Ristovski <aristovski@qnx.com>
To: gdb-patches@sources.redhat.com
Subject: [patch] Fix SIGSEGV in gdb when printing ctor of non-virtual class
Date: Tue, 09 Sep 2008 17:29:00 -0000	[thread overview]
Message-ID: <ga6bmt$6li$1@ger.gmane.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 554 bytes --]

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.

[-- Attachment #2: cppevalcrash20080909.diff --]
[-- Type: text/plain, Size: 1079 bytes --]

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
     {

[-- Attachment #3: cppeval.exp --]
[-- Type: text/plain, Size: 1302 bytes --]

# 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 <http://www.gnu.org/licenses/>.

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}"
  }
}



[-- Attachment #4: cppeval.cc --]
[-- Type: text/plain, Size: 299 bytes --]

#include <cstdlib>
#include <iostream>
#include <string.h>


/* 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;
}


             reply	other threads:[~2008-09-09 17:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-09 17:29 Aleksandar Ristovski [this message]
2008-09-26 17:32 ` Aleksandar Ristovski
2009-03-02 14:28   ` Aleksandar Ristovski
2009-03-02 15:24     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='ga6bmt$6li$1@ger.gmane.org' \
    --to=aristovski@qnx.com \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox