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
pavilion: {1965} i386-mingw32ce-gdb ctor.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 67436550]
Error while mapping shared library sections:
coredll.dll: No such file or directory.
Symbol file not found for coredll.dll
WinMainCRTStartup (hInst=0x5fd000a, hPrevInst=0x0, lpCmdLine=0x3001fc70,
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) s
44 _pei386_runtime_relocator ();
(gdb) s
_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) p start
No symbol "start" in current context.
(gdb) l
28 static void
29 do_pseudo_reloc (void* start, void* end, void* base)
30 {
31 DWORD reloc_target;
32 runtime_pseudo_reloc* r;
33 for (r = (runtime_pseudo_reloc*) start; r <
(runtime_pseudo_reloc*) end; r++)
34 {
35 reloc_target = (DWORD) base + r->target;
36 *((DWORD*) reloc_target) += r->addend;
37 }
(gdb) s
46 }
(gdb) p r
No symbol "r" in current context.
(gdb) p start
No symbol "start" in current context.
(gdb) where
#0 _pei386_runtime_relocator ()
at
/home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/pseudo-reloc.c:46
#1 0x00401011 in WinMainCRTStartup (hInst=0x5fd000a, hPrevInst=0x0,
lpCmdLine=0x3001fc70,
nCmdShow=5)
at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/crt3.c:44
(gdb) s
WinMainCRTStartup (hInst=0x5fd000a, hPrevInst=0x0, lpCmdLine=0x3001fc70,
nCmdShow=5)
at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/crt3.c:49
49 __atexit_init();
(gdb) s
__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) s
66 if (first_atexit == NULL ) /* can't allocate memory */
(gdb) s
73 *first_atexit = NULL;
(gdb) s
74 next_atexit = first_atexit;
(gdb)
76 }
(gdb)
WinMainCRTStartup (hInst=0x5fd000a, hPrevInst=0x0, lpCmdLine=0x3001fc70,
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:77
77 if (!initialized)
(gdb)
79 initialized = 1;
(gdb)
82 }
(gdb)
__gccmain ()
at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/gccmain.c:80
80 __mingw_do_global_ctors ();
(gdb)
__mingw_do_global_ctors ()
at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/gccmain.c:39
39 {
(gdb)
40 unsigned long nptrs = (unsigned long) __CTOR_LIST__[0];
(gdb)
48 if (nptrs == -1)
(gdb)
57 for (i = nptrs; i >= 1; i--)
(gdb)
59 __CTOR_LIST__[i] ();
(gdb)
global constructors keyed to b () at ctor.C:44
44 }
Current language: auto; currently c++
(gdb)
__static_initialization_and_destruction_0 (__initialize_p=1,
__priority=65535) at ctor.C:44
44 }
(gdb)
36 B b;
(gdb)
B (this=0x404000) at ctor.C:27
27 printf("ctor B\n");
(gdb)
Console NOT redirected for process 0x5FD000A
28 }
(gdb)
__static_initialization_and_destruction_0 (__initialize_p=1,
__priority=65535) at ctor.C:44
44 }
(gdb)
__mingw_do_global_ctors ()
at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/gccmain.c:57
57 for (i = nptrs; i >= 1; i--)
Current language: auto; currently c
(gdb) p nptrs
$1 = 1
(gdb) s
65 atexit (__mingw_do_global_dtors);
(gdb) s
atexit (pfn=0x4012fc <__mingw_do_global_dtors>)
at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/atexit.c:42
42 return (__dllonexit (pfn, &first_atexit, &next_atexit)
(gdb)
__dllonexit (func=0x4012fc <__mingw_do_global_dtors>, start=0x404004,
end=0x404008)
at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/atexit.c:115
115 if (!start || !*start || !end || !*end)
(gdb)
121 len = (*end - *start);
(gdb)
125 if (++len <= 0)
(gdb)
128 tmp = (p_atexit_fn *)realloc(*start, len * sizeof(tmp));
(gdb)
129 if (!tmp)
(gdb)
131 *start = tmp;
(gdb)
132 *end = tmp + len;
(gdb)
133 tmp[len - 1] = func;
(gdb)
135 return func;
(gdb)
136 }
(gdb)
atexit (pfn=0x4012fc <__mingw_do_global_dtors>)
at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/atexit.c:44
44 }
(gdb)
__mingw_do_global_ctors ()
at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/gccmain.c:66
66 }
(gdb)
WinMainCRTStartup (hInst=0x5fd000a, hPrevInst=0x0, lpCmdLine=0x3001fc70,
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=0x5fd000a, hPrevInst=0x0, szCmdLine=0x3001fc70, 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=0x3001fc70)
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=0x5fd000a, hPrevInst=0x0, szCmdLine=0x3001fc70, 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=0x5fd000a, hPrevInst=0x0, szCmdLine=0x3001fc70, 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=0x30020510) at ctor.C:39
39 {
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=0x30020510) at ctor.C:39
39 {
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 b () at ctor.C:44
44 }
Current language: auto; currently c++
(gdb)
__static_initialization_and_destruction_0 (__initialize_p=1,
__priority=65535) at ctor.C:44
44 }
(gdb)
36 B b;
(gdb)
B (this=0x404000) at ctor.C:27
27 printf("ctor B\n");
(gdb)
28 }
(gdb)
__static_initialization_and_destruction_0 (__initialize_p=1,
__priority=65535) at ctor.C:44
44 }
(gdb)
__do_global_ctors ()
at
/home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/gcc-4.4.0/libgcc/../gcc/libgcc2.c:2166
2166 atexit (__do_global_dtors);
Current language: auto; currently c
(gdb)
atexit (pfn=0x40168c <__do_global_dtors>)
at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/atexit.c:42
42 return (__dllonexit (pfn, &first_atexit, &next_atexit)
(gdb)
__dllonexit (func=0x40168c <__do_global_dtors>, start=0x404004,
end=0x404008)
at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/atexit.c:115
115 if (!start || !*start || !end || !*end)
(gdb)
121 len = (*end - *start);
(gdb)
125 if (++len <= 0)
(gdb)
128 tmp = (p_atexit_fn *)realloc(*start, len * sizeof(tmp));
(gdb)
129 if (!tmp)
(gdb)
131 *start = tmp;
(gdb) c
Continuing.
Program exited normally.
(gdb) q
pavilion: {1966}
On Wed, 2009-06-17 at 01:46 +0100, Dave Korn wrote:
> Danny Backx wrote:
> > The C++ library on x86 appears to crash at initialisation even in the
> > simplest of programs. At least, it does so when compiled against the DLL
> > version of the library.
> >
> > #include <iostream>
> > using namespace std;
> > int main(int argc, char *argv[])
> > {
> > cout << "Hello" << endl ;
> > }
> >
> > Are there any tricks involved in debugging this kind of stuff ?
> >
>
> The main thing here is to look at the .ctors and .dtors sections, ensure
> they have all the correct entries and step through them to make sure they're
> being called correctly; this maybe takes place in __main(), depending what
> you've done to teach the compiler about startup objects.
>
> cheers,
> DaveK
>
>
--
Danny Backx ; danny.backx - at - scarlet.be ; http://danny.backx.info
#include <stdio.h>
#include <stdlib.h>
// #include <iostream>
using namespace std;
class A {
public:
A()
{
printf("ctor A\n");
}
~A()
{
printf("dtor A\n");
}
};
class B {
public:
B()
{
printf("ctor B\n");
}
~B()
{
printf("dtor B\n");
}
};
B b;
int main(int argc, char *argv[])
{
A a;
// cout << "Hello" << endl ;
printf("Hello\n");
}
------------------------------------------------------------------------------
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