public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Jones <drjones@redhat.com>
To: kvm@vger.kernel.org
Cc: pfeiner@google.com, pbonzini@redhat.com, rkrcmar@redhat.com
Subject: [kvm-unit-tests PATCH v2 8/8] arm: stack: add dump_stack support
Date: Tue, 19 Apr 2016 18:19:32 +0200	[thread overview]
Message-ID: <1461082772-31121-9-git-send-email-drjones@redhat.com> (raw)
In-Reply-To: <1461082772-31121-1-git-send-email-drjones@redhat.com>

This actually fixes the arm build too, as arm's __builtin_return_address
doesn't allow any input other than zero, and thus the common backtrace()
wasn't compiling.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/Makefile.arm    |  4 ++++
 lib/arm/asm/stack.h |  3 +++
 lib/arm/processor.c |  1 +
 lib/arm/stack.c     | 41 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 49 insertions(+)
 create mode 100644 lib/arm/stack.c

diff --git a/arm/Makefile.arm b/arm/Makefile.arm
index 946422872532d..92f375700c45e 100644
--- a/arm/Makefile.arm
+++ b/arm/Makefile.arm
@@ -8,12 +8,16 @@ ldarch = elf32-littlearm
 kernel_offset = 0x10000
 machine = -marm
 
+# stack.o relies on frame pointers.
+KEEP_FRAME_POINTER := y
+
 CFLAGS += $(machine)
 CFLAGS += -mcpu=$(PROCESSOR)
 
 cstart.o = $(TEST_DIR)/cstart.o
 cflatobjs += lib/arm/spinlock.o
 cflatobjs += lib/arm/processor.o
+cflatobjs += lib/arm/stack.o
 
 # arm specific tests
 tests =
diff --git a/lib/arm/asm/stack.h b/lib/arm/asm/stack.h
index fe97ac5d4b7d9..ebcedc2ef938c 100644
--- a/lib/arm/asm/stack.h
+++ b/lib/arm/asm/stack.h
@@ -5,4 +5,7 @@
 #error Do not directly include <asm/stack.h>. Just use <stack.h>.
 #endif
 
+#define HAVE_ARCH_BACKTRACE_FRAME
+#define HAVE_ARCH_BACKTRACE
+
 #endif
diff --git a/lib/arm/processor.c b/lib/arm/processor.c
index 1cef46ab28647..54fdb87ef0196 100644
--- a/lib/arm/processor.c
+++ b/lib/arm/processor.c
@@ -108,6 +108,7 @@ void do_handle_exception(enum vector v, struct pt_regs *regs)
 		asm volatile("mrc p15, 0, %0, c5, c0, 1": "=r" (fsr));
 		printf("IFAR: %08lx    IFSR: %08lx\n", far, fsr);
 	}
+	dump_frame_stack((void *)regs->ARM_pc, (void *)regs->ARM_fp);
 	abort();
 }
 
diff --git a/lib/arm/stack.c b/lib/arm/stack.c
new file mode 100644
index 0000000000000..7d081be7c6d0e
--- /dev/null
+++ b/lib/arm/stack.c
@@ -0,0 +1,41 @@
+/*
+ * backtrace support (this is a modified lib/x86/stack.c)
+ *
+ * Copyright (C) 2016, Red Hat Inc, Andrew Jones <drjones@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+#include <libcflat.h>
+#include <stack.h>
+
+int backtrace_frame(const void *frame, const void **return_addrs,
+		    int max_depth)
+{
+	static int walking;
+	int depth;
+	const unsigned long *fp = (unsigned long *)frame;
+
+	if (walking) {
+		printf("RECURSIVE STACK WALK!!!\n");
+		return 0;
+	}
+	walking = 1;
+
+	for (depth = 0; depth < max_depth; depth++) {
+		if (!fp)
+			break;
+		return_addrs[depth] = (void *)fp[0];
+		if (return_addrs[depth] == 0)
+			break;
+		fp = (unsigned long *)fp[-1];
+	}
+
+	walking = 0;
+	return depth;
+}
+
+int backtrace(const void **return_addrs, int max_depth)
+{
+	return backtrace_frame(__builtin_frame_address(0),
+			       return_addrs, max_depth);
+}
-- 
2.4.11


  parent reply	other threads:[~2016-04-19 16:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-19 16:19 [kvm-unit-tests PATCH v2 0/8] arm: fix building by adding a feature Andrew Jones
2016-04-19 16:19 ` [kvm-unit-tests PATCH v2 1/8] x86: change exit to abort again Andrew Jones
2016-04-19 16:19 ` [kvm-unit-tests PATCH v2 2/8] x86: trivial: there's no dump_stack.o Andrew Jones
2016-04-19 16:19 ` [kvm-unit-tests PATCH v2 3/8] pretty_print_stacks: keep the 'STACK:' line Andrew Jones
2016-04-19 16:19 ` [kvm-unit-tests PATCH v2 4/8] pretty_print_stacks: use elf file for the kernel Andrew Jones
2016-04-19 16:19 ` [kvm-unit-tests PATCH v2 5/8] pretty_print_stacks: addr2line may need a cross prefix Andrew Jones
2016-04-19 16:19 ` [kvm-unit-tests PATCH v2 6/8] stack: share api prototypes Andrew Jones
2016-04-19 16:19 ` [kvm-unit-tests PATCH v2 7/8] stack: copy common asm/stack.h bits to all arches Andrew Jones
2016-04-19 16:19 ` Andrew Jones [this message]
2016-04-19 16:37   ` [kvm-unit-tests PATCH v2 8/8] arm: stack: add dump_stack support Peter Feiner
2016-04-25 15:31 ` [kvm-unit-tests PATCH v2 0/8] arm: fix building by adding a feature Radim Krčmář

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1461082772-31121-9-git-send-email-drjones@redhat.com \
    --to=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=pfeiner@google.com \
    --cc=rkrcmar@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox