Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch] Fix SIGSEGV in gdb when printing ctor of non-virtual class
@ 2008-09-09 17:29 Aleksandar Ristovski
  2008-09-26 17:32 ` Aleksandar Ristovski
  0 siblings, 1 reply; 4+ messages in thread
From: Aleksandar Ristovski @ 2008-09-09 17:29 UTC (permalink / raw)
  To: gdb-patches

[-- 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;
}


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-03-02 15:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-09 17:29 [patch] Fix SIGSEGV in gdb when printing ctor of non-virtual class Aleksandar Ristovski
2008-09-26 17:32 ` Aleksandar Ristovski
2009-03-02 14:28   ` Aleksandar Ristovski
2009-03-02 15:24     ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox