0

glog (c++)'s failure signal handler can print stacktrace on segfault etc (see here). Can the stacktrace include line number as well?

Edit: Even if I use LOG(FATAL), the stacktrace does not have line number.

*** Check failure stack trace: ***
    @     0x7f43546debd6  google::LogMessage::Fail()
    @     0x7f43546deb1a  google::LogMessage::SendToLog()
    @     0x7f43546de46b  google::LogMessage::Flush()
    @     0x7f43546e1530  google::LogMessageFatal::~LogMessageFatal()

I initializes glog as follows

  google::InstallFailureSignalHandler();
  google::InitGoogleLogging(argv[0]);
  gflags::ParseCommandLineFlags(&argc, &argv, /*remove_flags=*/true);

If you are seeing line numbers, what could I be missing? Thanks!

bill
  • 650
  • 8
  • 17
  • Checkout here https://stackoverflow.com/a/19094539/10035556 – Mayur Jan 28 '20 at 07:26
  • Thanks! That seems to be for go? Sorry about the confusion -- I edited the question to clarify. – bill Jan 28 '20 at 07:42
  • Do you mean the `LOG(FATAL)` level? If you do, the log line itself prints the line number so I am not sure what you mean. If you mean just printing the stack trace using glog that is not exposed to the user in the C++ library. (though I think you might be able to define a macro to do it using `FLAGS_log_backtrace_at`, `__FILE__` and `__LINE__` though probably not safe) – pooya13 Jan 28 '20 at 09:14
  • related: https://stackoverflow.com/questions/4636456/how-to-get-a-stack-trace-for-c-using-gcc-with-line-number-information – bill Aug 26 '20 at 02:51

1 Answers1

0

There is a fatal message before stack trace.

WARNING: Logging before InitGoogleLogging() is written to STDERR   // here
F1015 19:51:48.561210 15798 test.cc:36] []This is a test
*** Check failure stack trace: ***
Aborted (core dumped)

daohu527
  • 452
  • 4
  • 15