c++/2116: gdb crashes when calling "C" function from "C++" code

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

c++/2116: gdb crashes when calling "C" function from "C++" code


>Number:         2116
>Category:       c++
>Synopsis:       gdb crashes when calling "C" function from "C++" code
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Apr 17 23:28:01 GMT 2006
>Originator:     Paul Pluzhnikov
>Release:        6.4
Gdb crashes when calling plain-C function from C++ code.
AFAICT, this is a 6.4 regression (my 6.3 compile works fine).
$ cat foo.c
int foo(int x) { return x; }

$ cat main.cpp
int func(int x)
   return x;

int main()
    return func(0);
$ /usr/local/gcc-3.4.6/bin/gcc -g -c foo.c
$ /usr/local/gcc-3.4.6/bin/g++ -g  main.cpp foo.o

$ gdb-6.4 -q ./a.out
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) b func
Breakpoint 1 at 0x8048567: file main.cpp, line 3.
(gdb) r

Breakpoint 1, func (x=0) at main.cpp:3
3          return x;
(gdb) p foo(1)
Segmentation fault (core dumped)

##### And now for some debugging:

$ gdb-6.4 -q gdb-6.4 core
Using host libthread_db library "/lib/libthread_db.so.1".
Core was generated by `gdb-6.4 -q ./a.out'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /usr/lib/libncurses.so.4...done.
#0  0x0818db3a in cp_demangled_name_to_comp (demangled_name=0x0, memory=0xbfffd72c, errmsg=0x0) at cp-name-parser.y:1990
1990    cp-name-parser.y: No such file or directory.
        in cp-name-parser.y
(gdb) up 2
#2  0x080e60fd in find_overload_match (arg_types=0xbfffd7a0, nargs=1, name=0x0, method=0, lax=0, objp=0x0, fsym=0x831fdb0,
    valp=0x0, symp=0xbfffd8fc, staticp=0x0) at /home/camel1/paul/Archive/gdb-6.4/gdb/valops.c:1850
1850          func_name = cp_func_name (qualified_name);
(gdb) p *fsym
$1 = {ginfo = {name = 0x831a460 "foo", value = {ivalue = 137494040, block = 0x831fe18,
      bytes = 0x831fe18 "\230\205\004\b \205\004\b°ý1\bxþ1\b4þ1\b", address = 137494040, chain = 0x831fe18},
    language_specific = {cplus_specific = {demangled_name = 0x0}}, language = language_c, section = 11,
    bfd_section = 0x830c7cc}, type = 0x831fd58, domain = VAR_DOMAIN, aclass = LOC_BLOCK, line = 1, ops = 0x825a558,
  aux_value = {basereg = -552, ptr = 0x831fdd8}, hash_next = 0x0}

Note that 'foo' has language_c and no demangled_name ...