We are building a solution for Release, but when attempting to attach using studio 2010 professional, no thread is showing any stack information, nor any breakpoint can be set, etc.
The goal is to be able to attach the Visual Studio/JIT Debugger to the running process while having as many optimization benefits as possible.
Most of our searches comes down to 'compile with debug:full' and you will be able to debug, but that doesn't seem to be the case, I thing that the JIT optimizes the code in runtime and thus we cannot debug, is this true? Is it possible to compile and tell the JIT to downplay the optimizations and allow debugging? (while retaining other optimizations)
UPDATE
using @HansPassant's answer, I looked at the modules and saw that although the pdbs are in the same directory as the binaries, indeed no debug symbols were loaded. what I also saw is that the my libraries are marked as 'User Code'-'NO' which is probably the reason it was not loaded automatically. By loading symbols manually AND disabling 'just-my-code' I was also able to set breakpoints and see stacks.
Question now: why is my code not marked as User Code? is this normal behavior? can I configure this to my assemblies in some way to avoid this?
Some application examples might work in debug mode but not in release mode. This means that when you reset the microcontroller and try to run without a debugger connected, the application code might not execute as expected.
Sometimes, however, a bug may appear only in an optimized version of a program. In that case, we must debug the optimized code. – Set the mode Debug and Optimization level is should be same as Release and now run the application. – Set the Release mode and change the Optimization level and run the application.
The release configuration of your program has no symbolic debug information and is fully optimized. For managed code and C++ code, debug information can be generated in.pdb files, depending on the compiler options that are used. Creating.pdb files can be useful if you later have to debug your release version.
Look for code in TRACE () must be executed. TRACEs like ASSERTs are compiled out in release mode. If this fixes your problems in Debug mode, try rebuilding the Release mode version. It will very likely work this time. Are you assuming that your variables, and allocated data is initialized to some value (probably 0)?
Debugging optimized code is no great pleasure. You certainly may have trouble setting breakpoints, a method may have been inlined. And inspecting local variables and method arguments is liable to make the debugger sulky when the variable was optimized to be stored in a cpu register.
You however certainly can still inspect call stacks, you'll see the methods that didn't get inlined in the stack trace. Basic mistakes you might make:
Thought I'd follow up with an additional answer regarding your updated question to help others.
From Microsoft:
To distinguish user code from non-user code, Just My Code looks at symbol (.pdb) files and program optimizations. The debugger considers code to be non-user code when the binary is optimized or when the .pdb file is not available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With