lwps revision 1.5
11.5Smrg#	$NetBSD: lwps,v 1.5 2019/05/30 07:17:35 mrg Exp $
21.1Sad
31.1Saddefine lwps
41.1Sad	set $i = 0
51.1Sad
61.1Sad	while ($i < 2)
71.1Sad		if ($i == 0)
81.1Sad			set $p = allproc.lh_first
91.1Sad		end
101.1Sad		if ($p)
111.5Smrg			printf "\t       lwp   pid   lid     flag              wchan\n"
121.1Sad		end
131.1Sad		while ($p)
141.1Sad			set $l = $p->p_lwps.lh_first
151.1Sad			set $j = 0
161.1Sad			while ($j < $p->p_nlwps)
171.4Syamt				printf "0x%016lx %5d %5d %8x 0x%016lx", \
181.1Sad					$l, $p->p_pid, $l->l_lid, $l->l_flag, $l->l_wchan
191.1Sad				if ($l->l_wmesg)
201.1Sad					printf " (%s)", (char *)$l->l_wmesg
211.3Seeh# If the preceding command cannot dereference the pointer, use this instead:
221.3Seeh#					printf " (%lx)", $l->l_wmesg
231.1Sad				end
241.2Sskrll				set $l = $l->l_sibling.le_next
251.1Sad				printf "\n"
261.1Sad				set $j++
271.1Sad			end
281.1Sad			set $p = $p->p_list.le_next
291.1Sad		end
301.1Sad		set $i++
311.1Sad	end
321.1Sadend
331.3Seehdocument lwps
341.3Seehps for lwps
351.3Seehend
361.3Seeh
371.5Smrgdefine procs
381.5Smrg	set $p = allproc.lh_first
391.5Smrg
401.5Smrg	printf "           paddr   pid     flag  stat    n         firstlwp          command\n"                       
411.5Smrg	while ($p)
421.5Smrg		printf "%16lx %5d %8x %4x %5d %16lx %16s\n", \
431.5Smrg			$p, $p->p_pid, $p->p_flag, $p->p_stat, \
441.5Smrg			$nlwps, $p->p_lwps.lh_first, \
451.5Smrg			(char *) $p->p_comm
461.5Smrg		set $p = $p->p_list.le_next
471.5Smrg	end
481.5Smrgend
491.5Smrgdocument procs
501.5SmrgShow one line summary of all processes (ps)
511.5Smrgend
521.5Smrg
531.5Smrgdefine threadinfo
541.5Smrg	set $l = (struct lwp *)$arg0
551.5Smrg	set $pid = $arg1
561.5Smrg
571.5Smrg	set $j = 0
581.5Smrg	set $n = $l->l_name
591.5Smrg	#if ($n == 0)
601.5Smrg	#	set $n = (char *)""
611.5Smrg	#end
621.5Smrg	printf "           laddr   pid   lid     flag                 wchan\n"                       
631.5Smrg	printf "%16lx %5d %5d %8x      %16lx", \
641.5Smrg		$l, $pid, $l->l_lid, $l->l_flag, $l->l_wchan
651.5Smrg	if ($n != 0)
661.5Smrg		printf "  %16s", $n
671.5Smrg	end
681.5Smrg        printf "\n\n"
691.5Smrg        kvm proc $l
701.5Smrg	where
711.5Smrg        printf "\n"
721.5Smrgend
731.5Smrgdocument threadinfo
741.5SmrgPrint out the stack and other data of a single thread.
751.5Smrgend
761.5Smrg
771.5Smrgdefine procthreadsaddr
781.5Smrg	set $p = (struct proc *)$arg0
791.5Smrg	set $l = $p->p_lwps.lh_first
801.5Smrg	set $nlwps = $p->p_nlwps
811.5Smrg	set $pid = $p->p_pid
821.5Smrg
831.5Smrg	printf "           paddr   pid     flag  stat    n         firstlwp          command\n"                       
841.5Smrg	printf "%16lx %5d %8x %4x %5d %16lx %16s\n\n", \
851.5Smrg		$p, $pid, $p->p_flag, $p->p_stat, \
861.5Smrg		$nlwps, $p->p_lwps.lh_first, \
871.5Smrg		(char *) $p->p_comm
881.5Smrg	while ($l)
891.5Smrg		threadinfo $l $pid
901.5Smrg		set $l = $l->l_sibling.le_next
911.5Smrg		set $j++
921.5Smrg	end
931.5Smrgend
941.5Smrgdocument procthreadsaddr
951.5SmrgPrint out the stack of all threads in a particular process,
961.5Smrgfound via struct proc * address.
971.5Smrgend
981.3Seeh
991.5Smrgdefine procthreadspid
1001.5Smrg	set $pid = (unsigned)$arg0
1011.5Smrg	set $p = allproc.lh_first
1021.5Smrg	while ($p)
1031.5Smrg		if ($pid == $p->p_pid)
1041.5Smrg			procthreadsaddr $p
1051.5Smrg			loop_break
1061.3Seeh		end
1071.5Smrg		set $p = $p->p_list.le_next
1081.5Smrg	end
1091.5Smrgend
1101.5Smrgdocument procthreadspid
1111.5SmrgPrint out the stack of all threads in a particular process,
1121.5Smrgfound via PID.
1131.5Smrgend
1141.5Smrg
1151.5Smrgdefine threadlist
1161.5Smrg	set $p = allproc.lh_first
1171.5Smrg	while ($p)
1181.5Smrg		procthreadsaddr $p
1191.5Smrg		set $p = $p->p_list.le_next
1201.3Seeh	end
1211.3Seehend
1221.3Seehdocument threadlist
1231.3SeehPrint out the stack of all threads in the system.
1241.3Seehend
1251.3Seeh
1261.3Seehdefine lock
1271.3Seeh	set $ld = (struct lockdebug *)ld_rb_tree
1281.3Seeh	set $a = $ld->ld_lock
1291.3Seeh	set $b = (volatile void *)$arg0
1301.3Seeh
1311.3Seeh	while ($ld && $a != $b)
1321.3Seeh		if ($a < $b) 
1331.3Seeh			set $ld = (struct lockdebug *)$ld->ld_rb_node.rb_nodes[1]
1341.3Seeh		end
1351.3Seeh		if ($a > $b) 
1361.3Seeh			set $ld = (struct lockdebug *)$ld->ld_rb_node.rb_nodes[0]
1371.3Seeh		end
1381.3Seeh		if ($ld == 0)
1391.3Seeh			loop_break
1401.3Seeh		end
1411.3Seeh		set $a = $ld->ld_lock
1421.3Seeh# printf "a=%lx b=%lx ld=%lx a<b %d a>b %d\n", $a, $b, $ld,  ($a < $b), ($a > $b)
1431.3Seeh	end
1441.3Seeh	if ($ld)
1451.3Seeh		printf "lock address : %#018lx type     : ", \
1461.3Seeh			(long)$ld->ld_lock
1471.3Seeh		if ($ld->ld_flags & 0x2)
1481.3Seeh			printf "sleep/adaptive\n"
1491.3Seeh		else
1501.3Seeh			printf "spin\n"
1511.3Seeh		end
1521.3Seeh		printf "initialized  : %#018lx", \
1531.3Seeh			(long)$ld->ld_initaddr
1541.3Seeh		if ($ld->ld_lockops->lo_type == 0x2)
1551.3Seeh			printf " interlock: %#018lx\n", $ld->ld_locked
1561.3Seeh		else
1571.3Seeh			printf "\n"
1581.3Seeh			printf "shared holds : %18u exclusive: ", \
1591.3Seeh				$ld->ld_shares
1601.3Seeh			if (($ld->ld_flags & 0x1) != 0)
1611.3Seeh				printf "1\n"
1621.3Seeh			else
1631.3Seeh				printf "0\n"
1641.3Seeh			end
1651.3Seeh			printf "shares wanted: %18u exclusive: %18u\n", \
1661.3Seeh				(unsigned)$ld->ld_shwant, (unsigned)$ld->ld_exwant
1671.3Seeh			printf "cpu last held: %18u\n", \
1681.3Seeh				(unsigned)$ld->ld_cpu
1691.3Seeh			printf "current lwp  : %#018lx last held: %#018lx\n", \
1701.3Seeh				(long)0, (long)$ld->ld_lwp
1711.3Seeh			printf "last locked  : %#018lx unlocked : %#018lx\n", \
1721.3Seeh				(long)$ld->ld_locked, (long)$ld->ld_unlocked
1731.3Seeh		end
1741.3Seeh	end
1751.3Seehend
1761.3Seehdocument lock
1771.3SeehPrint out lockdebug info like ddb does.
1781.3Seehend
179