Bug 9540 - gdb crash when printing an instanced class name
Summary: gdb crash when printing an instanced class name
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.6
: P3 enhancement
Target Milestone: 7.2
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 9683 (view as bug list)
Depends on:
Blocks: 11211
  Show dependency treegraph
 
Reported: 2008-03-26 22:18 UTC by jlevine
Modified: 2010-03-13 00:46 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jlevine 2008-03-26 22:18:01 UTC
[Converted from Gnats 2435]

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.

Release:
gdb 6.6

Environment:
64bit ee4_0 using gnu g++ 3.2.3, 4.1.1, 4.1.2
gdb 6.6 and gdb 6.7.1

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
Comment 1 Tom Tromey 2010-01-25 16:35:49 UTC
*** Bug 9683 has been marked as a duplicate of this bug. ***
Comment 2 Tom Tromey 2010-03-13 00:46:11 UTC
Fixed on trunk.