This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Problem debugging statically linked c++ program with GDB 6.0
- From: Holger Sesterhenn <Holger dot Sesterhenn at smgwtest dot aachen dot utimaco dot de>
- To: gdb at sources dot redhat dot com
- Date: Fri, 02 Apr 2004 14:07:38 +0200
- Subject: Problem debugging statically linked c++ program with GDB 6.0
- Organization: Utimaco Safeware AG, NL Aachen
Hi,
I have a bug in my statically linked c++ program and would like to use
DDD with GDB to see whats wrong. I use <string> from the stdlibc++.
DDD/GDB shows a SIGSGV if I call a member function e.g. c_str() to take
a look at the value of the string.
I have written a little program to reproduce the problem (don't need
DDD). If the program is linked dynamically, everything works as expected!
If somebody can confirm the problem I would submit a bug report.
Searching the bug database I did not find any hint.
Running Linux 2.4.21 (IA86/32), compiled gcc 3.3.3, glibc 2.3.2 and gdb
6.0 myself (chrooted). The problem can be reproduced with a plain SuSE
9.0 installation (gcc 3.3.1, glibc 2.3.2, gdb 5.3.92).
Here is my screen dump.
#>g++ -g -static mytest.cpp
######################################
#>../gdb-6.0/gdb/gdb ./a.out
GNU gdb 6.0
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) l
1 #include <string>
2 #include <iostream>
3
4 int main () {
5 std::string a("Hello");
6
7 std::cout << a << std::endl;
8 } // main()
9
(gdb) b 7
Breakpoint 1 at 0x8048254: file mytest.cpp, line 7.
(gdb) r
Starting program: /src/fw/proxy/smtp/smtpd/test/a.out
Breakpoint 1, main () at mytest.cpp:7
7 std::cout << a << std::endl;
(gdb) p a
$1 = {static npos = 4294967295, _M_dataplus = {<allocator<char>> =
{<No data fields>}, _M_p = 0x8117d2c "Hello"},
static _S_empty_rep_storage = {0, 0, 0, 0}}
(gdb) p a.c_str()
Program received signal SIGSEGV, Segmentation fault.
0x08088546 in __libc_start_main ()
The program being debugged was signaled while in a function called from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use "set unwindonsignal on"
Evaluation of the expression containing the function
(std::string::c_str() const) will be abandoned.
(gdb)
#########################################
#>/lib/libc.so.6
GNU C Library stable release version 2.3.2, by Roland McGrath et al.
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 3.3.3.
Compiled on a Linux 2.4.23 system on 2004-04-01.
Available extensions:
GNU libio by Per Bothner
crypt add-on version 2.1 by Michael Glad and others
linuxthreads-0.10 by Xavier Leroy
BIND-8.2.3-T5B
libthread_db work sponsored by Alpha Processor Inc
NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
Report bugs using the `glibcbug' script to <bugs@gnu.org>.
##########################################
#>g++ -g mytest.cpp
#>ldd a.out
libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x40015000)
libm.so.6 => /lib/libm.so.6 (0x4013f000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x40162000)
libc.so.6 => /lib/libc.so.6 (0x401cf000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
######################################
#>../gdb-6.0/gdb/gdb ./a.out
GNU gdb 6.0
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) b 7
Breakpoint 1 at 0x80488c8: file mytest.cpp, line 7.
(gdb) r
Starting program: /src/fw/proxy/smtp/smtpd/test/a.out
Breakpoint 1, main () at mytest.cpp:7
7 std::cout << a << std::endl;
(gdb) p a
$1 = {static npos = 4294967295, _M_dataplus = {<allocator<char>> = {<No
data fields>}, _M_p = 0x8049db4 "Hello"},
static _S_empty_rep_storage = {0, 0, 0, 0}}
(gdb) p a.c_str()
$2 = 0x8049db4 "Hello"
########################################
Any hints?
--
Best Regards,
Holger Sesterhenn
---
Internet http://www.utimaco.com