17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23a1b5e537Sbmc  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_DT_PRINTF_H
287c478bd9Sstevel@tonic-gate #define	_DT_PRINTF_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <sys/types.h>
317c478bd9Sstevel@tonic-gate #include <libctf.h>
327c478bd9Sstevel@tonic-gate #include <dtrace.h>
337c478bd9Sstevel@tonic-gate #include <stdio.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
367c478bd9Sstevel@tonic-gate extern "C" {
377c478bd9Sstevel@tonic-gate #endif
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate struct dt_node;
407c478bd9Sstevel@tonic-gate struct dt_ident;
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate struct dt_pfconv;
43a1b5e537Sbmc struct dt_pfargv;
447c478bd9Sstevel@tonic-gate struct dt_pfargd;
457c478bd9Sstevel@tonic-gate 
46a1b5e537Sbmc typedef int dt_pfcheck_f(struct dt_pfargv *,
47a1b5e537Sbmc     struct dt_pfargd *, struct dt_node *);
487c478bd9Sstevel@tonic-gate typedef int dt_pfprint_f(dtrace_hdl_t *, FILE *, const char *,
497c478bd9Sstevel@tonic-gate     const struct dt_pfargd *, const void *, size_t, uint64_t);
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate typedef struct dt_pfconv {
527c478bd9Sstevel@tonic-gate 	const char *pfc_name;		/* string name of input conversion */
537c478bd9Sstevel@tonic-gate 	const char *pfc_ofmt;		/* string name of output conversion */
547c478bd9Sstevel@tonic-gate 	const char *pfc_tstr;		/* string name for conversion type */
557c478bd9Sstevel@tonic-gate 	dt_pfcheck_f *pfc_check;	/* function to use for type checking */
567c478bd9Sstevel@tonic-gate 	dt_pfprint_f *pfc_print;	/* function to use for formatting */
577c478bd9Sstevel@tonic-gate 	ctf_file_t *pfc_cctfp;		/* CTF container for "C" defn of type */
587c478bd9Sstevel@tonic-gate 	ctf_id_t pfc_ctype;		/* CTF type ID for "C" defn of type */
597c478bd9Sstevel@tonic-gate 	ctf_file_t *pfc_dctfp;		/* CTF container for "D" defn of type */
607c478bd9Sstevel@tonic-gate 	ctf_id_t pfc_dtype;		/* CTF type ID for "D" defn of type */
617c478bd9Sstevel@tonic-gate 	struct dt_pfconv *pfc_next;	/* next conversion in hash chain */
627c478bd9Sstevel@tonic-gate } dt_pfconv_t;
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate typedef struct dt_pfdict {
657c478bd9Sstevel@tonic-gate 	dt_pfconv_t **pdi_buckets;	/* hash bucket array */
667c478bd9Sstevel@tonic-gate 	uint_t pdi_nbuckets;		/* size of hash bucket array */
677c478bd9Sstevel@tonic-gate } dt_pfdict_t;
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate typedef struct dt_pfargd {
707c478bd9Sstevel@tonic-gate 	const char *pfd_prefix;		/* prefix string pointer (or NULL) */
717c478bd9Sstevel@tonic-gate 	size_t pfd_preflen;		/* length of prefix in bytes */
727c478bd9Sstevel@tonic-gate 	char pfd_fmt[8];		/* output format name to use */
737c478bd9Sstevel@tonic-gate 	uint_t pfd_flags;		/* format flags (see below) */
747c478bd9Sstevel@tonic-gate 	int pfd_width;			/* field width (or 0) */
757c478bd9Sstevel@tonic-gate 	int pfd_dynwidth;		/* dynamic field width (or 0) */
767c478bd9Sstevel@tonic-gate 	int pfd_prec;			/* field precision (or 0) */
777c478bd9Sstevel@tonic-gate 	const dt_pfconv_t *pfd_conv;	/* conversion specification */
787c478bd9Sstevel@tonic-gate 	const dtrace_recdesc_t *pfd_rec; /* pointer to current record */
797c478bd9Sstevel@tonic-gate 	struct dt_pfargd *pfd_next;	/* pointer to next arg descriptor */
807c478bd9Sstevel@tonic-gate } dt_pfargd_t;
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate #define	DT_PFCONV_ALT		0x0001	/* alternate print format (%#) */
837c478bd9Sstevel@tonic-gate #define	DT_PFCONV_ZPAD		0x0002	/* zero-pad integer field (%0) */
847c478bd9Sstevel@tonic-gate #define	DT_PFCONV_LEFT		0x0004	/* left-align field (%-) */
857c478bd9Sstevel@tonic-gate #define	DT_PFCONV_SPOS		0x0008	/* sign positive values (%+) */
867c478bd9Sstevel@tonic-gate #define	DT_PFCONV_DYNWIDTH	0x0010	/* dynamic width (%*.) */
877c478bd9Sstevel@tonic-gate #define	DT_PFCONV_DYNPREC	0x0020	/* dynamic precision (%.*) */
887c478bd9Sstevel@tonic-gate #define	DT_PFCONV_GROUP		0x0040	/* group thousands (%') */
897c478bd9Sstevel@tonic-gate #define	DT_PFCONV_SPACE		0x0080	/* insert leading space (% ) */
907c478bd9Sstevel@tonic-gate #define	DT_PFCONV_AGG		0x0100	/* use aggregation result (%@) */
917c478bd9Sstevel@tonic-gate #define	DT_PFCONV_SIGNED	0x0200	/* arg is a signed integer */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate typedef struct dt_pfargv {
94a1b5e537Sbmc 	dtrace_hdl_t *pfv_dtp;		/* libdtrace client handle */
957c478bd9Sstevel@tonic-gate 	char *pfv_format;		/* format string pointer */
967c478bd9Sstevel@tonic-gate 	dt_pfargd_t *pfv_argv;		/* list of argument descriptors */
977c478bd9Sstevel@tonic-gate 	uint_t pfv_argc;		/* number of argument descriptors */
987c478bd9Sstevel@tonic-gate 	uint_t pfv_flags;		/* flags used for validation */
997c478bd9Sstevel@tonic-gate } dt_pfargv_t;
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate typedef struct dt_pfwalk {
1027c478bd9Sstevel@tonic-gate 	const dt_pfargv_t *pfw_argv;	/* argument description list */
1037c478bd9Sstevel@tonic-gate 	uint_t pfw_aid;			/* aggregation variable identifier */
1047c478bd9Sstevel@tonic-gate 	FILE *pfw_fp;			/* file pointer to use for output */
1057c478bd9Sstevel@tonic-gate 	int pfw_err;			/* error status code */
1067c478bd9Sstevel@tonic-gate } dt_pfwalk_t;
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate extern int dt_pfdict_create(dtrace_hdl_t *);
1097c478bd9Sstevel@tonic-gate extern void dt_pfdict_destroy(dtrace_hdl_t *);
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate extern dt_pfargv_t *dt_printf_create(dtrace_hdl_t *, const char *);
1127c478bd9Sstevel@tonic-gate extern void dt_printf_destroy(dt_pfargv_t *);
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #define	DT_PRINTF_EXACTLEN	0x1	/* do not permit extra arguments */
1157c478bd9Sstevel@tonic-gate #define	DT_PRINTF_AGGREGATION	0x2	/* enable aggregation conversion */
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate extern void dt_printf_validate(dt_pfargv_t *, uint_t,
1187c478bd9Sstevel@tonic-gate     struct dt_ident *, int, dtrace_actkind_t, struct dt_node *);
1197c478bd9Sstevel@tonic-gate 
120*30ef842dSbmc extern void dt_printa_validate(struct dt_node *, struct dt_node *);
121*30ef842dSbmc 
1227c478bd9Sstevel@tonic-gate extern int dt_print_stack(dtrace_hdl_t *, FILE *,
123a1b5e537Sbmc     const char *, caddr_t, int, int);
1247c478bd9Sstevel@tonic-gate extern int dt_print_ustack(dtrace_hdl_t *, FILE *,
1257c478bd9Sstevel@tonic-gate     const char *, caddr_t, uint64_t);
126a1b5e537Sbmc extern int dt_print_mod(dtrace_hdl_t *, FILE *, const char *, caddr_t);
127a1b5e537Sbmc extern int dt_print_umod(dtrace_hdl_t *, FILE *, const char *, caddr_t);
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1307c478bd9Sstevel@tonic-gate }
1317c478bd9Sstevel@tonic-gate #endif
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate #endif	/* _DT_PRINTF_H */
134