From 22498e0b0954af6ffeba1f6252cf2d85e16f8643 Mon Sep 17 00:00:00 2001 From: Stefan Kalkowski Date: Tue, 21 Jan 2020 14:44:05 +0100 Subject: [PATCH] os: add backtrace utility for arm_64 Fix #3621 --- repos/os/include/spec/arm_64/os/backtrace.h | 41 +++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 repos/os/include/spec/arm_64/os/backtrace.h diff --git a/repos/os/include/spec/arm_64/os/backtrace.h b/repos/os/include/spec/arm_64/os/backtrace.h new file mode 100644 index 000000000..2f66a83b2 --- /dev/null +++ b/repos/os/include/spec/arm_64/os/backtrace.h @@ -0,0 +1,41 @@ +/* + * \brief Backtrace helper utility + * \date 2020-01-21 + * \author Stefan Kalkowski + */ + +/* + * Copyright (C) 2020 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +#ifndef _INCLUDE__SPEC__ARM_64__OS__BACKTRACE_H_ +#define _INCLUDE__SPEC__ARM_64__OS__BACKTRACE_H_ + +#include + +namespace Genode { void inline backtrace() __attribute__((always_inline)); } + +/** + * Print frame pointer based backtrace + * + * To use this function compile your code with the -fno-omit-frame-pointer GCC + * option. + */ +void inline Genode::backtrace() +{ + addr_t * fp; + + asm volatile ("mov %0, x29" : "=r"(fp) ::); + + while (fp) { + addr_t ip = fp[1]; + fp = (addr_t*) fp[0]; + Genode::log(Hex(ip)); + } +} + +#endif /* _INCLUDE__SPEC__ARM_64__OS__BACKTRACE_H_ */ +