xref: /netbsd-src/sys/gdbscripts/lwps (revision e1e3440e40d1a58abb1de87621470aa07bee1e65)
1*e1e3440eSskrll#	$NetBSD: lwps,v 1.6 2019/07/17 09:14:24 skrll Exp $
29c235d70Sad
39c235d70Saddefine lwps
49c235d70Sad	set $i = 0
59c235d70Sad
69c235d70Sad	while ($i < 2)
79c235d70Sad		if ($i == 0)
89c235d70Sad			set $p = allproc.lh_first
99c235d70Sad		end
109c235d70Sad		if ($p)
119c235d70Sad			printf "\t       lwp   pid   lid     flag              wchan\n"
129c235d70Sad		end
139c235d70Sad		while ($p)
149c235d70Sad			set $l = $p->p_lwps.lh_first
159c235d70Sad			set $j = 0
169c235d70Sad			while ($j < $p->p_nlwps)
1725c71c5eSyamt				printf "0x%016lx %5d %5d %8x 0x%016lx", \
189c235d70Sad					$l, $p->p_pid, $l->l_lid, $l->l_flag, $l->l_wchan
199c235d70Sad				if ($l->l_wmesg)
209c235d70Sad					printf " (%s)", (char *)$l->l_wmesg
214758e235Seeh# If the preceding command cannot dereference the pointer, use this instead:
224758e235Seeh#					printf " (%lx)", $l->l_wmesg
239c235d70Sad				end
2455222df8Sskrll				set $l = $l->l_sibling.le_next
259c235d70Sad				printf "\n"
269c235d70Sad				set $j++
279c235d70Sad			end
289c235d70Sad			set $p = $p->p_list.le_next
299c235d70Sad		end
309c235d70Sad		set $i++
319c235d70Sad	end
329c235d70Sadend
334758e235Seehdocument lwps
344758e235Seehps for lwps
354758e235Seehend
364758e235Seeh
3729b95c36Smrgdefine threadinfo
3829b95c36Smrg	set $l = (struct lwp *)$arg0
3929b95c36Smrg	set $pid = $arg1
4029b95c36Smrg
4129b95c36Smrg	set $j = 0
4229b95c36Smrg	set $n = $l->l_name
4329b95c36Smrg	#if ($n == 0)
4429b95c36Smrg	#	set $n = (char *)""
4529b95c36Smrg	#end
4629b95c36Smrg	printf "           laddr   pid   lid     flag                 wchan\n"
4729b95c36Smrg	printf "%16lx %5d %5d %8x      %16lx", \
4829b95c36Smrg		$l, $pid, $l->l_lid, $l->l_flag, $l->l_wchan
4929b95c36Smrg	if ($n != 0)
5029b95c36Smrg		printf "  %16s", $n
5129b95c36Smrg	end
5229b95c36Smrg        printf "\n\n"
534758e235Seeh        kvm proc $l
544758e235Seeh	where
554758e235Seeh        printf "\n"
5629b95c36Smrgend
5729b95c36Smrgdocument threadinfo
5829b95c36SmrgPrint out the stack and other data of a single thread.
5929b95c36Smrgend
6029b95c36Smrg
6129b95c36Smrgdefine procthreadsaddr
6229b95c36Smrg	set $p = (struct proc *)$arg0
6329b95c36Smrg	set $l = $p->p_lwps.lh_first
6429b95c36Smrg	set $nlwps = $p->p_nlwps
6529b95c36Smrg	set $pid = $p->p_pid
6629b95c36Smrg
6729b95c36Smrg	printf "           paddr   pid     flag  stat    n         firstlwp          command\n"
6829b95c36Smrg	printf "%16lx %5d %8x %4x %5d %16lx %16s\n\n", \
6929b95c36Smrg		$p, $pid, $p->p_flag, $p->p_stat, \
7029b95c36Smrg		$nlwps, $p->p_lwps.lh_first, \
7129b95c36Smrg		(char *) $p->p_comm
7229b95c36Smrg	while ($l)
7329b95c36Smrg		threadinfo $l $pid
744758e235Seeh		set $l = $l->l_sibling.le_next
754758e235Seeh		set $j++
764758e235Seeh	end
7729b95c36Smrgend
7829b95c36Smrgdocument procthreadsaddr
7929b95c36SmrgPrint out the stack of all threads in a particular process,
8029b95c36Smrgfound via struct proc * address.
8129b95c36Smrgend
8229b95c36Smrg
8329b95c36Smrgdefine procthreadspid
8429b95c36Smrg	set $pid = (unsigned)$arg0
8529b95c36Smrg	set $p = allproc.lh_first
8629b95c36Smrg	while ($p)
8729b95c36Smrg		if ($pid == $p->p_pid)
8829b95c36Smrg			procthreadsaddr $p
8929b95c36Smrg			loop_break
9029b95c36Smrg		end
914758e235Seeh		set $p = $p->p_list.le_next
924758e235Seeh	end
9329b95c36Smrgend
9429b95c36Smrgdocument procthreadspid
9529b95c36SmrgPrint out the stack of all threads in a particular process,
9629b95c36Smrgfound via PID.
9729b95c36Smrgend
9829b95c36Smrg
9929b95c36Smrgdefine threadlist
10029b95c36Smrg	set $p = allproc.lh_first
10129b95c36Smrg	while ($p)
10229b95c36Smrg		procthreadsaddr $p
10329b95c36Smrg		set $p = $p->p_list.le_next
1044758e235Seeh	end
1054758e235Seehend
1064758e235Seehdocument threadlist
1074758e235SeehPrint out the stack of all threads in the system.
1084758e235Seehend
1094758e235Seeh
1104758e235Seehdefine lock
1114758e235Seeh	set $ld = (struct lockdebug *)ld_rb_tree
1124758e235Seeh	set $a = $ld->ld_lock
1134758e235Seeh	set $b = (volatile void *)$arg0
1144758e235Seeh
1154758e235Seeh	while ($ld && $a != $b)
1164758e235Seeh		if ($a < $b)
1174758e235Seeh			set $ld = (struct lockdebug *)$ld->ld_rb_node.rb_nodes[1]
1184758e235Seeh		end
1194758e235Seeh		if ($a > $b)
1204758e235Seeh			set $ld = (struct lockdebug *)$ld->ld_rb_node.rb_nodes[0]
1214758e235Seeh		end
1224758e235Seeh		if ($ld == 0)
1234758e235Seeh			loop_break
1244758e235Seeh		end
1254758e235Seeh		set $a = $ld->ld_lock
1264758e235Seeh# printf "a=%lx b=%lx ld=%lx a<b %d a>b %d\n", $a, $b, $ld,  ($a < $b), ($a > $b)
1274758e235Seeh	end
1284758e235Seeh	if ($ld)
1294758e235Seeh		printf "lock address : %#018lx type     : ", \
1304758e235Seeh			(long)$ld->ld_lock
1314758e235Seeh		if ($ld->ld_flags & 0x2)
1324758e235Seeh			printf "sleep/adaptive\n"
1334758e235Seeh		else
1344758e235Seeh			printf "spin\n"
1354758e235Seeh		end
1364758e235Seeh		printf "initialized  : %#018lx", \
1374758e235Seeh			(long)$ld->ld_initaddr
1384758e235Seeh		if ($ld->ld_lockops->lo_type == 0x2)
1394758e235Seeh			printf " interlock: %#018lx\n", $ld->ld_locked
1404758e235Seeh		else
1414758e235Seeh			printf "\n"
1424758e235Seeh			printf "shared holds : %18u exclusive: ", \
1434758e235Seeh				$ld->ld_shares
1444758e235Seeh			if (($ld->ld_flags & 0x1) != 0)
1454758e235Seeh				printf "1\n"
1464758e235Seeh			else
1474758e235Seeh				printf "0\n"
1484758e235Seeh			end
1494758e235Seeh			printf "shares wanted: %18u exclusive: %18u\n", \
1504758e235Seeh				(unsigned)$ld->ld_shwant, (unsigned)$ld->ld_exwant
1514758e235Seeh			printf "cpu last held: %18u\n", \
1524758e235Seeh				(unsigned)$ld->ld_cpu
1534758e235Seeh			printf "current lwp  : %#018lx last held: %#018lx\n", \
1544758e235Seeh				(long)0, (long)$ld->ld_lwp
1554758e235Seeh			printf "last locked  : %#018lx unlocked : %#018lx\n", \
1564758e235Seeh				(long)$ld->ld_locked, (long)$ld->ld_unlocked
1574758e235Seeh		end
1584758e235Seeh	end
1594758e235Seehend
1604758e235Seehdocument lock
1614758e235SeehPrint out lockdebug info like ddb does.
1624758e235Seehend
163