-
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
-
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 :)
-
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
-
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.