This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/2435: gdb crash when printing an instanced class name


>Number:         2435
>Category:       c++
>Synopsis:       gdb crash when printing an instanced class name
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 26 22:18:01 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator:     Joshua Levine
>Release:        gdb 6.6
>Organization:
>Environment:
64bit ee4_0 using gnu g++ 3.2.3, 4.1.1, 4.1.2
gdb 6.6 and gdb 6.7.1
>Description:
GDB crashes when it tries to print a class name from inside an instanced class.  You can print the class name from outside the class fine, or from another class with a different name (for example: you can print myclass from inside myclass2, or you can print myclass2 from inside myclass, but printing myclass2 from myclass2 crashes).  GDB crashes at the following point:

Program received signal SIGSEGV, Segmentation fault.
0x00000000004adbf7 in value_fn_field (arg1p=0x7fbfffdba8, f=<value optimized
out>, j=<value optimized out>, type=0x1ecf978, offset=<value optimized out>) at
src/gdb-6.6/gdb/value.c:1400
1400	      VALUE_ADDRESS (v) = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));

(gdb) print *sym
$2 = {ginfo = {name = 0x2464fe0 "myclass", value = {ivalue = 0, block =
0x0, bytes = 0x0, address = 0, chain = 0x0}, language_specific =
{cplus_specific = {demangled_name = 0x0}}, language = language_cplus, section =
0, bfd_section = 0x0}, type = 0x2464f70, domain = VAR_DOMAIN, aclass =
LOC_TYPEDEF, line = 3, ops = 0x0, aux_value = {basereg = 0, ptr = 0x0},
hash_next = 0x25d78c0}

Notice that ginfo->value.block is 0, and this is what triggers the SIGSEGV.

Also tested with the latest gdb 6.7.1 and the crash is still there.
>How-To-Repeat:
// file test.cpp
#include <iostream>

class myclass {
public:
   myclass();

   bool myfunction();
};

myclass::myclass()
{
   printf ("inside myclass\n");
}

bool myclass::myfunction()
{
   printf("inside myfunction\n");
   return true;
}

int main(int argc, char** argv) {
  myclass a1;

  a1.myfunction();

  return 0;
}

Run with the following:

> g++ -g test.cpp -o runme
> gdb runme

(gdb) break myclass::myfunction
(gdb) run
(gdb) print myclass     // this only crashes g++ 4.1.x
(gdb) print myclass()   // this crashes with g++ 3.2.3 and 4.1.x
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]