]> sourceware.org Git - systemtap.git/blob - runtime/stack.c
9c01d65c25bb080be2e3b06248c368796dd173ac
[systemtap.git] / runtime / stack.c
1 /* -*- linux-c -*-
2 * Stack tracing functions
3 * Copyright (C) 2005, 2006, 2007 Red Hat Inc.
4 * Copyright (C) 2005 Intel Corporation.
5 *
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
9 * later version.
10 */
11
12 #ifndef _STACK_C_
13 #define _STACK_C_
14
15 /** @file stack.c
16 * @brief Stack Tracing Functions
17 */
18
19 /** @addtogroup stack Stack Tracing Functions
20 *
21 * @{
22 */
23
24 #include "sym.c"
25 #include "regs.h"
26
27 #define MAXBACKTRACE 20
28
29 #if defined (__x86_64__)
30 #include "stack-x86_64.c"
31 #elif defined (__ia64__)
32 #include "stack-ia64.c"
33 #elif defined (__i386__)
34 #include "stack-i386.c"
35 #elif defined (__powerpc64__)
36 #include "stack-ppc64.c"
37 #elif defined (__arm__)
38 #include "stack-arm.c"
39 #elif defined (__s390__) || defined (__s390x__)
40 #include "stack-s390.c"
41 #else
42 #error "Unsupported architecture"
43 #endif
44
45 /** Prints the stack backtrace
46 * @param regs A pointer to the struct pt_regs.
47 */
48
49 void _stp_stack_print(struct pt_regs *regs, int verbose, struct kretprobe_instance *pi)
50 {
51 if (verbose) {
52 /* print the current address */
53 if (pi) {
54 _stp_print("Returning from: ");
55 _stp_symbol_print((unsigned long)_stp_probe_addr_r(pi));
56 _stp_print("\nReturning to : ");
57 _stp_symbol_print((unsigned long)_stp_ret_addr_r(pi));
58 } else {
59 _stp_print_char(' ');
60 _stp_symbol_print (REG_IP(regs));
61 }
62 _stp_print_char('\n');
63 } else
64 _stp_printf ("%p ", (int64_t)REG_IP(regs));
65 __stp_stack_print (regs, verbose, 0);
66 }
67
68 /** Writes stack backtrace to a string
69 *
70 * @param str string
71 * @param regs A pointer to the struct pt_regs.
72 * @returns void
73 */
74 void _stp_stack_snprint (char *str, int size, struct pt_regs *regs, int verbose, struct kretprobe_instance *pi)
75 {
76 /* To get a string, we use a simple trick. First flush the print buffer, */
77 /* then call _stp_stack_print, then copy the result into the output string */
78 /* and clear the print buffer. */
79 _stp_pbuf *pb = per_cpu_ptr(Stp_pbuf, smp_processor_id());
80 _stp_print_flush();
81 _stp_stack_print(regs, verbose, pi);
82 strlcpy(str, pb->buf, size < (int)pb->len ? size : (int)pb->len);
83 pb->len = 0;
84 }
85
86
87 /** Prints the user stack backtrace
88 * @param str string
89 * @returns Same string as was input with trace info appended,
90 * @note Currently limited to a depth of two. Works from jprobes and kprobes.
91 */
92 #if 0
93 void _stp_ustack_print (char *str)
94 {
95 struct pt_regs *nregs = ((struct pt_regs *) (THREAD_SIZE + (unsigned long) current->thread_info)) - 1;
96 _stp_printf ("%p : [user]\n", (int64_t)REG_IP(nregs));
97 if (REG_SP(nregs))
98 _stp_printf ("%p : [user]\n", (int64_t)(*(unsigned long *)REG_SP(nregs)));
99 }
100 #endif /* 0 */
101
102 /** @} */
103 #endif /* _STACK_C_ */
This page took 0.041718 seconds and 4 git commands to generate.