]> sourceware.org Git - systemtap.git/blob - runtime/stack-x86_64.c
2007-01-31 Martin Hunt <hunt@redhat.com>
[systemtap.git] / runtime / stack-x86_64.c
1 /* -*- linux-c -*-
2 * x86_64 stack tracing functions
3 * Copyright (C) 2005, 2006, 2007 Red Hat Inc.
4 *
5 * This file is part of systemtap, and is free software. You can
6 * redistribute it and/or modify it under the terms of the GNU General
7 * Public License (GPL); either version 2, or (at your option) any
8 * later version.
9 */
10 #ifdef CONFIG_STACK_UNWIND
11 #include <linux/unwind.h>
12
13 static inline int _stp_valid_stack_ptr(struct unwind_frame_info *info)
14 {
15 unsigned long context = (unsigned long)UNW_SP(info) & ~(THREAD_SIZE - 1);
16 unsigned long p = UNW_PC(info);
17 return p > context && p < context + THREAD_SIZE - 3;
18 }
19
20 static int _stp_show_trace_unwind(struct unwind_frame_info *info, int verbose)
21 {
22 int n = 0;
23
24 while (unwind(info) == 0 && UNW_PC(info)) {
25 if (_stp_valid_stack_ptr(info))
26 break;
27 n++;
28 if (verbose) {
29 _stp_print_char(' ');
30 _stp_symbol_print (UNW_PC(info));
31 _stp_print_char('\n');
32 } else
33 _stp_printf ("%p ", UNW_PC(info));
34 if (arch_unw_user_mode(info))
35 break;
36 }
37 return n;
38 }
39 #endif /* CONFIG_STACK_UNWIND */
40
41 static void __stp_stack_print (struct pt_regs *regs, int verbose, int levels)
42 {
43 unsigned long *stack = (unsigned long *)&REG_SP(regs);
44 unsigned long addr;
45 int uw_ret = 0;
46
47 #ifdef CONFIG_STACK_UNWIND
48 struct unwind_frame_info info;
49 if (unwind_init_frame_info(&info, current, regs) == 0)
50 uw_ret = _stp_show_trace_unwind(&info, verbose);
51 stack = (void *)UNW_SP(&info);
52 #endif
53
54 if (uw_ret == 0)
55 _stp_print("Inexact backtrace:\n");
56
57 while ((long)stack & (THREAD_SIZE-1)) {
58 addr = *stack++;
59 if (_stp_kta(addr)) {
60 if (verbose) {
61 if (uw_ret) {
62 uw_ret = 0;
63 _stp_print("Leftover inexact backtrace:\n");
64 }
65 _stp_print_char(' ');
66 _stp_symbol_print(addr);
67 _stp_print_char('\n');
68 } else
69 _stp_printf("%p ", (void *)addr);
70 }
71 }
72 }
This page took 0.041005 seconds and 6 git commands to generate.