This was clearly an error but I can explain and fix it.

There were overlapping main/gccmain (or so) functions in src/mingw and
src/gcc-4.4.0/gcc/libgcc2.c . Both were calling constructors and
destructors.

Now, here's a debug session that shows that the constructor of the
iostream crashes.

How do I go about debugging this ?

        Danny

pavilion: {3} i386-mingw32ce-gdb hello.exe 
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show
copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu
--target=i386-mingw32ce"...
(gdb) target remote ebox:9999
Remote debugging using ebox:9999
[New Thread 96010250]
Error while mapping shared library sections:
\network\x86\libgcc_s_sjlj-1.dll: No such file or directory.
Error while mapping shared library sections:
libstdc++-6.dll: No such file or directory.
Error while mapping shared library sections:
\Windows\coredll.dll: No such file or directory.
Symbol file not found for \network\x86\libgcc_s_sjlj-1.dll
Symbol file not found for libstdc++-6.dll
Symbol file not found for \Windows\coredll.dll
WinMainCRTStartup (hInst=0x5b3000a, hPrevInst=0x0, lpCmdLine=0x2201fc70,
nCmdShow=5)

at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/crt3.c:35
35      {
Current language:  auto; currently c
(gdb) s
41        _fpreset ();                  /* Supplied by the runtime
library. */
(gdb) 
44        _pei386_runtime_relocator ();
(gdb) 
_pei386_runtime_relocator ()

at 
/home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/pseudo-reloc.c:33
33        for (r = (runtime_pseudo_reloc*) start; r <
(runtime_pseudo_reloc*) end; r++)
(gdb) 
46      }
(gdb) 
WinMainCRTStartup (hInst=0x5b3000a, hPrevInst=0x0, lpCmdLine=0x2201fc70,
nCmdShow=5)

at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/crt3.c:49
49        __atexit_init();
(gdb) 
__atexit_init ()
at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/atexit.c:65
65        first_atexit = (p_atexit_fn*) malloc (32 * sizeof
(p_atexit_fn));
(gdb) 
66        if (first_atexit == NULL ) /* can't allocate memory */
(gdb) 
73        *first_atexit =  NULL;
(gdb) 
74        next_atexit = first_atexit;
(gdb) 
76      }
(gdb) 
WinMainCRTStartup (hInst=0x5b3000a, hPrevInst=0x0, lpCmdLine=0x2201fc70,
nCmdShow=5)

at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/crt3.c:54
54        __gccmain();
(gdb) 
__gccmain ()
at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/gccmain.c:79
79        if (!initialized)
(gdb) 
81            initialized = 1;
(gdb) 
86      }
(gdb) 
WinMainCRTStartup (hInst=0x5b3000a, hPrevInst=0x0, lpCmdLine=0x2201fc70,
nCmdShow=5)

at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/crt3.c:62
62        nRet = WinMain(hInst, hPrevInst, lpCmdLine, nCmdShow);
(gdb) 
WinMain (hInst=0x5b3000a, hPrevInst=0x0, szCmdLine=0x2201fc70, nShow=5)

at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/winmain_ce.c:147
147       __mainArgs(&__argc, &__argv, szCmdLine);
(gdb) 
__mainArgs (cmdlinePtrW=0x2201fc70)

at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/winmain_ce.c:103
103         cmdnameBufW[0] = 0;
(gdb) 
104         modlen = GetModuleFileNameW(NULL, cmdnameBufW, sizeof
(cmdnameBufW)/sizeof (cmdnameBufW[0]));
(gdb) 
106         if (!cmdlinePtrW)
(gdb) 
109             cmdlineLen = wcslen(cmdlinePtrW);
(gdb) 
111         __cmdlinebuf = malloc (modlen + 1 + cmdlineLen + 1);
(gdb) 
112         if (!__cmdlinebuf)
(gdb) 
115         *argv = malloc (sizeof (char**) * 1);
(gdb) 
116         if (!*argv)
(gdb) 
119         (*argv)[0] = __cmdlinebuf;
(gdb) 
120         wcstombs((*argv)[0], cmdnameBufW, wcslen(cmdnameBufW) + 1);
(gdb) 
122         (*argc)++;
(gdb) 
124         if (cmdlineLen > 0)
(gdb) 
128             *argc = _parse_tokens(argv1, argv, 1);
(gdb) 
132         (*argv)[*argc] = 0;
(gdb) 
134     }
(gdb) 
WinMain (hInst=0x5b3000a, hPrevInst=0x0, szCmdLine=0x2201fc70, nShow=5)

at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/winmain_ce.c:151
151       return main(__argc, __argv, NULL);
(gdb) 
152     }
(gdb) 
WinMain (hInst=0x5b3000a, hPrevInst=0x0, szCmdLine=0x2201fc70, nShow=5)

