Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Are there tools to help find memory leaks, buffer overruns, etc?

0
Posted

Are there tools to help find memory leaks, buffer overruns, etc?

0

Yes! You’ll need to have built your own KOS to use it though. You have two options: turning on debugging in the standard malloc, and replacing malloc with a debug version. The former is definitely the recommended choice for most usage, and it’s not a bad idea to leave it on while developing. Edit kernel/libc/koslib/malloc.c, and look at the #define’s at the top. ‘DEBUG’ turns on internal checks in the malloc functions (mostly assert statements). These are basic and not too helpful unless you have a catastrophic failure. KM_DBG enables KOS memory debugging. This turns on “canary” zones before and after each block and tracks all allocated blocks in a linked list to find leaks. Combined with the INIT_MALLOCSTATS flag, you can see exactly where a piece of memory was allocated, which thread allocated it, the size, and so on. Using the sh-elf-addr2line util mentioned above, it’s easy to hunt down where the leak happened. KM_DBG_VERBOSE is like a sledge hammer to KM_DBG’s claw hammer. You hav

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123