10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*1677Sdp * Common Development and Distribution License (the "License"). 6*1677Sdp * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*1677Sdp * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <strings.h> 290Sstevel@tonic-gate #include <dt_impl.h> 300Sstevel@tonic-gate 310Sstevel@tonic-gate static const struct { 320Sstevel@tonic-gate int err; 330Sstevel@tonic-gate const char *msg; 340Sstevel@tonic-gate } _dt_errlist[] = { 350Sstevel@tonic-gate { EDT_VERSION, "Client requested version newer than library" }, 360Sstevel@tonic-gate { EDT_VERSINVAL, "Version is not properly formatted or is too large" }, 370Sstevel@tonic-gate { EDT_VERSUNDEF, "Requested version is not supported by compiler" }, 380Sstevel@tonic-gate { EDT_VERSREDUCED, "Requested version conflicts with earlier setting" }, 390Sstevel@tonic-gate { EDT_CTF, "Unexpected libctf error" }, 400Sstevel@tonic-gate { EDT_COMPILER, "Error in D program compilation" }, 410Sstevel@tonic-gate { EDT_NOREG, "Insufficient registers to generate code" }, 420Sstevel@tonic-gate { EDT_NOTUPREG, "Insufficient tuple registers to generate code" }, 430Sstevel@tonic-gate { EDT_NOMEM, "Memory allocation failure" }, 440Sstevel@tonic-gate { EDT_INT2BIG, "Integer constant table limit exceeded" }, 450Sstevel@tonic-gate { EDT_STR2BIG, "String constant table limit exceeded" }, 460Sstevel@tonic-gate { EDT_NOMOD, "Unknown module name" }, 470Sstevel@tonic-gate { EDT_NOPROV, "Unknown provider name" }, 480Sstevel@tonic-gate { EDT_NOPROBE, "No probe matches description" }, 490Sstevel@tonic-gate { EDT_NOSYM, "Unknown symbol name" }, 500Sstevel@tonic-gate { EDT_NOSYMADDR, "No symbol corresponds to address" }, 510Sstevel@tonic-gate { EDT_NOTYPE, "Unknown type name" }, 520Sstevel@tonic-gate { EDT_NOVAR, "Unknown variable name" }, 530Sstevel@tonic-gate { EDT_NOAGG, "Unknown aggregation name" }, 540Sstevel@tonic-gate { EDT_BADSCOPE, "Improper use of scoping operator in type name" }, 550Sstevel@tonic-gate { EDT_BADSPEC, "Overspecified probe description" }, 560Sstevel@tonic-gate { EDT_BADSPCV, "Undefined macro variable in probe description" }, 570Sstevel@tonic-gate { EDT_BADID, "Unknown probe identifier" }, 580Sstevel@tonic-gate { EDT_NOTLOADED, "Module is no longer loaded" }, 590Sstevel@tonic-gate { EDT_NOCTF, "Module does not contain any CTF data" }, 600Sstevel@tonic-gate { EDT_DATAMODEL, "Module and program data models do not match" }, 610Sstevel@tonic-gate { EDT_DIFVERS, "Library uses newer DIF version than kernel" }, 620Sstevel@tonic-gate { EDT_BADAGG, "Unknown aggregating action" }, 630Sstevel@tonic-gate { EDT_FIO, "Error occurred while reading from input stream" }, 640Sstevel@tonic-gate { EDT_DIFINVAL, "DIF program content is invalid" }, 650Sstevel@tonic-gate { EDT_DIFSIZE, "DIF program exceeds maximum program size" }, 660Sstevel@tonic-gate { EDT_DIFFAULT, "DIF program contains invalid pointer" }, 670Sstevel@tonic-gate { EDT_BADPROBE, "Invalid probe specification" }, 680Sstevel@tonic-gate { EDT_BADPGLOB, "Probe description has too many globbing characters" }, 690Sstevel@tonic-gate { EDT_NOSCOPE, "Declaration scope stack underflow" }, 700Sstevel@tonic-gate { EDT_NODECL, "Declaration stack underflow" }, 710Sstevel@tonic-gate { EDT_DMISMATCH, "Data record list does not match statement" }, 720Sstevel@tonic-gate { EDT_DOFFSET, "Data record offset exceeds buffer boundary" }, 730Sstevel@tonic-gate { EDT_DALIGN, "Data record has inappropriate alignment" }, 740Sstevel@tonic-gate { EDT_BADOPTNAME, "Invalid option name" }, 750Sstevel@tonic-gate { EDT_BADOPTVAL, "Invalid value for specified option" }, 760Sstevel@tonic-gate { EDT_BADOPTCTX, "Option cannot be used from within a D program" }, 770Sstevel@tonic-gate { EDT_CPPFORK, "Failed to fork preprocessor" }, 780Sstevel@tonic-gate { EDT_CPPEXEC, "Failed to exec preprocessor" }, 790Sstevel@tonic-gate { EDT_CPPENT, "Preprocessor not found" }, 800Sstevel@tonic-gate { EDT_CPPERR, "Preprocessor failed to process input program" }, 810Sstevel@tonic-gate { EDT_SYMOFLOW, "Symbol table identifier space exhausted" }, 820Sstevel@tonic-gate { EDT_ACTIVE, "Operation illegal when tracing is active" }, 830Sstevel@tonic-gate { EDT_DESTRUCTIVE, "Destructive actions not allowed" }, 840Sstevel@tonic-gate { EDT_NOANON, "No anonymous tracing state" }, 850Sstevel@tonic-gate { EDT_ISANON, "Can't claim anonymous state and enable probes" }, 860Sstevel@tonic-gate { EDT_ENDTOOBIG, "END enablings exceed size of principal buffer" }, 870Sstevel@tonic-gate { EDT_NOCONV, "Failed to load type for printf conversion" }, 880Sstevel@tonic-gate { EDT_BADCONV, "Incomplete printf conversion" }, 890Sstevel@tonic-gate { EDT_BADERROR, "Invalid library ERROR action" }, 900Sstevel@tonic-gate { EDT_ERRABORT, "Abort due to error" }, 910Sstevel@tonic-gate { EDT_DROPABORT, "Abort due to drop" }, 920Sstevel@tonic-gate { EDT_DIRABORT, "Abort explicitly directed" }, 930Sstevel@tonic-gate { EDT_BADRVAL, "Invalid return value from callback" }, 940Sstevel@tonic-gate { EDT_BADNORMAL, "Invalid normalization" }, 950Sstevel@tonic-gate { EDT_BUFTOOSMALL, "Enabling exceeds size of buffer" }, 960Sstevel@tonic-gate { EDT_BADTRUNC, "Invalid truncation" }, 970Sstevel@tonic-gate { EDT_BUSY, "DTrace cannot be used when kernel debugger is active" }, 980Sstevel@tonic-gate { EDT_ACCESS, "DTrace requires additional privileges" }, 99*1677Sdp { EDT_NOENT, "DTrace device not available on system" }, 1000Sstevel@tonic-gate { EDT_BRICKED, "Abort due to systemic unresponsiveness" }, 1010Sstevel@tonic-gate { EDT_HARDWIRE, "Failed to load language definitions" }, 1020Sstevel@tonic-gate { EDT_ELFVERSION, "libelf is out-of-date with respect to libdtrace" }, 1030Sstevel@tonic-gate { EDT_NOBUFFERED, "Attempt to buffer output without handler" }, 1040Sstevel@tonic-gate { EDT_UNSTABLE, "Description matched an unstable set of probes" }, 1051017Sbmc { EDT_BADSETOPT, "Invalid setopt() library action" }, 1061017Sbmc { EDT_BADSTACKPC, "Invalid stack program counter size" }, 1071017Sbmc { EDT_BADAGGVAR, "Invalid aggregation variable identifier" }, 1081017Sbmc { EDT_OVERSION, "Client requested deprecated version of library" } 1090Sstevel@tonic-gate }; 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate static const int _dt_nerr = sizeof (_dt_errlist) / sizeof (_dt_errlist[0]); 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate const char * 1140Sstevel@tonic-gate dtrace_errmsg(dtrace_hdl_t *dtp, int error) 1150Sstevel@tonic-gate { 1160Sstevel@tonic-gate const char *str; 1170Sstevel@tonic-gate int i; 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate if (error == EDT_COMPILER && dtp != NULL && dtp->dt_errmsg[0] != '\0') 1200Sstevel@tonic-gate str = dtp->dt_errmsg; 1210Sstevel@tonic-gate else if (error == EDT_CTF && dtp != NULL && dtp->dt_ctferr != 0) 1220Sstevel@tonic-gate str = ctf_errmsg(dtp->dt_ctferr); 1230Sstevel@tonic-gate else if (error >= EDT_BASE && (error - EDT_BASE) < _dt_nerr) { 1240Sstevel@tonic-gate for (i = 0; i < _dt_nerr; i++) { 1250Sstevel@tonic-gate if (_dt_errlist[i].err == error) 1260Sstevel@tonic-gate return (_dt_errlist[i].msg); 1270Sstevel@tonic-gate } 1280Sstevel@tonic-gate str = NULL; 1290Sstevel@tonic-gate } else 1300Sstevel@tonic-gate str = strerror(error); 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate return (str ? str : "Unknown error"); 1330Sstevel@tonic-gate } 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate int 1360Sstevel@tonic-gate dtrace_errno(dtrace_hdl_t *dtp) 1370Sstevel@tonic-gate { 1380Sstevel@tonic-gate return (dtp->dt_errno); 1390Sstevel@tonic-gate } 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate int 1420Sstevel@tonic-gate dt_set_errno(dtrace_hdl_t *dtp, int err) 1430Sstevel@tonic-gate { 1440Sstevel@tonic-gate dtp->dt_errno = err; 1450Sstevel@tonic-gate return (-1); 1460Sstevel@tonic-gate } 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate void 1490Sstevel@tonic-gate dt_set_errmsg(dtrace_hdl_t *dtp, const char *errtag, const char *region, 1500Sstevel@tonic-gate const char *filename, int lineno, const char *format, va_list ap) 1510Sstevel@tonic-gate { 1520Sstevel@tonic-gate size_t len, n; 1530Sstevel@tonic-gate char *p, *s; 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate s = dtp->dt_errmsg; 1560Sstevel@tonic-gate n = sizeof (dtp->dt_errmsg); 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate if (errtag != NULL && (yypcb->pcb_cflags & DTRACE_C_ETAGS)) 1590Sstevel@tonic-gate (void) snprintf(s, n, "[%s] ", errtag); 1600Sstevel@tonic-gate else 1610Sstevel@tonic-gate s[0] = '\0'; 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate len = strlen(dtp->dt_errmsg); 1640Sstevel@tonic-gate s = dtp->dt_errmsg + len; 1650Sstevel@tonic-gate n = sizeof (dtp->dt_errmsg) - len; 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate if (filename == NULL) 1680Sstevel@tonic-gate filename = dtp->dt_filetag; 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate if (filename != NULL) 1710Sstevel@tonic-gate (void) snprintf(s, n, "\"%s\", line %d: ", filename, lineno); 1720Sstevel@tonic-gate else if (lineno != 0) 1730Sstevel@tonic-gate (void) snprintf(s, n, "line %d: ", lineno); 1740Sstevel@tonic-gate else if (region != NULL) 1750Sstevel@tonic-gate (void) snprintf(s, n, "in %s: ", region); 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate len = strlen(dtp->dt_errmsg); 1780Sstevel@tonic-gate s = dtp->dt_errmsg + len; 1790Sstevel@tonic-gate n = sizeof (dtp->dt_errmsg) - len; 1800Sstevel@tonic-gate (void) vsnprintf(s, n, format, ap); 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate if ((p = strrchr(dtp->dt_errmsg, '\n')) != NULL) 1830Sstevel@tonic-gate *p = '\0'; /* remove trailing \n from message buffer */ 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate dtp->dt_errtag = errtag; 1860Sstevel@tonic-gate } 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate /*ARGSUSED*/ 1890Sstevel@tonic-gate const char * 1900Sstevel@tonic-gate dtrace_faultstr(dtrace_hdl_t *dtp, int fault) 1910Sstevel@tonic-gate { 1920Sstevel@tonic-gate int i; 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate static const struct { 1950Sstevel@tonic-gate int code; 1960Sstevel@tonic-gate const char *str; 1970Sstevel@tonic-gate } faults[] = { 1980Sstevel@tonic-gate { DTRACEFLT_BADADDR, "invalid address" }, 1990Sstevel@tonic-gate { DTRACEFLT_BADALIGN, "invalid alignment" }, 2000Sstevel@tonic-gate { DTRACEFLT_ILLOP, "illegal operation" }, 2010Sstevel@tonic-gate { DTRACEFLT_DIVZERO, "divide-by-zero" }, 2020Sstevel@tonic-gate { DTRACEFLT_NOSCRATCH, "out of scratch space" }, 2030Sstevel@tonic-gate { DTRACEFLT_KPRIV, "invalid kernel access" }, 2040Sstevel@tonic-gate { DTRACEFLT_UPRIV, "invalid user access" }, 2050Sstevel@tonic-gate { DTRACEFLT_TUPOFLOW, "tuple stack overflow" }, 2060Sstevel@tonic-gate { DTRACEFLT_LIBRARY, "library-level fault" }, 2070Sstevel@tonic-gate { 0, NULL } 2080Sstevel@tonic-gate }; 2090Sstevel@tonic-gate 2100Sstevel@tonic-gate for (i = 0; faults[i].str != NULL; i++) { 2110Sstevel@tonic-gate if (faults[i].code == fault) 2120Sstevel@tonic-gate return (faults[i].str); 2130Sstevel@tonic-gate } 2140Sstevel@tonic-gate 2150Sstevel@tonic-gate return ("unknown fault"); 2160Sstevel@tonic-gate } 217