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