Thread: Crash in Debugger

  1. #16
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Bubba View Post
    According to my experience the only variables intialized to zero in release are those specifically assigned a value of zero by the programmer. In other words I don't think that the assembly that MSVC spits out in any way auto-inits anything to zero. I remember back in the day that Borland and possibly DJGPP did do this which made debugging uninitialized variable/memory errors extremely difficult. Again I'm not sure if Borland and DJGPP only did this in release or in debug since I didn't even understand the concept of release and debug back then.
    This is correct of course, but the reason things end up "mostly" zero is simply because most memory is zero. The OS itself clears memory pages to zero when they are committed into a process's address space. It's not the program that does it, it's the OS itself.

    (If the OS didn't do that, then a program could get data from other extinct processes by just malloc'ing a big block of memory and looking at it -- that's obviously an unacceptable security problem)
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  2. #17
    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

  3. #18
    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);
    //}

  4. #19
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    For MSVC and Win32 (I think) all stack mem is init to 0xCCCCCCCC and dynamic is 0xCDCDCDCD. Free'd dynamic memory is 0xFEEEFEEE so if you see that one of your pointers has this address you know someone else pulled the rug out from under you.

    There are several other codes used like 0xDEADBEEF and so forth.

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