]>
sourceware.org Git - systemtap.git/blob - runtime/stack.c
9c01d65c25bb080be2e3b06248c368796dd173ac
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
27 #define MAXBACKTRACE 20
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"
42 #error "Unsupported architecture"
45 /** Prints the stack backtrace
46 * @param regs A pointer to the struct pt_regs.
49 void _stp_stack_print(struct pt_regs
*regs
, int verbose
, struct kretprobe_instance
*pi
)
52 /* print the current address */
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
));
60 _stp_symbol_print (REG_IP(regs
));
62 _stp_print_char('\n');
64 _stp_printf ("%p ", (int64_t)REG_IP(regs
));
65 __stp_stack_print (regs
, verbose
, 0);
68 /** Writes stack backtrace to a string
71 * @param regs A pointer to the struct pt_regs.
74 void _stp_stack_snprint (char *str
, int size
, struct pt_regs
*regs
, int verbose
, struct kretprobe_instance
*pi
)
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());
81 _stp_stack_print(regs
, verbose
, pi
);
82 strlcpy(str
, pb
->buf
, size
< (int)pb
->len
? size
: (int)pb
->len
);
87 /** Prints the user stack backtrace
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.
93 void _stp_ustack_print (char *str
)
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
));
98 _stp_printf ("%p : [user]\n", (int64_t)(*(unsigned long *)REG_SP(nregs
)));
103 #endif /* _STACK_C_ */
This page took 0.041718 seconds and 4 git commands to generate.