Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Ways to Debug a Release Mode Application

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

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.

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

like image 501
James Hall Avatar asked Aug 28 '08 21:08

James Hall


People also ask

Can you debug in Release mode?

The Release mode enables optimizations and generates without any debug data, so it is fully optimized. . Lots of your code could be completely removed or rewritten in Release mode. The resulting executable will most likely not match up with your written code.

Can you use breakpoints in Release mode?

You can then put a breakpoint on that int declaration line, and it'll be hit, even in release mode. Then just step up the stack in the debugger back to the function you actually wanted a breakpoint in.

How do you debug a flutter app in Release mode?

To compile in release mode, we just need to add the --release flag to the flutter run command and have a physical device connected. Although we can do so, we typically do not use the flutter run command with the --release flag.


2 Answers

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.

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).

like image 131
1800 INFORMATION Avatar answered Oct 09 '22 08:10

1800 INFORMATION


Tracefile is always a good idea. When 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.

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.

ADPlus is explained here: httx://support.microsoft.com/?scid=kb%3Ben-us%3B286350&x=15&y=12

Basically what you have to do is: 1. Download and install WinDbg into C:\debuggers httx://www.microsoft.com/whdc/devtools/debugging/default.mspx

  1. Start your application

  2. open a cmd and cd to c:\debuggers

  3. start adplus like this:

"adplus.bat -crash your_exe.exe"

  1. reproduce the crash

  2. analyze the crashdump in vs2005 or in windbg

like image 2
primeMover Avatar answered Oct 09 '22 07:10

primeMover