diff --git a/repos/os/include/spec/arm/os/backtrace.h b/repos/os/include/spec/arm/os/backtrace.h new file mode 100644 index 0000000000..dd25acd0ac --- /dev/null +++ b/repos/os/include/spec/arm/os/backtrace.h @@ -0,0 +1,40 @@ +/* + * \brief Backtrace helper utility + * \date 2015-09-18 + * \author Christian Prochaska + * \author Stefan Kalkowski + */ + +/* + * Copyright (C) 2015-2016 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _INCLUDE__SPEC__ARM__OS__BACKTRACE_H_ +#define _INCLUDE__SPEC__ARM__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, %%fp" : "=r"(fp) : :); + + while (fp && *fp) { + Genode::log(Hex(*fp)); + fp = (addr_t*)*(fp - 1); + } +} + +#endif /* _INCLUDE__SPEC__ARM__OS__BACKTRACE_H_ */ diff --git a/repos/os/include/spec/x86_32/os/backtrace.h b/repos/os/include/spec/x86_32/os/backtrace.h new file mode 100644 index 0000000000..95e083456d --- /dev/null +++ b/repos/os/include/spec/x86_32/os/backtrace.h @@ -0,0 +1,41 @@ +/* + * \brief Backtrace helper utility + * \date 2015-09-18 + * \author Christian Prochaska + * \author Stefan Kalkowski + */ + +/* + * Copyright (C) 2015-2016 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _INCLUDE__SPEC__X86_32__OS__BACKTRACE_H_ +#define _INCLUDE__SPEC__X86_32__OS__BACKTRACE_H_ + +#include +#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() +{ + Genode::addr_t * fp; + + asm volatile ("movl %%ebp, %0" : "=r"(fp) : :); + + while (fp && *(fp + 1)) { + Genode::log(Hex(*(fp + 1))); + fp = (Genode::addr_t*)*fp; + } +} + +#endif /* _INCLUDE__SPEC__X86_32__OS__BACKTRACE_H_ */ diff --git a/repos/os/include/spec/x86_64/os/backtrace.h b/repos/os/include/spec/x86_64/os/backtrace.h new file mode 100644 index 0000000000..06c6e20779 --- /dev/null +++ b/repos/os/include/spec/x86_64/os/backtrace.h @@ -0,0 +1,41 @@ +/* + * \brief Backtrace helper utility + * \date 2015-09-18 + * \author Christian Prochaska + * \author Stefan Kalkowski + */ + +/* + * Copyright (C) 2015-2016 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _INCLUDE__SPEC__X86_64__OS__BACKTRACE_H_ +#define _INCLUDE__SPEC__X86_64__OS__BACKTRACE_H_ + +#include +#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() +{ + Genode::addr_t * fp; + + asm volatile ("movq %%rbp, %0" : "=r"(fp) : :); + + while (fp && *(fp + 1)) { + Genode::log(Hex(*(fp + 1))); + fp = (Genode::addr_t*)*fp; + } +} + +#endif /* _INCLUDE__SPEC__X86_64__OS__BACKTRACE_H_ */