xref: /freebsd/cddl/contrib/opensolaris/lib/libdtrace/common/dt_printf.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
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  * Copyright 2023 Domagoj Stolfa. All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #ifndef	_DT_PRINTF_H
29 #define	_DT_PRINTF_H
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include <sys/types.h>
34 #include <libctf.h>
35 #include <dtrace.h>
36 #include <stdio.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 struct dt_node;
43 struct dt_ident;
44 
45 struct dt_pfconv;
46 struct dt_pfargv;
47 struct dt_pfargd;
48 
49 typedef int dt_pfcheck_f(struct dt_pfargv *,
50     struct dt_pfargd *, struct dt_node *);
51 typedef int dt_pfprint_f(dtrace_hdl_t *, FILE *, const char *,
52     const struct dt_pfargd *, const void *, size_t, uint64_t);
53 
54 typedef struct dt_pfconv {
55 	const char *pfc_name;		/* string name of input conversion */
56 	const char *pfc_ofmt;		/* string name of output conversion */
57 	const char *pfc_tstr;		/* string name for conversion type */
58 	dt_pfcheck_f *pfc_check;	/* function to use for type checking */
59 	dt_pfprint_f *pfc_print;	/* function to use for formatting */
60 	ctf_file_t *pfc_cctfp;		/* CTF container for "C" defn of type */
61 	ctf_id_t pfc_ctype;		/* CTF type ID for "C" defn of type */
62 	ctf_file_t *pfc_dctfp;		/* CTF container for "D" defn of type */
63 	ctf_id_t pfc_dtype;		/* CTF type ID for "D" defn of type */
64 	struct dt_pfconv *pfc_next;	/* next conversion in hash chain */
65 } dt_pfconv_t;
66 
67 typedef struct dt_pfdict {
68 	dt_pfconv_t **pdi_buckets;	/* hash bucket array */
69 	uint_t pdi_nbuckets;		/* size of hash bucket array */
70 } dt_pfdict_t;
71 
72 typedef struct dt_pfargd {
73 	const char *pfd_prefix;		/* prefix string pointer (or NULL) */
74 	size_t pfd_preflen;		/* length of prefix in bytes */
75 	char pfd_fmt[8];		/* output format name to use */
76 	uint_t pfd_flags;		/* format flags (see below) */
77 	int pfd_width;			/* field width (or 0) */
78 	int pfd_dynwidth;		/* dynamic field width (or 0) */
79 	int pfd_prec;			/* field precision (or 0) */
80 	const dt_pfconv_t *pfd_conv;	/* conversion specification */
81 	const dtrace_recdesc_t *pfd_rec; /* pointer to current record */
82 	struct dt_pfargd *pfd_next;	/* pointer to next arg descriptor */
83 } dt_pfargd_t;
84 
85 #define	DT_PFCONV_ALT		0x0001	/* alternate print format (%#) */
86 #define	DT_PFCONV_ZPAD		0x0002	/* zero-pad integer field (%0) */
87 #define	DT_PFCONV_LEFT		0x0004	/* left-align field (%-) */
88 #define	DT_PFCONV_SPOS		0x0008	/* sign positive values (%+) */
89 #define	DT_PFCONV_DYNWIDTH	0x0010	/* dynamic width (%*.) */
90 #define	DT_PFCONV_DYNPREC	0x0020	/* dynamic precision (%.*) */
91 #define	DT_PFCONV_GROUP		0x0040	/* group thousands (%') */
92 #define	DT_PFCONV_SPACE		0x0080	/* insert leading space (% ) */
93 #define	DT_PFCONV_AGG		0x0100	/* use aggregation result (%@) */
94 #define	DT_PFCONV_SIGNED	0x0200	/* arg is a signed integer */
95 
96 typedef struct dt_pfargv {
97 	dtrace_hdl_t *pfv_dtp;		/* libdtrace client handle */
98 	char *pfv_format;		/* format string pointer */
99 	dt_pfargd_t *pfv_argv;		/* list of argument descriptors */
100 	uint_t pfv_argc;		/* number of argument descriptors */
101 	uint_t pfv_flags;		/* flags used for validation */
102 } dt_pfargv_t;
103 
104 typedef struct dt_pfwalk {
105 	const dt_pfargv_t *pfw_argv;	/* argument description list */
106 	uint_t pfw_aid;			/* aggregation variable identifier */
107 	FILE *pfw_fp;			/* file pointer to use for output */
108 	int pfw_err;			/* error status code */
109 } dt_pfwalk_t;
110 
111 extern int dt_pfdict_create(dtrace_hdl_t *);
112 extern void dt_pfdict_destroy(dtrace_hdl_t *);
113 
114 extern dt_pfargv_t *dt_printf_create(dtrace_hdl_t *, const char *);
115 extern void dt_printf_destroy(dt_pfargv_t *);
116 
117 #define	DT_PRINTF_EXACTLEN	0x1	/* do not permit extra arguments */
118 #define	DT_PRINTF_AGGREGATION	0x2	/* enable aggregation conversion */
119 
120 extern void dt_printf_validate(dt_pfargv_t *, uint_t,
121     struct dt_ident *, int, dtrace_actkind_t, struct dt_node *);
122 
123 extern void dt_printa_validate(struct dt_node *, struct dt_node *);
124 
125 extern int dt_print_stack(dtrace_hdl_t *, FILE *,
126     const char *, caddr_t, int, int);
127 extern int dt_print_ustack(dtrace_hdl_t *, FILE *,
128     const char *, caddr_t, uint64_t);
129 extern int dt_print_mod(dtrace_hdl_t *, FILE *, const char *, caddr_t);
130 extern int dt_print_umod(dtrace_hdl_t *, FILE *, const char *, caddr_t);
131 
132 extern int dt_format_stack(dtrace_hdl_t *, caddr_t, int, int);
133 extern int dt_format_ustack(dtrace_hdl_t *, caddr_t, uint64_t);
134 extern int dt_format_mod(dtrace_hdl_t *, caddr_t);
135 extern int dt_format_umod(dtrace_hdl_t *, caddr_t);
136 
137 #ifdef	__cplusplus
138 }
139 #endif
140 
141 #endif	/* _DT_PRINTF_H */
142