xref: /illumos-gate/usr/src/cmd/mdb/common/mdb/mdb_gcore.h (revision 69a119ca)
1*69a119caSChristopher Siden /*
2*69a119caSChristopher Siden  * This file and its contents are supplied under the terms of the
3*69a119caSChristopher Siden  * Common Development and Distribution License ("CDDL"), version 1.0.
4*69a119caSChristopher Siden  * You may only use this file in accordance with the terms of version
5*69a119caSChristopher Siden  * 1.0 of the CDDL.
6*69a119caSChristopher Siden  *
7*69a119caSChristopher Siden  * A full copy of the text of the CDDL should have accompanied this
8*69a119caSChristopher Siden  * source.  A copy of the CDDL is also available via the Internet at
9*69a119caSChristopher Siden  * http://www.illumos.org/license/CDDL.
10*69a119caSChristopher Siden  */
11*69a119caSChristopher Siden /*
12*69a119caSChristopher Siden  * Copyright (c) 2013 by Delphix. All rights reserved.
13*69a119caSChristopher Siden  */
14*69a119caSChristopher Siden 
15*69a119caSChristopher Siden #ifndef	_MDB_GCORE_H
16*69a119caSChristopher Siden #define	_MDB_GCORE_H
17*69a119caSChristopher Siden 
18*69a119caSChristopher Siden /*
19*69a119caSChristopher Siden  * The kernel has its own definition of exit which has a different signature
20*69a119caSChristopher Siden  * than the user space definition.  This seems to be the standard way to deal
21*69a119caSChristopher Siden  * with this.
22*69a119caSChristopher Siden  */
23*69a119caSChristopher Siden #define	exit kern_exit
24*69a119caSChristopher Siden 
25*69a119caSChristopher Siden #include <sys/cpuvar.h>
26*69a119caSChristopher Siden #include <sys/cred_impl.h>
27*69a119caSChristopher Siden #include <sys/procfs.h>
28*69a119caSChristopher Siden #include <vm/anon.h>
29*69a119caSChristopher Siden 
30*69a119caSChristopher Siden #undef exit
31*69a119caSChristopher Siden 
32*69a119caSChristopher Siden /* mdb versions of kernel structures used for ctf read calls */
33*69a119caSChristopher Siden typedef struct mdb_proc {
34*69a119caSChristopher Siden 	uintptr_t	p_as;
35*69a119caSChristopher Siden 	uintptr_t	p_brkbase;
36*69a119caSChristopher Siden 	size_t		p_brksize;
37*69a119caSChristopher Siden 	uintptr_t	p_usrstack;
38*69a119caSChristopher Siden 	size_t		p_stksize;
39*69a119caSChristopher Siden 	user_t		p_user;
40*69a119caSChristopher Siden 	uintptr_t	p_agenttp;
41*69a119caSChristopher Siden 	uintptr_t	p_tlist;
42*69a119caSChristopher Siden 	uintptr_t	p_zone;
43*69a119caSChristopher Siden 	uintptr_t	p_ldt;
44*69a119caSChristopher Siden 	kcondvar_t	p_holdlwps;
45*69a119caSChristopher Siden 	int		p_lwpcnt;
46*69a119caSChristopher Siden 	uintptr_t	p_lwpdir;
47*69a119caSChristopher Siden 	uint_t		p_lwpdir_sz;
48*69a119caSChristopher Siden 	uintptr_t	p_cred;
49*69a119caSChristopher Siden 	uint_t		p_flag;
50*69a119caSChristopher Siden 	int		p_zombcnt;
51*69a119caSChristopher Siden 	uintptr_t	p_pidp;
52*69a119caSChristopher Siden 	pid_t		p_ppid;
53*69a119caSChristopher Siden 	uintptr_t	p_pgidp;
54*69a119caSChristopher Siden 	uintptr_t	p_sessp;
55*69a119caSChristopher Siden 	uintptr_t	p_task;
56*69a119caSChristopher Siden 	uintptr_t	p_pool;
57*69a119caSChristopher Siden 	model_t		p_model;
58*69a119caSChristopher Siden 	char		p_wcode;
59*69a119caSChristopher Siden 	ushort_t	p_ldtlimit;
60*69a119caSChristopher Siden 	uintptr_t	p_exec;
61*69a119caSChristopher Siden 	uint_t		p_proc_flag;
62*69a119caSChristopher Siden 	ushort_t	p_pidflag;
63*69a119caSChristopher Siden 	k_sigset_t	p_ignore;
64*69a119caSChristopher Siden 	k_sigset_t	p_siginfo;
65*69a119caSChristopher Siden 	k_sigset_t	p_sig;
66*69a119caSChristopher Siden 	k_sigset_t	p_sigmask;
67*69a119caSChristopher Siden 	k_fltset_t	p_fltmask;
68*69a119caSChristopher Siden 	int		p_wdata;
69*69a119caSChristopher Siden } mdb_proc_t;
70*69a119caSChristopher Siden 
71*69a119caSChristopher Siden typedef struct mdb_kthread {
72*69a119caSChristopher Siden 	ushort_t	t_proc_flag;
73*69a119caSChristopher Siden 	uint_t		t_state;
74*69a119caSChristopher Siden 	lwpchan_t	t_lwpchan;
75*69a119caSChristopher Siden 	ushort_t	t_whystop;
76*69a119caSChristopher Siden 	uint8_t		t_dtrace_stop;
77*69a119caSChristopher Siden 	uintptr_t	t_forw;
78*69a119caSChristopher Siden 	uintptr_t	t_lwp;
79*69a119caSChristopher Siden 	id_t		t_tid;
80*69a119caSChristopher Siden 	short		t_sysnum;
81*69a119caSChristopher Siden 	pri_t		t_pri;
82*69a119caSChristopher Siden 	time_t		t_start;
83*69a119caSChristopher Siden 	id_t		t_cid;
84*69a119caSChristopher Siden 	uintptr_t	t_cpu;
85*69a119caSChristopher Siden 	int		t_bind_pset;
86*69a119caSChristopher Siden 	short		t_bind_cpu;
87*69a119caSChristopher Siden 	uintptr_t	t_lpl;
88*69a119caSChristopher Siden 	ushort_t	t_schedflag;
89*69a119caSChristopher Siden 	ushort_t	t_whatstop;
90*69a119caSChristopher Siden 	k_sigset_t	t_sig;
91*69a119caSChristopher Siden 	uintptr_t	t_schedctl;
92*69a119caSChristopher Siden 	k_sigset_t	t_hold;
93*69a119caSChristopher Siden 	hrtime_t	t_stoptime;
94*69a119caSChristopher Siden } mdb_kthread_t;
95*69a119caSChristopher Siden 
96*69a119caSChristopher Siden typedef struct mdb_seg {
97*69a119caSChristopher Siden 	uintptr_t	s_base;
98*69a119caSChristopher Siden 	size_t		s_size;
99*69a119caSChristopher Siden 	uintptr_t	s_ops;
100*69a119caSChristopher Siden 	uintptr_t	s_data;
101*69a119caSChristopher Siden 	uintptr_t	s_as;
102*69a119caSChristopher Siden } mdb_seg_t;
103*69a119caSChristopher Siden 
104*69a119caSChristopher Siden typedef struct mdb_as {
105*69a119caSChristopher Siden 	uintptr_t	a_proc;
106*69a119caSChristopher Siden } mdb_as_t;
107*69a119caSChristopher Siden 
108*69a119caSChristopher Siden typedef struct mdb_segvn_data {
109*69a119caSChristopher Siden 	uintptr_t	vp;
110*69a119caSChristopher Siden 	uint64_t	offset;
111*69a119caSChristopher Siden 	uint16_t	flags;
112*69a119caSChristopher Siden 	uint8_t		pageprot;
113*69a119caSChristopher Siden 	uint8_t		prot;
114*69a119caSChristopher Siden 	uintptr_t	amp;
115*69a119caSChristopher Siden 	struct vpage	*vpage;
116*69a119caSChristopher Siden 	uint64_t	anon_index;
117*69a119caSChristopher Siden 	uint8_t		type;
118*69a119caSChristopher Siden } mdb_segvn_data_t;
119*69a119caSChristopher Siden 
120*69a119caSChristopher Siden typedef struct mdb_vnode {
121*69a119caSChristopher Siden 	enum vtype	v_type;
122*69a119caSChristopher Siden 	uintptr_t	v_data;
123*69a119caSChristopher Siden 	uintptr_t	v_op;
124*69a119caSChristopher Siden 	uintptr_t	v_path;
125*69a119caSChristopher Siden } mdb_vnode_t;
126*69a119caSChristopher Siden 
127*69a119caSChristopher Siden typedef struct mdb_znode {
128*69a119caSChristopher Siden 	uint64_t	z_size;
129*69a119caSChristopher Siden } mdb_znode_t;
130*69a119caSChristopher Siden 
131*69a119caSChristopher Siden typedef struct mdb_tmpnode {
132*69a119caSChristopher Siden 	vattr_t		tn_attr;
133*69a119caSChristopher Siden } mdb_tmpnode_t;
134*69a119caSChristopher Siden 
135*69a119caSChristopher Siden typedef struct mdb_vnodeops {
136*69a119caSChristopher Siden 	uintptr_t	vnop_name;
137*69a119caSChristopher Siden } mdb_vnodeops_t;
138*69a119caSChristopher Siden 
139*69a119caSChristopher Siden typedef struct mdb_shm_data {
140*69a119caSChristopher Siden 	uintptr_t	shm_sptseg;
141*69a119caSChristopher Siden } mdb_shm_data_t;
142*69a119caSChristopher Siden 
143*69a119caSChristopher Siden typedef struct mdb_watched_page {
144*69a119caSChristopher Siden 	uintptr_t	wp_vaddr;
145*69a119caSChristopher Siden 	uint8_t		wp_oprot;
146*69a119caSChristopher Siden } mdb_watched_page_t;
147*69a119caSChristopher Siden 
148*69a119caSChristopher Siden typedef struct mdb_pid {
149*69a119caSChristopher Siden 	pid_t		pid_id;
150*69a119caSChristopher Siden } mdb_pid_t;
151*69a119caSChristopher Siden 
152*69a119caSChristopher Siden typedef struct mdb_sess {
153*69a119caSChristopher Siden 	uintptr_t	s_sidp;
154*69a119caSChristopher Siden } mdb_sess_t;
155*69a119caSChristopher Siden 
156*69a119caSChristopher Siden typedef struct mdb_task {
157*69a119caSChristopher Siden 	taskid_t	tk_tkid;
158*69a119caSChristopher Siden 	uintptr_t	tk_proj;
159*69a119caSChristopher Siden } mdb_task_t;
160*69a119caSChristopher Siden 
161*69a119caSChristopher Siden typedef struct mdb_kproject {
162*69a119caSChristopher Siden 	projid_t	kpj_id;
163*69a119caSChristopher Siden } mdb_kproject_t;
164*69a119caSChristopher Siden 
165*69a119caSChristopher Siden typedef struct mdb_zone {
166*69a119caSChristopher Siden 	zoneid_t	zone_id;
167*69a119caSChristopher Siden 	uintptr_t	zone_name;
168*69a119caSChristopher Siden } mdb_zone_t;
169*69a119caSChristopher Siden 
170*69a119caSChristopher Siden typedef struct mdb_sc_shared {
171*69a119caSChristopher Siden 	char		sc_sigblock;
172*69a119caSChristopher Siden } mdb_sc_shared_t;
173*69a119caSChristopher Siden 
174*69a119caSChristopher Siden typedef struct mdb_klwp {
175*69a119caSChristopher Siden 	uintptr_t	lwp_regs;
176*69a119caSChristopher Siden 	struct pcb	lwp_pcb;
177*69a119caSChristopher Siden 	uchar_t		lwp_asleep;
178*69a119caSChristopher Siden 	uchar_t		lwp_cursig;
179*69a119caSChristopher Siden 	uintptr_t	lwp_curinfo;
180*69a119caSChristopher Siden 	k_siginfo_t	lwp_siginfo;
181*69a119caSChristopher Siden 	stack_t		lwp_sigaltstack;
182*69a119caSChristopher Siden 	uintptr_t	lwp_oldcontext;
183*69a119caSChristopher Siden 	short		lwp_badpriv;
184*69a119caSChristopher Siden 	uintptr_t	lwp_ustack;
185*69a119caSChristopher Siden 	char		lwp_eosys;
186*69a119caSChristopher Siden } mdb_klwp_t;
187*69a119caSChristopher Siden 
188*69a119caSChristopher Siden typedef struct mdb_cpu {
189*69a119caSChristopher Siden 	processorid_t	cpu_id;
190*69a119caSChristopher Siden } mdb_cpu_t;
191*69a119caSChristopher Siden 
192*69a119caSChristopher Siden typedef struct mdb_lpl {
193*69a119caSChristopher Siden 	lgrp_id_t	lpl_lgrpid;
194*69a119caSChristopher Siden } mdb_lpl_t;
195*69a119caSChristopher Siden 
196*69a119caSChristopher Siden typedef struct mdb_sigqueue {
197*69a119caSChristopher Siden 	k_siginfo_t	sq_info;
198*69a119caSChristopher Siden } mdb_sigqueue_t;
199*69a119caSChristopher Siden 
200*69a119caSChristopher Siden typedef struct mdb_pool {
201*69a119caSChristopher Siden 	poolid_t	pool_id;
202*69a119caSChristopher Siden } mdb_pool_t;
203*69a119caSChristopher Siden 
204*69a119caSChristopher Siden typedef struct mdb_amp {
205*69a119caSChristopher Siden 	uintptr_t	ahp;
206*69a119caSChristopher Siden } mdb_amp_t;
207*69a119caSChristopher Siden 
208*69a119caSChristopher Siden typedef struct mdb_anon_hdr {
209*69a119caSChristopher Siden 	pgcnt_t		size;
210*69a119caSChristopher Siden 	uintptr_t	array_chunk;
211*69a119caSChristopher Siden 	int		flags;
212*69a119caSChristopher Siden } mdb_anon_hdr_t;
213*69a119caSChristopher Siden 
214*69a119caSChristopher Siden typedef struct mdb_anon {
215*69a119caSChristopher Siden 	uintptr_t	an_vp;
216*69a119caSChristopher Siden 	anoff_t		an_off;
217*69a119caSChristopher Siden } mdb_anon_t;
218*69a119caSChristopher Siden 
219*69a119caSChristopher Siden /* Used to construct a linked list of prmap_ts */
220*69a119caSChristopher Siden typedef struct prmap_node {
221*69a119caSChristopher Siden 	struct prmap_node *next;
222*69a119caSChristopher Siden 	prmap_t		m;
223*69a119caSChristopher Siden } prmap_node_t;
224*69a119caSChristopher Siden 
225*69a119caSChristopher Siden /* Fields common to psinfo_t and pstatus_t */
226*69a119caSChristopher Siden typedef struct pcommon {
227*69a119caSChristopher Siden 	int		pc_nlwp;
228*69a119caSChristopher Siden 	int		pc_nzomb;
229*69a119caSChristopher Siden 	pid_t		pc_pid;
230*69a119caSChristopher Siden 	pid_t		pc_ppid;
231*69a119caSChristopher Siden 	pid_t		pc_pgid;
232*69a119caSChristopher Siden 	pid_t		pc_sid;
233*69a119caSChristopher Siden 	taskid_t	pc_taskid;
234*69a119caSChristopher Siden 	projid_t	pc_projid;
235*69a119caSChristopher Siden 	zoneid_t	pc_zoneid;
236*69a119caSChristopher Siden 	char		pc_dmodel;
237*69a119caSChristopher Siden } pcommon_t;
238*69a119caSChristopher Siden 
239*69a119caSChristopher Siden /* AVL walk callback structures */
240*69a119caSChristopher Siden typedef struct read_maps_cbarg {
241*69a119caSChristopher Siden 	mdb_proc_t	*p;
242*69a119caSChristopher Siden 	uintptr_t	brkseg;
243*69a119caSChristopher Siden 	uintptr_t	stkseg;
244*69a119caSChristopher Siden 	prmap_node_t	*map_head;
245*69a119caSChristopher Siden 	prmap_node_t	*map_tail;
246*69a119caSChristopher Siden 	int		map_len;
247*69a119caSChristopher Siden } read_maps_cbarg_t;
248*69a119caSChristopher Siden 
249*69a119caSChristopher Siden typedef struct as_segat_cbarg {
250*69a119caSChristopher Siden 	uintptr_t	addr;
251*69a119caSChristopher Siden 	uintptr_t	res;
252*69a119caSChristopher Siden } as_segat_cbarg_t;
253*69a119caSChristopher Siden 
254*69a119caSChristopher Siden typedef struct getwatchprot_cbarg {
255*69a119caSChristopher Siden 	uintptr_t	wp_vaddr;
256*69a119caSChristopher Siden 	mdb_watched_page_t wp;
257*69a119caSChristopher Siden 	boolean_t	found;
258*69a119caSChristopher Siden } getwatchprot_cbarg_t;
259*69a119caSChristopher Siden 
260*69a119caSChristopher Siden struct gcore_segops;
261*69a119caSChristopher Siden typedef struct gcore_seg {
262*69a119caSChristopher Siden 	mdb_seg_t	*gs_seg;
263*69a119caSChristopher Siden 	void		*gs_data;
264*69a119caSChristopher Siden 	struct gcore_segops *gs_ops;
265*69a119caSChristopher Siden } gcore_seg_t;
266*69a119caSChristopher Siden 
267*69a119caSChristopher Siden /*
268*69a119caSChristopher Siden  * These are the ISA-dependent functions that need to be
269*69a119caSChristopher Siden  * implemented for ::gcore.
270*69a119caSChristopher Siden  */
271*69a119caSChristopher Siden extern uintptr_t gcore_prgetstackbase(mdb_proc_t *);
272*69a119caSChristopher Siden extern int gcore_prfetchinstr(mdb_klwp_t *, ulong_t *);
273*69a119caSChristopher Siden extern int gcore_prisstep(mdb_klwp_t *);
274*69a119caSChristopher Siden extern void gcore_getgregs(mdb_klwp_t *, gregset_t);
275*69a119caSChristopher Siden extern int gcore_prgetrvals(mdb_klwp_t *, long *, long *);
276*69a119caSChristopher Siden 
277*69a119caSChristopher Siden #endif	/* _MDB_GCORE_H */
278