From: Janosch Frank <frankja@linux.ibm.com>
To: kvm@vger.kernel.org
Cc: linux-s390@vger.kernel.org, imbrenda@linux.ibm.com,
pmorel@linux.ibm.com, david@redhat.com, thuth@redhat.com
Subject: [kvm-unit-tests PATCH v3 4/7] s390x: Provide preliminary backtrace support
Date: Mon, 22 Feb 2021 03:57:53 -0500 [thread overview]
Message-ID: <20210222085756.14396-5-frankja@linux.ibm.com> (raw)
In-Reply-To: <20210222085756.14396-1-frankja@linux.ibm.com>
After the stack changes we can finally use -mbackchain and have a
working backtrace.
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
lib/s390x/stack.c | 20 ++++++++++++++------
s390x/Makefile | 1 +
s390x/macros.S | 5 +++++
3 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/lib/s390x/stack.c b/lib/s390x/stack.c
index 0fcd1afb..4cf80dae 100644
--- a/lib/s390x/stack.c
+++ b/lib/s390x/stack.c
@@ -3,24 +3,32 @@
* s390x stack implementation
*
* Copyright (c) 2017 Red Hat Inc
+ * Copyright 2021 IBM Corp
*
* Authors:
* Thomas Huth <thuth@redhat.com>
* David Hildenbrand <david@redhat.com>
+ * Janosch Frank <frankja@de.ibm.com>
*/
#include <libcflat.h>
#include <stack.h>
+#include <asm/arch_def.h>
int backtrace_frame(const void *frame, const void **return_addrs, int max_depth)
{
- printf("TODO: Implement backtrace_frame(%p, %p, %d) function!\n",
- frame, return_addrs, max_depth);
- return 0;
+ int depth = 0;
+ struct stack_frame *stack = (struct stack_frame *)frame;
+
+ for (depth = 0; stack && depth < max_depth; depth++) {
+ return_addrs[depth] = (void *)stack->grs[8];
+ stack = stack->back_chain;
+ }
+
+ return depth;
}
int backtrace(const void **return_addrs, int max_depth)
{
- printf("TODO: Implement backtrace(%p, %d) function!\n",
- return_addrs, max_depth);
- return 0;
+ return backtrace_frame(__builtin_frame_address(0),
+ return_addrs, max_depth);
}
diff --git a/s390x/Makefile b/s390x/Makefile
index f3b0fccf..20bb5683 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -39,6 +39,7 @@ CFLAGS += -ffreestanding
CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/s390x -I lib
CFLAGS += -O2
CFLAGS += -march=zEC12
+CFLAGS += -mbackchain
CFLAGS += -fno-delete-null-pointer-checks
LDFLAGS += -nostdlib -Wl,--build-id=none
diff --git a/s390x/macros.S b/s390x/macros.S
index 11f4397a..d4f41ec4 100644
--- a/s390x/macros.S
+++ b/s390x/macros.S
@@ -22,6 +22,11 @@
lgr %r2, %r15
/* Allocate stack space for called C function, as specified in s390 ELF ABI */
slgfi %r15, 160
+ /*
+ * Save the address of the interrupt stack into the back chain
+ * of the called function.
+ */
+ stg %r2, STACK_FRAME_INT_BACKCHAIN(%r15)
brasl %r14, \c_func
algfi %r15, 160
RESTORE_REGS_STACK
--
2.25.1
next prev parent reply other threads:[~2021-02-22 12:35 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-22 8:57 [kvm-unit-tests PATCH v3 0/7] s390x: Cleanup exception register save/restore and implement backtrace Janosch Frank
2021-02-22 8:57 ` [kvm-unit-tests PATCH v3 1/7] s390x: Fix fpc store address in RESTORE_REGS_STACK Janosch Frank
2021-02-22 8:57 ` [kvm-unit-tests PATCH v3 2/7] s390x: Fully commit to stack save area for exceptions Janosch Frank
2021-03-04 11:37 ` Thomas Huth
2021-03-04 15:57 ` Janosch Frank
2021-02-22 8:57 ` [kvm-unit-tests PATCH v3 3/7] s390x: Introduce and use CALL_INT_HANDLER macro Janosch Frank
2021-03-04 12:58 ` Claudio Imbrenda
2021-02-22 8:57 ` Janosch Frank [this message]
2021-03-04 12:23 ` [kvm-unit-tests PATCH v3 4/7] s390x: Provide preliminary backtrace support Thomas Huth
2021-03-04 13:02 ` Claudio Imbrenda
2021-02-22 8:57 ` [kvm-unit-tests PATCH v3 5/7] s390x: Print more information on program exceptions Janosch Frank
2021-03-04 12:24 ` Thomas Huth
2021-02-22 8:57 ` [kvm-unit-tests PATCH v3 6/7] s390x: Move diag308_load_reset to stack saving Janosch Frank
2021-03-04 12:26 ` Thomas Huth
2021-02-22 8:57 ` [kvm-unit-tests PATCH v3 7/7] s390x: Remove SAVE/RESTORE_STACK and lowcore fpc and fprs save areas Janosch Frank
2021-03-04 12:28 ` Thomas Huth
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=20210222085756.14396-5-frankja@linux.ibm.com \
--to=frankja@linux.ibm.com \
--cc=david@redhat.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=pmorel@linux.ibm.com \
--cc=thuth@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