Thread: Crash in Debugger

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by jeffcobb View Post
    Query: is this app multithreaded? Reason I ask is that in such a situation a crash can happen under a certain sequence of context switches and not (or worse, seemingly not as in the case of undetected memory corruption) in a different sequence. Two things to keep in mind here is that in some compilers (used to be all) in "debug" mode, all variables are initialized to a value of some kind whereas in release mode, only those that you specifically (programmatically) initialize are. Just by itself this behavior will result in release and debug mode running/acting differently. Then if you add in the fact that a debugger will enforce a specific or artificial sequence of context switches, you have a recipe for fun...
    Yes -- In debug mode, uninitialized memory is usually filled with a bit pattern that helps to shake out these kinds of bugs -- on Windows, debug uninit memory is filled with 0xCD repeated over and over. In release, the memory will probably just contain zeros. Since most variables are, or should have been, initialized to zero, this can hide the uninitialized memory bug.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  2. #2
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Quote Originally Posted by brewbuck View Post
    Yes -- In debug mode, uninitialized memory is usually filled with a bit pattern that helps to shake out these kinds of bugs -- on Windows, debug uninit memory is filled with 0xCD repeated over and over. In release, the memory will probably just contain zeros. Since most variables are, or should have been, initialized to zero, this can hide the uninitialized memory bug.
    l am trying to remember which system/OS filled memory with 0xDEADBEEF ... in any event I remember a single uninitialized var on Win31 causing us grief b/c if randomly initialized itself to zero on some machines (and this was a proper value as per the application) and some random non-zero number on others causing mayhem. Of course, the machines that it initialized to zero on were all dev boxen and the machine it went nuts on were the clients, 50 miles away...in the dead of winter....brrr! That lesson alone as re-inforced the "init your vars" rule in my mind ever since....even if the vars are not yours (worked on a team) there was never a case where it was "right" not to init....

    <rant mode off...I now return you to your bug...>

    Peace
    Jeff
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  3. #3
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    Quote Originally Posted by brewbuck View Post
    Yes -- In debug mode, uninitialized memory is usually filled with a bit pattern that helps to shake out these kinds of bugs -- on Windows, debug uninit memory is filled with 0xCD repeated over and over. In release, the memory will probably just contain zeros. Since most variables are, or should have been, initialized to zero, this can hide the uninitialized memory bug.
    As far as I can see, and have seen, when writing apps for windows using Visual Studio with debug config, all vars are filled with 0xCC, not 0xcd, but obviously, that is an irrelevant detail.
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  4. #4
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Quote Originally Posted by IceDane View Post
    As far as I can see, and have seen, when writing apps for windows using Visual Studio with debug config, all vars are filled with 0xCC, not 0xcd, but obviously, that is an irrelevant detail.
    There was a time when 0xCDCD was the default although IIRC isn't there a setting somewhere in VS where you can set what the default value is? Been so long I cannot remember...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by jeffcobb View Post
    There was a time when 0xCDCD was the default although IIRC isn't there a setting somewhere in VS where you can set what the default value is? Been so long I cannot remember...
    I think you can probably configure it. In any case, you can always override the global new operator to fill dynamic memory with anything you want, really.

    In our software testing, we enable floating-point exceptions so that FP divides by zero or other bad things will cause a crash that we can track. Once, we had a very rare crash due to an invalid IEEE bit pattern that was very hard to track down. We knew it was uninitialized memory, but it was difficult to figure out where, because most of the time, although the value was uninitialized, it represented some valid number and everything worked okay. A developer around here had the bright idea to fill all dynamic memory with the value 0x7fc00001, which represents an invalid 32-bit IEEE float value. We INSTANTLY found the problem.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. executing from debugger
    By hedwin in forum C++ Programming
    Replies: 8
    Last Post: 10-11-2007, 04:05 PM
  2. Replies: 3
    Last Post: 07-24-2007, 04:25 PM
  3. Can not debug a crash
    By hannibar in forum Windows Programming
    Replies: 2
    Last Post: 06-30-2007, 10:02 AM
  4. FYI: asctime(gmtime(&mytime)) = crash!
    By anonytmouse in forum C Programming
    Replies: 2
    Last Post: 09-29-2003, 02:24 AM
  5. MSVC++ Debugger (it kills me)
    By lightatdawn in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 06-29-2002, 07:37 PM