blob: 894c8d303cda7c753b000bb3edba035974930b84 [file] [log] [blame]
Jeff Dikec5d4bb12008-02-04 22:31:14 -08001/*
2 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
Richard Weinberger9d1ee8c2013-09-23 17:38:01 +02003 * Copyright (C) 2013 Richard Weinberger <richrd@nod.at>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
Jeff Dikec5d4bb12008-02-04 22:31:14 -080010#include <linux/kallsyms.h>
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/sched.h>
Al Viro382d95f2012-10-08 03:26:54 +010014#include <asm/sysrq.h>
Daniel Walter970e51f2014-08-20 10:56:00 +010015#include <asm/stacktrace.h>
Richard Weinbergerf72c22e2013-09-23 17:38:02 +020016#include <os.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Daniel Walter970e51f2014-08-20 10:56:00 +010018static void _print_addr(void *data, unsigned long address, int reliable)
19{
20 pr_info(" [<%08lx>]", address);
21 pr_cont(" %s", reliable ? "" : "? ");
22 print_symbol("%s", address);
23 pr_cont("\n");
24}
25
26static const struct stacktrace_ops stackops = {
27 .address = _print_addr
Richard Weinberger9d1ee8c2013-09-23 17:38:01 +020028};
29
Richard Weinberger9d1ee8c2013-09-23 17:38:01 +020030void show_stack(struct task_struct *task, unsigned long *stack)
31{
32 unsigned long *sp = stack, bp = 0;
Richard Weinbergerf72c22e2013-09-23 17:38:02 +020033 struct pt_regs *segv_regs = current->thread.segv_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 int i;
35
Richard Weinbergerf72c22e2013-09-23 17:38:02 +020036 if (!segv_regs && os_is_signal_stack()) {
Daniel Walter970e51f2014-08-20 10:56:00 +010037 pr_err("Received SIGSEGV in SIGSEGV handler,"
Richard Weinbergerf72c22e2013-09-23 17:38:02 +020038 " aborting stack trace!\n");
39 return;
40 }
41
Richard Weinberger9d1ee8c2013-09-23 17:38:01 +020042#ifdef CONFIG_FRAME_POINTER
Richard Weinbergerf72c22e2013-09-23 17:38:02 +020043 bp = get_frame_pointer(task, segv_regs);
Richard Weinberger9d1ee8c2013-09-23 17:38:01 +020044#endif
45
Richard Weinbergerf72c22e2013-09-23 17:38:02 +020046 if (!stack)
47 sp = get_stack_pointer(task, segv_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Daniel Walter970e51f2014-08-20 10:56:00 +010049 pr_info("Stack:\n");
Richard Weinberger9d1ee8c2013-09-23 17:38:01 +020050 stack = sp;
Richard Weinbergere96d1c362013-09-23 17:38:04 +020051 for (i = 0; i < 3 * STACKSLOTS_PER_LINE; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 if (kstack_end(stack))
53 break;
Richard Weinberger9d1ee8c2013-09-23 17:38:01 +020054 if (i && ((i % STACKSLOTS_PER_LINE) == 0))
Daniel Walter970e51f2014-08-20 10:56:00 +010055 pr_cont("\n");
56 pr_cont(" %08lx", *stack++);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 }
Daniel Walter970e51f2014-08-20 10:56:00 +010058 pr_cont("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Daniel Walter970e51f2014-08-20 10:56:00 +010060 pr_info("Call Trace:\n");
61 dump_trace(current, &stackops, NULL);
62 pr_info("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}