How to do memory analysis of heap allocated objects in an embedded systems?

I’m trying to analyze the memory usage of our systems. We have some singleton objects that are allocated on the heap at start-up. I would like to get the size of those objects. The information has to be there, since the debugger knows how big they are. How can I dump that info out of dwarf2 debugging information? Our compiler is WindRiver (Diab).

GNU objdump seems to do the trick, objdump -W myfile.elf dumps the debug info in text format, and that can be searched to find the information.

I’d probably add a bit of debug code that spit the result of a sizeof operation to the console or a log file. I don’t know if there’s a utility already out there that’ll do what you want; there probably is, but I’m unaware of it (someone will likely chime in here).

The size of an object is a compile time constant. That is what the sizeof() operator returns and how the debugger knows, but it does not include memory dynamically allocated by that object.

VxWorks has a showMem() function for monitoring heap usage. I have used it in the past to measure object footprint by writing test code to instantiate it with showMem calls before and after. I have also used it to test that all memory is returned when the destructor is called.

For more sophisticated memory analysis, port the code to Linux and use a tool such as Valgrind.

Leave a Comment