对于 FreeRTOS,我使用以下 gdb 脚本:
define printtasklist
# $arg0 is a pointer to an uxList of tasks.
set $plist = (List_t*)$arg0
printf ": %d tasks\n", $plist->uxNumberOfItems
set $iter = $plist->xListEnd.pxNext
while ($iter != &$plist->xListEnd)
set $vtask = ($iter->pvOwner)
set $task = (tskTCB*)$vtask
print $task
print $task->pcTaskName
set $iter = $iter->pxNext
end
end
define printtasks
printf "%d tasks:\n", uxCurrentNumberOfTasks
printf "pending ready"
printtasklist &xPendingReadyList
printf "suspended"
printtasklist &xSuspendedTaskList
printf "delayedW"
printtasklist pxDelayedTaskList
printf "delayedO"
printtasklist pxOverflowDelayedTaskList
set $prio = 0
set $maxprio = sizeof(pxReadyTasksLists) / sizeof(pxReadyTasksLists[0])
while ($prio < $maxprio)
printf " ready at prio"
printf "%d", $prio
printtasklist &pxReadyTasksLists[$prio]
set $prio = $prio + 1
end
end
define savestate
set $svpc = $pc
set $svsp = $sp
set $svlr = $lr
end
define restorestate
set $pc = $svpc
set $sp = $svsp
set $lr = $svlr
end
define cm3bttask
# arg0: task handle (pointer to tskTCB)
savestate
set $ptsk = (tskTCB*)$arg0
set $tskstk = (uint32_t*)$ptsk->pxTopOfStack
set $lr = $tskstk[13]
set $pc = $tskstk[14]
set $sp= $tskstk + 16
bt
end
这个想法是我printtasks
用来获取任务控制块的列表,然后cm3bttask $26
如果我感兴趣的任务在 GDB 历史记录中具有打印为 $26 行的控制块指针,则使用它。我可以在 printtasks 的输出中看到这一点。