1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef	_MDB_TARGET_H
28*7c478bd9Sstevel@tonic-gate #define	_MDB_TARGET_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
34*7c478bd9Sstevel@tonic-gate #include <gelf.h>
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
37*7c478bd9Sstevel@tonic-gate extern "C" {
38*7c478bd9Sstevel@tonic-gate #endif
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate /*
41*7c478bd9Sstevel@tonic-gate  * Forward declaration of the target structure: the target itself is defined in
42*7c478bd9Sstevel@tonic-gate  * mdb_tgt_impl.h and is opaque with respect to callers of this interface.
43*7c478bd9Sstevel@tonic-gate  */
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate struct mdb_tgt;
46*7c478bd9Sstevel@tonic-gate struct mdb_arg;
47*7c478bd9Sstevel@tonic-gate struct ctf_file;
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate typedef struct mdb_tgt mdb_tgt_t;
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate extern void mdb_create_builtin_tgts(void);
52*7c478bd9Sstevel@tonic-gate extern void mdb_create_loadable_disasms(void);
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate /*
55*7c478bd9Sstevel@tonic-gate  * Target Constructors
56*7c478bd9Sstevel@tonic-gate  *
57*7c478bd9Sstevel@tonic-gate  * These functions are used to create a complete debugger target.  The
58*7c478bd9Sstevel@tonic-gate  * constructor is passed as an argument to mdb_tgt_create().
59*7c478bd9Sstevel@tonic-gate  */
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate extern int mdb_value_tgt_create(mdb_tgt_t *, int, const char *[]);
62*7c478bd9Sstevel@tonic-gate #ifndef _KMDB
63*7c478bd9Sstevel@tonic-gate extern int mdb_kvm_tgt_create(mdb_tgt_t *, int, const char *[]);
64*7c478bd9Sstevel@tonic-gate extern int mdb_proc_tgt_create(mdb_tgt_t *, int, const char *[]);
65*7c478bd9Sstevel@tonic-gate extern int mdb_kproc_tgt_create(mdb_tgt_t *, int, const char *[]);
66*7c478bd9Sstevel@tonic-gate extern int mdb_rawfile_tgt_create(mdb_tgt_t *, int, const char *[]);
67*7c478bd9Sstevel@tonic-gate #else
68*7c478bd9Sstevel@tonic-gate extern int kmdb_kvm_create(mdb_tgt_t *, int, const char *[]);
69*7c478bd9Sstevel@tonic-gate #endif
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate /*
72*7c478bd9Sstevel@tonic-gate  * Targets are created by calling mdb_tgt_create() with an optional set of
73*7c478bd9Sstevel@tonic-gate  * target flags, an argument list, and a target constructor (see above):
74*7c478bd9Sstevel@tonic-gate  */
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_F_RDWR		0x0001	/* Open for writing (else read-only) */
77*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_F_ALLOWIO	0x0002	/* Allow I/O mem access (live only) */
78*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_F_FORCE		0x0004	/* Force open (even if non-exclusive) */
79*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_F_PRELOAD	0x0008	/* Preload all symbol tables */
80*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_F_NOLOAD	0x0010	/* Do not do load-object processing */
81*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_F_NOSTOP	0x0020	/* Do not stop target on attach */
82*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_F_STEP		0x0040	/* Single-step is pending */
83*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_F_STEP_OUT	0x0080	/* Step-out is pending */
84*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_F_STEP_BRANCH	0x0100	/* Step-branch is pending */
85*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_F_NEXT		0x0200	/* Step-over is pending */
86*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_F_CONT		0x0400	/* Continue is pending */
87*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_F_BUSY		0x0800	/* Target is busy executing */
88*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_F_ASIO		0x1000	/* Use t_aread and t_awrite for i/o */
89*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_F_UNLOAD	0x2000	/* Unload has been requested */
90*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_F_ALL		0x3fff	/* Mask of all valid flags */
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate typedef int mdb_tgt_ctor_f(mdb_tgt_t *, int, const char *[]);
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate extern mdb_tgt_t *mdb_tgt_create(mdb_tgt_ctor_f *, int, int, const char *[]);
95*7c478bd9Sstevel@tonic-gate extern void mdb_tgt_destroy(mdb_tgt_t *);
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_getflags(mdb_tgt_t *);
98*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_setflags(mdb_tgt_t *, int);
99*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_setcontext(mdb_tgt_t *, void *);
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate /*
102*7c478bd9Sstevel@tonic-gate  * Targets are activated and de-activated by the debugger framework.  An
103*7c478bd9Sstevel@tonic-gate  * activation occurs after construction when the target becomes the current
104*7c478bd9Sstevel@tonic-gate  * target in the debugger.  A target is de-activated prior to its destructor
105*7c478bd9Sstevel@tonic-gate  * being called by mdb_tgt_destroy, or when another target is activated.
106*7c478bd9Sstevel@tonic-gate  * These callbacks are suitable for loading support modules and other tasks.
107*7c478bd9Sstevel@tonic-gate  */
108*7c478bd9Sstevel@tonic-gate extern void mdb_tgt_activate(mdb_tgt_t *);
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate /*
111*7c478bd9Sstevel@tonic-gate  * Prior to issuing a new command prompt, the debugger framework calls the
112*7c478bd9Sstevel@tonic-gate  * target's periodic callback to allow it to load new modules or perform
113*7c478bd9Sstevel@tonic-gate  * other background tasks.
114*7c478bd9Sstevel@tonic-gate  */
115*7c478bd9Sstevel@tonic-gate extern void mdb_tgt_periodic(mdb_tgt_t *);
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate /*
118*7c478bd9Sstevel@tonic-gate  * Convenience functions for accessing miscellaneous target information.
119*7c478bd9Sstevel@tonic-gate  */
120*7c478bd9Sstevel@tonic-gate extern const char *mdb_tgt_name(mdb_tgt_t *);
121*7c478bd9Sstevel@tonic-gate extern const char *mdb_tgt_isa(mdb_tgt_t *);
122*7c478bd9Sstevel@tonic-gate extern const char *mdb_tgt_platform(mdb_tgt_t *);
123*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_uname(mdb_tgt_t *, struct utsname *);
124*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_dmodel(mdb_tgt_t *);
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate /*
127*7c478bd9Sstevel@tonic-gate  * Address Space Interface
128*7c478bd9Sstevel@tonic-gate  *
129*7c478bd9Sstevel@tonic-gate  * Each target can provide access to a set of address spaces, which may include
130*7c478bd9Sstevel@tonic-gate  * a primary virtual address space, a physical address space, an object file
131*7c478bd9Sstevel@tonic-gate  * address space (where virtual addresses are converted to file offsets in an
132*7c478bd9Sstevel@tonic-gate  * object file), and an I/O port address space.  Additionally, the target can
133*7c478bd9Sstevel@tonic-gate  * provide access to alternate address spaces, which are identified by the
134*7c478bd9Sstevel@tonic-gate  * opaque mdb_tgt_as_t type.  If the 'as' parameter to mdb_tgt_aread or
135*7c478bd9Sstevel@tonic-gate  * mdb_tgt_awrite is one of the listed constants, these calls are equivalent
136*7c478bd9Sstevel@tonic-gate  * to mdb_tgt_{v|p|f|io}read or write.
137*7c478bd9Sstevel@tonic-gate  */
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate typedef void *		mdb_tgt_as_t;		/* Opaque address space id */
140*7c478bd9Sstevel@tonic-gate typedef uint64_t	mdb_tgt_addr_t;		/* Generic unsigned address */
141*7c478bd9Sstevel@tonic-gate typedef uint64_t	physaddr_t;		/* Physical memory address */
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_AS_VIRT	((mdb_tgt_as_t)-1L)	/* Virtual address space */
144*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_AS_PHYS	((mdb_tgt_as_t)-2L)	/* Physical address space */
145*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_AS_FILE	((mdb_tgt_as_t)-3L)	/* Object file address space */
146*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_AS_IO	((mdb_tgt_as_t)-4L)	/* I/o address space */
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate extern ssize_t mdb_tgt_aread(mdb_tgt_t *, mdb_tgt_as_t,
149*7c478bd9Sstevel@tonic-gate 	void *, size_t, mdb_tgt_addr_t);
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate extern ssize_t mdb_tgt_awrite(mdb_tgt_t *, mdb_tgt_as_t,
152*7c478bd9Sstevel@tonic-gate 	const void *, size_t, mdb_tgt_addr_t);
153*7c478bd9Sstevel@tonic-gate 
154*7c478bd9Sstevel@tonic-gate extern ssize_t mdb_tgt_vread(mdb_tgt_t *, void *, size_t, uintptr_t);
155*7c478bd9Sstevel@tonic-gate extern ssize_t mdb_tgt_vwrite(mdb_tgt_t *, const void *, size_t, uintptr_t);
156*7c478bd9Sstevel@tonic-gate extern ssize_t mdb_tgt_pread(mdb_tgt_t *, void *, size_t, physaddr_t);
157*7c478bd9Sstevel@tonic-gate extern ssize_t mdb_tgt_pwrite(mdb_tgt_t *, const void *, size_t, physaddr_t);
158*7c478bd9Sstevel@tonic-gate extern ssize_t mdb_tgt_fread(mdb_tgt_t *, void *, size_t, uintptr_t);
159*7c478bd9Sstevel@tonic-gate extern ssize_t mdb_tgt_fwrite(mdb_tgt_t *, const void *, size_t, uintptr_t);
160*7c478bd9Sstevel@tonic-gate extern ssize_t mdb_tgt_ioread(mdb_tgt_t *, void *, size_t, uintptr_t);
161*7c478bd9Sstevel@tonic-gate extern ssize_t mdb_tgt_iowrite(mdb_tgt_t *, const void *, size_t, uintptr_t);
162*7c478bd9Sstevel@tonic-gate 
163*7c478bd9Sstevel@tonic-gate /*
164*7c478bd9Sstevel@tonic-gate  * Convert an address-space's virtual address to the corresponding
165*7c478bd9Sstevel@tonic-gate  * physical address (only useful for kernel targets):
166*7c478bd9Sstevel@tonic-gate  */
167*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_vtop(mdb_tgt_t *, mdb_tgt_as_t, uintptr_t, physaddr_t *);
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate /*
170*7c478bd9Sstevel@tonic-gate  * Convenience functions for reading and writing null-terminated
171*7c478bd9Sstevel@tonic-gate  * strings from any of the target address spaces:
172*7c478bd9Sstevel@tonic-gate  */
173*7c478bd9Sstevel@tonic-gate extern ssize_t mdb_tgt_readstr(mdb_tgt_t *, mdb_tgt_as_t,
174*7c478bd9Sstevel@tonic-gate 	char *, size_t, mdb_tgt_addr_t);
175*7c478bd9Sstevel@tonic-gate 
176*7c478bd9Sstevel@tonic-gate extern ssize_t mdb_tgt_writestr(mdb_tgt_t *, mdb_tgt_as_t,
177*7c478bd9Sstevel@tonic-gate 	const char *, mdb_tgt_addr_t);
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate /*
180*7c478bd9Sstevel@tonic-gate  * Symbol Table Interface
181*7c478bd9Sstevel@tonic-gate  *
182*7c478bd9Sstevel@tonic-gate  * Each target can provide access to one or more symbol tables, which can be
183*7c478bd9Sstevel@tonic-gate  * iterated over, or used to lookup symbols by either name or address.  The
184*7c478bd9Sstevel@tonic-gate  * target can support a primary executable and primary dynamic symbol table,
185*7c478bd9Sstevel@tonic-gate  * a symbol table for its run-time link-editor, and symbol tables for one or
186*7c478bd9Sstevel@tonic-gate  * more loaded objects.  A symbol is uniquely identified by an object name,
187*7c478bd9Sstevel@tonic-gate  * a symbol table id, and a symbol id.  Symbols can be discovered by iterating
188*7c478bd9Sstevel@tonic-gate  * over them, looking them up by name, or looking them up by address.
189*7c478bd9Sstevel@tonic-gate  */
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate typedef struct mdb_syminfo {
192*7c478bd9Sstevel@tonic-gate 	uint_t sym_table;	/* Symbol table id (see symbol_iter, below) */
193*7c478bd9Sstevel@tonic-gate 	uint_t sym_id;		/* Symbol identifier */
194*7c478bd9Sstevel@tonic-gate } mdb_syminfo_t;
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate /*
197*7c478bd9Sstevel@tonic-gate  * Reserved object names for mdb_tgt_lookup_by_name():
198*7c478bd9Sstevel@tonic-gate  */
199*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_OBJ_EXEC	((const char *)0L)	/* Executable symbols */
200*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_OBJ_RTLD	((const char *)1L)	/* Ldso/krtld symbols */
201*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_OBJ_EVERY	((const char *)-1L)	/* All known symbols */
202*7c478bd9Sstevel@tonic-gate 
203*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_lookup_by_scope(mdb_tgt_t *, const char *,
204*7c478bd9Sstevel@tonic-gate 	GElf_Sym *, mdb_syminfo_t *);
205*7c478bd9Sstevel@tonic-gate 
206*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_lookup_by_name(mdb_tgt_t *, const char *,
207*7c478bd9Sstevel@tonic-gate 	const char *, GElf_Sym *, mdb_syminfo_t *);
208*7c478bd9Sstevel@tonic-gate 
209*7c478bd9Sstevel@tonic-gate /*
210*7c478bd9Sstevel@tonic-gate  * Flag bit passed to mdb_tgt_lookup_by_addr():
211*7c478bd9Sstevel@tonic-gate  */
212*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_SYM_FUZZY	0	/* Match closest address */
213*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_SYM_EXACT	1	/* Match exact address only */
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_SYM_NAMLEN	1024	/* Recommended max symbol name length */
216*7c478bd9Sstevel@tonic-gate 
217*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_lookup_by_addr(mdb_tgt_t *, uintptr_t, uint_t,
218*7c478bd9Sstevel@tonic-gate 	char *, size_t, GElf_Sym *, mdb_syminfo_t *);
219*7c478bd9Sstevel@tonic-gate 
220*7c478bd9Sstevel@tonic-gate /*
221*7c478bd9Sstevel@tonic-gate  * Callback function prototype for mdb_tgt_symbol_iter():
222*7c478bd9Sstevel@tonic-gate  */
223*7c478bd9Sstevel@tonic-gate typedef int mdb_tgt_sym_f(void *, const GElf_Sym *, const char *,
224*7c478bd9Sstevel@tonic-gate 	const mdb_syminfo_t *sip, const char *);
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate /*
227*7c478bd9Sstevel@tonic-gate  * Values for selecting symbol tables with mdb_tgt_symbol_iter():
228*7c478bd9Sstevel@tonic-gate  */
229*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_PRVSYM		0	/* User's private symbol table */
230*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_SYMTAB		1	/* Normal symbol table (.symtab) */
231*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_DYNSYM		2	/* Dynamic symbol table (.dynsym) */
232*7c478bd9Sstevel@tonic-gate 
233*7c478bd9Sstevel@tonic-gate /*
234*7c478bd9Sstevel@tonic-gate  * Values for selecting symbols of interest by binding and type.  These flags
235*7c478bd9Sstevel@tonic-gate  * can be used to construct a bitmask to pass to mdb_tgt_symbol_iter():
236*7c478bd9Sstevel@tonic-gate  */
237*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_BIND_LOCAL	0x0001	/* Local (static-scope) symbols */
238*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_BIND_GLOBAL	0x0002	/* Global symbols */
239*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_BIND_WEAK	0x0004	/* Weak binding symbols */
240*7c478bd9Sstevel@tonic-gate 
241*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_BIND_ANY	0x0007	/* Any of the above */
242*7c478bd9Sstevel@tonic-gate 
243*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_TYPE_NOTYPE	0x0100	/* Symbol has no type */
244*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_TYPE_OBJECT	0x0200	/* Symbol refers to data */
245*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_TYPE_FUNC	0x0400	/* Symbol refers to text */
246*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_TYPE_SECT	0x0800	/* Symbol refers to a section */
247*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_TYPE_FILE	0x1000	/* Symbol refers to a source file */
248*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_TYPE_COMMON	0x2000	/* Symbol refers to a common block */
249*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_TYPE_TLS	0x4000	/* Symbol refers to TLS */
250*7c478bd9Sstevel@tonic-gate 
251*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_TYPE_ANY	0x7f00	/* Any of the above */
252*7c478bd9Sstevel@tonic-gate 
253*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_symbol_iter(mdb_tgt_t *, const char *, uint_t, uint_t,
254*7c478bd9Sstevel@tonic-gate 	mdb_tgt_sym_f *, void *);
255*7c478bd9Sstevel@tonic-gate 
256*7c478bd9Sstevel@tonic-gate /*
257*7c478bd9Sstevel@tonic-gate  * Convenience functions for reading and writing at the address specified
258*7c478bd9Sstevel@tonic-gate  * by a given object file and symbol name:
259*7c478bd9Sstevel@tonic-gate  */
260*7c478bd9Sstevel@tonic-gate extern ssize_t mdb_tgt_readsym(mdb_tgt_t *, mdb_tgt_as_t, void *, size_t,
261*7c478bd9Sstevel@tonic-gate 	const char *, const char *);
262*7c478bd9Sstevel@tonic-gate 
263*7c478bd9Sstevel@tonic-gate extern ssize_t mdb_tgt_writesym(mdb_tgt_t *, mdb_tgt_as_t, const void *, size_t,
264*7c478bd9Sstevel@tonic-gate 	const char *, const char *);
265*7c478bd9Sstevel@tonic-gate 
266*7c478bd9Sstevel@tonic-gate /*
267*7c478bd9Sstevel@tonic-gate  * Virtual Address Mapping and Load Object interface
268*7c478bd9Sstevel@tonic-gate  *
269*7c478bd9Sstevel@tonic-gate  * These interfaces allow the caller to iterate over the various virtual
270*7c478bd9Sstevel@tonic-gate  * address space mappings, or only those mappings corresponding to load objects.
271*7c478bd9Sstevel@tonic-gate  * The mapping name (MDB_TGT_MAPSZ) is defined to be large enough for a string
272*7c478bd9Sstevel@tonic-gate  * of length MAXPATHLEN, plus space for "LM`<lmid>" where lmid is a hex number.
273*7c478bd9Sstevel@tonic-gate  */
274*7c478bd9Sstevel@tonic-gate 
275*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_MAPSZ		1048	/* Maximum length of mapping name */
276*7c478bd9Sstevel@tonic-gate 
277*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_MAP_R		0x01	/* Mapping is readable */
278*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_MAP_W		0x02	/* Mapping is writeable */
279*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_MAP_X		0x04	/* Mapping is executable */
280*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_MAP_SHMEM	0x08	/* Mapping is shared memory */
281*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_MAP_STACK	0x10	/* Mapping is a stack of some kind */
282*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_MAP_HEAP	0x20	/* Mapping is a heap of some kind */
283*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_MAP_ANON	0x40	/* Mapping is anonymous memory */
284*7c478bd9Sstevel@tonic-gate 
285*7c478bd9Sstevel@tonic-gate typedef struct mdb_map {
286*7c478bd9Sstevel@tonic-gate 	char map_name[MDB_TGT_MAPSZ];	/* Name of mapped object */
287*7c478bd9Sstevel@tonic-gate 	uintptr_t map_base;		/* Virtual address of base of mapping */
288*7c478bd9Sstevel@tonic-gate 	size_t map_size;		/* Size of mapping in bytes */
289*7c478bd9Sstevel@tonic-gate 	uint_t map_flags;		/* Flags (see above) */
290*7c478bd9Sstevel@tonic-gate } mdb_map_t;
291*7c478bd9Sstevel@tonic-gate 
292*7c478bd9Sstevel@tonic-gate typedef int mdb_tgt_map_f(void *, const mdb_map_t *, const char *);
293*7c478bd9Sstevel@tonic-gate 
294*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_mapping_iter(mdb_tgt_t *, mdb_tgt_map_f *, void *);
295*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_object_iter(mdb_tgt_t *, mdb_tgt_map_f *, void *);
296*7c478bd9Sstevel@tonic-gate 
297*7c478bd9Sstevel@tonic-gate extern const mdb_map_t *mdb_tgt_addr_to_map(mdb_tgt_t *, uintptr_t);
298*7c478bd9Sstevel@tonic-gate extern const mdb_map_t *mdb_tgt_name_to_map(mdb_tgt_t *, const char *);
299*7c478bd9Sstevel@tonic-gate 
300*7c478bd9Sstevel@tonic-gate extern struct ctf_file *mdb_tgt_addr_to_ctf(mdb_tgt_t *, uintptr_t);
301*7c478bd9Sstevel@tonic-gate extern struct ctf_file *mdb_tgt_name_to_ctf(mdb_tgt_t *, const char *);
302*7c478bd9Sstevel@tonic-gate 
303*7c478bd9Sstevel@tonic-gate /*
304*7c478bd9Sstevel@tonic-gate  * Execution Control Interface
305*7c478bd9Sstevel@tonic-gate  *
306*7c478bd9Sstevel@tonic-gate  * For in-situ debugging, we provide a relatively simple interface for target
307*7c478bd9Sstevel@tonic-gate  * execution control.  The target can be continued, or the representative
308*7c478bd9Sstevel@tonic-gate  * thread of control can be single-stepped.  Once the target has stopped, the
309*7c478bd9Sstevel@tonic-gate  * status of the representative thread is returned (this status can also be
310*7c478bd9Sstevel@tonic-gate  * obtained using mdb_tgt_status()).  Upon continue, the target's internal list
311*7c478bd9Sstevel@tonic-gate  * of software event specifiers determines what types of events will cause the
312*7c478bd9Sstevel@tonic-gate  * target to stop and transfer control back to the debugger.  The target
313*7c478bd9Sstevel@tonic-gate  * allows any number of virtual event specifiers to be registered, along with
314*7c478bd9Sstevel@tonic-gate  * an associated callback.  These virtual specifiers are layered on top of
315*7c478bd9Sstevel@tonic-gate  * underlying software event specifiers that are private to the target.  The
316*7c478bd9Sstevel@tonic-gate  * virtual event specifier list can be manipulated by the functions described
317*7c478bd9Sstevel@tonic-gate  * below.  We currently support the following types of traced events:
318*7c478bd9Sstevel@tonic-gate  * breakpoints, watchpoints, system call entry, system call exit, signals,
319*7c478bd9Sstevel@tonic-gate  * and machine faults.
320*7c478bd9Sstevel@tonic-gate  */
321*7c478bd9Sstevel@tonic-gate 
322*7c478bd9Sstevel@tonic-gate typedef uintptr_t mdb_tgt_tid_t;	/* Opaque thread identifier */
323*7c478bd9Sstevel@tonic-gate 
324*7c478bd9Sstevel@tonic-gate typedef struct mdb_tgt_status {
325*7c478bd9Sstevel@tonic-gate 	mdb_tgt_tid_t st_tid;		/* Id of thread in question */
326*7c478bd9Sstevel@tonic-gate 	uintptr_t st_pc;		/* Program counter, if stopped */
327*7c478bd9Sstevel@tonic-gate 	uint_t st_state;		/* Program state (see below) */
328*7c478bd9Sstevel@tonic-gate 	uint_t st_flags;		/* Status flags (see below) */
329*7c478bd9Sstevel@tonic-gate } mdb_tgt_status_t;
330*7c478bd9Sstevel@tonic-gate 
331*7c478bd9Sstevel@tonic-gate /*
332*7c478bd9Sstevel@tonic-gate  * Program state (st_state):
333*7c478bd9Sstevel@tonic-gate  * (MDB_STATE_* definitions in the module API need to be in sync with these)
334*7c478bd9Sstevel@tonic-gate  */
335*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_IDLE		0	/* Target is idle (not running yet) */
336*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_RUNNING		1	/* Target is currently executing */
337*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_STOPPED		2	/* Target is stopped */
338*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_UNDEAD		3	/* Target is undead (zombie) */
339*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_DEAD		4	/* Target is dead (core dump) */
340*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_LOST		5	/* Target lost by debugger */
341*7c478bd9Sstevel@tonic-gate 
342*7c478bd9Sstevel@tonic-gate /*
343*7c478bd9Sstevel@tonic-gate  * Status flags (st_flags):
344*7c478bd9Sstevel@tonic-gate  */
345*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_ISTOP		0x1	/* Stop on event of interest */
346*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_DSTOP		0x2	/* Stop directive is pending */
347*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_BUSY		0x4	/* Busy in debugger */
348*7c478bd9Sstevel@tonic-gate 
349*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_status(mdb_tgt_t *, mdb_tgt_status_t *);
350*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_run(mdb_tgt_t *, int, const struct mdb_arg *);
351*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_step(mdb_tgt_t *, mdb_tgt_status_t *);
352*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_step_out(mdb_tgt_t *, mdb_tgt_status_t *);
353*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_step_branch(mdb_tgt_t *, mdb_tgt_status_t *);
354*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_next(mdb_tgt_t *, mdb_tgt_status_t *);
355*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_continue(mdb_tgt_t *, mdb_tgt_status_t *);
356*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_signal(mdb_tgt_t *, int);
357*7c478bd9Sstevel@tonic-gate 
358*7c478bd9Sstevel@tonic-gate /*
359*7c478bd9Sstevel@tonic-gate  * Iterating through the specifier list yields the integer id (VID) and private
360*7c478bd9Sstevel@tonic-gate  * data pointer for each specifier.
361*7c478bd9Sstevel@tonic-gate  */
362*7c478bd9Sstevel@tonic-gate typedef int mdb_tgt_vespec_f(mdb_tgt_t *, void *, int, void *);
363*7c478bd9Sstevel@tonic-gate 
364*7c478bd9Sstevel@tonic-gate /*
365*7c478bd9Sstevel@tonic-gate  * Each event specifier is defined to be in one of the following states.  The
366*7c478bd9Sstevel@tonic-gate  * state transitions are discussed in detail in the comments in mdb_target.c.
367*7c478bd9Sstevel@tonic-gate  */
368*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_SPEC_IDLE	1	/* Inactive (e.g. object not loaded) */
369*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_SPEC_ACTIVE	2	/* Active but not armed in target */
370*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_SPEC_ARMED	3	/* Active and armed (e.g. bkpt set) */
371*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_SPEC_ERROR	4	/* Failed to arm event */
372*7c478bd9Sstevel@tonic-gate 
373*7c478bd9Sstevel@tonic-gate /*
374*7c478bd9Sstevel@tonic-gate  * Event specifiers may also have one or more of the following additional
375*7c478bd9Sstevel@tonic-gate  * properties (spec_flags bits):
376*7c478bd9Sstevel@tonic-gate  */
377*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_SPEC_INTERNAL	0x0001	/* Internal to target implementation */
378*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_SPEC_SILENT	0x0002	/* Do not describe when matched */
379*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_SPEC_TEMPORARY	0x0004	/* Delete next time target stops */
380*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_SPEC_MATCHED	0x0008	/* Specifier matched at last stop */
381*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_SPEC_DISABLED	0x0010	/* Specifier cannot be armed */
382*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_SPEC_DELETED	0x0020	/* Specifier has been deleted */
383*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_SPEC_AUTODEL	0x0040	/* Delete when match limit reached */
384*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_SPEC_AUTODIS	0x0080	/* Disable when match limit reached */
385*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_SPEC_AUTOSTOP	0x0100	/* Stop when match limit reached */
386*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_SPEC_STICKY	0x0200	/* Do not delete as part of :z */
387*7c478bd9Sstevel@tonic-gate 
388*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_SPEC_HIDDEN	(MDB_TGT_SPEC_INTERNAL | MDB_TGT_SPEC_SILENT)
389*7c478bd9Sstevel@tonic-gate 
390*7c478bd9Sstevel@tonic-gate typedef struct mdb_tgt_spec_desc {
391*7c478bd9Sstevel@tonic-gate 	int spec_id;			/* Event specifier id (VID) */
392*7c478bd9Sstevel@tonic-gate 	uint_t spec_flags;		/* Flags (see above) */
393*7c478bd9Sstevel@tonic-gate 	uint_t spec_hits;		/* Count of number of times matched */
394*7c478bd9Sstevel@tonic-gate 	uint_t spec_limit;		/* Limit on number of times matched */
395*7c478bd9Sstevel@tonic-gate 	int spec_state;			/* State (see above) */
396*7c478bd9Sstevel@tonic-gate 	int spec_errno;			/* Last error code (if IDLE or ERROR) */
397*7c478bd9Sstevel@tonic-gate 	uintptr_t spec_base;		/* Start of affected memory region */
398*7c478bd9Sstevel@tonic-gate 	size_t spec_size;		/* Size of affected memory region */
399*7c478bd9Sstevel@tonic-gate 	void *spec_data;		/* Callback private data */
400*7c478bd9Sstevel@tonic-gate } mdb_tgt_spec_desc_t;
401*7c478bd9Sstevel@tonic-gate 
402*7c478bd9Sstevel@tonic-gate /*
403*7c478bd9Sstevel@tonic-gate  * The target provides functions to convert a VID into the private data pointer,
404*7c478bd9Sstevel@tonic-gate  * or a complete description of the event specifier and its state.
405*7c478bd9Sstevel@tonic-gate  */
406*7c478bd9Sstevel@tonic-gate extern void *mdb_tgt_vespec_data(mdb_tgt_t *, int);
407*7c478bd9Sstevel@tonic-gate extern char *mdb_tgt_vespec_info(mdb_tgt_t *, int,
408*7c478bd9Sstevel@tonic-gate     mdb_tgt_spec_desc_t *, char *, size_t);
409*7c478bd9Sstevel@tonic-gate 
410*7c478bd9Sstevel@tonic-gate /*
411*7c478bd9Sstevel@tonic-gate  * The common target layer provides functions to iterate over the list of
412*7c478bd9Sstevel@tonic-gate  * registered event specifiers, modify or disable them, and delete them.
413*7c478bd9Sstevel@tonic-gate  */
414*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_vespec_iter(mdb_tgt_t *, mdb_tgt_vespec_f *, void *);
415*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_vespec_modify(mdb_tgt_t *, int, uint_t, uint_t, void *);
416*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_vespec_enable(mdb_tgt_t *, int);
417*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_vespec_disable(mdb_tgt_t *, int);
418*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_vespec_delete(mdb_tgt_t *, int);
419*7c478bd9Sstevel@tonic-gate 
420*7c478bd9Sstevel@tonic-gate /*
421*7c478bd9Sstevel@tonic-gate  * The mdb_tgt_add_* functions are used to add software event specifiers to the
422*7c478bd9Sstevel@tonic-gate  * target.  The caller provides a bitmask of flags (spec_flags above), callback
423*7c478bd9Sstevel@tonic-gate  * function pointer, and callback data as arguments.  Whenever a matching event
424*7c478bd9Sstevel@tonic-gate  * is detected, a software event callback function is invoked.  The callback
425*7c478bd9Sstevel@tonic-gate  * receives a pointer to the target, the VID of the corresponding event
426*7c478bd9Sstevel@tonic-gate  * specifier, and a private data pointer as arguments.  If no callback is
427*7c478bd9Sstevel@tonic-gate  * desired, the caller can specify a pointer to the no_se_f default callback.
428*7c478bd9Sstevel@tonic-gate  * Unlike other target layer functions, the mdb_tgt_add_* interfaces return the
429*7c478bd9Sstevel@tonic-gate  * VID of the new event (which may be positive or negative), or 0 if the new
430*7c478bd9Sstevel@tonic-gate  * event could not be created.
431*7c478bd9Sstevel@tonic-gate  */
432*7c478bd9Sstevel@tonic-gate typedef void mdb_tgt_se_f(mdb_tgt_t *, int, void *);
433*7c478bd9Sstevel@tonic-gate extern void no_se_f(mdb_tgt_t *, int, void *);
434*7c478bd9Sstevel@tonic-gate 
435*7c478bd9Sstevel@tonic-gate /*
436*7c478bd9Sstevel@tonic-gate  * Breakpoints can be set at a specified virtual address or using MDB's
437*7c478bd9Sstevel@tonic-gate  * symbol notation:
438*7c478bd9Sstevel@tonic-gate  */
439*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_add_vbrkpt(mdb_tgt_t *, uintptr_t,
440*7c478bd9Sstevel@tonic-gate     int, mdb_tgt_se_f *, void *);
441*7c478bd9Sstevel@tonic-gate 
442*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_add_sbrkpt(mdb_tgt_t *, const char *,
443*7c478bd9Sstevel@tonic-gate     int, mdb_tgt_se_f *, void *);
444*7c478bd9Sstevel@tonic-gate 
445*7c478bd9Sstevel@tonic-gate /*
446*7c478bd9Sstevel@tonic-gate  * Watchpoints can be set at physical, virtual, or I/O port addresses for any
447*7c478bd9Sstevel@tonic-gate  * combination of read, write, or execute operations.
448*7c478bd9Sstevel@tonic-gate  */
449*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_WA_R		0x1	/* Read watchpoint */
450*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_WA_W		0x2	/* Write watchpoint */
451*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_WA_X		0x4	/* Execute watchpoint */
452*7c478bd9Sstevel@tonic-gate 
453*7c478bd9Sstevel@tonic-gate #define	MDB_TGT_WA_RWX	(MDB_TGT_WA_R | MDB_TGT_WA_W | MDB_TGT_WA_X)
454*7c478bd9Sstevel@tonic-gate 
455*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_add_pwapt(mdb_tgt_t *, physaddr_t, size_t, uint_t,
456*7c478bd9Sstevel@tonic-gate     int, mdb_tgt_se_f *, void *);
457*7c478bd9Sstevel@tonic-gate 
458*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_add_vwapt(mdb_tgt_t *, uintptr_t, size_t, uint_t,
459*7c478bd9Sstevel@tonic-gate     int, mdb_tgt_se_f *, void *);
460*7c478bd9Sstevel@tonic-gate 
461*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_add_iowapt(mdb_tgt_t *, uintptr_t, size_t, uint_t,
462*7c478bd9Sstevel@tonic-gate     int, mdb_tgt_se_f *, void *);
463*7c478bd9Sstevel@tonic-gate 
464*7c478bd9Sstevel@tonic-gate /*
465*7c478bd9Sstevel@tonic-gate  * For user process debugging, tracepoints can be set on entry or exit from
466*7c478bd9Sstevel@tonic-gate  * a system call, or on receipt of a software signal or fault.
467*7c478bd9Sstevel@tonic-gate  */
468*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_add_sysenter(mdb_tgt_t *, int, int, mdb_tgt_se_f *, void *);
469*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_add_sysexit(mdb_tgt_t *, int, int, mdb_tgt_se_f *, void *);
470*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_add_signal(mdb_tgt_t *, int, int, mdb_tgt_se_f *, void *);
471*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_add_fault(mdb_tgt_t *, int, int, mdb_tgt_se_f *, void *);
472*7c478bd9Sstevel@tonic-gate 
473*7c478bd9Sstevel@tonic-gate /*
474*7c478bd9Sstevel@tonic-gate  * Machine Register Interface
475*7c478bd9Sstevel@tonic-gate  *
476*7c478bd9Sstevel@tonic-gate  * The machine registers for a given thread can be manipulated using the
477*7c478bd9Sstevel@tonic-gate  * getareg and putareg interface; the caller must know the naming convention
478*7c478bd9Sstevel@tonic-gate  * for registers for the given target architecture.  For the purposes of
479*7c478bd9Sstevel@tonic-gate  * this interface, we declare the register container to be the largest
480*7c478bd9Sstevel@tonic-gate  * current integer container.
481*7c478bd9Sstevel@tonic-gate  */
482*7c478bd9Sstevel@tonic-gate 
483*7c478bd9Sstevel@tonic-gate typedef uint64_t mdb_tgt_reg_t;
484*7c478bd9Sstevel@tonic-gate 
485*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_getareg(mdb_tgt_t *, mdb_tgt_tid_t,
486*7c478bd9Sstevel@tonic-gate 	const char *, mdb_tgt_reg_t *);
487*7c478bd9Sstevel@tonic-gate 
488*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_putareg(mdb_tgt_t *, mdb_tgt_tid_t,
489*7c478bd9Sstevel@tonic-gate 	const char *, mdb_tgt_reg_t);
490*7c478bd9Sstevel@tonic-gate 
491*7c478bd9Sstevel@tonic-gate /*
492*7c478bd9Sstevel@tonic-gate  * Stack Interface
493*7c478bd9Sstevel@tonic-gate  *
494*7c478bd9Sstevel@tonic-gate  * The target stack interface provides the ability to iterate backward through
495*7c478bd9Sstevel@tonic-gate  * the frames of an execution stack.  For the purposes of this interface, the
496*7c478bd9Sstevel@tonic-gate  * mdb_tgt_gregset (general purpose register set) is an opaque type: there must
497*7c478bd9Sstevel@tonic-gate  * be an implicit contract between the target implementation and any debugger
498*7c478bd9Sstevel@tonic-gate  * modules that must interpret the contents of this structure.  The callback
499*7c478bd9Sstevel@tonic-gate  * function is provided with the only elements of a stack frame which we can
500*7c478bd9Sstevel@tonic-gate  * reasonably abstract: the virtual address corresponding to a program counter
501*7c478bd9Sstevel@tonic-gate  * value, and an array of arguments passed to the function call represented by
502*7c478bd9Sstevel@tonic-gate  * this frame.  The rest of the frame is presumed to be contained within the
503*7c478bd9Sstevel@tonic-gate  * mdb_tgt_gregset_t, and is architecture-specific.
504*7c478bd9Sstevel@tonic-gate  */
505*7c478bd9Sstevel@tonic-gate 
506*7c478bd9Sstevel@tonic-gate typedef struct mdb_tgt_gregset mdb_tgt_gregset_t;
507*7c478bd9Sstevel@tonic-gate 
508*7c478bd9Sstevel@tonic-gate typedef int mdb_tgt_stack_f(void *, uintptr_t, uint_t, const long *,
509*7c478bd9Sstevel@tonic-gate 	const mdb_tgt_gregset_t *);
510*7c478bd9Sstevel@tonic-gate typedef int mdb_tgt_stack_iter_f(mdb_tgt_t *, const mdb_tgt_gregset_t *,
511*7c478bd9Sstevel@tonic-gate 	mdb_tgt_stack_f *, void *);
512*7c478bd9Sstevel@tonic-gate 
513*7c478bd9Sstevel@tonic-gate extern mdb_tgt_stack_iter_f mdb_tgt_stack_iter;
514*7c478bd9Sstevel@tonic-gate 
515*7c478bd9Sstevel@tonic-gate /*
516*7c478bd9Sstevel@tonic-gate  * External Data Interface
517*7c478bd9Sstevel@tonic-gate  *
518*7c478bd9Sstevel@tonic-gate  * The external data interface provides each target with the ability to export
519*7c478bd9Sstevel@tonic-gate  * a set of named buffers that contain data which is associated with the
520*7c478bd9Sstevel@tonic-gate  * target, but is somehow not accessible through one of its address spaces and
521*7c478bd9Sstevel@tonic-gate  * does not correspond to a machine register.  A process credential is an
522*7c478bd9Sstevel@tonic-gate  * example of such a buffer: the credential is associated with the given
523*7c478bd9Sstevel@tonic-gate  * process, but is stored in the kernel (not the process's address space) and
524*7c478bd9Sstevel@tonic-gate  * thus is not accessible through any other target interface.  Since it is
525*7c478bd9Sstevel@tonic-gate  * exported via /proc, the user process target can export this information as a
526*7c478bd9Sstevel@tonic-gate  * named buffer for target-specific dcmds to consume.
527*7c478bd9Sstevel@tonic-gate  */
528*7c478bd9Sstevel@tonic-gate 
529*7c478bd9Sstevel@tonic-gate typedef int mdb_tgt_xdata_f(void *, const char *, const char *, size_t);
530*7c478bd9Sstevel@tonic-gate 
531*7c478bd9Sstevel@tonic-gate extern int mdb_tgt_xdata_iter(mdb_tgt_t *, mdb_tgt_xdata_f *, void *);
532*7c478bd9Sstevel@tonic-gate extern ssize_t mdb_tgt_getxdata(mdb_tgt_t *, const char *, void *, size_t);
533*7c478bd9Sstevel@tonic-gate 
534*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
535*7c478bd9Sstevel@tonic-gate }
536*7c478bd9Sstevel@tonic-gate #endif
537*7c478bd9Sstevel@tonic-gate 
538*7c478bd9Sstevel@tonic-gate #endif	/* _MDB_TARGET_H */
539