This solution allows switch to any task from almost any context while debugging via GNU GDB debugger (even in Eclipse IDE !).
- ARM Cortex-M3
- ARM Cortex-M3 MPU
(Switching from system exceptions (first 15 vectors) IS NOT supported.)
Supported compiler: gcc
Archive contains .gdbinit script with commands and port-dependent source file (contains alternative context-switcher and debug-interface variables).
- add corresponding source file to your project (freertos port folder is good location for placing)
- add following replacement macro in FreeRTOSConfig.h:
#define xPortPendSVHandler xPortPendSVHandler_native // any valid c identifier name
Macro name must match PendSV vector name in startup file. Startup file should NOT #include FreeRTOSConfig.h (either directly, or indirectly through freertos headers and other headers). Example provided for CMSIS-based project.
- execute .gdbinit script file at start of debug session (source -v <script file>)
While debugging you can stop execution at almost any place (manually or via breakpoint hits) and use following commands in debug console:
Shows tasks table: handle(xTaskHandle) and name
Switches debugging context to specified task. Argument: task handle taken from freertos_show_threads output.
You can switch to any task many times as desired to view their context. BUT don't step/execute anything from switched state because you will break freertos state machine and following program execution will be unpredictable (for example, task may be in blocked state waiting to receive item from a queue).
Restores current running context. This command will return you to initial state and you can resume execution !
Backtrace looks broken in some situations (i.e. tasks switched out in vTaskDelay()). I described problem here:
Question isn't answered yet. Current workaround is show_broken_backtrace command, but it's very specific for case I personally faced with. It may not work in your situation and may damage execution context (or even cause crash after you continue debugging).
- Sometimes (rarely) one instruction may be executed during switch.
- Sometimes Eclipse shows errors in Variables view. These variables are ok and may be inspected with any other method (but I don't know how to change their values, maybe via console only).
UPDATED (13 june 2013):
- added ARM Cortex-M3 port (non-MPU);
- fixed critical error with integer size mismatching (might cause hard fault).
UPDATED (04 april 2013):
- added support for switching from exception context (except system exceptions);
- fixed case when interrupts globally disabled (PRIMASK set to 1 or context is within __disable_irq()/__enable_irq() section);
- fixed case when pending context switch (requested from interrupt) was lost;
- added validating of running context before trying to switch;
- added "RUNNING" label to task table;
- fixed error with nameless tasks output;
- added early checking for freertos_switch_to_task argument (before it fails in the middle of command execution);
- "freertos_restore_running_task" command renamed to "freertos_restore_running_context".