2013-04-09 48 views
2

程序由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似乎沒有到達那裏。

答案就像是評論說的:一個圖書館搞亂了一切。爲了解決這個問題,我將每個庫一個一個地關聯起來,直到它變成主要的。

+0

全局對象在'main'之前被實例化。也許其中一人正在造成墜機。嘗試在全局對象構造函數中放置斷點。 – 2013-04-09 19:42:47

+0

你可以發佈你的代碼的一部分(主要的,全局變量...)嗎? – Bechir 2013-04-09 19:50:40

+0

@Bechir我只有c代碼中的全局變量(沒有初始化)。除此之外,還有太多的代碼需要發佈,因爲我甚至無法進入主體。我確實使用可能包含全局變量的C++庫,但我無法幫助您。 – chacham15 2013-04-09 19:52:00

回答

6

我會懷疑你有一個靜態或全局變量初始化,它會拋出一個SIGSEGV或其他錯誤......所有靜態和全局變量在執行main之前被初始化。

另外...我看到你正在運行MinGW - 你有你的路徑正確設置到MinGW bin目錄?當我構建MinGW應用程序(通過Eclipse)時,我有一個啓動器應用程序和兩個都構建的應用程序。除非我的Windows路徑上有MinGW bin目錄,否則我必須使用啓動器。

進一步閱讀,值得注意的是,在調用mainCRTStartup之前加載DLL。對於Windoze應用程序,您通常會在_DllMain上處理該問題。我不確定在MinGW中如何處理?

+0

我將如何檢查這個(即找出在哪裏)?(我不認爲我自己已經使用過它們,所以也許是一個庫) – chacham15 2013-04-09 19:43:58

+1

我認爲同樣的事情,但是'__tmainCRTStartup'會停止調試器,我相信。 – 2013-04-09 19:44:07

+0

@ chacham15 - 請參閱編輯我的答案。 – 2013-04-09 19:49:03

0

我使用Cygwin的時候有這個同樣的問題,我發現了一個解決方案:給可執行權限的共享庫:

$ chmod a+x lib<name>.so.<ver> 

,並且還添加選項-m0755到我的$(INSTALL )命令。

+1

根據OP的評論,這似乎不太可能是同一個問題。 – 2014-11-24 13:30:53