Debian Codegraph @

tapset/errno.stp

raw
1 // errno tapset
2 // Copyright (C) 2006-2018 Red Hat Inc.
3 //
4 // This file is part of SystemTap, and is free software. You can
5 // redistribute it and/or modify it under the terms of the GNU General
6 // Public License (GPL); either version 2, or (at your option) any
7 // later version.
8
9 %{
10 #define N(a) [a]=#a
11
12 static const char * const errlist[] = {
13 /* from asm-generic/errno-base.h */
14 [1] = "EPERM",
15 [2] = "ENOENT",
16 [3] = "ESRCH",
17 [4] = "EINTR",
18 [5] = "EIO",
19 [6] = "ENXIO",
20 [7] = "E2BIG",
21 [8] = "ENOEXEC",
22 [9] = "EBADF",
23 [10]= "ECHILD",
24 [11]= "EAGAIN",
25 [12]= "ENOMEM",
26 [13]= "EACCES",
27 [14]= "EFAULT",
28 [15]= "ENOTBLK",
29 [16]= "EBUSY",
30 [17]= "EEXIST",
31 [18]= "EXDEV",
32 [19]= "ENODEV",
33 [20]= "ENOTDIR",
34 [21]= "EISDIR",
35 [22]= "EINVAL",
36 [23]= "ENFILE",
37 [24]= "EMFILE",
38 [25]= "ENOTTY",
39 [26]= "ETXTBSY",
40 [27]= "EFBIG",
41 [28]= "ENOSPC",
42 [29]= "ESPIPE",
43 [30]= "EROFS",
44 [31]= "EMLINK",
45 [32]= "EPIPE",
46 [33]= "EDOM",
47 [34]= "ERANGE",
48 /* end of errno-base.h */
49 /* The rest of this is arch-dependent */
50 #ifdef EDEADLK
51 N(EDEADLK),
52 #endif
53 #ifdef ENAMETOOLONG
54 N(ENAMETOOLONG),
55 #endif
56 #ifdef ENOLCK
57 N(ENOLCK),
58 #endif
59 #ifdef ENOSYS
60 N(ENOSYS),
61 #endif
62 #ifdef ENOTEMPTY
63 N(ENOTEMPTY),
64 #endif
65 #ifdef ELOOP
66 N(ELOOP),
67 #endif
68 #ifdef ENOMSG
69 N(ENOMSG),
70 #endif
71 #ifdef EIDRM
72 N(EIDRM),
73 #endif
74 #ifdef ECHRNG
75 N(ECHRNG),
76 #endif
77 #ifdef EL2NSYNC
78 N(EL2NSYNC),
79 #endif
80 #ifdef EL3HLT
81 N(EL3HLT),
82 #endif
83 #ifdef EL3RST
84 N(EL3RST),
85 #endif
86 #ifdef ELNRNG
87 N(ELNRNG),
88 #endif
89 #ifdef EUNATCH
90 N(EUNATCH),
91 #endif
92 #ifdef ENOCSI
93 N(ENOCSI),
94 #endif
95 #ifdef EL2HLT
96 N(EL2HLT),
97 #endif
98 #ifdef EBADE
99 N(EBADE),
100 #endif
101 #ifdef EBADR
102 N(EBADR),
103 #endif
104 #ifdef EXFULL
105 N(EXFULL),
106 #endif
107 #ifdef ENOANO
108 N(ENOANO),
109 #endif
110 #ifdef EBADRQC
111 N(EBADRQC),
112 #endif
113 #ifdef EBADSLT
114 N(EBADSLT),
115 #endif
116 #ifdef EBFONT
117 N(EBFONT),
118 #endif
119 #ifdef ENOSTR
120 N(ENOSTR),
121 #endif
122 #ifdef ENODATA
123 N(ENODATA),
124 #endif
125 #ifdef ETIME
126 N(ETIME),
127 #endif
128 #ifdef ENOSR
129 N(ENOSR),
130 #endif
131 #ifdef ENONET
132 N(ENONET),
133 #endif
134 #ifdef ENOPKG
135 N(ENOPKG),
136 #endif
137 #ifdef EREMOTE
138 N(EREMOTE),
139 #endif
140 #ifdef ENOLINK
141 N(ENOLINK),
142 #endif
143 #ifdef EADV
144 N(EADV),
145 #endif
146 #ifdef ESRMNT
147 N(ESRMNT),
148 #endif
149 #ifdef ECOMM
150 N(ECOMM),
151 #endif
152 #ifdef EPROTO
153 N(EPROTO),
154 #endif
155 #ifdef EMULTIHOP
156 N(EMULTIHOP),
157 #endif
158 #ifdef EDOTDOT
159 N(EDOTDOT),
160 #endif
161 #ifdef EBADMSG
162 N(EBADMSG),
163 #endif
164 #ifdef EOVERFLOW
165 N(EOVERFLOW),
166 #endif
167 #ifdef ENOTUNIQ
168 N(ENOTUNIQ),
169 #endif
170 #ifdef EBADFD
171 N(EBADFD),
172 #endif
173 #ifdef EREMCHG
174 N(EREMCHG),
175 #endif
176 #ifdef ELIBACC
177 N(ELIBACC),
178 #endif
179 #ifdef ELIBBAD
180 N(ELIBBAD),
181 #endif
182 #ifdef ELIBSCN
183 N(ELIBSCN),
184 #endif
185 #ifdef ELIBMAX
186 N(ELIBMAX),
187 #endif
188 #ifdef ELIBEXEC
189 N(ELIBEXEC),
190 #endif
191 #ifdef EILSEQ
192 N(EILSEQ),
193 #endif
194 #ifdef ERESTART
195 N(ERESTART),
196 #endif
197 #ifdef ESTRPIPE
198 N(ESTRPIPE),
199 #endif
200 #ifdef EUSERS
201 N(EUSERS),
202 #endif
203 #ifdef ENOTSOCK
204 N(ENOTSOCK),
205 #endif
206 #ifdef EDESTADDRREQ
207 N(EDESTADDRREQ),
208 #endif
209 #ifdef EMSGSIZE
210 N(EMSGSIZE),
211 #endif
212 #ifdef EPROTOTYPE
213 N(EPROTOTYPE),
214 #endif
215 #ifdef ENOPROTOOPT
216 N(ENOPROTOOPT),
217 #endif
218 #ifdef EPROTONOSUPPORT
219 N(EPROTONOSUPPORT),
220 #endif
221 #ifdef ESOCKTNOSUPPORT
222 N(ESOCKTNOSUPPORT),
223 #endif
224 #ifdef EOPNOTSUPP
225 N(EOPNOTSUPP),
226 #endif
227 #ifdef EPFNOSUPPORT
228 N(EPFNOSUPPORT),
229 #endif
230 #ifdef EAFNOSUPPORT
231 N(EAFNOSUPPORT),
232 #endif
233 #ifdef EADDRINUSE
234 N(EADDRINUSE),
235 #endif
236 #ifdef EADDRNOTAVAIL
237 N(EADDRNOTAVAIL),
238 #endif
239 #ifdef ENETDOWN
240 N(ENETDOWN),
241 #endif
242 #ifdef ENETUNREACH
243 N(ENETUNREACH),
244 #endif
245 #ifdef ENETRESET
246 N(ENETRESET),
247 #endif
248 #ifdef ECONNABORTED
249 N(ECONNABORTED),
250 #endif
251 #ifdef ECONNRESET
252 N(ECONNRESET),
253 #endif
254 #ifdef ENOBUFS
255 N(ENOBUFS),
256 #endif
257 #ifdef EISCONN
258 N(EISCONN),
259 #endif
260 #ifdef ENOTCONN
261 N(ENOTCONN),
262 #endif
263 #ifdef ESHUTDOWN
264 N(ESHUTDOWN),
265 #endif
266 #ifdef ETOOMANYREFS
267 N(ETOOMANYREFS),
268 #endif
269 #ifdef ETIMEDOUT
270 N(ETIMEDOUT),
271 #endif
272 #ifdef ECONNREFUSED
273 N(ECONNREFUSED),
274 #endif
275 #ifdef EHOSTDOWN
276 N(EHOSTDOWN),
277 #endif
278 #ifdef EHOSTUNREACH
279 N(EHOSTUNREACH),
280 #endif
281 #ifdef EALREADY
282 N(EALREADY),
283 #endif
284 #ifdef EINPROGRESS
285 N(EINPROGRESS),
286 #endif
287 #ifdef ESTALE
288 N(ESTALE),
289 #endif
290 #ifdef EUCLEAN
291 N(EUCLEAN),
292 #endif
293 #ifdef ENOTNAM
294 N(ENOTNAM),
295 #endif
296 #ifdef ENAVAIL
297 N(ENAVAIL),
298 #endif
299 #ifdef EISNAM
300 N(EISNAM),
301 #endif
302 #ifdef EREMOTEIO
303 N(EREMOTEIO),
304 #endif
305 #ifdef EDQUOT
306 N(EDQUOT),
307 #endif
308 #ifdef ENOMEDIUM
309 N(ENOMEDIUM),
310 #endif
311 #ifdef EMEDIUMTYPE
312 N(EMEDIUMTYPE),
313 #endif
314 #ifdef ECANCELED
315 N(ECANCELED),
316 #endif
317 #ifdef ENOKEY
318 N(ENOKEY),
319 #endif
320 #ifdef EKEYEXPIRED
321 N(EKEYEXPIRED),
322 #endif
323 #ifdef EKEYREVOKED
324 N(EKEYREVOKED),
325 #endif
326 #ifdef EKEYREJECTED
327 N(EKEYREJECTED),
328 #endif
329 #ifdef EOWNERDEAD
330 N(EOWNERDEAD),
331 #endif
332 #ifdef ENOTRECOVERABLE
333 N(ENOTRECOVERABLE),
334 #endif
335 #if defined (EDEADLOCK) && EDEADLOCK != EDEADLK
336 N(EDEADLOCK),
337 #endif
338 #ifdef E
339 N(EADV),
340 #endif
341 };
342 #undef N
343 static const int Maxerrno = sizeof(errlist)/sizeof(char *);
344 %}
345
346 /**
347 * sfunction errno_str - Symbolic string associated with error code
348 *
349 * @err: The error number received
350 *
351 * Description: This function returns the symbolic string associated
352 * with the giver error code, such as ENOENT for the number 2, or
353 * E#3333 for an out-of-range value such as 3333.
354 */
355 function errno_str:string (err:long) %{ /* pure */
356 long e = STAP_ARG_err;
357 e = (e > 0 ? e : -e);
358 if (e > 0 && e < Maxerrno && errlist[e])
359 strlcpy (STAP_RETVALUE, errlist[e], MAXSTRINGLEN);
360 %}
361
362 function errno_p:long (err:long) %{ /* pure */
363 long e = STAP_ARG_err;
364 e = (e > 0 ? e : -e);
365 if (e > 0 && e < Maxerrno && errlist[e])
366 STAP_RETVALUE = e;
367 else
368 STAP_RETVALUE = 0;
369 %}
370
371 %{
372 static long _stp_returnval(struct pt_regs *regs) {
373 if (regs) {
374 #if defined (STAPCONF_X86_UNIREGS) && (defined (__x86_64__) || defined (__i386__))
375 return regs->ax;
376 #elif defined (__i386__)
377 return regs->eax;
378 #elif defined (__x86_64__)
379 // TODO: Handle -m32 apps.
380 return regs->rax;
381 #elif defined (__powerpc__)
382 return regs->gpr[3];
383 #elif defined (__ia64__)
384 return regs->r8;
385 #elif defined (__sparc64__)
386 return regs->u_regs[UREG_RETPC];
387 #elif defined (__s390x__)
388 return regs->gprs[2];
389 #elif defined (__aarch64__)
390 return regs->regs[0];
391 #elif defined (__arm__)
392 return regs->ARM_r0;
393 #elif defined (__mips__)
394 return regs->regs[2];
395 #else
396 _stp_error("returnval() not defined for this architecture");
397 return 0;
398 #endif
399 }
400
401 _stp_error("_stp_returnval called with 0"); /* non-crashy assert */
402 return 0;}
403 %}
404
405
406 %( systemtap_v <= "4.0" %?
407 %{
408 #define STAP_NEED_CONTEXT_RETURNVAL 1
409 %}
410
411 function set_returnval(val:long) %{
412 CONTEXT->returnval_override = STAP_ARG_val;
413 CONTEXT->returnval_override_p = 1;
414 %}
415 %) /* compatible <= 4.0 */
416
417
418 /* NB: The following function is not STABLE because it depends on varying
419 state in the context. */
420 /**
421 * sfunction returnval - Possible return value of probed function
422 *
423 * Description: Return the value of the register in which function values
424 * are typically returned. Can be used in probes where $return isn't
425 * available. This is only a guess of the actual return value and can be
426 * totally wrong. Normally only used in dwarfless probes.
427 */
428 function returnval:long () %{ /* pure */
429 struct pt_regs *regs;
430 #if STAP_COMPAT_VERSION <= STAP_VERSION(4,0)
431 if (CONTEXT->returnval_override_p)
432 STAP_RETURN(CONTEXT->returnval_override);
433 #endif
434 regs = (CONTEXT->user_mode_p ? CONTEXT->uregs : CONTEXT->kregs);
435 if (regs)
436 STAP_RETURN(_stp_returnval(regs));
437 else
438 STAP_ERROR("returnval() not defined in this context %s", CONTEXT->probe_point);
439 %}
440
441 /**
442 * sfunction returnstr - Formats the return value as a string
443 *
444 * @format: Variable to determine return type base value
445 *
446 * Description: This function is used by the nd_syscall tapset, and
447 * returns a string. Set format equal to 1 for a decimal,
448 * 2 for hex, 3 for octal.
449 *
450 * Note that this function should only be used in dwarfless probes
451 * (i.e. 'kprobe.function("foo")'). Other probes should use
452 * return_str().
453 */
454 function returnstr:string (format:long) %{ /* pure */
455 struct pt_regs *regs;
456 regs = (CONTEXT->user_mode_p ? CONTEXT->uregs : CONTEXT->kregs);
457 if (regs) {
458 long ret = _stp_returnval(regs);
459 if (ret < 0 && ret > -Maxerrno && errlist[-ret])
460 snprintf (STAP_RETVALUE, MAXSTRINGLEN, "%ld (%s)", ret, errlist[-ret]);
461 else if (STAP_ARG_format == 2)
462 snprintf (STAP_RETVALUE, MAXSTRINGLEN, "0x%lx", ret);
463 else if (STAP_ARG_format == 3)
464 snprintf (STAP_RETVALUE, MAXSTRINGLEN, "%#lo", ret);
465 else
466 snprintf (STAP_RETVALUE, MAXSTRINGLEN, "%ld", ret);
467 } else {
468 no_ret:
469 strlcpy(STAP_RETVALUE, "N/A", MAXSTRINGLEN); // XXX: empty string better
470 }
471 %}
472
473 /**
474 * sfunction return_str - Formats the return value as a string
475 *
476 * @format: Variable to determine return type base value
477 * @ret: Return value (typically $return)
478 *
479 * Description: This function is used by the syscall tapset, and
480 * returns a string. Set format equal to 1 for a decimal,
481 * 2 for hex, 3 for octal.
482 *
483 * Note that this function is preferred over returnstr().
484 */
485 function return_str:string(format:long, ret:long)
486 {
487 if (ret < 0 && errno_p(ret))
488 return sprintf("%d (%s)", ret, errno_str(ret))
489
490 if (format == 2)
491 return sprintf("0x%x", ret)
492 else if (format == 3)
493 return sprintf("%#o", ret)
494 else
495 return sprintf("%d", ret)
496 }