]>
sourceware.org Git - systemtap.git/blob - runtime/stack.c
2 * Stack tracing functions
3 * Copyright (C) 2005, 2006, 2007 Red Hat Inc.
4 * Copyright (C) 2005 Intel Corporation.
6 * This file is part of systemtap, and is free software. You can
7 * redistribute it and/or modify it under the terms of the GNU General
8 * Public License (GPL); either version 2, or (at your option) any
16 * @brief Stack Tracing Functions
19 /** @addtogroup stack Stack Tracing Functions
26 static int _stp_kta(unsigned long addr
);
28 #define MAXBACKTRACE 20
30 #if defined (__x86_64__)
31 #include "stack-x86_64.c"
32 #elif defined (__ia64__)
33 #include "stack-ia64.c"
34 #elif defined (__i386__)
35 #include "stack-i386.c"
36 #elif defined (__powerpc64__)
37 #include "stack-ppc64.c"
38 #elif defined (__s390__) || defined (__s390x__)
39 #include "stack-s390.c"
41 #error "Unsupported architecture"
45 /* our copy of kernel_text_address() */
46 static int _stp_kta(unsigned long addr
)
48 static unsigned long stext
, etext
, sinittext
, einittext
;
53 etext
= _stp_kallsyms_lookup_name("_etext");
54 stext
= _stp_kallsyms_lookup_name("_stext");
55 sinittext
= _stp_kallsyms_lookup_name("_sinittext");
56 einittext
= _stp_kallsyms_lookup_name("_einittext");
59 if (addr
>= stext
&& addr
<= etext
)
62 if (addr
>= sinittext
&& addr
<= einittext
)
68 /** Prints the stack backtrace
69 * @param regs A pointer to the struct pt_regs.
72 void _stp_stack_print(struct pt_regs
*regs
, int verbose
, struct kretprobe_instance
*pi
)
75 /* print the current address */
77 _stp_print("Returning from: ");
78 _stp_symbol_print((unsigned long)_stp_probe_addr_r(pi
));
79 _stp_print("\nReturning to : ");
80 _stp_symbol_print((unsigned long)_stp_ret_addr_r(pi
));
83 _stp_symbol_print (REG_IP(regs
));
85 _stp_print_char('\n');
87 _stp_printf ("%p ", REG_IP(regs
));
88 __stp_stack_print (regs
, verbose
, 0);
91 /** Writes stack backtrace to a string
94 * @param regs A pointer to the struct pt_regs.
97 void _stp_stack_snprint (char *str
, int size
, struct pt_regs
*regs
, int verbose
, struct kretprobe_instance
*pi
)
99 /* To get a string, we use a simple trick. First flush the print buffer, */
100 /* then call _stp_stack_print, then copy the result into the output string */
101 /* and clear the print buffer. */
102 _stp_pbuf
*pb
= per_cpu_ptr(Stp_pbuf
, smp_processor_id());
104 _stp_stack_print(regs
, verbose
, pi
);
105 strlcpy(str
, pb
->buf
, size
< pb
->len
? size
: pb
->len
);
110 /** Prints the user stack backtrace
112 * @returns Same string as was input with trace info appended,
113 * @note Currently limited to a depth of two. Works from jprobes and kprobes.
116 void _stp_ustack_print (char *str
)
118 struct pt_regs
*nregs
= ((struct pt_regs
*) (THREAD_SIZE
+ (unsigned long) current
->thread_info
)) - 1;
119 _stp_printf ("%p : [user]\n", REG_IP(nregs
));
121 _stp_printf ("%p : [user]\n", *(unsigned long *)REG_SP(nregs
));
126 #endif /* _STACK_C_ */
This page took 0.045807 seconds and 6 git commands to generate.