This is the mail archive of the cygwin mailing list for the Cygwin 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]

Re: Segmentation fault when debugging C++ with gdb.

Mikael Rosbacke wrote:

I'm having problem to debug my C++ programs using GDB under cygwin. I
get a seg-fault in the c-startup before the main function has been

The following test program is used:
mikaelr@MSUNDMIKAELR2 /cygdrive/c/testcase$ more

#include <iostream>
#include <string>

int main()
    std::string t;

    std::cout << "Hello world!" << std::endl;
    std::cin >> t;
    std::cout << "Hello " << t << "!" << std::endl;

Trying to compile and run this program in cygwin give me the following

mikaelr@MSUNDMIKAELR2 ~$ cd /cygdrive/c/testcase/

mikaelr@MSUNDMIKAELR2 /cygdrive/c/testcase$ ls
a.exe  test.cpp  test.cpp~

mikaelr@MSUNDMIKAELR2 /cygdrive/c/testcase$ /bin/g++ -v
Reading specs from /bin/../lib/gcc/i686-pc-cygwin/3.4.4/specs
Configured with: /gcc/gcc-3.4.4/gcc-3.4.4-1/configure --verbose
--prefix=/usr --
exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib
--libexecdir=/usr/lib --man
dir=/usr/share/man --infodir=/usr/share/info
java,objc --enable-nls --without-included-gettext
ime-libs --without-x --enable-libgcj --disable-java-awt
--with-system-zlib --ena
ble-interpreter --disable-libgcj-debug --enable-threads=posix
oehm --disable-win32-registry --enable-sjlj-exceptions
tion --enable-libstdcxx-debug : (reconfigured)
Thread model: posix
gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)

mikaelr@MSUNDMIKAELR2 /cygdrive/c/testcase$ /usr/bin/g++ -g test.cpp

mikaelr@MSUNDMIKAELR2 /cygdrive/c/testcase$ /bin/gdb a.exe
GNU gdb 6.3.50_2004-12-28-cvs (cygwin-special)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you
welcome to change it and/or distribute copies of it under certain
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for
This GDB was configured as "i686-pc-cygwin"...
(gdb) run
Starting program: /cygdrive/c/testcase/a.exe

Program received signal SIGSEGV, Segmentation fault.
0x610ae938 in pthread_key_create () from /usr/bin/cygwin1.dll
(gdb) bt
#0  0x610ae938 in pthread_key_create () from /usr/bin/cygwin1.dll
#1  0x6108dd7f in _sigfe () from /usr/bin/cygwin1.dll
#2  0x59432d52 in ?? ()
#3  0x004ce348 in ?? ()
#4  0x004ce31b in ?? ()
#5  0x004ce348 in ?? ()
#6  0x0022edc8 in ?? ()
#7  0x610af6b7 in pthread::once () from /usr/bin/cygwin1.dll
#8  0x610af6b7 in pthread::once () from /usr/bin/cygwin1.dll
#9  0x6108dd7f in _sigfe () from /usr/bin/cygwin1.dll
#10 0x0022edf8 in ?? ()
#11 0x0040f5c5 in _Unwind_SjLj_Register ()
    at /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/iostream:77
#12 0x0040f5c5 in _Unwind_SjLj_Register ()
    at /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/iostream:77
#13 0x004011a4 in main () at test.cpp:6
(gdb) exit
Undefined command: "exit".  Try "help".
(gdb) quit
The program is running.  Exit anyway? (y or n) y

mikaelr@MSUNDMIKAELR2 /cygdrive/c/testcase$

Seems like the initialization of the static iostream objects causes the

I've tried to download gcc version 4.0 and a new gdb as tarballs and
compiled it from source. Using these tools it seems to work. But it is
not a good solution for us to have a separate compiler from the rest of
the distribution. Any ideas how to fix this?

Yes. Start by checking the email archives for previous discussions of this issue. Sounds to me like you have half the real solution already (gdb sources, presumably from CVS). Grab the latest Cygwin DLL snapshot and you're done. Otherwise, live with typing "c <return>" as many times as necessary until you're by the problem.

In case it's not clear from the above, this has been talked to death on this
list so if you have any thoughts about re-opening this subject for discussion,
you better wear your flame-resistant suit!

Larry Hall                    
RFK Partners, Inc.                      (508) 893-9779 - RFK Office
838 Washington Street                   (508) 893-9889 - FAX
Holliston, MA 01746

Unsubscribe info:
Problem reports:

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