Release mode debugging with vc ++

zhaozj2021-02-16  65

The debug configuration of VC projects is the configuration that most debugging and development is done on. This is entirely appropriate because the debug information, lack of optimizations, and the extra debug checks in the Microsoft libraries, make stepping through your code and finding bugs much Easier Than in Release Builds.

However, Sometimes you have to try and debug your release builds. Possible Reasons Include:

You may have a bug that only occurs in your release builds (for information on why this happens see this article) that you need to debug. You may be trying to optimize your code, in which case stepping through the code and seeing what the compiler has created is essential. your shipped product may be crashing on a customer's machine. you may be able to avoid release only crashes, and you may not need to optimize your release builds, but you never know when your program is going to start crashing on A Distant Customer's Machine - And if you wait Until It Happens, It's to Late.

If you want to be prepared and professional when your program crashes after you've released it then you need to create debug information for the version that you shipped, you need to archive the debug information, and you need to know how to use it.

At this point somebody inevitably says that it is obvious that enabling debug information is a nonsensical thing to do on a release build. They then claim that enabling debug information will make your program too big or too slow, and you certainly do not want to SHIP Your Precious Program with Symbols.

To this I say, the debug information in VC will not make your program bigger, it will not make it slower, and of course you do not ship your symbols. Done properly, enabling debug information lets you ship an executable that is less than . a hundred bytes larger The cost is essentially zero, and the benefits are huge In fact, I claim that all executables and DLLs created with VC should be built with symbols -.. no exceptions I further claim that failing to do this is irresponsible. Enabling Debug Information in VC 6.0 IS Relatively Easy - But Terribly Non-Obvious. There Are Three Separate Settings That You Have To Change.

First Go to Project-> Settings, Select The Release Build, Then:

On the C / C tab for all librarys, DLLs and executables, in the general category, set Debug Info to Program Database. This tells the compiler to generate debug information. On the link tab for all DLLs and executables, in the general category, put a check mark beside Generate Debug Info. This tells the linker to collate debug information into .pdb files. The linker also puts the name of the .pdb file in the executable, so the debugger can find it. That's why your executable gets a . bit bigger Dumpbin / headers will show you that information On the link tab, in the Project Options field, type in. "/ OPT: REF" This tells the linker to continue optimizing away unreferenced code This is the default when debug information.. is turned off, but it defaults to off when you tell the linker to generate debug information Failing to specify this will cause your executables and DLLs to get 10-20% larger you should also specify / ignore:.. 4089 to tell the linker to Not generate Warnings if it Optimizes Away All References To A DLL (this Tip Works with VC .NET Also). This msdn article-http: //msdn.microsoft.com/library/default.asp? URL = / library / techart / gendepdebug.htm - Talks About ........................ ..

Creating debug information is nice, but it only helps if the debug information is available when you need it. In order to get maximum use out of the debug information, your build script (you do have an automated build script do not you?) should archive the .pdb file along with the executable (you do archive the executables you release do not you?), and you should put a label in your version control (you do use version control do not you?) so that you . can recover the source code Without these steps the debug information can easily be useless.If you are using VC .Net or WinDbg and you are creating minidumps when your program crashes then the following steps are not necessary -. just load the minidump See this Article for Information On Creating and use minidumps. However if you are useful VC 6.0 or you aren't yet create minidumps, FOLLOW THESE STEPS:

To analyze a crash address, load the .exe into DevStudio (yes, you can do that) Then instead of select Debug-> Go, single step to load it into the debugger, and make sure the debug information loads -. Check the output Window to see what its............... ..

When you hit enter, the debugger will take you to that address. Because you are in the debugger, the debugger will load the source code associated with that instruction, exactly as if you had crashed in the debugger.

Well, NOT EXACTLY. The Other Registers Aren't loaded, The Stack ISN 'above You can Frequently Figure out what happened.

If you want to improve your odds, you should collect more information than just the instruction pointer Check out John Robbins book "Debugging Applications" or download one of many exception handling articles -. My favourite is here.With all this information and a .pdb or .map file you can write tools to create call stacks -. either starting from the EIP and working up the stack, or starting from a return address in WinMain and working down the stack you can also programmatically load the stack and registers into the executable While It's in the debugger, to let the debugger girl you more assistance in diagnosing the crash.

Let me know if you find this paper useful.

Please contact me if you have any quest qus.

转载请注明原文地址:https://www.9cbs.com/read-16185.html

New Post(0)