Why do some things never crash the debugger?

My application uses GLUTesselator to tessellate complex concave polygons. It accidentally crashes when I run the regular exe release, but it never crashes if I start debugging in VS. I found this right here, which is basically my problem:

The multi-thread debug CRT (/MTd) masks the problem, because, like 

Windows does with the processes generated by the debugger, it provides a program to debug a bunch, that is, it is initialized with the 0xCD template. Perhaps somewhere you use some uninitialized memory from the heap as a pointer, and you look for It; with two debugged heaps that you get away with it for some reason (maybe because the addresses 0xbaadf00d and 0xcdcdcdcd have real allocated memory), but with a "normal" heap (which is often initialized to 0), you get an access violation, because that you search for a NULL pointer.

The problem is a glitch in GLU32.dll, and I have no way to find out why it sometimes tries to dereference a null pointer. this is similar to when my polygons get pretty big and have a lot of points. What can I do?

thanks

+4
source share
3 answers

It is a fact of life that sometimes programs behave differently in the debugger. In your case, some memory is initialized differently, and it probably also differs differently. Another common case in parallel programs is that the time is different, and race conditions often happen less frequently in the debugger.

You can try to manually initialize the heap to a different value (or see if there is an option for this in Visual Studio). Initially, non-zero initialization catches more errors, but this may not be the case in your situation. You can also try playing the memory card of your program to ensure that the 0xcdcdc000 page is not displayed.

Visual Studio can set a breakpoint when accessing a specific memory address, you can try this (this can slow down your program much more than a variable breakpoint).

+3
source

but it never fails if I start debugging in VS.

Well, I don’t know exactly why, but while debugging in a visual studio program can sometimes go away with access to some areas of memory that could destroy it without a debugger. However, I don’t know the exact reasons, but sometimes 0xcdcdcdcd and 0xbaadfood have nothing to do with it. Just access to specific addresses does not cause problems. When this happens, you will need to find alternative methods of guessing the problem.

What can I do?

Possible solutions:

  • Install an exception handler in your program ( _ set_se_translator , if I remember correctly). If access is violated, try MinidumpWriteDump . Debug it later using Visual Studio (afaik, debugging a crash dump - not in the express edition) or using windbg.
  • Use on-time debugging devices. This function has a non-express version of the visual studio. There are probably alternatives.
  • Write a custom memory manager (which will override the new / delete and provide malloc / free alternatives (if you use them)) that will capture a large amount of memory, block all unused memory using VirtualProtect . In this case, all invalid access will lead to crashes even in debug mode. For such a memory manager, you will need a lot of memory, because to block each block must be aligned on the pages.
  • Add excessive registration of all calls to suspicious functions. Dump a lot of text / debugging information to a file (or stderr) - parameter values, arrays, everything that you suspect may be related to a failure, reset after each write to the file, otherwise some information will be lost during the failure. That way, you can guess what happened before the program crashed.
  • Try a debug build of releases. You should be able to do this to some extent if you enable "debugging information" to create the release in the project settings.
  • Try turning on / off "basic runtime checks" and "buffer security checks" in the project properties ( configuration properties->c/c++->code genration ).
  • Try to find some kind of external tool - something like validating valgrind or bounds. Although, in my experience, No. 3 is more reliable than this approach. Although it really depends on the problem.
+2
source

Link to an earlier question and two thoughts.

First, you can look at the previous question about valgrind substitutes for windows. A lot of good tips about programs that will help you.

Now thoughts:

1) The debugger can stop your program from failing in the test code, but this does not fix the problem. In the worst case scenario, you simply kicked a can down the street, there is still corruption, but this is not visible from the way you run. When you submit, you can be sure that someone will encounter a problem again.

2) What often happens in such cases is that the error is not next to the problem. Although you may have noticed a problem in GLU32.dll, there may have been corruption before, perhaps even in a different thread or function, which did not cause a problem, and at some point the program returned to the damaged region and failed.

+2
source

All Articles