【问题标题】:c++ on mac / eclipse does not show error when crashingmac / eclipse上的c ++崩溃时不显示错误
【发布时间】:2016-08-04 14:46:51
【问题描述】:

您好,我正在使用全新安装的 c++/eclipse。我正在使用 Cross GCC,我的所有选项看起来都像

-O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -v

当应用程序崩溃时,当我在 c++ 上刷新自己时,它会很好地退出,没有堆栈跟踪,没有,嘿,你有一个 seg 错误消息。没有。不得到错误输出说明崩溃的位置是不可用的。

我缺少什么简单的步骤或标志?

一个我写出越界的例子。

cout << "this will crash! " << endl;
int foo[1000];
for (int i = 0; i <= 3000 ; i++)
    foo[i] = i;
cout << "!Hello World!!!" << endl; // prints !!!Hello World!!!

输出

this will crash! 

没有别的了。

谢谢! 哦,我正在为调试器运行 GDB。调试器可以在断点等处工作。

【问题讨论】:

  • 您是否尝试过从命令行在gdb 中运行它,看看会发生什么?

标签: c++ eclipse macos debugging


【解决方案1】:

你确定它是用 -O0 编译的吗?

当我用 -O2 编译这段代码时,编译器检测到初始化数组没有外部副作用或依赖关系,并完全忽略它。

.LC0:
        .string "this will crash! "
main:
        subq    $8, %rsp
        movl    $17, %edx
        movl    $.LC0, %esi
        movl    std::cout, %edi
        call    std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)
        movl    std::cout, %edi
        call    std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)
        xorl    %eax, %eax
        addq    $8, %rsp
        ret
        subq    $8, %rsp
        movl    std::__ioinit, %edi
        call    std::ios_base::Init::Init()
        movl    $__dso_handle, %edx
        movl    std::__ioinit, %esi
        movl    std::ios_base::Init::~Init(), %edi
        addq    $8, %rsp
        jmp     __cxa_atexit

【讨论】:

    猜你喜欢
    • 2015-08-28
    • 1970-01-01
    • 2021-01-29
    • 2010-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-07
    • 1970-01-01
    相关资源
    最近更新 更多