Skip to content

Commit af559a8

Browse files
anchaoxiaoxiang781216
authored andcommitted
tools/nuttx-gdbinit: improve experience of gdb backend scripts
Redefine built-in command (info thread/thread/c) to compatible with developer habits Test board: ./tools/configure.sh -E lm3s6965-ek:qemu-flat 1. start qemu: qemu-system-arm -M lm3s6965evb -device loader,file=nuttx -serial mon:stdio -nographic -s 2. gdb attach: gdb-multiarch -ix tools/nuttx-gdbinit nuttx -ex "target extended-remote localhost:1234" 3. show thread info and callstack: | (gdb) info thread | * 0 Thread 0x20001548 (Name: Idle Task, State: Running, Priority: 0, Stack: 1000) PC: 0x9eee in up_idle() | 1 Thread 0x20005058 (Name: hpwork, State: Waiting,Semaphore, Priority: 224, Stack: 1992) PC: 0xa124 in up_switch_context() | 2 Thread 0x20005c20 (Name: nsh_main, State: Waiting,Semaphore, Priority: 100, Stack: 2000) PC: 0xa124 in up_switch_context() | 3 Thread 0x20006b30 (Name: NTP daemon, State: Waiting,Semaphore, Priority: 100, Stack: 1952) PC: 0xa124 in up_switch_context() | 4 Thread 0x200086f0 (Name: telnetd, State: Waiting,Semaphore, Priority: 100, Stack: 2008) PC: 0xa124 in up_switch_context() | (gdb) bt | #0 0x00009eee in up_idle () at chip/common/tiva_idle.c:62 | #1 0x00003dd2 in nx_start () at init/nx_start.c:698 | #2 0x00000190 in __start () at chip/common/lmxx_tm4c_start.c:177 | (gdb) thread 4 | 4 Thread 0x200086f0 (Name: telnetd, State: Waiting,Semaphore, Priority: 100, Stack: 2008) PC: 0xa124 in up_switch_context() | (gdb) bt | #0 up_switch_context (tcb=0x20001548 <g_idletcb>, rtcb=rtcb@entry=0x200086f0) at common/arm_switchcontext.c:95 | #1 0x0000453a in nxsem_wait (sem=sem@entry=0x2000916c) at semaphore/sem_wait.c:176 | #2 0x0000197e in _net_timedwait (sem=sem@entry=0x2000916c, interruptible=interruptible@entry=true, timeout=timeout@entry=4294967295) at utils/net_lock.c:101 | apache#3 0x0000198e in net_sem_timedwait (sem=sem@entry=0x2000916c, timeout=timeout@entry=4294967295) at utils/net_lock.c:242 | apache#4 0x00001996 in net_sem_wait (sem=sem@entry=0x2000916c) at utils/net_lock.c:330 | apache#5 0x00025f84 in psock_tcp_accept (psock=<optimized out>, addr=<optimized out>, addrlen=<optimized out>, newconn=newconn@entry=0x2000956c) at tcp/tcp_accept.c:274 | apache#6 0x00025432 in inet_accept (psock=<optimized out>, addr=<optimized out>, addrlen=<optimized out>, newsock=0x20009568, flags=0) at inet/inet_sockif.c:1443 | apache#7 0x00027a10 in psock_accept (psock=0x200044b8, addr=addr@entry=0x2000921c, addrlen=addrlen@entry=0x2000920c, newsock=newsock@entry=0x20009568, flags=flags@entry=0) at socket/accept.c:149 | apache#8 0x00027a8c in accept4 (sockfd=sockfd@entry=3, addr=addr@entry=0x2000921c, addrlen=addrlen@entry=0x2000920c, flags=flags@entry=0) at socket/accept.c:280 | apache#9 0x0002a256 in accept (sockfd=sockfd@entry=3, addr=addr@entry=0x2000921c, addrlen=addrlen@entry=0x2000920c) at net/lib_accept.c:50 | apache#10 0x0001efaa in telnetd_daemon (config=config@entry=0x20009290) at telnetd_daemon.c:200 | apache#11 0x0001e508 in telnetd_main (argc=1, argv=0x20008af8) at telnetd.c:98 | apache#12 0x00008486 in nxtask_startup (entrypt=0x1e4bd <telnetd_main>, entrypt@entry=0x1 <up_putc>, argc=1, argv=0x20008af8) at sched/task_startup.c:70 | apache#13 0x000056d2 in nxtask_start () at task/task_start.c:134 | apache#14 0x00000000 in ?? () | (gdb) c Signed-off-by: chao an <anchao@xiaomi.com>
1 parent 0460165 commit af559a8

File tree

1 file changed

+37
-40
lines changed

1 file changed

+37
-40
lines changed

