xref: /titanic_44/usr/src/lib/libdtrace/common/dt_printf.h (revision aad98a6d8e89f8f5a62a1793da807d4bc5e5b159)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_DT_PRINTF_H
28 #define	_DT_PRINTF_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <libctf.h>
34 #include <dtrace.h>
35 #include <stdio.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 struct dt_node;
42 struct dt_ident;
43 
44 struct dt_pfconv;
45 struct dt_pfargv;
46 struct dt_pfargd;
47 
48 typedef int dt_pfcheck_f(struct dt_pfargv *,
49     struct dt_pfargd *, struct dt_node *);
50 typedef int dt_pfprint_f(dtrace_hdl_t *, FILE *, const char *,
51     const struct dt_pfargd *, const void *, size_t, uint64_t);
52 
53 typedef struct dt_pfconv {
54 	const char *pfc_name;		/* string name of input conversion */
55 	const char *pfc_ofmt;		/* string name of output conversion */
56 	const char *pfc_tstr;		/* string name for conversion type */
57 	dt_pfcheck_f *pfc_check;	/* function to use for type checking */
58 	dt_pfprint_f *pfc_print;	/* function to use for formatting */
59 	ctf_file_t *pfc_cctfp;		/* CTF container for "C" defn of type */
60 	ctf_id_t pfc_ctype;		/* CTF type ID for "C" defn of type */
61 	ctf_file_t *pfc_dctfp;		/* CTF container for "D" defn of type */
62 	ctf_id_t pfc_dtype;		/* CTF type ID for "D" defn of type */
63 	struct dt_pfconv *pfc_next;	/* next conversion in hash chain */
64 } dt_pfconv_t;
65 
66 typedef struct dt_pfdict {
67 	dt_pfconv_t **pdi_buckets;	/* hash bucket array */
68 	uint_t pdi_nbuckets;		/* size of hash bucket array */
69 } dt_pfdict_t;
70 
71 typedef struct dt_pfargd {
72 	const char *pfd_prefix;		/* prefix string pointer (or NULL) */
73 	size_t pfd_preflen;		/* length of prefix in bytes */
74 	char pfd_fmt[8];		/* output format name to use */
75 	uint_t pfd_flags;		/* format flags (see below) */
76 	int pfd_width;			/* field width (or 0) */
77 	int pfd_dynwidth;		/* dynamic field width (or 0) */
78 	int pfd_prec;			/* field precision (or 0) */
79 	const dt_pfconv_t *pfd_conv;	/* conversion specification */
80 	const dtrace_recdesc_t *pfd_rec; /* pointer to current record */
81 	struct dt_pfargd *pfd_next;	/* pointer to next arg descriptor */
82 } dt_pfargd_t;
83 
84 #define	DT_PFCONV_ALT		0x0001	/* alternate print format (%#) */
85 #define	DT_PFCONV_ZPAD		0x0002	/* zero-pad integer field (%0) */
86 #define	DT_PFCONV_LEFT		0x0004	/* left-align field (%-) */
87 #define	DT_PFCONV_SPOS		0x0008	/* sign positive values (%+) */
88 #define	DT_PFCONV_DYNWIDTH	0x0010	/* dynamic width (%*.) */
89 #define	DT_PFCONV_DYNPREC	0x0020	/* dynamic precision (%.*) */
90 #define	DT_PFCONV_GROUP		0x0040	/* group thousands (%') */
91 #define	DT_PFCONV_SPACE		0x0080	/* insert leading space (% ) */
92 #define	DT_PFCONV_AGG		0x0100	/* use aggregation result (%@) */
93 #define	DT_PFCONV_SIGNED	0x0200	/* arg is a signed integer */
94 
95 typedef struct dt_pfargv {
96 	dtrace_hdl_t *pfv_dtp;		/* libdtrace client handle */
97 	char *pfv_format;		/* format string pointer */
98 	dt_pfargd_t *pfv_argv;		/* list of argument descriptors */
99 	uint_t pfv_argc;		/* number of argument descriptors */
100 	uint_t pfv_flags;		/* flags used for validation */
101 } dt_pfargv_t;
102 
103 typedef struct dt_pfwalk {
104 	const dt_pfargv_t *pfw_argv;	/* argument description list */
105 	uint_t pfw_aid;			/* aggregation variable identifier */
106 	FILE *pfw_fp;			/* file pointer to use for output */
107 	int pfw_err;			/* error status code */
108 } dt_pfwalk_t;
109 
110 extern int dt_pfdict_create(dtrace_hdl_t *);
111 extern void dt_pfdict_destroy(dtrace_hdl_t *);
112 
113 extern dt_pfargv_t *dt_printf_create(dtrace_hdl_t *, const char *);
114 extern void dt_printf_destroy(dt_pfargv_t *);
115 
116 #define	DT_PRINTF_EXACTLEN	0x1	/* do not permit extra arguments */
117 #define	DT_PRINTF_AGGREGATION	0x2	/* enable aggregation conversion */
118 
119 extern void dt_printf_validate(dt_pfargv_t *, uint_t,
120     struct dt_ident *, int, dtrace_actkind_t, struct dt_node *);
121 
122 extern void dt_printa_validate(struct dt_node *, struct dt_node *);
123 
124 extern int dt_print_stack(dtrace_hdl_t *, FILE *,
125     const char *, caddr_t, int, int);
126 extern int dt_print_ustack(dtrace_hdl_t *, FILE *,
127     const char *, caddr_t, uint64_t);
128 extern int dt_print_mod(dtrace_hdl_t *, FILE *, const char *, caddr_t);
129 extern int dt_print_umod(dtrace_hdl_t *, FILE *, const char *, caddr_t);
130 
131 #ifdef	__cplusplus
132 }
133 #endif
134 
135 #endif	/* _DT_PRINTF_H */
136