Finding a call stack programmatically (unwind?).

I am attempting to write a routine that monitors the heap in order to track down a memory leak.  I've seen similar tools on other platforms and found them quite helpful.  To make this even more effective, I want to record the caller to malloc() that made the request. To do this, the routine would need to read the call stack (sometimes called unwind).  I've been googling and found clues for the GNU compiler, and other platforms but nothing that seems pertinent to my platform: nRF52840/ARM/IAR/FreeRTOS.

I realize this is extremely unportable, but this is only needed for debugging on occasion.

Anyone have any suggestions?  I've seen references to unwind.h, but they appear to only be for GNU.

Parents
  • Hi,

     

    malloc is a part of the compiler suite libc.

    These issues are usually tracked with entering debug mode and having a plugin to make your IDE rtos-aware. I am not sure what IAR offers, but it seems that they have something for freertos:

    https://www.iar.com/products/integrations/

     

    Kind regards,

    Håkon

  • Thanks, but that's not what I asked.  I am aware that IAR (and other IDEs) have the ability to generate a call stack after stopping the processor.  What I was after is getting the program itself to tell me who called this function/method.  This allows me to log these callers and identify them long after the event has happened.  In this case, when the malloc is called, I would log the event along with the caller's location.  After detecting that this buffer was not returned, I can then look up what the buffer was requested for, and thus determine why it was not returned to the heap.  Other environments, like Linux, Unix, and Windows have this capability. 

Reply
  • Thanks, but that's not what I asked.  I am aware that IAR (and other IDEs) have the ability to generate a call stack after stopping the processor.  What I was after is getting the program itself to tell me who called this function/method.  This allows me to log these callers and identify them long after the event has happened.  In this case, when the malloc is called, I would log the event along with the caller's location.  After detecting that this buffer was not returned, I can then look up what the buffer was requested for, and thus determine why it was not returned to the heap.  Other environments, like Linux, Unix, and Windows have this capability. 

Children
Related