diff --git a/tools/nuttx-gdbinit b/tools/nuttx-gdbinit index 52093681a46c9..981b9444f0755 100644 --- a/tools/nuttx-gdbinit +++ b/tools/nuttx-gdbinit @@ -20,7 +20,7 @@ # NOTE: you need to use gdb configured '--with-python' # usage: gdb -ix=./tools/nuttx-gdbinit nuttx -# new commands: info_nxthreads, nxthread pid, nxcontinue, nxthread_all_bt +# new commands: nxthread pid, nxthread_all_bt # Do not stop with SIGUSR1 which is used for the NuttX sim SMP handle SIGUSR1 "nostop" "pass" "noprint" @@ -78,24 +78,23 @@ define _examine_target python if (type(gdb.lookup_global_symbol("g_assignedtasks")) is gdb.Symbol) : \ gdb.execute("set $_target_has_smp = 1") - set $_target_max_tasks = g_npidhash - - printf "target examined\n" - python print("_target_arch.name=" + _target_arch.name()) - - # NOTE: i386:x86-64 (qemu) does not work - #printf "$_target_arch : %s\n", $_target_arch - - printf "$_target_has_fpu : %d\n", $_target_has_fpu - printf "$_target_has_smp : %d\n", $_target_has_smp set $_target_examined = 1 end end +define _running_task + if ($_target_has_smp == 0) + set $rtcb = (struct tcb_s *)g_readytorun->head + else + set $rtcb = (struct tcb_s *)g_assignedtasks[up_cpu_index()]->head + end +end + define _print_thread set $tcb = (struct tcb_s *)$arg0 + _running_task - if ($tcb == $_current_tcb) + if ($tcb == $rtcb) printf "* " else printf " " @@ -137,21 +136,13 @@ define _save_current_tcb _examine_target if ($_current_tcb == 0) - if ($_target_has_smp == 0) - set $tcb = (struct tcb_s *)g_readytorun->head - _save_tcb $tcb - else - set $cpu = up_cpu_index() - set $tcb = (struct tcb_s *)g_assignedtasks[$cpu]->head - _save_tcb $tcb - end - printf "saved current_tcb (pid=%d)\n", $tcb->pid - set $_current_tcb = $tcb + _running_task + _save_tcb $rtcb + set $_current_tcb = $rtcb end end define _switch_tcb - _examine_target _save_current_tcb # set the current frame to the newest before switching @@ -406,36 +397,31 @@ define _switch_tcb_simx86 end define _restore_current_tcb - # TODO: SMP - set $tcb = g_readytorun->head - _switch_tcb $tcb + _examine_target + _running_task + _switch_tcb $rtcb set $_current_tcb = 0x0 end define nxthread - _examine_target - _save_current_tcb - set $hash = ($arg0 & ($_target_max_tasks - 1)) + set $hash = ($arg0 & (g_npidhash - 1)) set $tcb = g_pidhash[$hash] if ($tcb != 0x0) + _switch_tcb $tcb _print_thread $tcb - if ($argc == 1) - _switch_tcb $tcb - end if ($argc == 2) if ($arg1 == 1) - _switch_tcb $tcb - where + _switch_tcb $tcb + where end end end - _restore_current_tcb end define nxthread_all_bt _save_current_tcb set $i = 0 - while ($i < $_target_max_tasks) + while ($i < g_npidhash) # 1: backtrace nxthread $i 1 set $i = $i + 1 @@ -443,10 +429,10 @@ define nxthread_all_bt _restore_current_tcb end -define info_nxthreads +define info threads _save_current_tcb set $i = 0 - while ($i < $_target_max_tasks) + while ($i < g_npidhash) # dummy : 0 0 nxthread $i 0 0 set $i = $i + 1 @@ -454,8 +440,19 @@ define info_nxthreads _restore_current_tcb end -define nxcontinue - printf "nxcontinue\n" +define c _restore_current_tcb continue end + +define thread + _save_current_tcb + if ($argc == 0) + _running_task + set $pid = $rtcb->pid + else + set $pid = $arg0 + end + + nxthread $pid +end