can we debug into delete

This is a discussion on can we debug into delete within the C++ Programming forums, part of the General Programming Boards category; Hello everyone, I am using Visual Studio 2005 and I am wondering whether we could debug into the global delete ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    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,

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

    thanks in advance,
    George

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,248
    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
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

    --
    Mats
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 05: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, 10: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, 04:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21