Thread: can we debug into delete

  1. #1
    Registered User
    Join Date
    May 2006

    can we debug into delete

    Hello everyone,

    I am using Visual Studio 2005 and I am wondering whether we could debug into the global delete operator?

    I have tried to debug by setting a break point to delete statement, but I could only debug into destructor.

    My understanding is, when we call delete, the internal operations are,

    1. invoking destructor;
    2. invoking global delete operator.

    Is my understanding correct?

    For example,

    class Foo {
    int i;
    		i = 100;
    		i = 0;
    int main (int argc, char** argv)
    	Foo* f = new Foo();
    	delete f;  // can not debug inside
    	return 0;

    thanks in advance,

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Portland, OR
    You can't "debug" there because you don't have source code to the built-in delete. The debugger will probably allow you to step into it, but you are only going to see machine instructions, not "code."

    Why do you want to do this? Hopefully not because your program is crashing inside delete. If that's happening, it means you've corrupted memory somewhere, it DOESN'T mean there's a bug in delete

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    I think you can actuall install some of the C runtime source code with Visual Studio [at least I seem to have such on my machine], in which case you can step into delete, new, malloc, free, etc. But as brewbuck states, it's probably not what you want to do, even if you have the source - the code is usually quite convoluted, and if you have corrupted memory, it's not going to really help, because it will just be crashing trying to access some memory that you can't fathom out what it does anyways [unless you are well versed in the internal workings of the C++ free store (aka heap) management].

    Further, you can set a breakpoint in your destructor if that's what you want to see happen.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Whether you can step into the source code of the run-time depends on the "you get what you paid for" category.
    - no, if you got the freebie express version.
    - yes, if you've spent the $$$ on the pro version.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BST delete again, but this time I think I'm close
    By tms43 in forum C++ Programming
    Replies: 9
    Last Post: 11-05-2006, 06:24 PM
  2. delete and delete []
    By Lionel in forum C++ Programming
    Replies: 8
    Last Post: 05-19-2005, 01:52 PM
  3. why is this prog crashing on delete?
    By Waldo2k2 in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 11:17 PM
  4. Problem need help
    By Srpurdy in forum C++ Programming
    Replies: 1
    Last Post: 07-24-2002, 12:45 PM
  5. memory management...
    By master5001 in forum Game Programming
    Replies: 24
    Last Post: 01-07-2002, 05:50 PM