Home | History | Annotate | Line # | Download | only in gdbscripts
lwps revision 1.4.56.1
      1  1.4.56.1  christos #	$NetBSD: lwps,v 1.4.56.1 2019/06/10 22:09:02 christos Exp $
      2       1.1        ad 
      3       1.1        ad define lwps
      4       1.1        ad 	set $i = 0
      5       1.1        ad 
      6       1.1        ad 	while ($i < 2)
      7       1.1        ad 		if ($i == 0)
      8       1.1        ad 			set $p = allproc.lh_first
      9       1.1        ad 		end
     10       1.1        ad 		if ($p)
     11  1.4.56.1  christos 			printf "\t       lwp   pid   lid     flag              wchan\n"
     12       1.1        ad 		end
     13       1.1        ad 		while ($p)
     14       1.1        ad 			set $l = $p->p_lwps.lh_first
     15       1.1        ad 			set $j = 0
     16       1.1        ad 			while ($j < $p->p_nlwps)
     17       1.4      yamt 				printf "0x%016lx %5d %5d %8x 0x%016lx", \
     18       1.1        ad 					$l, $p->p_pid, $l->l_lid, $l->l_flag, $l->l_wchan
     19       1.1        ad 				if ($l->l_wmesg)
     20       1.1        ad 					printf " (%s)", (char *)$l->l_wmesg
     21       1.3       eeh # If the preceding command cannot dereference the pointer, use this instead:
     22       1.3       eeh #					printf " (%lx)", $l->l_wmesg
     23       1.1        ad 				end
     24       1.2     skrll 				set $l = $l->l_sibling.le_next
     25       1.1        ad 				printf "\n"
     26       1.1        ad 				set $j++
     27       1.1        ad 			end
     28       1.1        ad 			set $p = $p->p_list.le_next
     29       1.1        ad 		end
     30       1.1        ad 		set $i++
     31       1.1        ad 	end
     32       1.1        ad end
     33       1.3       eeh document lwps
     34       1.3       eeh ps for lwps
     35       1.3       eeh end
     36       1.3       eeh 
     37  1.4.56.1  christos define procs
     38  1.4.56.1  christos 	set $p = allproc.lh_first
     39       1.3       eeh 
     40  1.4.56.1  christos 	printf "           paddr   pid     flag  stat    n         firstlwp          command\n"                       
     41  1.4.56.1  christos 	while ($p)
     42  1.4.56.1  christos 		printf "%16lx %5d %8x %4x %5d %16lx %16s\n", \
     43  1.4.56.1  christos 			$p, $p->p_pid, $p->p_flag, $p->p_stat, \
     44  1.4.56.1  christos 			$nlwps, $p->p_lwps.lh_first, \
     45  1.4.56.1  christos 			(char *) $p->p_comm
     46  1.4.56.1  christos 		set $p = $p->p_list.le_next
     47  1.4.56.1  christos 	end
     48  1.4.56.1  christos end
     49  1.4.56.1  christos document procs
     50  1.4.56.1  christos Show one line summary of all processes (ps)
     51  1.4.56.1  christos end
     52  1.4.56.1  christos 
     53  1.4.56.1  christos define threadinfo
     54  1.4.56.1  christos 	set $l = (struct lwp *)$arg0
     55  1.4.56.1  christos 	set $pid = $arg1
     56  1.4.56.1  christos 
     57  1.4.56.1  christos 	set $j = 0
     58  1.4.56.1  christos 	set $n = $l->l_name
     59  1.4.56.1  christos 	#if ($n == 0)
     60  1.4.56.1  christos 	#	set $n = (char *)""
     61  1.4.56.1  christos 	#end
     62  1.4.56.1  christos 	printf "           laddr   pid   lid     flag                 wchan\n"                       
     63  1.4.56.1  christos 	printf "%16lx %5d %5d %8x      %16lx", \
     64  1.4.56.1  christos 		$l, $pid, $l->l_lid, $l->l_flag, $l->l_wchan
     65  1.4.56.1  christos 	if ($n != 0)
     66  1.4.56.1  christos 		printf "  %16s", $n
     67  1.4.56.1  christos 	end
     68  1.4.56.1  christos         printf "\n\n"
     69  1.4.56.1  christos         kvm proc $l
     70  1.4.56.1  christos 	where
     71  1.4.56.1  christos         printf "\n"
     72  1.4.56.1  christos end
     73  1.4.56.1  christos document threadinfo
     74  1.4.56.1  christos Print out the stack and other data of a single thread.
     75  1.4.56.1  christos end
     76  1.4.56.1  christos 
     77  1.4.56.1  christos define procthreadsaddr
     78  1.4.56.1  christos 	set $p = (struct proc *)$arg0
     79  1.4.56.1  christos 	set $l = $p->p_lwps.lh_first
     80  1.4.56.1  christos 	set $nlwps = $p->p_nlwps
     81  1.4.56.1  christos 	set $pid = $p->p_pid
     82  1.4.56.1  christos 
     83  1.4.56.1  christos 	printf "           paddr   pid     flag  stat    n         firstlwp          command\n"                       
     84  1.4.56.1  christos 	printf "%16lx %5d %8x %4x %5d %16lx %16s\n\n", \
     85  1.4.56.1  christos 		$p, $pid, $p->p_flag, $p->p_stat, \
     86  1.4.56.1  christos 		$nlwps, $p->p_lwps.lh_first, \
     87  1.4.56.1  christos 		(char *) $p->p_comm
     88  1.4.56.1  christos 	while ($l)
     89  1.4.56.1  christos 		threadinfo $l $pid
     90  1.4.56.1  christos 		set $l = $l->l_sibling.le_next
     91  1.4.56.1  christos 		set $j++
     92  1.4.56.1  christos 	end
     93  1.4.56.1  christos end
     94  1.4.56.1  christos document procthreadsaddr
     95  1.4.56.1  christos Print out the stack of all threads in a particular process,
     96  1.4.56.1  christos found via struct proc * address.
     97  1.4.56.1  christos end
     98  1.4.56.1  christos 
     99  1.4.56.1  christos define procthreadspid
    100  1.4.56.1  christos 	set $pid = (unsigned)$arg0
    101  1.4.56.1  christos 	set $p = allproc.lh_first
    102  1.4.56.1  christos 	while ($p)
    103  1.4.56.1  christos 		if ($pid == $p->p_pid)
    104  1.4.56.1  christos 			procthreadsaddr $p
    105  1.4.56.1  christos 			loop_break
    106       1.3       eeh 		end
    107  1.4.56.1  christos 		set $p = $p->p_list.le_next
    108  1.4.56.1  christos 	end
    109  1.4.56.1  christos end
    110  1.4.56.1  christos document procthreadspid
    111  1.4.56.1  christos Print out the stack of all threads in a particular process,
    112  1.4.56.1  christos found via PID.
    113  1.4.56.1  christos end
    114  1.4.56.1  christos 
    115  1.4.56.1  christos define threadlist
    116  1.4.56.1  christos 	set $p = allproc.lh_first
    117  1.4.56.1  christos 	while ($p)
    118  1.4.56.1  christos 		procthreadsaddr $p
    119  1.4.56.1  christos 		set $p = $p->p_list.le_next
    120       1.3       eeh 	end
    121       1.3       eeh end
    122       1.3       eeh document threadlist
    123       1.3       eeh Print out the stack of all threads in the system.
    124       1.3       eeh end
    125       1.3       eeh 
    126       1.3       eeh define lock
    127       1.3       eeh 	set $ld = (struct lockdebug *)ld_rb_tree
    128       1.3       eeh 	set $a = $ld->ld_lock
    129       1.3       eeh 	set $b = (volatile void *)$arg0
    130       1.3       eeh 
    131       1.3       eeh 	while ($ld && $a != $b)
    132       1.3       eeh 		if ($a < $b) 
    133       1.3       eeh 			set $ld = (struct lockdebug *)$ld->ld_rb_node.rb_nodes[1]
    134       1.3       eeh 		end
    135       1.3       eeh 		if ($a > $b) 
    136       1.3       eeh 			set $ld = (struct lockdebug *)$ld->ld_rb_node.rb_nodes[0]
    137       1.3       eeh 		end
    138       1.3       eeh 		if ($ld == 0)
    139       1.3       eeh 			loop_break
    140       1.3       eeh 		end
    141       1.3       eeh 		set $a = $ld->ld_lock
    142       1.3       eeh # printf "a=%lx b=%lx ld=%lx a<b %d a>b %d\n", $a, $b, $ld,  ($a < $b), ($a > $b)
    143       1.3       eeh 	end
    144       1.3       eeh 	if ($ld)
    145       1.3       eeh 		printf "lock address : %#018lx type     : ", \
    146       1.3       eeh 			(long)$ld->ld_lock
    147       1.3       eeh 		if ($ld->ld_flags & 0x2)
    148       1.3       eeh 			printf "sleep/adaptive\n"
    149       1.3       eeh 		else
    150       1.3       eeh 			printf "spin\n"
    151       1.3       eeh 		end
    152       1.3       eeh 		printf "initialized  : %#018lx", \
    153       1.3       eeh 			(long)$ld->ld_initaddr
    154       1.3       eeh 		if ($ld->ld_lockops->lo_type == 0x2)
    155       1.3       eeh 			printf " interlock: %#018lx\n", $ld->ld_locked
    156       1.3       eeh 		else
    157       1.3       eeh 			printf "\n"
    158       1.3       eeh 			printf "shared holds : %18u exclusive: ", \
    159       1.3       eeh 				$ld->ld_shares
    160       1.3       eeh 			if (($ld->ld_flags & 0x1) != 0)
    161       1.3       eeh 				printf "1\n"
    162       1.3       eeh 			else
    163       1.3       eeh 				printf "0\n"
    164       1.3       eeh 			end
    165       1.3       eeh 			printf "shares wanted: %18u exclusive: %18u\n", \
    166       1.3       eeh 				(unsigned)$ld->ld_shwant, (unsigned)$ld->ld_exwant
    167       1.3       eeh 			printf "cpu last held: %18u\n", \
    168       1.3       eeh 				(unsigned)$ld->ld_cpu
    169       1.3       eeh 			printf "current lwp  : %#018lx last held: %#018lx\n", \
    170       1.3       eeh 				(long)0, (long)$ld->ld_lwp
    171       1.3       eeh 			printf "last locked  : %#018lx unlocked : %#018lx\n", \
    172       1.3       eeh 				(long)$ld->ld_locked, (long)$ld->ld_unlocked
    173       1.3       eeh 		end
    174       1.3       eeh 	end
    175       1.3       eeh end
    176       1.3       eeh document lock
    177       1.3       eeh Print out lockdebug info like ddb does.
    178       1.3       eeh end
    179