Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable

I'm calling malloc in my program many times. So it is working fine but at some points in my program, it fails to allocate memory.
I' m using semihosting and nano lib to output infos about malloc. The non in use heap size (free space inside heap) is far enough to allocate more heap memory
but malloc fails. I know where it fails but not why ?.

So, I need to debug malloc but it is not possible with compiled libraries provided with DAVE4, as newlib and nano are built without enabling debug info.

There is some informations about "Rebuilding the GNU ARM Libraries" in internet but this it was with prior versions of newlib and nano lib where they were located in different folders.
Now ,newlib and nano are in the same folder and built without debug informations.

So, is there anyone how knows some informations how to build the latest new-lib with debug informations or how to debug malloc from naon libc in DAVE4?

Thank you.
4 Replies
Not applicable
Hey, there are a lot of things that can go wrong using malloc. Most likely you are overwriting memory management structures, for example by an buffer overflow (most likely) or use-after-free. Also "malloc" is not reentrant. So if you have multiple threads or use it from within an interrupt you are also likely to break your memory management structures. There's more on that in the newlib-docs.
As Eclipse has support for autotools, you should be able to compile the library from within Dave.
Not applicable
Hi Morty,

Thank you for your response.
Actually, I'm not using threads or OS. So I don't have access to analysis tools within Eclipse or I can't use them (as I know they need an OS).
I'm calling malloc from normal c program code.

I'm suspecting the problem to be corruption of memory management structures but I don't know how to debug inside nano-lib (at least to be sure about the reason).
You mention "As Eclipse has support for autotools", Which autotools ?
"you should be able to compile the library from within Dave" how ?
It would be helpful if you link me or write some hints.

Not applicable

even without threads you run into trouble using malloc in interrupts (and of course in anything called from an interrupt).
As for autotools. You have three options to build newlib with debug information using autotools: Install *NUX, use cygwin or get autotools running in eclipse. I'm afraid you'll have to do that research yourself. This is just drive-by support, while waiting for stuff to build. 🙂

Not applicable
I get maloc infos using mallinfo and malloc_usable_size.