xref: /freebsd/cddl/contrib/opensolaris/lib/libdtrace/common/dtrace.h (revision 096a5c6cd28c417456d5ce3598be15e6b656af5c)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Copyright (c) 2023 by Domagoj Stolfa. All rights reserved.
29  * Copyright (c) 2014, 2016 by Delphix. All rights reserved.
30  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
31  */
32 
33 #ifndef	_DTRACE_H
34 #define	_DTRACE_H
35 
36 #include <sys/dtrace.h>
37 #include <stdarg.h>
38 #include <stdio.h>
39 #include <gelf.h>
40 #include <libproc.h>
41 #ifndef illumos
42 #include <rtld_db.h>
43 #endif
44 
45 #ifdef	__cplusplus
46 extern "C" {
47 #endif
48 
49 /*
50  * DTrace Dynamic Tracing Software: Library Interfaces
51  *
52  * Note: The contents of this file are private to the implementation of the
53  * Solaris system and DTrace subsystem and are subject to change at any time
54  * without notice.  Applications and drivers using these interfaces will fail
55  * to run on future releases.  These interfaces should not be used for any
56  * purpose except those expressly outlined in dtrace(7D) and libdtrace(3LIB).
57  * Please refer to the "Solaris Dynamic Tracing Guide" for more information.
58  */
59 
60 #define	DTRACE_VERSION	3		/* library ABI interface version */
61 
62 struct ps_prochandle;
63 struct dt_node;
64 typedef struct dtrace_hdl dtrace_hdl_t;
65 typedef struct dtrace_prog dtrace_prog_t;
66 typedef struct dtrace_vector dtrace_vector_t;
67 typedef struct dtrace_aggdata dtrace_aggdata_t;
68 
69 #define	DTRACE_O_NODEV		0x01	/* do not open dtrace(7D) device */
70 #define	DTRACE_O_NOSYS		0x02	/* do not load /system/object modules */
71 #define	DTRACE_O_LP64		0x04	/* force D compiler to be LP64 */
72 #define	DTRACE_O_ILP32		0x08	/* force D compiler to be ILP32 */
73 #define	DTRACE_O_MODEL_MASK	(DTRACE_O_LP64 | DTRACE_O_ILP32)
74 #define	DTRACE_O_MASK		0x0f	/* mask of valid flags to dtrace_open */
75 
76 extern dtrace_hdl_t *dtrace_open(int, int, int *);
77 extern dtrace_hdl_t *dtrace_vopen(int, int, int *,
78     const dtrace_vector_t *, void *);
79 
80 extern int dtrace_go(dtrace_hdl_t *);
81 extern int dtrace_stop(dtrace_hdl_t *);
82 extern void dtrace_sleep(dtrace_hdl_t *);
83 extern void dtrace_close(dtrace_hdl_t *);
84 
85 extern int dtrace_errno(dtrace_hdl_t *);
86 extern const char *dtrace_errmsg(dtrace_hdl_t *, int);
87 extern const char *dtrace_faultstr(dtrace_hdl_t *, int);
88 extern const char *dtrace_subrstr(dtrace_hdl_t *, int);
89 
90 extern int dtrace_setopt(dtrace_hdl_t *, const char *, const char *);
91 extern int dtrace_getopt(dtrace_hdl_t *, const char *, dtrace_optval_t *);
92 
93 extern void dtrace_update(dtrace_hdl_t *);
94 extern int dtrace_ctlfd(dtrace_hdl_t *);
95 
96 /*
97  * DTrace Program Interface
98  *
99  * DTrace programs can be created by compiling ASCII text files containing
100  * D programs or by compiling in-memory C strings that specify a D program.
101  * Once created, callers can examine the list of program statements and
102  * enable the probes and actions described by these statements.
103  */
104 
105 typedef struct dtrace_proginfo {
106 	dtrace_attribute_t dpi_descattr; /* minimum probedesc attributes */
107 	dtrace_attribute_t dpi_stmtattr; /* minimum statement attributes */
108 	uint_t dpi_aggregates;	/* number of aggregates specified in program */
109 	uint_t dpi_recgens;	/* number of record generating probes in prog */
110 	uint_t dpi_matches;	/* number of probes matched by program */
111 	uint_t dpi_speculations; /* number of speculations specified in prog */
112 } dtrace_proginfo_t;
113 
114 #define	DTRACE_C_DIFV	0x0001	/* DIF verbose mode: show each compiled DIFO */
115 #define	DTRACE_C_EMPTY	0x0002	/* Permit compilation of empty D source files */
116 #define	DTRACE_C_ZDEFS	0x0004	/* Permit probe defs that match zero probes */
117 #define	DTRACE_C_EATTR	0x0008	/* Error if program attributes less than min */
118 #define	DTRACE_C_CPP	0x0010	/* Preprocess input file with cpp(1) utility */
119 #define	DTRACE_C_KNODEF	0x0020	/* Permit unresolved kernel symbols in DIFO */
120 #define	DTRACE_C_UNODEF	0x0040	/* Permit unresolved user symbols in DIFO */
121 #define	DTRACE_C_PSPEC	0x0080	/* Interpret ambiguous specifiers as probes */
122 #define	DTRACE_C_ETAGS	0x0100	/* Prefix error messages with error tags */
123 #define	DTRACE_C_ARGREF	0x0200	/* Do not require all macro args to be used */
124 #define	DTRACE_C_SUGAR	0x0400	/* Dump D script post-dt_sugar */
125 #define	DTRACE_C_DEFARG	0x0800	/* Use 0/"" as value for unspecified args */
126 #define	DTRACE_C_NOLIBS	0x1000	/* Do not process D system libraries */
127 #define	DTRACE_C_CTL	0x2000	/* Only process control directives */
128 #define	DTRACE_C_MASK	0x3fff	/* mask of all valid flags to dtrace_*compile */
129 
130 extern dtrace_prog_t *dtrace_program_strcompile(dtrace_hdl_t *,
131     const char *, dtrace_probespec_t, uint_t, int, char *const []);
132 
133 extern dtrace_prog_t *dtrace_program_fcompile(dtrace_hdl_t *,
134     FILE *, uint_t, int, char *const []);
135 
136 extern int dtrace_program_exec(dtrace_hdl_t *, dtrace_prog_t *,
137     dtrace_proginfo_t *);
138 extern void dtrace_program_info(dtrace_hdl_t *, dtrace_prog_t *,
139     dtrace_proginfo_t *);
140 
141 #define	DTRACE_D_STRIP	0x01	/* strip non-loadable sections from program */
142 #define	DTRACE_D_PROBES	0x02	/* include provider and probe definitions */
143 #define	DTRACE_D_MASK	0x03	/* mask of valid flags to dtrace_dof_create */
144 
145 extern int dtrace_program_link(dtrace_hdl_t *, dtrace_prog_t *,
146     uint_t, const char *, int, char *const []);
147 
148 extern int dtrace_program_header(dtrace_hdl_t *, FILE *, const char *);
149 
150 extern void *dtrace_dof_create(dtrace_hdl_t *, dtrace_prog_t *, uint_t);
151 extern void dtrace_dof_destroy(dtrace_hdl_t *, void *);
152 
153 extern void *dtrace_getopt_dof(dtrace_hdl_t *);
154 extern void *dtrace_geterr_dof(dtrace_hdl_t *);
155 
156 typedef struct dtrace_stmtdesc {
157 	dtrace_ecbdesc_t *dtsd_ecbdesc;		/* ECB description */
158 	dtrace_actdesc_t *dtsd_action;		/* action list */
159 	dtrace_actdesc_t *dtsd_action_last;	/* last action in action list */
160 	void *dtsd_aggdata;			/* aggregation data */
161 	void *dtsd_fmtdata;			/* type-specific output data */
162 	void *dtsd_strdata;			/* type-specific string data */
163 	void (*dtsd_callback)(void);		/* callback function for EPID */
164 	void *dtsd_data;			/* callback data pointer */
165 	dtrace_attribute_t dtsd_descattr;	/* probedesc attributes */
166 	dtrace_attribute_t dtsd_stmtattr;	/* statement attributes */
167 } dtrace_stmtdesc_t;
168 
169 typedef int dtrace_stmt_f(dtrace_hdl_t *, dtrace_prog_t *,
170     dtrace_stmtdesc_t *, void *);
171 
172 extern dtrace_stmtdesc_t *dtrace_stmt_create(dtrace_hdl_t *,
173     dtrace_ecbdesc_t *);
174 extern dtrace_actdesc_t *dtrace_stmt_action(dtrace_hdl_t *,
175     dtrace_stmtdesc_t *);
176 extern int dtrace_stmt_add(dtrace_hdl_t *, dtrace_prog_t *,
177     dtrace_stmtdesc_t *);
178 extern int dtrace_stmt_iter(dtrace_hdl_t *, dtrace_prog_t *,
179     dtrace_stmt_f *, void *);
180 extern void dtrace_stmt_destroy(dtrace_hdl_t *, dtrace_stmtdesc_t *);
181 
182 /*
183  * DTrace Data Consumption Interface
184  */
185 typedef enum {
186 	DTRACEFLOW_ENTRY,
187 	DTRACEFLOW_RETURN,
188 	DTRACEFLOW_NONE
189 } dtrace_flowkind_t;
190 
191 #define	DTRACE_CONSUME_ERROR		-1	/* error while processing */
192 #define	DTRACE_CONSUME_THIS		0	/* consume this probe/record */
193 #define	DTRACE_CONSUME_NEXT		1	/* advance to next probe/rec */
194 #define	DTRACE_CONSUME_ABORT		2	/* abort consumption */
195 
196 typedef struct dtrace_probedata {
197 	dtrace_hdl_t *dtpda_handle;		/* handle to DTrace library */
198 	dtrace_eprobedesc_t *dtpda_edesc;	/* enabled probe description */
199 	dtrace_probedesc_t *dtpda_pdesc;	/* probe description */
200 	processorid_t dtpda_cpu;		/* CPU for data */
201 	caddr_t dtpda_data;			/* pointer to raw data */
202 	dtrace_flowkind_t dtpda_flow;		/* flow kind */
203 	const char *dtpda_prefix;		/* recommended flow prefix */
204 	int dtpda_indent;			/* recommended flow indent */
205 	uint64_t dtpda_timestamp;		/* hrtime of snapshot */
206 } dtrace_probedata_t;
207 
208 typedef int dtrace_consume_probe_f(const dtrace_probedata_t *, void *);
209 typedef int dtrace_consume_rec_f(const dtrace_probedata_t *,
210     const dtrace_recdesc_t *, void *);
211 
212 extern int dtrace_consume(dtrace_hdl_t *, FILE *,
213     dtrace_consume_probe_f *, dtrace_consume_rec_f *, void *);
214 
215 #define	DTRACE_STATUS_NONE	0	/* no status; not yet time */
216 #define	DTRACE_STATUS_OKAY	1	/* status okay */
217 #define	DTRACE_STATUS_EXITED	2	/* exit() was called; tracing stopped */
218 #define	DTRACE_STATUS_FILLED	3	/* fill buffer filled; tracing stoped */
219 #define	DTRACE_STATUS_STOPPED	4	/* tracing already stopped */
220 
221 extern int dtrace_status(dtrace_hdl_t *);
222 
223 /*
224  * DTrace Formatted Output Interfaces
225  *
226  * To format output associated with a given dtrace_stmtdesc, the caller can
227  * invoke one of the following functions, passing the opaque dtsd_fmtdata and a
228  * list of record descriptions.  These functions return either -1 to indicate
229  * an error, or a positive integer indicating the number of records consumed.
230  * For anonymous enablings, the consumer can use the dtrd_format member of
231  * the record description to obtain a format description.  The dtfd_string
232  * member of the format description may be passed to dtrace_print{fa}_create()
233  * to create the opaque format data.
234  */
235 extern void *dtrace_printf_create(dtrace_hdl_t *, const char *);
236 extern void *dtrace_printa_create(dtrace_hdl_t *, const char *);
237 extern size_t dtrace_printf_format(dtrace_hdl_t *, void *, char *, size_t);
238 
239 extern int dtrace_sprintf(dtrace_hdl_t *, FILE *, void *,
240     const dtrace_recdesc_t *, uint_t,
241     const void *, size_t);
242 
243 extern int dtrace_fprintf(dtrace_hdl_t *, FILE *, void *,
244     const dtrace_probedata_t *, const dtrace_recdesc_t *, uint_t,
245     const void *, size_t);
246 
247 extern int dtrace_fprinta(dtrace_hdl_t *, FILE *, void *,
248     const dtrace_probedata_t *, const dtrace_recdesc_t *, uint_t,
249     const void *, size_t);
250 
251 extern int dtrace_system(dtrace_hdl_t *, FILE *, void *,
252     const dtrace_probedata_t *, const dtrace_recdesc_t *, uint_t,
253     const void *, size_t);
254 
255 extern int dtrace_freopen(dtrace_hdl_t *, FILE *, void *,
256     const dtrace_probedata_t *, const dtrace_recdesc_t *, uint_t,
257     const void *, size_t);
258 
259 /*
260  * Type-specific output printing
261  *
262  * The print() action will associate a string data record that is actually the
263  * fully-qualified type name of the data traced by the DIFEXPR action.  This is
264  * stored in the same 'format' record from the kernel, but we know by virtue of
265  * the fact that the action is still DIFEXPR that it is actually a reference to
266  * plain string data.
267  */
268 extern int dtrace_print(dtrace_hdl_t *, FILE *, const char *,
269     caddr_t, size_t);
270 extern int dtrace_format_print(dtrace_hdl_t *, FILE *, const char *,
271     caddr_t, size_t);
272 
273 /*
274  * DTrace Work Interface
275  */
276 typedef enum {
277 	DTRACE_WORKSTATUS_ERROR = -1,
278 	DTRACE_WORKSTATUS_OKAY,
279 	DTRACE_WORKSTATUS_DONE
280 } dtrace_workstatus_t;
281 
282 extern dtrace_workstatus_t dtrace_work(dtrace_hdl_t *, FILE *,
283     dtrace_consume_probe_f *, dtrace_consume_rec_f *, void *);
284 
285 /*
286  * DTrace Handler Interface
287  */
288 #define	DTRACE_HANDLE_ABORT		-1	/* abort current operation */
289 #define	DTRACE_HANDLE_OK		0	/* handled okay; continue */
290 
291 typedef struct dtrace_errdata {
292 	dtrace_hdl_t *dteda_handle;		/* handle to DTrace library */
293 	dtrace_eprobedesc_t *dteda_edesc;	/* enabled probe inducing err */
294 	dtrace_probedesc_t *dteda_pdesc;	/* probe inducing error */
295 	processorid_t dteda_cpu;		/* CPU of error */
296 	int dteda_action;			/* action inducing error */
297 	int dteda_offset;			/* offset in DIFO of error */
298 	int dteda_fault;			/* specific fault */
299 	uint64_t dteda_addr;			/* address of fault, if any */
300 	const char *dteda_msg;			/* preconstructed message */
301 } dtrace_errdata_t;
302 
303 typedef int dtrace_handle_err_f(const dtrace_errdata_t *, void *);
304 extern int dtrace_handle_err(dtrace_hdl_t *, dtrace_handle_err_f *, void *);
305 
306 typedef enum {
307 	DTRACEDROP_PRINCIPAL,			/* drop to principal buffer */
308 	DTRACEDROP_AGGREGATION,			/* drop to aggregation buffer */
309 	DTRACEDROP_DYNAMIC,			/* dynamic drop */
310 	DTRACEDROP_DYNRINSE,			/* dyn drop due to rinsing */
311 	DTRACEDROP_DYNDIRTY,			/* dyn drop due to dirty */
312 	DTRACEDROP_SPEC,			/* speculative drop */
313 	DTRACEDROP_SPECBUSY,			/* spec drop due to busy */
314 	DTRACEDROP_SPECUNAVAIL,			/* spec drop due to unavail */
315 	DTRACEDROP_STKSTROVERFLOW,		/* stack string tab overflow */
316 	DTRACEDROP_DBLERROR			/* error in ERROR probe */
317 } dtrace_dropkind_t;
318 
319 typedef struct dtrace_dropdata {
320 	dtrace_hdl_t *dtdda_handle;		/* handle to DTrace library */
321 	processorid_t dtdda_cpu;		/* CPU, if any */
322 	dtrace_dropkind_t dtdda_kind;		/* kind of drop */
323 	uint64_t dtdda_drops;			/* number of drops */
324 	uint64_t dtdda_total;			/* total drops */
325 	const char *dtdda_msg;			/* preconstructed message */
326 } dtrace_dropdata_t;
327 
328 typedef int dtrace_handle_drop_f(const dtrace_dropdata_t *, void *);
329 extern int dtrace_handle_drop(dtrace_hdl_t *, dtrace_handle_drop_f *, void *);
330 
331 typedef void dtrace_handle_proc_f(struct ps_prochandle *, const char *, void *);
332 extern int dtrace_handle_proc(dtrace_hdl_t *, dtrace_handle_proc_f *, void *);
333 
334 #define	DTRACE_BUFDATA_AGGKEY		0x0001	/* aggregation key */
335 #define	DTRACE_BUFDATA_AGGVAL		0x0002	/* aggregation value */
336 #define	DTRACE_BUFDATA_AGGFORMAT	0x0004	/* aggregation format data */
337 #define	DTRACE_BUFDATA_AGGLAST		0x0008	/* last for this key/val */
338 
339 typedef struct dtrace_bufdata {
340 	dtrace_hdl_t *dtbda_handle;		/* handle to DTrace library */
341 	const char *dtbda_buffered;		/* buffered output */
342 	dtrace_probedata_t *dtbda_probe;	/* probe data */
343 	const dtrace_recdesc_t *dtbda_recdesc;	/* record description */
344 	const dtrace_aggdata_t *dtbda_aggdata;	/* aggregation data, if agg. */
345 	uint32_t dtbda_flags;			/* flags; see above */
346 } dtrace_bufdata_t;
347 
348 typedef int dtrace_handle_buffered_f(const dtrace_bufdata_t *, void *);
349 extern int dtrace_handle_buffered(dtrace_hdl_t *,
350     dtrace_handle_buffered_f *, void *);
351 
352 typedef struct dtrace_setoptdata {
353 	dtrace_hdl_t *dtsda_handle;		/* handle to DTrace library */
354 	const dtrace_probedata_t *dtsda_probe;	/* probe data */
355 	const char *dtsda_option;		/* option that was set */
356 	dtrace_optval_t dtsda_oldval;		/* old value */
357 	dtrace_optval_t dtsda_newval;		/* new value */
358 } dtrace_setoptdata_t;
359 
360 typedef int dtrace_handle_setopt_f(const dtrace_setoptdata_t *, void *);
361 extern int dtrace_handle_setopt(dtrace_hdl_t *,
362     dtrace_handle_setopt_f *, void *);
363 
364 /*
365  * DTrace Aggregate Interface
366  */
367 
368 #define	DTRACE_A_PERCPU		0x0001
369 #define	DTRACE_A_KEEPDELTA	0x0002
370 #define	DTRACE_A_ANONYMOUS	0x0004
371 #define	DTRACE_A_TOTAL		0x0008
372 #define	DTRACE_A_MINMAXBIN	0x0010
373 #define	DTRACE_A_HASNEGATIVES	0x0020
374 #define	DTRACE_A_HASPOSITIVES	0x0040
375 
376 #define	DTRACE_AGGZOOM_MAX		0.95	/* height of max bar */
377 
378 #define	DTRACE_AGGWALK_ERROR		-1	/* error while processing */
379 #define	DTRACE_AGGWALK_NEXT		0	/* proceed to next element */
380 #define	DTRACE_AGGWALK_ABORT		1	/* abort aggregation walk */
381 #define	DTRACE_AGGWALK_CLEAR		2	/* clear this element */
382 #define	DTRACE_AGGWALK_NORMALIZE	3	/* normalize this element */
383 #define	DTRACE_AGGWALK_DENORMALIZE	4	/* denormalize this element */
384 #define	DTRACE_AGGWALK_REMOVE		5	/* remove this element */
385 
386 struct dtrace_aggdata {
387 	dtrace_hdl_t *dtada_handle;		/* handle to DTrace library */
388 	dtrace_aggdesc_t *dtada_desc;		/* aggregation description */
389 	dtrace_eprobedesc_t *dtada_edesc;	/* enabled probe description */
390 	dtrace_probedesc_t *dtada_pdesc;	/* probe description */
391 	caddr_t dtada_data;			/* pointer to raw data */
392 	uint64_t dtada_normal;			/* the normal -- 1 for denorm */
393 	size_t dtada_size;			/* total size of the data */
394 	caddr_t dtada_delta;			/* delta data, if available */
395 	caddr_t *dtada_percpu;			/* per CPU data, if avail */
396 	caddr_t *dtada_percpu_delta;		/* per CPU delta, if avail */
397 	int64_t dtada_total;			/* per agg total, if avail */
398 	uint16_t dtada_minbin;			/* minimum bin, if avail */
399 	uint16_t dtada_maxbin;			/* maximum bin, if avail */
400 	uint32_t dtada_flags;			/* flags */
401 };
402 
403 typedef int dtrace_aggregate_f(const dtrace_aggdata_t *, void *);
404 typedef int dtrace_aggregate_walk_f(dtrace_hdl_t *,
405     dtrace_aggregate_f *, void *);
406 typedef int dtrace_aggregate_walk_joined_f(const dtrace_aggdata_t **,
407     const int, void *);
408 
409 extern void dtrace_aggregate_clear(dtrace_hdl_t *);
410 extern int dtrace_aggregate_snap(dtrace_hdl_t *);
411 extern int dtrace_aggregate_print(dtrace_hdl_t *, FILE *,
412     dtrace_aggregate_walk_f *);
413 
414 extern int dtrace_aggregate_walk(dtrace_hdl_t *, dtrace_aggregate_f *, void *);
415 
416 extern int dtrace_aggregate_walk_joined(dtrace_hdl_t *,
417     dtrace_aggvarid_t *, int, dtrace_aggregate_walk_joined_f *, void *);
418 
419 extern int dtrace_aggregate_walk_sorted(dtrace_hdl_t *,
420     dtrace_aggregate_f *, void *);
421 
422 extern int dtrace_aggregate_walk_keysorted(dtrace_hdl_t *,
423     dtrace_aggregate_f *, void *);
424 
425 extern int dtrace_aggregate_walk_valsorted(dtrace_hdl_t *,
426     dtrace_aggregate_f *, void *);
427 
428 extern int dtrace_aggregate_walk_keyvarsorted(dtrace_hdl_t *,
429     dtrace_aggregate_f *, void *);
430 
431 extern int dtrace_aggregate_walk_valvarsorted(dtrace_hdl_t *,
432     dtrace_aggregate_f *, void *);
433 
434 extern int dtrace_aggregate_walk_keyrevsorted(dtrace_hdl_t *,
435     dtrace_aggregate_f *, void *);
436 
437 extern int dtrace_aggregate_walk_valrevsorted(dtrace_hdl_t *,
438     dtrace_aggregate_f *, void *);
439 
440 extern int dtrace_aggregate_walk_keyvarrevsorted(dtrace_hdl_t *,
441     dtrace_aggregate_f *, void *);
442 
443 extern int dtrace_aggregate_walk_valvarrevsorted(dtrace_hdl_t *,
444     dtrace_aggregate_f *, void *);
445 
446 #define	DTRACE_AGD_PRINTED	0x1	/* aggregation printed in program */
447 
448 /*
449  * DTrace Process Control Interface
450  *
451  * Library clients who wish to have libdtrace create or grab processes for
452  * monitoring of their symbol table changes may use these interfaces to
453  * request that libdtrace obtain control of the process using libproc.
454  */
455 
456 extern struct ps_prochandle *dtrace_proc_create(dtrace_hdl_t *,
457     const char *, char *const *, proc_child_func *, void *);
458 
459 extern struct ps_prochandle *dtrace_proc_grab(dtrace_hdl_t *, pid_t, int);
460 extern void dtrace_proc_release(dtrace_hdl_t *, struct ps_prochandle *);
461 extern void dtrace_proc_continue(dtrace_hdl_t *, struct ps_prochandle *);
462 
463 /*
464  * DTrace Object, Symbol, and Type Interfaces
465  *
466  * Library clients can use libdtrace to perform symbol and C type information
467  * lookups by symbol name, symbol address, or C type name, or to lookup meta-
468  * information cached for each of the program objects in use by DTrace.  The
469  * resulting struct contain pointers to arbitrary-length strings, including
470  * object, symbol, and type names, that are persistent until the next call to
471  * dtrace_update().  Once dtrace_update() is called, any cached values must
472  * be flushed and not used subsequently by the client program.
473  */
474 
475 #define	DTRACE_OBJ_EXEC	 ((const char *)0L)	/* primary executable file */
476 #define	DTRACE_OBJ_RTLD	 ((const char *)1L)	/* run-time link-editor */
477 #define	DTRACE_OBJ_CDEFS ((const char *)2L)	/* C include definitions */
478 #define	DTRACE_OBJ_DDEFS ((const char *)3L)	/* D program definitions */
479 #define	DTRACE_OBJ_EVERY ((const char *)-1L)	/* all known objects */
480 #define	DTRACE_OBJ_KMODS ((const char *)-2L)	/* all kernel objects */
481 #define	DTRACE_OBJ_UMODS ((const char *)-3L)	/* all user objects */
482 
483 typedef struct dtrace_objinfo {
484 	const char *dto_name;			/* object file scope name */
485 	const char *dto_file;			/* object file path (if any) */
486 	int dto_id;				/* object file id (if any) */
487 	uint_t dto_flags;			/* object flags (see below) */
488 	GElf_Addr dto_text_va;			/* address of text section */
489 	GElf_Xword dto_text_size;		/* size of text section */
490 	GElf_Addr dto_data_va;			/* address of data section */
491 	GElf_Xword dto_data_size;		/* size of data section */
492 	GElf_Addr dto_bss_va;			/* address of BSS */
493 	GElf_Xword dto_bss_size;		/* size of BSS */
494 } dtrace_objinfo_t;
495 
496 #define	DTRACE_OBJ_F_KERNEL	0x1		/* object is a kernel module */
497 #define	DTRACE_OBJ_F_PRIMARY	0x2		/* object is a primary module */
498 
499 typedef int dtrace_obj_f(dtrace_hdl_t *, const dtrace_objinfo_t *, void *);
500 
501 extern int dtrace_object_iter(dtrace_hdl_t *, dtrace_obj_f *, void *);
502 extern int dtrace_object_info(dtrace_hdl_t *, const char *, dtrace_objinfo_t *);
503 
504 typedef struct dtrace_syminfo {
505 	const char *dts_object;			/* object name */
506 	const char *dts_name;			/* symbol name */
507 	ulong_t dts_id;				/* symbol id */
508 } dtrace_syminfo_t;
509 
510 extern int dtrace_lookup_by_name(dtrace_hdl_t *, const char *, const char *,
511     GElf_Sym *, dtrace_syminfo_t *);
512 
513 extern int dtrace_lookup_by_addr(dtrace_hdl_t *, GElf_Addr addr,
514     GElf_Sym *, dtrace_syminfo_t *);
515 
516 typedef struct dtrace_typeinfo {
517 	const char *dtt_object;			/* object containing type */
518 	ctf_file_t *dtt_ctfp;			/* CTF container handle */
519 	ctf_id_t dtt_type;			/* CTF type identifier */
520 	uint_t dtt_flags;			/* Misc. flags */
521 } dtrace_typeinfo_t;
522 
523 #define	DTT_FL_USER	0x1			/* user type */
524 
525 extern int dtrace_lookup_by_type(dtrace_hdl_t *, const char *, const char *,
526     dtrace_typeinfo_t *);
527 
528 extern int dtrace_symbol_type(dtrace_hdl_t *, const GElf_Sym *,
529     const dtrace_syminfo_t *, dtrace_typeinfo_t *);
530 
531 extern int dtrace_type_strcompile(dtrace_hdl_t *,
532     const char *, dtrace_typeinfo_t *);
533 
534 extern int dtrace_type_fcompile(dtrace_hdl_t *,
535     FILE *, dtrace_typeinfo_t *);
536 
537 extern struct dt_node *dt_compile_sugar(dtrace_hdl_t *,
538     struct dt_node *);
539 
540 
541 /*
542  * DTrace Probe Interface
543  *
544  * Library clients can use these functions to iterate over the set of available
545  * probe definitions and inquire as to their attributes.  The probe iteration
546  * interfaces report probes that are declared as well as those from dtrace(7D).
547  */
548 typedef struct dtrace_probeinfo {
549 	dtrace_attribute_t dtp_attr;		/* name attributes */
550 	dtrace_attribute_t dtp_arga;		/* arg attributes */
551 	const dtrace_typeinfo_t *dtp_argv;	/* arg types */
552 	int dtp_argc;				/* arg count */
553 } dtrace_probeinfo_t;
554 
555 typedef int dtrace_probe_f(dtrace_hdl_t *, const dtrace_probedesc_t *, void *);
556 
557 extern int dtrace_probe_iter(dtrace_hdl_t *,
558     const dtrace_probedesc_t *pdp, dtrace_probe_f *, void *);
559 
560 extern int dtrace_probe_info(dtrace_hdl_t *,
561     const dtrace_probedesc_t *, dtrace_probeinfo_t *);
562 
563 /*
564  * DTrace Vector Interface
565  *
566  * The DTrace library normally speaks directly to dtrace(7D).  However,
567  * this communication may be vectored elsewhere.  Consumers who wish to
568  * perform a vectored open must fill in the vector, and use the dtrace_vopen()
569  * entry point to obtain a library handle.
570  */
571 struct dtrace_vector {
572 #ifdef illumos
573 	int (*dtv_ioctl)(void *, int, void *);
574 #else
575 	int (*dtv_ioctl)(void *, u_long, void *);
576 #endif
577 	int (*dtv_lookup_by_addr)(void *, GElf_Addr, GElf_Sym *,
578 	    dtrace_syminfo_t *);
579 	int (*dtv_status)(void *, processorid_t);
580 	long (*dtv_sysconf)(void *, int);
581 };
582 
583 /*
584  * DTrace Utility Functions
585  *
586  * Library clients can use these functions to convert addresses strings, to
587  * convert between string and integer probe descriptions and the
588  * dtrace_probedesc_t representation, and to perform similar conversions on
589  * stability attributes.
590  */
591 extern int dtrace_addr2str(dtrace_hdl_t *, uint64_t, char *, int);
592 extern int dtrace_uaddr2str(dtrace_hdl_t *, pid_t, uint64_t, char *, int);
593 
594 extern int dtrace_xstr2desc(dtrace_hdl_t *, dtrace_probespec_t,
595     const char *, int, char *const [], dtrace_probedesc_t *);
596 
597 extern int dtrace_str2desc(dtrace_hdl_t *, dtrace_probespec_t,
598     const char *, dtrace_probedesc_t *);
599 
600 extern int dtrace_id2desc(dtrace_hdl_t *, dtrace_id_t, dtrace_probedesc_t *);
601 
602 #define	DTRACE_DESC2STR_MAX	1024	/* min buf size for dtrace_desc2str() */
603 
604 extern char *dtrace_desc2str(const dtrace_probedesc_t *, char *, size_t);
605 
606 #define	DTRACE_ATTR2STR_MAX	64	/* min buf size for dtrace_attr2str() */
607 
608 extern char *dtrace_attr2str(dtrace_attribute_t, char *, size_t);
609 extern int dtrace_str2attr(const char *, dtrace_attribute_t *);
610 
611 extern const char *dtrace_stability_name(dtrace_stability_t);
612 extern const char *dtrace_class_name(dtrace_class_t);
613 
614 extern int dtrace_provider_modules(dtrace_hdl_t *, const char **, int);
615 
616 extern const char *const _dtrace_version;
617 extern int _dtrace_debug;
618 
619 #ifdef	__cplusplus
620 }
621 #endif
622 
623 #ifndef illumos
624 #define _SC_CPUID_MAX		_SC_NPROCESSORS_CONF
625 #define _SC_NPROCESSORS_MAX	_SC_NPROCESSORS_CONF
626 #endif
627 
628 /*
629  * Values for the dt_oformat property.
630  */
631 #define	DTRACE_OFORMAT_TEXT		0
632 #define	DTRACE_OFORMAT_STRUCTURED	1
633 
634 extern int dtrace_oformat_configure(dtrace_hdl_t *);
635 extern int dtrace_oformat(dtrace_hdl_t *);
636 extern void dtrace_set_outfp(const FILE *);
637 extern void dtrace_oformat_setup(dtrace_hdl_t *);
638 extern void dtrace_oformat_teardown(dtrace_hdl_t *);
639 extern void dtrace_oformat_probe(dtrace_hdl_t *, const dtrace_probedata_t *,
640     processorid_t, dtrace_probedesc_t *);
641 
642 #endif	/* _DTRACE_H */
643