Skip to content

WhichTaskJustExited

Simon Wright edited this page Mar 13, 2020 · 1 revision

If a task exits, System.Tasking.Restricted.Stages.Wrapper says

--  If we return here, the task procedure has exited (and not
--  because of an exception, which would already have reached
--  the last chance handler).
raise Program_Error with "task exited, not allowed in Ravenscar”;

but it’s not at all obvious how to tell which task is involved.

Assuming you're in the debugger, you can break (C-c), and then (modulo your file locations) you'll see

^C
Program received signal SIGTRAP, Trace/breakpoint trap.
<__gnat_last_chance_handler> (
    message=0xb0830 "System.Tasking.Restricted.Stages.Wrapper: task exited, not allowed in Ravenscar["00"]", line=0)
    at /Users/simon/cortex-gnat-rts/test-common/last_chance_handler.adb:44

The backtrace shows

(gdb) bt
#0  <__gnat_last_chance_handler> (
    message=0xb0830 "System.Tasking.Restricted.Stages.Wrapper: task exited, not allowed in Ravenscar["00"]", line=0)
    at /Users/simon/cortex-gnat-rts/test-common/last_chance_handler.adb:44
#1  0x000a3ca6 in ada.exceptions.raise_exception (e=e@entry=-1, message=...)
    at /Users/simon/cortex-gnat-rts/common/a-except.adb:38
#2  0x000a8902 in system.tasking.restricted.stages.wrapper (arg1=0x20079aa8)
    at /Users/simon/cortex-gnat-rts/common/gcc8/s-tarest.adb:113
#3  0x000a48fc in pxPortInitialiseStack (pxTopOfStack=0xa5a5a5a5,
    pxCode=0xa5a5a5a5,
    pvParameters=0xa8903 <system.tasking.restricted.stages.wrapper+38>)
    at /Users/simon/FreeRTOSv10.0.1/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c:189
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Going up two frames to System.Tasking.Restricted.Stages.Wrapper, we see

(gdb) up 2
#2  0x000a8902 in system.tasking.restricted.stages.wrapper (arg1=0x20079aa8)
    at /Users/simon/cortex-gnat-rts/common/gcc8/s-tarest.adb:113
113	      raise Program_Error with "task exited, not allowed in Ravenscar";

and the task that's just executed's Ada Task Control Block is

(gdb) p p.atcb
$1 = (access system.tasking.ada_task_control_block) 0x20070eec <so.tick+4>

This is a Ravenscar runtime, there are no dynamic tasks, so things like the ATCB are allocated statically by the compiler. The ATCB is 4 bytes into the area allocated for the task tick in the package so: in the map,

 .bss.so__tick  0x0000000020070ee8       0x24 /Users/simon/cortex-gnat-rts/test-arduino-due/.build/so.o
Clone this wiki locally