The function was setting elem to the init_stack_trace_elem_current()'s
frame which is error prone because after function returns its stack
frame might be overriden by another function calls done from the
caller.

A fix for that is to make init_stack_trace_elem_current() set elem to
the caller's frame. We must make it a macro becasue we can't rely on
__builtin_frame_address(1) because of gcc optimizations.

Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 include/vm/stack-trace.h   |    8 +++++++-
 test/vm/stack-trace-stub.c |    4 ----
 vm/stack-trace.c           |    7 -------
 3 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/include/vm/stack-trace.h b/include/vm/stack-trace.h
index a913f18..34af859 100644
--- a/include/vm/stack-trace.h
+++ b/include/vm/stack-trace.h
@@ -88,6 +88,13 @@ static inline void *vm_native_stack_get_frame(void)
                        __builtin_frame_address(0);                     \
        } while (0)
 
+#define init_stack_trace_elem_current(elem) do {                       \
+       __lab:                                                          \
+               init_stack_trace_elem(elem,                             \
+                                     (unsigned long)&&__lab,           \
+                                     __builtin_frame_address(0));      \
+       } while (0)
+
 enum stack_trace_elem_type {
        STACK_TRACE_ELEM_TYPE_JIT,
        STACK_TRACE_ELEM_TYPE_JNI,
@@ -131,7 +138,6 @@ stack_trace_elem_type_is_java(enum stack_trace_elem_type 
type)
 void init_stack_trace_printing(void);
 void init_stack_trace_elem(struct stack_trace_elem *elem, unsigned long addr,
                           void *frame);
-void init_stack_trace_elem_current(struct stack_trace_elem *elem);
 int stack_trace_elem_next(struct stack_trace_elem *elem);
 int stack_trace_elem_next_java(struct stack_trace_elem *elem);
 int skip_frames_from_class(struct stack_trace_elem *elem, struct vm_class 
*class);
diff --git a/test/vm/stack-trace-stub.c b/test/vm/stack-trace-stub.c
index 38e3df7..c2ef8af 100644
--- a/test/vm/stack-trace-stub.c
+++ b/test/vm/stack-trace-stub.c
@@ -44,10 +44,6 @@ void init_stack_trace_elem(struct stack_trace_elem *elem, 
unsigned long addr,
 {
 }
 
-void init_stack_trace_elem_current(struct stack_trace_elem *elem)
-{
-}
-
 int stack_trace_elem_next(struct stack_trace_elem *elem)
 {
        return -1;
diff --git a/vm/stack-trace.c b/vm/stack-trace.c
index d02d9d0..0d12c4e 100644
--- a/vm/stack-trace.c
+++ b/vm/stack-trace.c
@@ -310,13 +310,6 @@ void init_stack_trace_elem(struct stack_trace_elem *elem, 
unsigned long addr,
        }
 }
 
-void init_stack_trace_elem_current(struct stack_trace_elem *elem)
-{
-       init_stack_trace_elem(elem,
-                             (unsigned long)&init_stack_trace_elem_current,
-                             __builtin_frame_address(0));
-}
-
 struct compilation_unit *stack_trace_elem_get_cu(struct stack_trace_elem *elem)
 {
        if (elem->type == STACK_TRACE_ELEM_TYPE_OTHER)
-- 
1.6.0.4


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to