1

I am wanting to see all the code which gets called when an object is created on the heap using new().

Initially I had the project in debug but then I realised there were debug-specific malloc() functions getting called. Due to this I changed to "Release" mode to see how far through the code I could step in to.

I got this far:

void * __cdecl _malloc_base (size_t size)
{
    void *res = NULL;

    //  validate size
    if (size <= _HEAP_MAXREQ) {
        for (;;) {

            //  allocate memory block
            res = _heap_alloc(size);

but when I tried breaking in to _heap_alloc() the debugger just skipped over the line.

What would be the best strategy for me to complete this exercise (being able to see all of the code which gets called when memory is allocated) but without seeing all the excess debug code?

EDIT: I guess the question I am asking is, if I come across a function I cannot step in to, is there any way for me to be able to search for the function name somewhere and find the implementation?

user997112
  • 29,025
  • 43
  • 182
  • 361
  • You might find [this earlier answer](http://stackoverflow.com/questions/654696/how-to-debug-external-class-library-projects-in-visual-studio) tells you exactly what you need to know. If so, then this is a duplicate. – Floris Dec 15 '13 at 01:17
  • tools->options->debugging->"Enable just my code" (the answer from the question you linked to) is already unticked in my VS session. – user997112 Dec 15 '13 at 01:19
  • Oh well - did you try the other solutions given (not the accepted answer)? It should be possible at least to step into the assembler instructions even if you can't see the original code. – Floris Dec 15 '13 at 01:22
  • walk through the disassembly (alt-8). The code you want may not be public, or may not be C/C++! – Yakk - Adam Nevraumont Dec 15 '13 at 01:26
  • @all If I change the mode to debug I can step in to _heap_alloc_dbg and that is in a file called dbgheap.c- so this suggests heap.c should be public too? – user997112 Dec 15 '13 at 01:37
  • Does anyone know if I tried the same with Eclipse and GCC how far down the function stack I would be able to see the code? Assume on Linux – user997112 Dec 15 '13 at 02:11
  • I guess `_heap_alloc_dbg` is public as the debugging wrapper around the real thing, the Windows operating system is not public ( I go from `00007FF662C8BE54 call qword ptr [__imp_HeapAlloc (07FF662D0F0A0h)]` to `ntdll.dll!RtlAllocateHeap()`) – Liviu Aug 11 '16 at 09:38

0 Answers0