1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1994, by Sun Microsytems, Inc. 24*7c478bd9Sstevel@tonic-gate */ 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 27*7c478bd9Sstevel@tonic-gate 28*7c478bd9Sstevel@tonic-gate /* 29*7c478bd9Sstevel@tonic-gate * Includes 30*7c478bd9Sstevel@tonic-gate */ 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #ifndef DEBUG 33*7c478bd9Sstevel@tonic-gate #define NDEBUG 1 34*7c478bd9Sstevel@tonic-gate #endif 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #include <assert.h> 37*7c478bd9Sstevel@tonic-gate #include <limits.h> 38*7c478bd9Sstevel@tonic-gate #include <values.h> 39*7c478bd9Sstevel@tonic-gate #include <stdio.h> 40*7c478bd9Sstevel@tonic-gate #include <string.h> 41*7c478bd9Sstevel@tonic-gate #include <unistd.h> 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate #include <tnf/probe.h> 44*7c478bd9Sstevel@tonic-gate #include "tnf_trace.h" 45*7c478bd9Sstevel@tonic-gate #include "tnf_args.h" 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate /* 48*7c478bd9Sstevel@tonic-gate * tnf_probe_debug() - a debug final function 49*7c478bd9Sstevel@tonic-gate */ 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate #define BUF_LIMIT 1024 52*7c478bd9Sstevel@tonic-gate #define NAME_LIMIT 32 53*7c478bd9Sstevel@tonic-gate #define ATTR_LIMIT 128 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate /* 56*7c478bd9Sstevel@tonic-gate * code coverage comment out 57*7c478bd9Sstevel@tonic-gate * #pragma covcc !instr 58*7c478bd9Sstevel@tonic-gate */ 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate void 61*7c478bd9Sstevel@tonic-gate tnf_probe_debug(tnf_probe_setup_t *set_p) 62*7c478bd9Sstevel@tonic-gate { 63*7c478bd9Sstevel@tonic-gate char tmp_buf[BUF_LIMIT]; 64*7c478bd9Sstevel@tonic-gate char *buf_p; 65*7c478bd9Sstevel@tonic-gate tnf_probe_control_t *probe_p; 66*7c478bd9Sstevel@tonic-gate const char *attr_start, *name_start, *name_end; 67*7c478bd9Sstevel@tonic-gate ulong_t attr_len; 68*7c478bd9Sstevel@tonic-gate int num_args, i, str_len, name_len; 69*7c478bd9Sstevel@tonic-gate void *arg_position; 70*7c478bd9Sstevel@tonic-gate tnf_arg_kind_t arg_type; 71*7c478bd9Sstevel@tonic-gate void *buffer; 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate buf_p = tmp_buf; 74*7c478bd9Sstevel@tonic-gate probe_p = set_p->probe_p; 75*7c478bd9Sstevel@tonic-gate buffer = set_p->buffer_p; 76*7c478bd9Sstevel@tonic-gate 77*7c478bd9Sstevel@tonic-gate /* get the name of the probe */ 78*7c478bd9Sstevel@tonic-gate attr_start = tnf_probe_get_value(probe_p, "name", &attr_len); 79*7c478bd9Sstevel@tonic-gate assert(attr_start); 80*7c478bd9Sstevel@tonic-gate attr_len = (attr_len > (NAME_LIMIT - 1)) ? (NAME_LIMIT - 1) : attr_len; 81*7c478bd9Sstevel@tonic-gate str_len = sprintf(buf_p, "probe %.*s; ", attr_len, attr_start); 82*7c478bd9Sstevel@tonic-gate buf_p += str_len; 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate /* get the sunw%debug attribute */ 85*7c478bd9Sstevel@tonic-gate attr_start = tnf_probe_get_value(probe_p, "sunw%debug", &attr_len); 86*7c478bd9Sstevel@tonic-gate if (attr_start) { 87*7c478bd9Sstevel@tonic-gate attr_len = (attr_len > (ATTR_LIMIT - 1)) ? 88*7c478bd9Sstevel@tonic-gate (ATTR_LIMIT - 1) : attr_len; 89*7c478bd9Sstevel@tonic-gate str_len = sprintf(buf_p, "sunw%%debug \"%.*s\"; ", 90*7c478bd9Sstevel@tonic-gate attr_len, attr_start); 91*7c478bd9Sstevel@tonic-gate buf_p += str_len; 92*7c478bd9Sstevel@tonic-gate } 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate /* number of args ? we are done if there are only standard args */ 95*7c478bd9Sstevel@tonic-gate num_args = tnf_probe_get_num_args(probe_p); 96*7c478bd9Sstevel@tonic-gate if (num_args <= 2) { 97*7c478bd9Sstevel@tonic-gate (void) sprintf(buf_p, "\n"); 98*7c478bd9Sstevel@tonic-gate (void) write(STDERR_FILENO, tmp_buf, strlen(tmp_buf)); 99*7c478bd9Sstevel@tonic-gate return; 100*7c478bd9Sstevel@tonic-gate } 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate /* get the slot names */ 103*7c478bd9Sstevel@tonic-gate name_start = tnf_probe_get_value(probe_p, "slots", &attr_len); 104*7c478bd9Sstevel@tonic-gate assert(name_start); 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate num_args = tnf_probe_get_num_args(probe_p); 107*7c478bd9Sstevel@tonic-gate if (num_args <= 2) 108*7c478bd9Sstevel@tonic-gate return; 109*7c478bd9Sstevel@tonic-gate /* print each of the arguments to the probe */ 110*7c478bd9Sstevel@tonic-gate for (i = 2; i < num_args; i++) { 111*7c478bd9Sstevel@tonic-gate /* find slot names - number of spaces is equal to number of args */ 112*7c478bd9Sstevel@tonic-gate name_end = strchr(name_start, VAL_SEPARATOR); 113*7c478bd9Sstevel@tonic-gate /* LINTED - result is <= string length */ 114*7c478bd9Sstevel@tonic-gate name_len = name_end - name_start; 115*7c478bd9Sstevel@tonic-gate name_len = (name_len > (NAME_LIMIT - 1)) ? 116*7c478bd9Sstevel@tonic-gate (NAME_LIMIT - 1) : name_len; 117*7c478bd9Sstevel@tonic-gate str_len = sprintf(buf_p, "%.*s=", name_len, name_start); 118*7c478bd9Sstevel@tonic-gate buf_p += str_len; 119*7c478bd9Sstevel@tonic-gate name_start = name_end + 1; 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate arg_position = tnf_probe_get_arg_indexed(probe_p, i, buffer); 122*7c478bd9Sstevel@tonic-gate arg_type = tnf_probe_get_type_indexed(probe_p, i); 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate switch (arg_type) { 125*7c478bd9Sstevel@tonic-gate case TNF_UNKNOWN: 126*7c478bd9Sstevel@tonic-gate str_len = sprintf(buf_p, "<unknown>; "); 127*7c478bd9Sstevel@tonic-gate buf_p += str_len; 128*7c478bd9Sstevel@tonic-gate break; 129*7c478bd9Sstevel@tonic-gate case TNF_INT32: 130*7c478bd9Sstevel@tonic-gate str_len = sprintf(buf_p, "%ld; ", 131*7c478bd9Sstevel@tonic-gate tnf_probe_get_int(arg_position)); 132*7c478bd9Sstevel@tonic-gate buf_p += str_len; 133*7c478bd9Sstevel@tonic-gate break; 134*7c478bd9Sstevel@tonic-gate case TNF_UINT32: 135*7c478bd9Sstevel@tonic-gate str_len = sprintf(buf_p, "%lu; ", 136*7c478bd9Sstevel@tonic-gate tnf_probe_get_uint(arg_position)); 137*7c478bd9Sstevel@tonic-gate buf_p += str_len; 138*7c478bd9Sstevel@tonic-gate break; 139*7c478bd9Sstevel@tonic-gate case TNF_INT64: 140*7c478bd9Sstevel@tonic-gate /* LINTED malformed format string */ 141*7c478bd9Sstevel@tonic-gate str_len = sprintf(buf_p, "%lld; ", 142*7c478bd9Sstevel@tonic-gate tnf_probe_get_longlong(arg_position)); 143*7c478bd9Sstevel@tonic-gate buf_p += str_len; 144*7c478bd9Sstevel@tonic-gate break; 145*7c478bd9Sstevel@tonic-gate case TNF_UINT64: 146*7c478bd9Sstevel@tonic-gate /* LINTED malformed format string */ 147*7c478bd9Sstevel@tonic-gate str_len = sprintf(buf_p, "%llu; ", 148*7c478bd9Sstevel@tonic-gate tnf_probe_get_ulonglong(arg_position)); 149*7c478bd9Sstevel@tonic-gate buf_p += str_len; 150*7c478bd9Sstevel@tonic-gate break; 151*7c478bd9Sstevel@tonic-gate case TNF_FLOAT32: 152*7c478bd9Sstevel@tonic-gate str_len = sprintf(buf_p, "%f; ", 153*7c478bd9Sstevel@tonic-gate tnf_probe_get_float(arg_position)); 154*7c478bd9Sstevel@tonic-gate buf_p += str_len; 155*7c478bd9Sstevel@tonic-gate break; 156*7c478bd9Sstevel@tonic-gate case TNF_FLOAT64: 157*7c478bd9Sstevel@tonic-gate str_len = sprintf(buf_p, "%f; ", 158*7c478bd9Sstevel@tonic-gate tnf_probe_get_double(arg_position)); 159*7c478bd9Sstevel@tonic-gate buf_p += str_len; 160*7c478bd9Sstevel@tonic-gate break; 161*7c478bd9Sstevel@tonic-gate case TNF_STRING: 162*7c478bd9Sstevel@tonic-gate attr_start = tnf_probe_get_chars(arg_position); 163*7c478bd9Sstevel@tonic-gate attr_len = strlen(attr_start); 164*7c478bd9Sstevel@tonic-gate attr_len = (attr_len > (ATTR_LIMIT - 1)) ? (ATTR_LIMIT - 1) : 165*7c478bd9Sstevel@tonic-gate attr_len; 166*7c478bd9Sstevel@tonic-gate str_len = sprintf(buf_p, "\"%.*s\"; ", attr_len, attr_start); 167*7c478bd9Sstevel@tonic-gate buf_p += str_len; 168*7c478bd9Sstevel@tonic-gate break; 169*7c478bd9Sstevel@tonic-gate case TNF_ARRAY: 170*7c478bd9Sstevel@tonic-gate /* no break */ 171*7c478bd9Sstevel@tonic-gate case TNF_STRUCT: 172*7c478bd9Sstevel@tonic-gate /* no break */ 173*7c478bd9Sstevel@tonic-gate case TNF_OPAQUE: 174*7c478bd9Sstevel@tonic-gate str_len = sprintf(buf_p, "0x%lx; ", 175*7c478bd9Sstevel@tonic-gate tnf_probe_get_ulong(arg_position)); 176*7c478bd9Sstevel@tonic-gate buf_p += str_len; 177*7c478bd9Sstevel@tonic-gate break; 178*7c478bd9Sstevel@tonic-gate default: 179*7c478bd9Sstevel@tonic-gate str_len = sprintf(buf_p, "<error>; "); 180*7c478bd9Sstevel@tonic-gate buf_p += str_len; 181*7c478bd9Sstevel@tonic-gate break; 182*7c478bd9Sstevel@tonic-gate } 183*7c478bd9Sstevel@tonic-gate } 184*7c478bd9Sstevel@tonic-gate 185*7c478bd9Sstevel@tonic-gate (void) sprintf(buf_p, "\n"); 186*7c478bd9Sstevel@tonic-gate (void) write(STDERR_FILENO, tmp_buf, strlen(tmp_buf)); 187*7c478bd9Sstevel@tonic-gate 188*7c478bd9Sstevel@tonic-gate return; 189*7c478bd9Sstevel@tonic-gate 190*7c478bd9Sstevel@tonic-gate } /* end tnf_probe_debug */ 191*7c478bd9Sstevel@tonic-gate 192*7c478bd9Sstevel@tonic-gate 193*7c478bd9Sstevel@tonic-gate /* 194*7c478bd9Sstevel@tonic-gate * code coverage comment out 195*7c478bd9Sstevel@tonic-gate * #pragma covcc instr 196*7c478bd9Sstevel@tonic-gate */ 197*7c478bd9Sstevel@tonic-gate 198*7c478bd9Sstevel@tonic-gate #ifdef TESTING 199*7c478bd9Sstevel@tonic-gate /* 200*7c478bd9Sstevel@tonic-gate * tnf_probe_empty() - an empty final function 201*7c478bd9Sstevel@tonic-gate */ 202*7c478bd9Sstevel@tonic-gate 203*7c478bd9Sstevel@tonic-gate /*ARGSUSED0*/ 204*7c478bd9Sstevel@tonic-gate void 205*7c478bd9Sstevel@tonic-gate tnf_probe_empty(tnf_probe_setup_t *set_p) 206*7c478bd9Sstevel@tonic-gate { 207*7c478bd9Sstevel@tonic-gate 208*7c478bd9Sstevel@tonic-gate return; 209*7c478bd9Sstevel@tonic-gate 210*7c478bd9Sstevel@tonic-gate } /* end tnf_probe_empty */ 211*7c478bd9Sstevel@tonic-gate #endif 212