Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lack of debug symbols in binary built with optimizations enabled #64

Open
Poldraunic opened this issue Feb 8, 2021 · 2 comments
Open

Comments

@Poldraunic
Copy link

Poldraunic commented Feb 8, 2021

Hello.

I am developing an app which is currently built with MinGW-W64 5.3.0 on Windows. As it always goes, a need arose to see stacktrace when on crash on consumer machine. Quick Google search led me to "Printing a Stack Trace with MinGW" article. I mindlessly copied code to see if it even works (article is almost 5 years now). Indeed it does and it is quite satisfactorily for my needs.

And so I started tinkering with it. Compiling without optimizations produces satisfactory trace for my needs.

PS F:\Projects\C++\mingw_stacktrace> g++.exe -std=c++11 -g main.cpp -lDbgHelp -o main.exe; ./cv2pdb.exe main.exe; ./main.exe
[0] function_c
[1] function_b
[2] function_a
[3] main
[4] public_all
[5] BaseThreadInitThunk
[6] RtlGetAppContainerNamedObjectPath
[7] RtlGetAppContainerNamedObjectPath

However, the moment I turn on regular optimization level (-O2) all info is lost.

PS F:\Projects\C++\mingw_stacktrace> g++.exe -std=c++11 -O2 -g main.cpp -lDbgHelp -o main.exe; ./cv2pdb.exe main.exe; ./main.exe
[0] public_all
[1] BaseThreadInitThunk
[2] RtlGetAppContainerNamedObjectPath
[3] RtlGetAppContainerNamedObjectPath

After that I decided to see if anything changes if I switch to MinGW-W64 8.1.0. Yes, some things have changed: stack trace without optimizations looks about the same, and with optimizations turned on it is a little bit better:

PS F:\Projects\C++\mingw_stacktrace> g++.exe -std=c++11 -O2 -g main.cpp -lDbgHelp -o main.exe; ./cv2pdb.exe main.exe; ./main.exe
[0] stack_trace
[1] main
[2] public_all
[3] public_all
[4] BaseThreadInitThunk
[5] RtlUserThreadStart

As of this moment, I cannot migrate to a newer version of MinGW-W64 (or to another compiler altogether).


Is it possible to get any kind of info with MinGW-W64 5.3.0? Upgrade to a newer version is planned, but it is a quite a long way away from now on still.

@rainers
Copy link
Owner

rainers commented Feb 9, 2021

I suspect that your code for functiion_a/b/c is inlined, so there are no stack frames to follow. Maybe using -fno-inline while keeping the rest of the optimizations helps.

@Poldraunic
Copy link
Author

Hello.

The moment I noticed lack of function names, I put a no inline attribute (__attribute__ ((noinline))) and it didn't help. Just now tried also with the compile flag and nothing has changed as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants