<p>Im sure this has happened to folks before, something works in debug mode, you compile in release, and something breaks.</p>

<p>This happened to me while working on a Embedded XP environment, the best way i found to do it really was to write a log file to determine where it would go wrong.</p>

<p>What are your experiences/ discoveries trying to tackle an annoying Release-mode bug?</p>

[{'answer_id': 33393, 'author': 'pauldoo', 'author_id': 755, 'author_profile': 'https://Stackoverflow.com/users/755', 'pm_score': 0, 'selected': False, 'text': "<p>If it's only a small portion of the application that needs debugging then you can change those source files only to be built without optimisations.  Presumably you generate debug info for all builds, and so this makes the application run mostly as it would in release, but allows you to debug the interesting parts properly.</p>\n"}, {'answer_id': 33394, 'author': 'Vin', 'author_id': 1747, 'author_profile': 'https://Stackoverflow.com/users/1747', 'pm_score': 0, 'selected': False, 'text': '<p>How about using Trace statements. They are there for Release mode value checking.</p>\n\n<pre><code>Trace.WriteLine(myVar);\n</code></pre>\n'}, {'answer_id': 33398, 'author': '1800 INFORMATION', 'author_id': 3146, 'author_profile': 'https://Stackoverflow.com/users/3146', 'pm_score': 2, 'selected': False, 'text': '<p>Make sure you have good debug symbols available (you can do this even with a release build, even on embedded devices). You should be able to get a stack trace and hopefully the values of some variables. A good knowledge of assembly language is probably also useful at this point.</p>\n\n<p>My experience is that generally the bug is related to code that is near the area of breakage. That is to say, if you are seeing an issue arising in the function "LoadConfigInfoFromFile" then probably you should start by closely analysing that for issues, rather than "DrawControlsOnScreen", if you know what I mean. "Spooky action at a distance" type bugs do not tend to arise often (although when they do, they tend to be a major bear).</p>\n'}, {'answer_id': 33401, 'author': 'Ed Haber', 'author_id': 2926, 'author_profile': 'https://Stackoverflow.com/users/2926', 'pm_score': 0, 'selected': False, 'text': '<p>I agree on log file debugging to narrow it down.</p>\n\n<p>I\'ve used "Entering FunctionName" "Leaving FunctionName" until I can find what method it enters before the crash. Then I add more log messages re-compile and re-release.</p>\n'}, {'answer_id': 33408, 'author': 'crashmstr', 'author_id': 1441, 'author_profile': 'https://Stackoverflow.com/users/1441', 'pm_score': 0, 'selected': False, 'text': '<p>Besides playing with turning off optimization and/or turning on debug information for your Release build as <a href="https://stackoverflow.com/users/755/pauldoo">pauldoo</a> said, a log file will good data can really help. I once wrote a "trace" app that would capture trace logs for the app if it was running when the release build started (otherwise the results would go to the debugger\'s output window if running under the debugger). I was able to have end-users email me log files from them reproducing the bugs they were seeing, and it was the only way I would have found the problem in at least one case.</p>\n'}, {'answer_id': 33694, 'author': 'newdayrising', 'author_id': 3126, 'author_profile': 'https://Stackoverflow.com/users/3126', 'pm_score': 0, 'selected': False, 'text': '<p>Though it\'s probably not usable in an embedded environment, I\'ve had good luck with <a href="http://en.wikipedia.org/wiki/WinDbg" rel="nofollow noreferrer">WinDbg</a> for debugging release-mode Windows applications.  Even if the application is not compiled with symbol information, you can at least get a usable stack trace and plenty of other useful crash information.</p>\n'}, {'answer_id': 33709, 'author': 'juan', 'author_id': 1782, 'author_profile': 'https://Stackoverflow.com/users/1782', 'pm_score': 0, 'selected': False, 'text': '<p>You could also copy your debug symbols to the production environment even if it\'s compiled in relase mode</p>\n\n<p><a href="http://www.juanformoso.com.ar/post/2008/03/06/e28098PDBs-are-evile28099-myth.aspx" rel="nofollow noreferrer">Here</a>\'s an article with more information</p>\n'}, {'answer_id': 70451, 'author': 'Ilya', 'author_id': 6807, 'author_profile': 'https://Stackoverflow.com/users/6807', 'pm_score': 0, 'selected': False, 'text': '<p>If you problem is synchronization related dumping log in the file might be problematic.<br>\nIn this case i usually will use some big array of string and dump this to screen/file after the problem was reproduces.<br>\nThis is of course depend on your memory restriction, sometime i use just few symbols and numbers to store in the array if the memory on the platform is limited. Reading such logs is not a big pleasure, but sometimes this is the only choice.</p>\n'}, {'answer_id': 911259, 'author': 'primeMover', 'author_id': 74638, 'author_profile': 'https://Stackoverflow.com/users/74638', 'pm_score': 2, 'selected': False, 'text': '<p>Tracefile is always a good idea.\nWhen it\'s about crashes, I\'m using adplus, which is part of debugging tools for windows. basically what adplus does, is, it attaches windbg to the executable you\'re monitoring. When the application crashes, you get a crash dump and a log file. You can load the crash dump in your preferred debugger and find out, which instruction lead to the crash.</p>\n\n<p>As release builds are heavily optimized compared to debug builds, the way you compile your code affects its behaviour. This is basically true when crashes in multithreaded code happen in the release version but not the debug version. adplus and windbg helped me, to find out, where this happened.</p>\n\n<p>ADPlus is explained here:\nhttx://support.microsoft.com/?scid=kb%3Ben-us%3B286350&amp;x=15&amp;y=12</p>\n\n<p>Basically what you have to do is:\n1. Download and install WinDbg into C:\\debuggers\nhttx://www.microsoft.com/whdc/devtools/debugging/default.mspx</p>\n\n<ol start="2">\n<li><p>Start your application</p></li>\n<li><p>open a cmd and cd to c:\\debuggers</p></li>\n<li><p>start adplus like this: </p></li>\n</ol>\n\n<p>"adplus.bat -crash your_exe.exe"</p>\n\n<ol start="5">\n<li><p>reproduce the crash</p></li>\n<li><p>analyze the crashdump in vs2005 or in windbg</p></li>\n</ol>\n'}]
['https://Stackoverflow.com/questions/33386', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/514/']