程序由g ++用-g標誌,-static-libgcc和-static-libstdC++編譯。沒有包含優化標誌。不過由於某種原因,我無法進入主體。爲什麼?爲什麼我的程序在啓動之前崩潰?
$ nm -C test.exe | grep main 006c05b0 T __getmainargs 006b0ad0 T __main 0088d0e8 B __mingw_winmain_hInstance 0088d0e4 B __mingw_winmain_lpCmdLine 0088d0ec B __mingw_winmain_nShowCmd 006ce518 D __native_dllmain_reason 00401180 t __tmainCRTStartup 0088edc8 I _imp____getmainargs 007491c0 r jisx0213_to_ucs_main 00405f0c T main 00401570 T mainCRTStartup 00884010 b mainret 004a3371 T sqlite3_backup_remaining 0078ada0 r uhc_1_2charset_main 0078c440 r uhc_1_2uni_main_page81 007899a0 r uhc_2_2charset_main 0078db00 r uhc_2_2uni_main_pagea1 $ gdb test.exe GNU gdb (pcx32) 7.3.50.20111127-cvs Copyright (C) 2011 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later 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 "i686-w64-mingw32". For bug reporting instructions, please see: ... Reading symbols from c:\test.exe ...done. (gdb) break main Breakpoint 1 at 0x405f15: file test.cpp, line 1054. (gdb) break mainCRTStartup Breakpoint 2 at 0x401570 (gdb) break __tmainCRTStartup Breakpoint 3 at 0x40118c (gdb) break __main Breakpoint 4 at 0x6b0ad0 (gdb) break __getmainargs Breakpoint 5 at 0x6c05b0 (gdb) run Starting program: c:\test.exe [New Thread 5832.0xc0c] During startup program exited with code 0xc0000022. (gdb)
P.S.依賴walker顯示它不能打開SYSNTFY.DLL並找不到IEFRAME.DLL。然而,這不是新的,不應該是問題。
(gdb) info files Symbols from "c:\test.exe". Local exec file: `c:\test.exe', file type pei-i386. Entry point: 0x401570 0x00401000 - 0x006c14c4 is .text 0x006c2000 - 0x006ce5d0 is .data 0x006cf000 - 0x0080c3e0 is .rdata 0x0080d000 - 0x00883c58 is .eh_frame 0x00884000 - 0x0088d178 is .bss 0x0088e000 - 0x00891d40 is .idata 0x00892000 - 0x00892038 is .CRT 0x00893000 - 0x00893020 is .tls (gdb) break *0x401570 Note: breakpoint 2 also set at pc 0x401570. Breakpoint 6 at 0x401570 (gdb) run Starting program: c:\test.exe [New Thread 5332.0x28b0] During startup program exited with code 0xc0000022.
這說明入口點確實__tmainCRTStartup
,但GDB似乎沒有到達那裏。
答案就像是評論說的:一個圖書館搞亂了一切。爲了解決這個問題,我將每個庫一個一個地關聯起來,直到它變成主要的。
全局對象在'main'之前被實例化。也許其中一人正在造成墜機。嘗試在全局對象構造函數中放置斷點。 – 2013-04-09 19:42:47
你可以發佈你的代碼的一部分(主要的,全局變量...)嗎? – Bechir 2013-04-09 19:50:40
@Bechir我只有c代碼中的全局變量(沒有初始化)。除此之外,還有太多的代碼需要發佈,因爲我甚至無法進入主體。我確實使用可能包含全局變量的C++庫,但我無法幫助您。 – chacham15 2013-04-09 19:52:00