idealvin / coost

A tiny boost library in C++11.
Other
3.91k stars 558 forks source link

windows平台X86下无法打印出异常时的栈调用信息 #326

Open bigbao9494 opened 1 year ago

bigbao9494 commented 1 year ago

windows平台X86下无法打印出异常时的栈调用信息(X64没有此问题),只打印了2行 F0516 17:24:33.963] Error: EXCEPTION_ACCESS_VIOLATION 778F75C4 (ntdll): (filename not available): RtlGetAppContainerNamedObjectPath

测试代码:

include "co/log.h"

include "co/cout.h"

include "co/time.h"

DEF_bool(perf, false, "performance testing"); int nested_log() { DLOG << ">>>> nested log.."; return 123; } void raise_error() { char p = NULL; p = 0x11; } int main(int argc, char** argv) { flag::parse(argc, argv); FLG_cout = true;

if (FLG_perf) {
    // test performance by writting 100W logs
    co::print("print 100W logs, every log is about 50 bytes");

    co::Timer t;
    for (int k = 0; k < 1000000; k++) {
        LOG << "hello world " << 3;
    }
    int64 write_to_cache = t.us();

    log::exit();
    int64 write_to_file = t.us();

    co::print("All logs written to cache in ", write_to_cache, " us");
    co::print("All logs written to file in ", write_to_file, " us");

} else {
    // usage of other logs
    DLOG << "This is DLOG (debug).. " << 23;
    LOG  << "This is LOG  (info).. " << 23;
    WLOG << "This is WLOG (warning).. " << 23;
    ELOG << "This is ELOG (error).. " << 23;
    //FLOG << "This is FLOG (fatal).. " << 23;
    LOG << "hello " << nested_log() << "  " << nested_log();
    TLOG("co") << "hello co";
    TLOG("bob") << "hello bob";
}

raise_error();
return 0;

}

idealvin commented 1 year ago

编译时,需要添加调试信息,参考 test/stack.cc,

    if test[1] == "stack" then
        set_symbols("debug")    -- dbg symbols
        set_strip("none")
        set_optimize("none")
    end
bigbao9494 commented 1 year ago

感谢回复 没太懂您的意思,我是用的cmake构建的,相同条件下为什么编译成X64可以打印出异常栈信息,而X86不行。 x86的构建需要单独添加编译条件 ?