Hi Sergio

W dniu 2011-08-19 17:53, Sergio Campamá pisze:
Thanks for the insight into the problem. The thing is that I have a task
scheduler, a linked list that, well, lists the tasks to perform... Since
linked lists are dynamic in nature, I need malloc to create the new "task"
and append it to the list.. And after the task is done, I free the task and
go on to the next one...  The other place I use linked lists is to maintain
a list of timers that the application uses to signal certain events... after
the timer activates, it also gets freed...

You wrote that you access the list from two places, the latter in interrupt I assume.
Is this access safe from race conditions?
This may be the second probable reason of random, difficult to repeat crash.

Please try to analyze the crash in more detail. First you need to define some condition that would be used for crash condition. If it happens you will execute your extra debug procedure, that will do 'post-mortem' dump. You can easily transfer contents of the RAM and registers via serial port to your console in text mode. After that you can synchronize RAM addresses with symbolic names (information about variable location may be obtained by msp430-nm). You will be able also to see stack trace, so you will know what
was the last executed location.
If your crash means that your micro resets, you can hook at reset vector and make there the dump (RAM contents
should be preserved).

I have one more idea of possible error, maybe you somehow use an item of the list that is removed from the list. In order to detect it you can use 'poison code' written into pointers fields when you detached it. The code should be
easy to recognize (e.g. 0xDEAD) and point to some non-RAM location.

Regards
Piotr Romaniuk
ELESOFTROM
So that is why I need malloc and can't (or don't know how) to do it with
other types of dynamic storage, or static. (On that subject, what other
types of dynamic storage exist?)

On Fri, Aug 19, 2011 at 10:49 AM, JMGross<[email protected]>  wrote:


----- Ursprüngliche Nachricht -----
Von: Sergio Campamá
Gesendet am: 19 Aug 2011 14:39:52

I am currently building a somewhat complex application for the MSP430,
and
it randomly crashes and I don't seem to know why. I have a suspicion that
it's RAM related, because I call many mallocs (I have checked that I free
the memory after it's no longer needed), but maybe I am filling up the
RAM
and when it does, it crashes... How can I check at runtime the amount of
memory free in RAM? Is there any function that will tell me this?
the problem with malloc is that it can easily cause heap congestion.
If you always malloc and free the same size, it isn't a problem. But when
you have different zizes and do not free them in reverse order, you might
end up with one used byte here, one used byte there and in between
not enough space for the next malloc.
It's always a good thing to bail out if malloc returns null.
I use malloc too, but only for dynamically reserving data space that is
never freed again (but not known at compile-time).
(well, that's not entirely true, my multithreader reserves stack space for
new threads dynamically, and threads may end, freeing this space again. But
in my projects no thread ever ends)

Also, malloc needs some bytes additional ram for organization. I don't know
the MSP implementation, but unde rDOS, it was using space immediately before
the allocated ram, so a free can check whether you're
freeing a malloced object, and may also join freed areas. All used and free
areas form a chain, connecteed by this data. And even if the MSP
implementation does not use full 16 bytes for each data block (as DOS did),
it is still wasted ram (and you have to store the pointer to it in a
variable too, so more space needed).
You should consider other types of dynamic data storage. Or a static
storage mechanism.

JMGross



------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system,
user administration capabilities and model configuration. Take
the hassle out of deploying and managing Subversion and the
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________
Mspgcc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users




------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system,
user administration capabilities and model configuration. Take
the hassle out of deploying and managing Subversion and the
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2


_______________________________________________
Mspgcc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, 
user administration capabilities and model configuration. Take 
the hassle out of deploying and managing Subversion and the 
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________
Mspgcc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to