From 4e2a054c745a6bc87637df0b2dbc7b213e5a4fa5 Mon Sep 17 00:00:00 2001
From: Yuriy Vostrikov <vostrikov@corp.mail.ru>
Date: Fri, 10 Dec 2010 15:52:37 +0300
Subject: [PATCH] [core] Fix rbp printing.

---
 core/fiber.c     | 15 ++++++---------
 core/tarantool.c |  5 ++---
 core/util.c      | 16 +---------------
 include/util.h   | 13 ++++++++++++-
 4 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/core/fiber.c b/core/fiber.c
index 328e4d0253..5dbb5992ce 100644
--- a/core/fiber.c
+++ b/core/fiber.c
@@ -102,9 +102,8 @@ fiber_call(struct fiber *callee)
 	fiber = callee;
 	*sp++ = caller;
 
-#if CORO_ASM
-	save_rbp(&caller->rbp);
-#endif
+	save_rbp(caller->rbp);
+
 	callee->csw++;
 	coro_transfer(&caller->coro.ctx, &callee->coro.ctx);
 }
@@ -120,9 +119,8 @@ fiber_raise(struct fiber *callee, jmp_buf exc, int value)
 	fiber = callee;
 	*sp++ = caller;
 
-#if CORO_ASM
-	save_rbp(&caller->rbp);
-#endif
+	save_rbp(caller->rbp);
+
 	callee->csw++;
 	coro_save_and_longjmp(&caller->coro.ctx, exc, value);
 }
@@ -134,9 +132,8 @@ yield(void)
 	struct fiber *caller = fiber;
 
 	fiber = callee;
-#if CORO_ASM
-	save_rbp(&caller->rbp);
-#endif
+	save_rbp(caller->rbp);
+
 	callee->csw++;
 	coro_transfer(&caller->coro.ctx, &callee->coro.ctx);
 }
diff --git a/core/tarantool.c b/core/tarantool.c
index 4a7f79c71f..061e9f64b0 100644
--- a/core/tarantool.c
+++ b/core/tarantool.c
@@ -231,9 +231,8 @@ main(int argc, char **argv)
 	int n_accepted, n_skipped;
 	FILE *f;
 
-#if CORO_ASM
-	save_rbp(&main_stack_frame);
-#endif
+	save_rbp(main_stack_frame);
+
 	master_pid = getpid();
 	stat_init();
 	palloc_init();
diff --git a/core/util.c b/core/util.c
index 0c7ba4eec7..a4949d6d8e 100644
--- a/core/util.c
+++ b/core/util.c
@@ -95,26 +95,13 @@ xrealloc(void *ptr, size_t size)
 	return ret;
 }
 
-#if CORO_ASM
-void
-save_rbp(void **rbp)
-{
-#  if __amd64
-	asm("movq %%rbp, %0"::"m"(*rbp));
-#  elif __i386
-	asm("movl %%ebp, %0"::"m"(*rbp));
-#  else
-#  error unsupported architecture
-#  endif
-}
-
 void *main_stack_frame;
 static void
 print_trace(FILE *f)
 {
 	void *dummy;
 	struct frame *frame;
-	save_rbp(&dummy);
+	save_rbp(dummy);
 	frame = dummy;
 
 	void *stack_top = fiber->coro.stack + fiber->coro.stack_size;
@@ -129,7 +116,6 @@ print_trace(FILE *f)
 		frame = frame->rbp;
 	}
 }
-#endif
 
 void __attribute__ ((noreturn))
     assert_fail(const char *assertion, const char *file, unsigned int line, const char *function)
diff --git a/include/util.h b/include/util.h
index bc7e6f5370..fe10daa5aa 100644
--- a/include/util.h
+++ b/include/util.h
@@ -117,7 +117,18 @@ struct frame {
 	void *ret;
 };
 
-void save_rbp(void **rbp);
+#if CORO_ASM
+#  if __amd64
+#    define save_rbp(rbp) asm("movq %%rbp, %0"::"m"(rbp))
+#  elif __i386
+#    define save_rbp(rbp) asm("movl %%ebp, %0"::"m"(rbp))
+#  else
+#  error unsupported architecture
+#  endif
+# else
+#   define save_rbp(rbp) (void)0
+#endif
+
 extern void *main_stack_frame;
 
 #ifdef NDEBUG
-- 
GitLab