Reputation: 59633
I was involved in a debugging situation where I had no PDBs at all (unfortunately this still happens). In the particular case I was researching a stack corruption and I tried to do a manual stack walk. However, there was a strong mismatch between the ESP and the EBP registers, so I think the code was compiled with the /Oy
optimization (frame pointer omission) turned on. In this case, I had to give up.
My question now is: from the Visual Studio 2015 C++ compiler switches for optmization, which ones will make debugging hard? A short explanation why it becomes hard would be great.
To limit the scope of the question, answers should consider x86 (32 bit) only.
The available options can be found on MSDN, as there are:
O1
- creates small codeOs
- favors small codeO2
- creates fast codeOt
- favors fast codeOb
- controls inline expansionOi
- generate intrinsic functionsThe following ones do not need to be considered:
Od
- disables optimization. This will obviously cause the least troubleOg
- is deprecatedOx
- is just a combination of others. This will obviously cause the sum of troubles of the individual switchesOy
- omit frame pointers. I already know about it. It makes stack walking really difficult. It much about guessing.Upvotes: 2
Views: 344
Reputation: 880
Wow, there are a lot of different types of code optimisation, way more than I have a detailed knowledge of, but I will try to detail different optimisations that significantly affect the debugging experience, knowledge of an optimisation can help guide which compiler switches will enable it.
All the optimisation flags are frowned upon these days, Profile Guided Optimisation is by far the preferable way to use optimisations in release and if you want to debug release-ish code you should use the -Zo flag which will produce better pdb's which can get you more information about inlined functions and variables in registers.
GCC & clang have a per optimisation set of flags the -O flags are just amalgamations of those flags and looking at how GCC distributes the optimisations and details about what each optimisation is will help further understanding about all the different optimisations compilers, in general, do.
EDIT: Also if you want to turn on individual compiler flags and see what it does to the compiled code for GCC and clang god bolt is really useful https://gcc.godbolt.org
Upvotes: 2
Reputation: 2788
As far as I know, debugging problems may be mostly caused by information omission in the compiled binary.
Some of the causes are:
My personal opinion is that a binary without debugging information (.PDB file) is usually "hard enough" to be debugged, at least not worth my time :-)
Upvotes: -1