qwait() chDbgPanic()

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
likewise
Posts: 18
Joined: Tue Jun 14, 2011 3:43 pm

qwait() chDbgPanic()

Post by likewise »

This is on ChibiOS/RT trunk.

I modified syscalls.c/_write_t() with the intention to print "\r\n" if the last character is '\n', as follows:

if (ptr[len - 1] == '\n') {
sdWrite(&STDOUT_SD, (uint8_t *)ptr, (size_t)len - 1);
sdWrite(&STDOUT_SD, "\r\n", 2);
} else
{
sdWrite(&STDOUT_SD, (uint8_t *)ptr, (size_t)len);
}

I have added a printf("conn = %p\n"); to the http_server(); and this is what happens:

Program received signal SIGINT, Interrupt.
port_halt () at ../../os/ports/GCC/ARMCMx/chcore.c:43
43 }
(gdb) bt
#0 port_halt () at ../../os/ports/GCC/ARMCMx/chcore.c:43
#1 0x08000696 in chDbgPanic (msg=0x0) at ../../os/kernel/src/chdebug.c:91
#2 0x08000a06 in chSchGoSleepS (newstate=13 '\r')
at ../../os/kernel/src/chschd.c:117
#3 0x08000ae4 in chSchGoSleepTimeoutS (newstate=13 '\r', time=4294967295)
at ../../os/kernel/src/chschd.c:186
#4 0x08002ec0 in qwait (qp=0x200071f4, time=4294967295)
at ../../os/kernel/src/chqueues.c:71
#5 0x0800336c in chOQWriteTimeout (oqp=0x200071f4, bp=0x8033331 "\n", n=1,
time=4294967295) at ../../os/kernel/src/chqueues.c:400
#6 0x0800d40a in _write_r (r=0x20000108, file=1,
ptr=0x20008fa0 "conn = 0x2000a0b8\nking\n\354l\324\301\177\356\065\215$Ik\361\026\330b\375껇\031\252sGZm\375\205\061\256\\\272\024&\216*\353\016^?{t\337X\340?\302\357\366\206\254j\202\265!_\363\301\034", len=18)
at ../../os/various/syscalls.c:119
#7 0x08030f94 in __swrite ()
#8 0x0802f3b6 in _fflush_r ()
#9 0x0802fb7a in __sfvwrite_r ()
#10 0x20008e1c in ?? ()
#11 0x20008e1c in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)

What did I overlook?

qwait() is reasonably new, maybe it tries to put the thread on the queue twice?

Regards,

Leon.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: qwait() chDbgPanic()

Post by Giovanni »

qwait() inserts only once. Is it possible that the printf() you inserted eats too much stack space and makes the webthread crash, can you should verify this? I wouldn't be surprised if takes 1-2KBs.

Giovanni
likewise
Posts: 18
Joined: Tue Jun 14, 2011 3:43 pm

Re: qwait() chDbgPanic()

Post by likewise »

Confirmed. I think having a panic_msg for "stack overflow" makes good sense, like the (newer?) non-GCC ports for ARM seem to have.

Regards,

Leon.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: qwait() chDbgPanic()

Post by Giovanni »

Stack overflow checking is scheduled for a revision, probably it will performed in the kernel directly instead of leaving it to the port layer, I also think to add another stack checking scheme: guard pages, possibly with HW support for MCUs with MPU (all most recent Cortex-M3 and M4).

Giovanni
Post Reply