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 2004 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_pfargd; 46 47 typedef int dt_pfcheck_f(struct dt_pfargd *, struct dt_node *); 48 typedef int dt_pfprint_f(dtrace_hdl_t *, FILE *, const char *, 49 const struct dt_pfargd *, const void *, size_t, uint64_t); 50 51 typedef struct dt_pfconv { 52 const char *pfc_name; /* string name of input conversion */ 53 const char *pfc_ofmt; /* string name of output conversion */ 54 const char *pfc_tstr; /* string name for conversion type */ 55 dt_pfcheck_f *pfc_check; /* function to use for type checking */ 56 dt_pfprint_f *pfc_print; /* function to use for formatting */ 57 ctf_file_t *pfc_cctfp; /* CTF container for "C" defn of type */ 58 ctf_id_t pfc_ctype; /* CTF type ID for "C" defn of type */ 59 ctf_file_t *pfc_dctfp; /* CTF container for "D" defn of type */ 60 ctf_id_t pfc_dtype; /* CTF type ID for "D" defn of type */ 61 struct dt_pfconv *pfc_next; /* next conversion in hash chain */ 62 } dt_pfconv_t; 63 64 typedef struct dt_pfdict { 65 dt_pfconv_t **pdi_buckets; /* hash bucket array */ 66 uint_t pdi_nbuckets; /* size of hash bucket array */ 67 } dt_pfdict_t; 68 69 typedef struct dt_pfargd { 70 const char *pfd_prefix; /* prefix string pointer (or NULL) */ 71 size_t pfd_preflen; /* length of prefix in bytes */ 72 char pfd_fmt[8]; /* output format name to use */ 73 uint_t pfd_flags; /* format flags (see below) */ 74 int pfd_width; /* field width (or 0) */ 75 int pfd_dynwidth; /* dynamic field width (or 0) */ 76 int pfd_prec; /* field precision (or 0) */ 77 const dt_pfconv_t *pfd_conv; /* conversion specification */ 78 const dtrace_recdesc_t *pfd_rec; /* pointer to current record */ 79 struct dt_pfargd *pfd_next; /* pointer to next arg descriptor */ 80 } dt_pfargd_t; 81 82 #define DT_PFCONV_ALT 0x0001 /* alternate print format (%#) */ 83 #define DT_PFCONV_ZPAD 0x0002 /* zero-pad integer field (%0) */ 84 #define DT_PFCONV_LEFT 0x0004 /* left-align field (%-) */ 85 #define DT_PFCONV_SPOS 0x0008 /* sign positive values (%+) */ 86 #define DT_PFCONV_DYNWIDTH 0x0010 /* dynamic width (%*.) */ 87 #define DT_PFCONV_DYNPREC 0x0020 /* dynamic precision (%.*) */ 88 #define DT_PFCONV_GROUP 0x0040 /* group thousands (%') */ 89 #define DT_PFCONV_SPACE 0x0080 /* insert leading space (% ) */ 90 #define DT_PFCONV_AGG 0x0100 /* use aggregation result (%@) */ 91 #define DT_PFCONV_SIGNED 0x0200 /* arg is a signed integer */ 92 93 typedef struct dt_pfargv { 94 char *pfv_format; /* format string pointer */ 95 dt_pfargd_t *pfv_argv; /* list of argument descriptors */ 96 uint_t pfv_argc; /* number of argument descriptors */ 97 uint_t pfv_flags; /* flags used for validation */ 98 } dt_pfargv_t; 99 100 typedef struct dt_pfwalk { 101 dtrace_hdl_t *pfw_dtp; /* libdtrace client handle */ 102 const dt_pfargv_t *pfw_argv; /* argument description list */ 103 uint_t pfw_aid; /* aggregation variable identifier */ 104 FILE *pfw_fp; /* file pointer to use for output */ 105 int pfw_err; /* error status code */ 106 } dt_pfwalk_t; 107 108 extern int dt_pfdict_create(dtrace_hdl_t *); 109 extern void dt_pfdict_destroy(dtrace_hdl_t *); 110 111 extern dt_pfargv_t *dt_printf_create(dtrace_hdl_t *, const char *); 112 extern void dt_printf_destroy(dt_pfargv_t *); 113 114 #define DT_PRINTF_EXACTLEN 0x1 /* do not permit extra arguments */ 115 #define DT_PRINTF_AGGREGATION 0x2 /* enable aggregation conversion */ 116 117 extern void dt_printf_validate(dt_pfargv_t *, uint_t, 118 struct dt_ident *, int, dtrace_actkind_t, struct dt_node *); 119 120 extern int dt_print_stack(dtrace_hdl_t *, FILE *, 121 const char *, caddr_t, int); 122 extern int dt_print_ustack(dtrace_hdl_t *, FILE *, 123 const char *, caddr_t, uint64_t); 124 125 #ifdef __cplusplus 126 } 127 #endif 128 129 #endif /* _DT_PRINTF_H */ 130