at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/winmain_ce.c:151
151       return main(__argc, __argv, NULL);
(gdb) 
main (argc=1, argv=0x22020690) at hello.C:6
6       {
Current language:  auto; currently c++
(gdb) 
_alloca ()

at 
/home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/gcc-4.4.0/libgcc/../gcc/config/i386/cygwin.asm:38
38              pushl   %ecx            /* save temp */
Current language:  auto; currently asm
(gdb) 
39              leal    8(%esp), %ecx   /* point past return addr */
(gdb) 
40              cmpl    $0x1000, %eax   /* > 4k ?*/
(gdb) 
41              jb      Ldone
(gdb) 
51              subl    %eax, %ecx         
(gdb) 
52              orl     $0x0, (%ecx)    /* less than 4k, just peek here
*/
(gdb) 
54              movl    %esp, %eax      /* save old stack pointer */
(gdb) 
55              movl    %ecx, %esp      /* decrement stack */
(gdb) 
_alloca ()

at 
/home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/gcc-4.4.0/libgcc/../gcc/config/i386/cygwin.asm:56
56              movl    (%eax), %ecx    /* recover saved temp */
(gdb) 
57              movl    4(%eax), %eax   /* recover return address */
(gdb) 
62              pushl   %eax
(gdb) 
_alloca ()

at 
/home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/gcc-4.4.0/libgcc/../gcc/config/i386/cygwin.asm:63
63              ret
(gdb) 
main (argc=1, argv=0x22020690) at hello.C:6
6       {
Current language:  auto; currently c++
(gdb) 
__main ()

at 
/home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/gcc-4.4.0/libgcc/../gcc/libgcc2.c:2185
2185      if (! initialized)
Current language:  auto; currently c
(gdb) 
2187          initialized = 1;
(gdb) 
2190    }
(gdb) 
__main ()

at 
/home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/gcc-4.4.0/libgcc/../gcc/libgcc2.c:2188
2188          __do_global_ctors ();
(gdb) 
__do_global_ctors ()

at 
/home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/gcc-4.4.0/libgcc/../gcc/libgcc2.c:2158
2158    {
(gdb) 
_alloca ()

at 
/home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/gcc-4.4.0/libgcc/../gcc/config/i386/cygwin.asm:38
38              pushl   %ecx            /* save temp */
Current language:  auto; currently asm
(gdb) 
39              leal    8(%esp), %ecx   /* point past return addr */
(gdb) 
40              cmpl    $0x1000, %eax   /* > 4k ?*/
(gdb) 
41              jb      Ldone
(gdb) 
51              subl    %eax, %ecx         
(gdb) 
52              orl     $0x0, (%ecx)    /* less than 4k, just peek here
*/
(gdb) 
54              movl    %esp, %eax      /* save old stack pointer */
(gdb) 
55              movl    %ecx, %esp      /* decrement stack */
(gdb) 
_alloca ()

at 
/home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/gcc-4.4.0/libgcc/../gcc/config/i386/cygwin.asm:56
56              movl    (%eax), %ecx    /* recover saved temp */
(gdb) 
57              movl    4(%eax), %eax   /* recover return address */
(gdb) 
62              pushl   %eax
(gdb) 
_alloca ()

at 
/home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/gcc-4.4.0/libgcc/../gcc/config/i386/cygwin.asm:63
63              ret
(gdb) 
__do_global_ctors ()

at 
/home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/gcc-4.4.0/libgcc/../gcc/libgcc2.c:2165
2165      DO_GLOBAL_CTORS_BODY;
Current language:  auto; currently c
(gdb) 
global constructors keyed to main () at hello.C:9
9       }
Current language:  auto; currently c++
(gdb) 
__static_initialization_and_destruction_0 (__initialize_p=1,
__priority=65535) at hello.C:9
9       }
(gdb) 
72        static ios_base::Init __ioinit;
(gdb) 

Program received signal SIGSEGV, Segmentation fault.
0x42351505 in ?? ()
(gdb) detach
Ending remote debugging.
(gdb) q
pavilion: {4} 

On Wed, 2009-06-17 at 18:17 +0200, Danny Backx wrote:
> Hmm, very interesting.
> 
> \network\x86> gdbserver :9999 /network/x86/ctor.exe
> Process /network/x86/ctor.exe created; pid = 100466698
> Listening on port 9999
> Remote debugging from host 172.17.1.10
> ctor B
> ctor B
> ctor A
> Hello
> dtor A
> dtor B
> dtor B
> 
> Child exited with status 0
> GDBserver exiting
> 
> The constructor and destructor for B are called twice instead of once.
> 
>       Danny

-- 
Danny Backx ; danny.backx - at - scarlet.be ; http://danny.backx.info


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Cegcc-devel mailing list
Cegcc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cegcc-devel

Reply via email to