From d639f0b9a3ff7b432dbdfcffe0515ae1a29d16e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludwig=20Kn=C3=BCpfer?= <ludwig.knuepfer@fu-berlin.de> Date: Fri, 22 Jul 2016 21:33:11 +0200 Subject: [PATCH] cpu/native: rewrite cpu_print_last_instruction circumvent assembly by using a GCC/LLVM builtin --- cpu/native/include/cpu.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cpu/native/include/cpu.h b/cpu/native/include/cpu.h index a544ef5469..efc4ad7660 100644 --- a/cpu/native/include/cpu.h +++ b/cpu/native/include/cpu.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de> + * Copyright (C) 2013 - 2016 Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de> * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -27,13 +27,14 @@ extern "C" { #endif /** - * @brief Prints the last instruction's address + * @brief Prints the address the callee will return to */ -static inline void cpu_print_last_instruction(void) +__attribute__((always_inline)) static inline void cpu_print_last_instruction(void) { - void *p; - __asm__("1: mov 1b, %0" : "=r" (p)); - printf("%p\n", p); + /* __builtin_return_address will return the address the calling function + * will return to - since cpu_print_last_instruction is forced inline, + * it is the return address of the user of this function */ + printf("%p\n", __builtin_return_address(0)); } #ifdef __cplusplus -- GitLab