In order to generate a stack trace I am using boost::stacktrace. I have a build agent on Debian that is compiling a unix and a windows version of the program. The Unix version is compiled using the native g++ installed and the windows cross compilation is created using mingw-w64. I am using the libbacktrace backend for both compilations. Both boost and libbacktrace are themselves compiled on the Debian machine using the same mingw-w64 compiler.
In my CMakeLists.txt I specify: add_definitions(-DBOOST_STACKTRACE_USE_BACKTRACE)
A stacktrace is generated like this:
namespace foo { class Bar { public: void fooBar() { std::cout << boost::stacktrace::stacktrace() << std::endl; } }; } int main(int argc, char *argv[]) { foo::Bar bar; bar.fooBar(); } This results in the following output (with -g and no optimization) when compiled on my computer (elementary OS) and when downloaded from the build server on my unix machine.
0# foo::Bar::fooBar() in /home/cromon/CLionProjects/test-proj/cmake-build-debug/test-proj 1# main at /home/cromon/CLionProjects/test-proj/main.cpp:31 2# __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6 3# _start in /home/cromon/CLionProjects/test-proj/cmake-build-debug/test-proj This is the output with the binary created on the build server on my unix machine:
0# foo::Bar::fooBar() in ./test-proj 1# main at /opt/teamcity/2018.2/TeamCity/buildAgent/work/d79789e141c5605f/test-proj/main.cpp:31 2# __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6 3# _start in ./test-proj Now if I am using the binary that was compiled using mingw on Unix on my Windows machine the following output can be observed
0# ZN5boost10stacktrace16basic_stacktraceISaINS0_5frameEEE4initEyy at /opt/teamcity/boost/1_69/windows/include/boost-1_69/boost/stacktrace/stacktrace.hpp:75 1# ZN3foo3Bar6fooBarEv at /opt/teamcity/2018.2/TeamCity/buildAgent/work/eb975d0a928ba129/test_proj/main.cpp:22 2# main at /opt/teamcity/2018.2/TeamCity/buildAgent/work/eb975d0a928ba129/test_proj/main.cpp:31 3# _tmainCRTStartup at ./mingw-w64-crt/crt/crtexe.c:336 4# mainCRTStartup at ./mingw-w64-crt/crt/crtexe.c:214 5# register_frame_ctor in C:\WINDOWS\System32\KERNEL32.DLL 6# register_frame_ctor in C:\WINDOWS\SYSTEM32\ntdll.dll I have also tried to loop through the frames and run a boost::core::demangle on them, but it fails to do so.
There is so far only one difference I can see between the compilation environment on unix and the runtime environment on my windows machine. On Windows I have g++ of version 8.2.0 and on unix it is 6.3.0. Is this causing any problems? What else could cause the demangling to fail only on windows when cross compiled?
_, for examplemainCRTStartupis actually named_mainCRTStartupand_tmainCRTStartupwould be__tmainCRTStartup. Also_ZN3foo3Bar6fooBarEvsould properly be demangled online by a GCC demangler...