blob: 34bf6d6bf6e8ff40d1ddc112242e7b5142b17f35 [file] [log] [blame]
Thomas Gleixner457c8992019-05-19 13:08:55 +01001// SPDX-License-Identifier: GPL-2.0-only
Helge Deller548f1172009-02-06 21:50:39 +01002/*
3 * Stack trace management functions
4 *
5 * Copyright (C) 2009 Helge Deller <deller@gmx.de>
6 * based on arch/x86/kernel/stacktrace.c by Ingo Molnar <mingo@redhat.com>
7 * and parisc unwind functions by Randolph Chung <tausq@debian.org>
8 *
9 * TODO: Userspace stacktrace (CONFIG_USER_STACKTRACE_SUPPORT)
10 */
11#include <linux/module.h>
12#include <linux/stacktrace.h>
13
14#include <asm/unwind.h>
15
16static void dump_trace(struct task_struct *task, struct stack_trace *trace)
17{
18 struct unwind_frame_info info;
19
Helge Deller9e0d5c42018-08-17 17:00:08 +020020 unwind_frame_init_task(&info, task, NULL);
Helge Deller548f1172009-02-06 21:50:39 +010021
22 /* unwind stack and save entries in stack_trace struct */
23 trace->nr_entries = 0;
24 while (trace->nr_entries < trace->max_entries) {
25 if (unwind_once(&info) < 0 || info.ip == 0)
26 break;
27
28 if (__kernel_text_address(info.ip))
29 trace->entries[trace->nr_entries++] = info.ip;
30 }
31}
32
Helge Deller548f1172009-02-06 21:50:39 +010033/*
34 * Save stack-backtrace addresses into a stack_trace buffer.
35 */
36void save_stack_trace(struct stack_trace *trace)
37{
38 dump_trace(current, trace);
Helge Deller548f1172009-02-06 21:50:39 +010039}
40EXPORT_SYMBOL_GPL(save_stack_trace);
41
42void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
43{
44 dump_trace(tsk, trace);
Helge Deller548f1172009-02-06 21:50:39 +010045}
46EXPORT_SYMBOL_GPL(save_stack_trace_tsk);