tools/nuttx-gdbinit

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
# NOTE: you need to use gdb configured '--with-python'
2222
# usage: gdb -ix=./tools/nuttx-gdbinit nuttx
23-
# new commands: info_nxthreads, nxthread pid, nxcontinue, nxthread_all_bt
23+
# new commands: nxthread pid, nxthread_all_bt
2424

2525
# Do not stop with SIGUSR1 which is used for the NuttX sim SMP
2626
handle SIGUSR1 "nostop" "pass" "noprint"
@@ -78,24 +78,23 @@ define _examine_target
7878
python if (type(gdb.lookup_global_symbol("g_assignedtasks")) is gdb.Symbol) : \
7979
gdb.execute("set $_target_has_smp = 1")
8080

81-
set $_target_max_tasks = g_npidhash
82-
83-
printf "target examined\n"
84-
python print("_target_arch.name=" + _target_arch.name())
85-
86-
# NOTE: i386:x86-64 (qemu) does not work
87-
#printf "$_target_arch : %s\n", $_target_arch
88-
89-
printf "$_target_has_fpu : %d\n", $_target_has_fpu
90-
printf "$_target_has_smp : %d\n", $_target_has_smp
9181
set $_target_examined = 1
9282
end
9383
end
9484

85+
define _running_task
86+
if ($_target_has_smp == 0)
87+
set $rtcb = (struct tcb_s *)g_readytorun->head
88+
else
89+
set $rtcb = (struct tcb_s *)g_assignedtasks[up_cpu_index()]->head
90+
end
91+
end
92+
9593
define _print_thread
9694
set $tcb = (struct tcb_s *)$arg0
95+
_running_task
9796

98-
if ($tcb == $_current_tcb)
97+
if ($tcb == $rtcb)
9998
printf "* "
10099
else
101100
printf " "
@@ -137,21 +136,13 @@ define _save_current_tcb
137136
_examine_target
138137

139138
if ($_current_tcb == 0)
140-
if ($_target_has_smp == 0)
141-
set $tcb = (struct tcb_s *)g_readytorun->head
142-
_save_tcb $tcb
143-
else
144-
set $cpu = up_cpu_index()
145-
set $tcb = (struct tcb_s *)g_assignedtasks[$cpu]->head
146-
_save_tcb $tcb
147-
end
148-
printf "saved current_tcb (pid=%d)\n", $tcb->pid
149-
set $_current_tcb = $tcb
139+
_running_task
140+
_save_tcb $rtcb
141+
set $_current_tcb = $rtcb
150142
end
151143
end
152144

153145
define _switch_tcb
154-
_examine_target
155146
_save_current_tcb
156147

157148
# set the current frame to the newest before switching
@@ -406,56 +397,62 @@ define _switch_tcb_simx86
406397
end
407398

408399
define _restore_current_tcb
409-
# TODO: SMP
410-
set $tcb = g_readytorun->head
411-
_switch_tcb $tcb
400+
_examine_target
401+
_running_task
402+
_switch_tcb $rtcb
412403
set $_current_tcb = 0x0
413404
end
414405

415406
define nxthread
416-
_examine_target
417-
_save_current_tcb
418-
set $hash = ($arg0 & ($_target_max_tasks - 1))
407+
set $hash = ($arg0 & (g_npidhash - 1))
419408
set $tcb = g_pidhash[$hash]
420409
if ($tcb != 0x0)
410+
_switch_tcb $tcb
421411
_print_thread $tcb
422-
if ($argc == 1)
423-
_switch_tcb $tcb
424-
end
425412
if ($argc == 2)
426413
if ($arg1 == 1)
427-
_switch_tcb $tcb
428-
where
414+
_switch_tcb $tcb
415+
where
429416
end
430417
end
431418
end
432-
_restore_current_tcb
433419
end
434420

435421
define nxthread_all_bt
436422
_save_current_tcb
437423
set $i = 0
438-
while ($i < $_target_max_tasks)
424+
while ($i < g_npidhash)
439425
# 1: backtrace
440426
nxthread $i 1
441427
set $i = $i + 1
442428
end
443429
_restore_current_tcb
444430
end
445431

446-
define info_nxthreads
432+
define info threads
447433
_save_current_tcb
448434
set $i = 0
449-
while ($i < $_target_max_tasks)
435+
while ($i < g_npidhash)
450436
# dummy : 0 0
451437
nxthread $i 0 0
452438
set $i = $i + 1
453439
end
454440
_restore_current_tcb
455441
end
456442

457-
define nxcontinue
458-
printf "nxcontinue\n"
443+
define c
459444
_restore_current_tcb
460445
continue
461446
end
447+
448+
define thread
449+
_save_current_tcb
450+
if ($argc == 0)
451+
_running_task
452+
set $pid = $rtcb->pid
453+
else
454+
set $pid = $arg0
455+
end
456+
457+
nxthread $pid
458+
end

0 commit comments

Comments
 (0)