Deleted Added
sdiff udiff text old ( 249573 ) new ( 250812 )
full compact
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 (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#include <string.h>
27#include <strings.h>
28#include <dt_impl.h>
29
30static const struct {
31 int err;
32 const char *msg;
33} _dt_errlist[] = {
34 { EDT_VERSION, "Client requested version newer than library" },
35 { EDT_VERSINVAL, "Version is not properly formatted or is too large" },
36 { EDT_VERSUNDEF, "Requested version is not supported by compiler" },
37 { EDT_VERSREDUCED, "Requested version conflicts with earlier setting" },
38 { EDT_CTF, "Unexpected libctf error" },
39 { EDT_COMPILER, "Error in D program compilation" },
40 { EDT_NOREG, "Insufficient registers to generate code" },
41 { EDT_NOTUPREG, "Insufficient tuple registers to generate code" },
42 { EDT_NOMEM, "Memory allocation failure" },
43 { EDT_INT2BIG, "Integer constant table limit exceeded" },
44 { EDT_STR2BIG, "String constant table limit exceeded" },
45 { EDT_NOMOD, "Unknown module name" },
46 { EDT_NOPROV, "Unknown provider name" },
47 { EDT_NOPROBE, "No probe matches description" },
48 { EDT_NOSYM, "Unknown symbol name" },
49 { EDT_NOSYMADDR, "No symbol corresponds to address" },
50 { EDT_NOTYPE, "Unknown type name" },
51 { EDT_NOVAR, "Unknown variable name" },
52 { EDT_NOAGG, "Unknown aggregation name" },
53 { EDT_BADSCOPE, "Improper use of scoping operator in type name" },
54 { EDT_BADSPEC, "Overspecified probe description" },
55 { EDT_BADSPCV, "Undefined macro variable in probe description" },
56 { EDT_BADID, "Unknown probe identifier" },
57 { EDT_NOTLOADED, "Module is no longer loaded" },
58 { EDT_NOCTF, "Module does not contain any CTF data" },
59 { EDT_DATAMODEL, "Module and program data models do not match" },
60 { EDT_DIFVERS, "Library uses newer DIF version than kernel" },
61 { EDT_BADAGG, "Unknown aggregating action" },
62 { EDT_FIO, "Error occurred while reading from input stream" },
63 { EDT_DIFINVAL, "DIF program content is invalid" },
64 { EDT_DIFSIZE, "DIF program exceeds maximum program size" },
65 { EDT_DIFFAULT, "DIF program contains invalid pointer" },
66 { EDT_BADPROBE, "Invalid probe specification" },
67 { EDT_BADPGLOB, "Probe description has too many globbing characters" },
68 { EDT_NOSCOPE, "Declaration scope stack underflow" },
69 { EDT_NODECL, "Declaration stack underflow" },
70 { EDT_DMISMATCH, "Data record list does not match statement" },
71 { EDT_DOFFSET, "Data record offset exceeds buffer boundary" },
72 { EDT_DALIGN, "Data record has inappropriate alignment" },
73 { EDT_BADOPTNAME, "Invalid option name" },
74 { EDT_BADOPTVAL, "Invalid value for specified option" },
75 { EDT_BADOPTCTX, "Option cannot be used from within a D program" },
76 { EDT_CPPFORK, "Failed to fork preprocessor" },
77 { EDT_CPPEXEC, "Failed to exec preprocessor" },
78 { EDT_CPPENT, "Preprocessor not found" },
79 { EDT_CPPERR, "Preprocessor failed to process input program" },
80 { EDT_SYMOFLOW, "Symbol table identifier space exhausted" },
81 { EDT_ACTIVE, "Operation illegal when tracing is active" },
82 { EDT_DESTRUCTIVE, "Destructive actions not allowed" },
83 { EDT_NOANON, "No anonymous tracing state" },
84 { EDT_ISANON, "Can't claim anonymous state and enable probes" },
85 { EDT_ENDTOOBIG, "END enablings exceed size of principal buffer" },
86 { EDT_NOCONV, "Failed to load type for printf conversion" },
87 { EDT_BADCONV, "Incomplete printf conversion" },
88 { EDT_BADERROR, "Invalid library ERROR action" },
89 { EDT_ERRABORT, "Abort due to error" },
90 { EDT_DROPABORT, "Abort due to drop" },
91 { EDT_DIRABORT, "Abort explicitly directed" },
92 { EDT_BADRVAL, "Invalid return value from callback" },
93 { EDT_BADNORMAL, "Invalid normalization" },
94 { EDT_BUFTOOSMALL, "Enabling exceeds size of buffer" },
95 { EDT_BADTRUNC, "Invalid truncation" },
96 { EDT_BUSY, "DTrace cannot be used when kernel debugger is active" },
97 { EDT_ACCESS, "DTrace requires additional privileges" },
98 { EDT_NOENT, "DTrace device not available on system" },
99 { EDT_BRICKED, "Abort due to systemic unresponsiveness" },
100 { EDT_HARDWIRE, "Failed to load language definitions" },
101 { EDT_ELFVERSION, "libelf is out-of-date with respect to libdtrace" },
102 { EDT_NOBUFFERED, "Attempt to buffer output without handler" },
103 { EDT_UNSTABLE, "Description matched an unstable set of probes" },
104 { EDT_BADSETOPT, "Invalid setopt() library action" },
105 { EDT_BADSTACKPC, "Invalid stack program counter size" },
106 { EDT_BADAGGVAR, "Invalid aggregation variable identifier" },
107 { EDT_OVERSION, "Client requested deprecated version of library" },
108 { EDT_ENABLING_ERR, "Failed to enable probe" }
109};
110
111static const int _dt_nerr = sizeof (_dt_errlist) / sizeof (_dt_errlist[0]);
112
113const char *
114dtrace_errmsg(dtrace_hdl_t *dtp, int error)
115{
116 const char *str;
117 int i;
118
119 if (error == EDT_COMPILER && dtp != NULL && dtp->dt_errmsg[0] != '\0')
120 str = dtp->dt_errmsg;
121 else if (error == EDT_CTF && dtp != NULL && dtp->dt_ctferr != 0)
122 str = ctf_errmsg(dtp->dt_ctferr);
123 else if (error >= EDT_BASE && (error - EDT_BASE) < _dt_nerr) {
124 for (i = 0; i < _dt_nerr; i++) {
125 if (_dt_errlist[i].err == error)
126 return (_dt_errlist[i].msg);
127 }
128 str = NULL;
129 } else
130 str = strerror(error);
131
132 return (str ? str : "Unknown error");
133}
134
135int
136dtrace_errno(dtrace_hdl_t *dtp)
137{
138 return (dtp->dt_errno);
139}
140
141#if defined(sun)
142int
143dt_set_errno(dtrace_hdl_t *dtp, int err)
144{
145 dtp->dt_errno = err;
146 return (-1);
147}
148#else
149int
150_dt_set_errno(dtrace_hdl_t *dtp, int err, const char *errfile, int errline)
151{
152 dtp->dt_errno = err;
153 dtp->dt_errfile = errfile;
154 dtp->dt_errline = errline;
155 return (-1);
156}
157
158void dt_get_errloc(dtrace_hdl_t *dtp, const char **p_errfile, int *p_errline)
159{
160 *p_errfile = dtp->dt_errfile;
161 *p_errline = dtp->dt_errline;
162}
163#endif
164
165void
166dt_set_errmsg(dtrace_hdl_t *dtp, const char *errtag, const char *region,
167 const char *filename, int lineno, const char *format, va_list ap)
168{
169 size_t len, n;
170 char *p, *s;
171
172 s = dtp->dt_errmsg;
173 n = sizeof (dtp->dt_errmsg);
174
175 if (errtag != NULL && (yypcb->pcb_cflags & DTRACE_C_ETAGS))
176 (void) snprintf(s, n, "[%s] ", errtag);
177 else
178 s[0] = '\0';
179
180 len = strlen(dtp->dt_errmsg);
181 s = dtp->dt_errmsg + len;
182 n = sizeof (dtp->dt_errmsg) - len;
183
184 if (filename == NULL)
185 filename = dtp->dt_filetag;
186
187 if (filename != NULL)
188 (void) snprintf(s, n, "\"%s\", line %d: ", filename, lineno);
189 else if (lineno != 0)
190 (void) snprintf(s, n, "line %d: ", lineno);
191 else if (region != NULL)
192 (void) snprintf(s, n, "in %s: ", region);
193
194 len = strlen(dtp->dt_errmsg);
195 s = dtp->dt_errmsg + len;
196 n = sizeof (dtp->dt_errmsg) - len;
197 (void) vsnprintf(s, n, format, ap);
198
199 if ((p = strrchr(dtp->dt_errmsg, '\n')) != NULL)
200 *p = '\0'; /* remove trailing \n from message buffer */
201
202 dtp->dt_errtag = errtag;
203}
204
205/*ARGSUSED*/
206const char *
207dtrace_faultstr(dtrace_hdl_t *dtp, int fault)
208{
209 int i;
210
211 static const struct {
212 int code;
213 const char *str;
214 } faults[] = {
215 { DTRACEFLT_BADADDR, "invalid address" },
216 { DTRACEFLT_BADALIGN, "invalid alignment" },
217 { DTRACEFLT_ILLOP, "illegal operation" },
218 { DTRACEFLT_DIVZERO, "divide-by-zero" },
219 { DTRACEFLT_NOSCRATCH, "out of scratch space" },
220 { DTRACEFLT_KPRIV, "invalid kernel access" },
221 { DTRACEFLT_UPRIV, "invalid user access" },
222 { DTRACEFLT_TUPOFLOW, "tuple stack overflow" },
223 { DTRACEFLT_BADSTACK, "bad stack" },
224 { DTRACEFLT_LIBRARY, "library-level fault" },
225 { 0, NULL }
226 };
227
228 for (i = 0; faults[i].str != NULL; i++) {
229 if (faults[i].code == fault)
230 return (faults[i].str);
231 }
232
233 return ("unknown fault");
234}