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