简体   繁体   English

Google glog不打印堆栈跟踪

[英]Google glog prints no stack trace

I'm using the google glog library for my C++ program. 我正在为我的C ++程序使用google glog库。 I have used the glog library before, so I know that it should print out the stack trace when there is a CHECK failure. 我以前使用过glog库,所以我知道当CHECK失败时,它应该打印出堆栈跟踪。 But it does not print any stack trace for my program: 但是它不会为我的程序打印任何堆栈跟踪:

#include <glog/logging.h>

void bar(int x) {
  CHECK_EQ(x, 1);
}

void foo(int x) {
  bar(x + 1);
}

int main() {
  foo(1);
}

The Makefile is Makefile是

all: Makefile test.cpp
    g++ -g -O3 test.cpp -lglog -o test

And the output I'm getting is 我得到的输出是

$ ./test 
WARNING: Logging before InitGoogleLogging() is written to STDERR
F0629 14:09:45.900789 37730 test.cpp:4] Check failed: x == 1 (2 vs. 1) 
*** Check failure stack trace: ***
Aborted

Am I missing something here? 我在这里想念什么吗?

Thank you! 谢谢!

Cui ui

I turns out that I should first call the InstallFailureSignalHandler() function to initialize glog, if I want my stack trace to be printed. 事实证明,如果要打印堆栈跟踪,应该首先调用InstallFailureSignalHandler()函数来初始化glog。 So the fixed program is: 因此,固定程序为:

#include <glog/logging.h>

void bar(int x) {
  CHECK_EQ(x, 1);
}

void foo(int x) {
  bar(x + 1);
}

int main(int argc, char** argv) {
  google::InstallFailureSignalHandler();
  foo(1);
}

And the output is: 输出为:

$ ./test 
WARNING: Logging before InitGoogleLogging() is written to STDERR
F0708 09:15:35.401262 44752 test.cpp:4] Check failed: x == 1 (2 vs. 1) 
*** Check failure stack trace: ***
*** Aborted at 1467990935 (unix time) try "date -d @1467990935" if you are using GNU date ***
PC: @     0x7f3c96566f89 (unknown)
*** SIGABRT (@0x275c0000aed0) received by PID 44752 (TID 0x7f3c9725b780) from PID 44752; stack trace: ***
    @     0x7f3c96567000 (unknown)
    @     0x7f3c96566f89 (unknown)
    @     0x7f3c9656a398 (unknown)
    @     0x7f3c96e28d81 (unknown)
    @     0x7f3c96e28daa (unknown)
    @     0x7f3c96e28ce4 (unknown)
    @     0x7f3c96e286e6 (unknown)
    @     0x7f3c96e2b687 (unknown)
    @           0x400d80 bar()
    @           0x400dab foo()
    @           0x400dcb main
    @     0x7f3c96551ec5 (unknown)
    @           0x400c39 (unknown)
    @                0x0 (unknown)
Aborted

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM