Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Debugging

IEnv and IHeap1 allow developers to specify a debug name for a block of memory with a given module (for example, for reporting memory leaks) more conveniently than MALLOC() and REALLOC().

To help track down memory leaks, it is possible to compile code such that it will automatically label heap allocations with the filename and line number at which the memory allocation occurred. For the application-layer interfaces, the flag is AEE_DBG_HEAP=1; for IEnv and IHeap1, the flag is _HEAP_DEBUG=1.

DUMPHEAP() is a useful helper for debugging. It outputs the entire content of the heap, along with block names, to the current debug channel (such as the debug output window in the Brew MP Simulator or through the QXDM output channel on target device). For example:

static void Release(TestSuite *po)
{
   ME *me = (ME *)po;

   // Free any memory allocated or classes instantiated in this test context
   RELEASEIF(me->m_pIRamCache);
   RELEASEIF(me->m_pIRootCerts);
   RELEASEIF(me->m_pIOpts);
   RELEASEIF(me->piGetLine);
   RELEASEIF(me->m_pIWResp);
   RELEASEIF(me->m_pIWeb);
   
   DUMPHEAP();

   // clean up the context
   FREE(me);
}