11.6Sskrll# $NetBSD: lwps,v 1.6 2019/07/17 09:14:24 skrll 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 threadinfo 381.5Smrg set $l = (struct lwp *)$arg0 391.5Smrg set $pid = $arg1 401.5Smrg 411.5Smrg set $j = 0 421.5Smrg set $n = $l->l_name 431.5Smrg #if ($n == 0) 441.5Smrg # set $n = (char *)"" 451.5Smrg #end 461.5Smrg printf " laddr pid lid flag wchan\n" 471.5Smrg printf "%16lx %5d %5d %8x %16lx", \ 481.5Smrg $l, $pid, $l->l_lid, $l->l_flag, $l->l_wchan 491.5Smrg if ($n != 0) 501.5Smrg printf " %16s", $n 511.5Smrg end 521.5Smrg printf "\n\n" 531.5Smrg kvm proc $l 541.5Smrg where 551.5Smrg printf "\n" 561.5Smrgend 571.5Smrgdocument threadinfo 581.5SmrgPrint out the stack and other data of a single thread. 591.5Smrgend 601.5Smrg 611.5Smrgdefine procthreadsaddr 621.5Smrg set $p = (struct proc *)$arg0 631.5Smrg set $l = $p->p_lwps.lh_first 641.5Smrg set $nlwps = $p->p_nlwps 651.5Smrg set $pid = $p->p_pid 661.5Smrg 671.5Smrg printf " paddr pid flag stat n firstlwp command\n" 681.5Smrg printf "%16lx %5d %8x %4x %5d %16lx %16s\n\n", \ 691.5Smrg $p, $pid, $p->p_flag, $p->p_stat, \ 701.5Smrg $nlwps, $p->p_lwps.lh_first, \ 711.5Smrg (char *) $p->p_comm 721.5Smrg while ($l) 731.5Smrg threadinfo $l $pid 741.5Smrg set $l = $l->l_sibling.le_next 751.5Smrg set $j++ 761.5Smrg end 771.5Smrgend 781.5Smrgdocument procthreadsaddr 791.5SmrgPrint out the stack of all threads in a particular process, 801.5Smrgfound via struct proc * address. 811.5Smrgend 821.3Seeh 831.5Smrgdefine procthreadspid 841.5Smrg set $pid = (unsigned)$arg0 851.5Smrg set $p = allproc.lh_first 861.5Smrg while ($p) 871.5Smrg if ($pid == $p->p_pid) 881.5Smrg procthreadsaddr $p 891.5Smrg loop_break 901.3Seeh end 911.5Smrg set $p = $p->p_list.le_next 921.5Smrg end 931.5Smrgend 941.5Smrgdocument procthreadspid 951.5SmrgPrint out the stack of all threads in a particular process, 961.5Smrgfound via PID. 971.5Smrgend 981.5Smrg 991.5Smrgdefine threadlist 1001.5Smrg set $p = allproc.lh_first 1011.5Smrg while ($p) 1021.5Smrg procthreadsaddr $p 1031.5Smrg set $p = $p->p_list.le_next 1041.3Seeh end 1051.3Seehend 1061.3Seehdocument threadlist 1071.3SeehPrint out the stack of all threads in the system. 1081.3Seehend 1091.3Seeh 1101.3Seehdefine lock 1111.3Seeh set $ld = (struct lockdebug *)ld_rb_tree 1121.3Seeh set $a = $ld->ld_lock 1131.3Seeh set $b = (volatile void *)$arg0 1141.3Seeh 1151.3Seeh while ($ld && $a != $b) 1161.3Seeh if ($a < $b) 1171.3Seeh set $ld = (struct lockdebug *)$ld->ld_rb_node.rb_nodes[1] 1181.3Seeh end 1191.3Seeh if ($a > $b) 1201.3Seeh set $ld = (struct lockdebug *)$ld->ld_rb_node.rb_nodes[0] 1211.3Seeh end 1221.3Seeh if ($ld == 0) 1231.3Seeh loop_break 1241.3Seeh end 1251.3Seeh set $a = $ld->ld_lock 1261.3Seeh# printf "a=%lx b=%lx ld=%lx a<b %d a>b %d\n", $a, $b, $ld, ($a < $b), ($a > $b) 1271.3Seeh end 1281.3Seeh if ($ld) 1291.3Seeh printf "lock address : %#018lx type : ", \ 1301.3Seeh (long)$ld->ld_lock 1311.3Seeh if ($ld->ld_flags & 0x2) 1321.3Seeh printf "sleep/adaptive\n" 1331.3Seeh else 1341.3Seeh printf "spin\n" 1351.3Seeh end 1361.3Seeh printf "initialized : %#018lx", \ 1371.3Seeh (long)$ld->ld_initaddr 1381.3Seeh if ($ld->ld_lockops->lo_type == 0x2) 1391.3Seeh printf " interlock: %#018lx\n", $ld->ld_locked 1401.3Seeh else 1411.3Seeh printf "\n" 1421.3Seeh printf "shared holds : %18u exclusive: ", \ 1431.3Seeh $ld->ld_shares 1441.3Seeh if (($ld->ld_flags & 0x1) != 0) 1451.3Seeh printf "1\n" 1461.3Seeh else 1471.3Seeh printf "0\n" 1481.3Seeh end 1491.3Seeh printf "shares wanted: %18u exclusive: %18u\n", \ 1501.3Seeh (unsigned)$ld->ld_shwant, (unsigned)$ld->ld_exwant 1511.3Seeh printf "cpu last held: %18u\n", \ 1521.3Seeh (unsigned)$ld->ld_cpu 1531.3Seeh printf "current lwp : %#018lx last held: %#018lx\n", \ 1541.3Seeh (long)0, (long)$ld->ld_lwp 1551.3Seeh printf "last locked : %#018lx unlocked : %#018lx\n", \ 1561.3Seeh (long)$ld->ld_locked, (long)$ld->ld_unlocked 1571.3Seeh end 1581.3Seeh end 1591.3Seehend 1601.3Seehdocument lock 1611.3SeehPrint out lockdebug info like ddb does. 1621.3Seehend 163