为什么我的程序在启动之前崩溃? [英] Why is my program crashing before it starts?

查看:133
本文介绍了为什么我的程序在启动之前崩溃?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该程序由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.
许可证GPLv3 +:GNU GPL版本3或更高版本
这是免费软件:您可以自由更改和重新分配它。
在法律允许的范围内,不存在任何担保。有关详细信息,请键入显示复制
和显示保修。
此GDB被配置为i686-w64-mingw32。
有关错误报告的说明,请参阅:
...
从c:\ test.exe
... done中读取符号。
(gdb)break main
断点1在0x405f15处:文件test.cpp,行1054.
(gdb)break mainCRTStartup
断点2在0x401570
(gdb) break __tmainCRTStartup
断点3在0x40118c
(gdb)断点__main
断点4在0x6b0ad0
(gdb)断点__getmainargs
断点5在0x6c05b0
(gdb )运行
启动程序:c:\ test.exe
[新线程5832.0xc0c]
在启动程序期间退出代码为0xc0000022。
(gdb)

依赖walker显示它不能打开SYSNTFY.DLL并找不到IEFRAME.DLL。

 
(gdb)信息文件
来自c: \test.exe。
本地exec文件:
`c:\ test.exe',
文件类型pei-i386。
入口点:0x401570
0x00401000 - 0x006c14c4是.text
0x006c2000 - 0x006ce5d0是.data
0x006cf000 - 0x0080c3e0是.rdata
0x0080d000 - 0x00883c58是.eh_frame
0x00884000 - 0x0088d178是.bss
0x0088e000 - 0x00891d40是.idata
0x00892000 - 0x00892038是.CRT
0x00893000 - 0x00893020是.tls
(gdb)break * 0x401570
注意:断点2也设置在pc 0x401570处。
断点6在0x401570
(gdb)运行
启动程序:c:\ test.exe
[New Thread 5332.0x28b0]
在启动过程中, 0xc0000022。

这表明入口点的确是 __ tmainCRTStartup ,但是gdb似乎并不到达那里。



答案就像是评论说的:一个图书馆把所有东西搞乱了。为了解决这个问题,我将每个库一个一个地取消链接,直到它设法进入main。

解决方案

我会怀疑你有一个静态或全局变量初始化,它会抛出一个SIGSEGV或其他错误......所有静态和全局变量在执行main之前被初始化。



另外... I看你正在运行MinGW - 你的路径是否正确设置到MinGW bin目录?当我构建MinGW应用程序(通过Eclipse)时,我有一个启动器应用程序和两个都构建的应用程序。我必须使用启动程序,除非我的Windows路径上有MinGW bin目录。



进一步阅读,值得注意的是在调用mainCRTStartup之前加载DLL。对于Windoze应用程序,您通常会在_DllMain上处理该问题。我不确定在MinGW中如何/在哪里得到处理?


The program was compiled by g++ with the -g flag, -static-libgcc, and -static-libstdc++. No optimization flags were included. For some reason though, I cant get into main. Why?

$ 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. dependency walker shows that it cant open SYSNTFY.DLL and cant find IEFRAME.DLL. This, however, is not new and should not be the problem.

(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.

This illustrates that the entry point is indeed __tmainCRTStartup, but that gdb doesnt seem to get there.

The answer was like commented: a library was messing everything up. In order to figure it out I unlinked every library one by one until it managed to get to main.

解决方案

I would suspect that you have a static or global variable initialization that's throwing a SIGSEGV or other error... all static and global vars are initialized before main is executed.

Also... I see you are running MinGW -- do you have your paths set up correctly to the MinGW bin directories? When I build MinGW apps (via Eclipse) I have a launcher app and the app that both get built. I have to use the launcher unless I have the MinGW bin directories on my Windows path.

Reading further, it's worthy of note that DLLs are loaded before mainCRTStartup is called. For a Windoze app, you would normally break on _DllMain to deal with that. I'm not sure how/where that gets handled in MinGW?

这篇关于为什么我的程序在启动之前崩溃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