Stack size and overflows

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

User avatar
kulve
Posts: 86
Joined: Mon Nov 28, 2011 8:36 pm

Re: Stack size and overflows

Post by kulve »

I downloaded it but it seems to be Windows only :/
User avatar
kulve
Posts: 86
Joined: Mon Nov 28, 2011 8:36 pm

Re: Stack size and overflows

Post by kulve »

After clicking around a bit (thanks for the Eclipse setup docs) I got the stack dump with the ChibiOS plugin.

I attached it as a screenshot as I don't know how to get it out as text:
Stack dump
Stack dump
stk-dump01.png (22.85 KiB) Viewed 7069 times


Anyway, to me it looks like there's plenty of free stack available for threads still..? (EDIT: well, I'm not sure how to read those..)
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Stack size and overflows

Post by Giovanni »

StkUnused is the available stack size in the moment you refreshed the view, apparently there is enough stack size. Note that the stack overflow check is done during context switching only so there could be instances of stack overflows not caught by the OS, for example calling a library function the does not perform any context switching inside.

Just a question, do you have the state checker enabled? Analyzing the trace buffer could also give an hint about the sequence of operations that brought to the overflow.

Without looking at the actual code and performing debug there is not much else I can do. BTW, is that a smart card related application?

Giovanni
User avatar
kulve
Posts: 86
Joined: Mon Nov 28, 2011 8:36 pm

Re: Stack size and overflows

Post by kulve »

I debugged this a bit further and started to write what actually happens when I realized that I'm calling chBSemWaitS(&sem) to lock a semaphore but I was calling chBSemSignal(&sem) to unlock it, instead of chBSemSignalI(&sem).

No "overflows" after fixing that.

Again just a stupid user error. But as always, thanks for your prompt replies.
mabl
Posts: 417
Joined: Tue Dec 21, 2010 10:19 am
Been thanked: 1 time

Re: Stack size and overflows

Post by mabl »

But this would have been coughed by the state checker if you had enabled debugging, wouldn't it? :twisted:
User avatar
kulve
Posts: 86
Joined: Mon Nov 28, 2011 8:36 pm

Re: Stack size and overflows

Post by kulve »

At least I have this defined:

Code: Select all

#define CH_DBG_ENABLE_STACK_CHECK       TRUE


I'm assuming that enables the state checker?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Stack size and overflows

Post by Giovanni »

Nope, that is the stack check, it is CH_DBG_SYSTEM_STATE_CHECK. Regardless, during development all debug options should be enabled, the system is designed to catch a lot of errors if you allow it to do so.

Giovanni
User avatar
kulve
Posts: 86
Joined: Mon Nov 28, 2011 8:36 pm

Re: Stack size and overflows

Post by kulve »

Well, I must be blind. I did double check that I have all the defines set that are there in the debug wiki page. But I guess I can't distinguish stack from state :/
User avatar
kulve
Posts: 86
Joined: Mon Nov 28, 2011 8:36 pm

Re: Stack size and overflows

Post by kulve »

Thank you for the state checker. My locking stuff was a mess but now it's mostly fixed. Still something (hopefully small) remaining.
Post Reply