问题
I'm making a program with C++ and Lua. When I run the program in Release mode OUTSIDE of the debugger, the program doesn't behave as expected (it doesn't crash, it just doesn't do what I thought it would). When I start it from the debugger, it behaves just fine.
I understand that there are differences in the way a program will be run in a debugger vs outside of one (Heap differences? Some uninitialized variables?). Is it possible to configure the debugger so it will run the Release version of my program with as few changes as possible, so I can try to make this problem happen while debugging?
回答1:
Here's a couple of things to try:
- Run outside the debugger but then attach to the process afterwards. When the process is started from the debugger it will have a slightly different environment, so if that is the cause of the different behaviour then this will allow you to debug it
- Create a release build with optimisation turned off and see if you get the same behaviour running inside and outside of the debugger. If you can still reproduce the issue then this will make debugging it (by using the above Attach Process method) a lot easier
回答2:
Not sure about making the debugger act like a release build but you can simulate them somewhat.
Depends on what exactly the differences in behaviour are.
Are all the variables initialised? The debugger does that. You can also use asm { int 3 } to break in release mode.
来源:https://stackoverflow.com/questions/11146301/release-build-changes-behavior-when-run-outside-of-the-debugger