Debian Codegraph @

tapset/linux/ucontext.stp

raw
1 // User context tapset
2 // Copyright (C) 2010-2011 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 * sfunction umodname - Returns the (short) name of the user module.
11 * @addr: User-space address
12 *
13 * Returns the short name of the user space module for the current task that
14 * that the given address is part of. Reports an error when the address
15 * isn't in a (mapped in) module, or the module cannot be found for some reason.
16 */
17 function umodname:string (addr:long) %{
18 /* pure */ /* myproc-unprivileged */ /* pragma:vma */
19 const char *name = NULL;
20 _stp_umod_lookup(STAP_ARG_addr, current, &name, NULL, NULL, NULL);
21 if (!name) {
22 name = "<unknown>";
23 #if STAP_COMPAT_VERSION >= STAP_VERSION(2,3) // PR15044
24 CONTEXT->last_error = "module cannot be found";
25 #endif
26 }
27 strlcpy (STAP_RETVALUE, name, MAXSTRINGLEN);
28 %}
29
30 /**
31 * sfunction ucallers - Return first n elements of user stack backtrace
32 *
33 * @n: number of levels to descend in the stack (not counting the top
34 * level). If n is -1, print the entire stack.
35 *
36 * Description: This function returns a string of the first n hex
37 * addresses from the backtrace of the user stack. Output may be
38 * truncated as per maximum string length (MAXSTRINGLEN).
39 *
40 * Note: To get (full) backtraces for user space applications and shared
41 * shared libraries not mentioned in the current script run stap with
42 * -d /path/to/exe-or-so and/or add --ldd to load all needed unwind data.
43 */
44 function ucallers:string (n:long) {
45 __str = ""; __l = 0
46 for (__i = 0; __i <= n || n == -1; __i++) {
47 __foo = __i > 0 ? " " : ""
48 try {
49 __foo .= sprintf("0x%x", ustack(__i))
50 } catch { /* assume we've hit the end of the stack */
51 if (n == -1) break
52 @__context_unwind_error(n)
53 }
54 // ensure string cuts off cleanly at MAXSTRINGLEN:
55 __l += strlen(__foo); if (__l > @MAXSTRINGLEN) break
56 __str .= __foo
57 }
58 return __str
59 }