Debugging memory leaks and errors

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Hi, I am developping on a SAML 21J18A board, and I would like to know if there is any tools/ways to debug memory leakage, like Valgrind does for regular C programs ?

Thanks.

Last Edited: Fri. Mar 11, 2016 - 09:36 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You aren't going to find anything like Valgrind for a micro (well not until you reach the level where the micros themselves are running Linux). The best bet is to ad code to the C start-up that floods RAM with some known byte then look for signs of usage after the code has been run.

 

(BTW I'll move this to an ARM forum)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, thanks for the advice, but I don't really see how it would work. How are you usually debugging memory leaks or how do you ensure that there is no leaks in your code ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One good strategy is simply never using dynamic memory allocation (in an embedded/micro) project.  I can't think of a case where that would be a hindrance.  Of course some clib calls might do this, but you can usually presume those to be somewhat 'safe'.  C++ is also more trouble then its worth on this class of device.  If you are leaking memory you'll probably crash pretty quick.  32K doesn't go very far.  Even with no leaks you may well crash due to fragmentation.  No dynamic memory, no leaks.  Simple.

 

Cheers!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the answer, Colin, we will try to improve that.