KjellKod / g3log

G3log is an asynchronous, "crash safe", logger that is easy to use with default logging sinks or you can add your own. G3log is made with plain C++14 (C++11 support up to release 1.3.2) with no external libraries (except gtest used for unit tests). G3log is made to be cross-platform, currently running on OSX, Windows and several Linux distros. See Readme below for details of usage.
http://github.com/KjellKod/g3log
The Unlicense
908 stars 271 forks source link

[Question] Cannot demangle and get real function name under Linux #503

Closed Ace-Radom closed 11 months ago

Ace-Radom commented 11 months ago

I tried to use g3log in my project, and I realized that the library cannot get real function name when the program crashes. I also tried with the examples provided with the library, it didn't work either.

I get a dump like (with the example g3log-FATAL-choice, run in a separate thread, choice 14):

***** SIGNAL SIGSEGV(11)

******* STACKDUMP *******
        stack dump [1]  ~/g3log/build/libg3log.so.2(+0x15f5f) [0x7f9522c69f5f]
        stack dump [2]  /lib/x86_64-linux-gnu/libpthread.so.0(+0x13140) [0x7f9522c39140]
        stack dump [3]  ./g3log-FATAL-choice(+0xfca0) [0x5576c21beca0]
        stack dump [4]  std::_Function_handler<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> (), std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<void>, std::__future_base::_Result_base::_Deleter>, std::thread::_Invoker<std::tuple<void (*)()> >, void> >::_M_invoke(std::_Any_data const&) + 0x16
        stack dump [5]  std::__future_base::_State_baseV2::_M_do_set(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*) + 0x1b
        stack dump [6]  /lib/x86_64-linux-gnu/libpthread.so.0(+0x1034f) [0x7f9522c3634f]
        stack dump [7]  std::thread::_State_impl<std::thread::_Invoker<std::tuple<std::__future_base::_Async_state_impl<std::thread::_Invoker<std::tuple<void (*)()> >, void>::_Async_state_impl(std::thread::_Invoker<std::tuple<void (*)()> >&&)::{lambda()#1}> > >::_M_run() + 0xfa
        stack dump [8]  /lib/x86_64-linux-gnu/libstdc++.so.6(+0xceed0) [0x7f9522b27ed0]
        stack dump [9]  /lib/x86_64-linux-gnu/libpthread.so.0(+0x7ea7) [0x7f9522c2dea7]
        stack dump [10]  clone + 0x3f

Exiting after fatal event  (FATAL_SIGNAL). Fatal type:  SIGSEGV
Log content flushed successfully to sink

g3log g3FileSink shutdown at: 21:22:53 571038
Log file at: [/tmp/g3log-FATAL-choice.g3log.20231124-212249.log]

exitWithDefaultSignalHandler:244. Exiting due to FATAL_SIGNAL, 11

I picked out all programs for crash handling in file src/crashhandler_unix.cpp and did some tests. It seems like most of the times there is no mangled name before +. Therefore I got an empty mangled_name here, always.

https://github.com/KjellKod/g3log/blob/63f327270325d827181ae1eaa0a4601c61fba67e/src/crashhandler_unix.cpp#L167-L171

And also, __cxa_demangle never works. I'm not sure if it's also caused by the same issue.

I'm wondering if it is normal? If not, what may be wrong?

KjellKod commented 11 months ago

So if I understand you correctly, you get the correct demangled dump when you run the examples but not when it's integrated with your software.

Typically when that happens it's due to not linking with access to the object symbols. Exactly how you do this is dependent on your compiler and platform.

Ref #5 Handling of fatal

Ace-Radom commented 11 months ago

Typically when that happens it's due to not linking with access to the object symbols. Exactly how you do this is dependent on your compiler and platform.

Thanks for your response xD I added -rdynamic to global compile flags and it does solve my problem. Again thx a lot.