It makes the output corrupted. We make show_exe_function()
print to a buffer which is printed only when function
succeeds.

Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 arch/x86/backtrace.c   |   21 +++++++++++++++------
 include/vm/backtrace.h |    4 +++-
 vm/signal.c            |    2 ++
 vm/stack-trace.c       |   11 ++++++++---
 4 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/arch/x86/backtrace.c b/arch/x86/backtrace.c
index 684fcaa..500b420 100644
--- a/arch/x86/backtrace.c
+++ b/arch/x86/backtrace.c
@@ -40,6 +40,8 @@
 #include "vm/stack-trace.h"
 #include "vm/trace.h"
 
+#include "lib/string.h"
+
 /* get REG_EIP from ucontext.h */
 #include <ucontext.h>
 
@@ -59,7 +61,7 @@ static asymbol *lookup_symbol(asymbol ** symbols, int 
nr_symbols,
        return NULL;
 }
 
-bool show_exe_function(void *addr)
+bool show_exe_function(void *addr, struct string *str)
 {
        bool ret;
        const char *function_name;
@@ -114,8 +116,8 @@ bool show_exe_function(void *addr)
        symbol_start = bfd_asymbol_value(symbol);
        symbol_offset = (unsigned long) addr - symbol_start;
 
-       trace_printf("%s+%llx (%s:%i)\n",
-               function_name, (long long) symbol_offset, filename, line);
+       str_append(str, "%s+%llx (%s:%i)\n",
+                  function_name, (long long) symbol_offset, filename, line);
        ret = true;
 
 out:
@@ -132,10 +134,17 @@ failed:
 
 void show_function(void *addr)
 {
-       if (show_exe_function(addr))
-               return;
+       struct string *str;
+
+       str = alloc_str();
+
+       if (show_exe_function(addr, str)) {
+               trace_printf("%s", str->value);
+       } else {
+               trace_printf("<unknown>\n");
+       }
 
-       trace_printf("<unknown>\n");
+       free_str(str);
 }
 
 static unsigned long get_greg(gregset_t gregs, int reg)
diff --git a/include/vm/backtrace.h b/include/vm/backtrace.h
index c7dd4de..6cb2406 100644
--- a/include/vm/backtrace.h
+++ b/include/vm/backtrace.h
@@ -4,10 +4,12 @@
 #include <signal.h>
 #include <stdbool.h>
 
+struct string;
+
 extern void print_backtrace_and_die(int, siginfo_t *, void *);
 extern void print_trace(void);
 extern void print_trace_from(unsigned long, void*);
-extern bool show_exe_function(void *addr);
+extern bool show_exe_function(void *addr, struct string *str);
 extern void show_function(void *addr);
 
 #endif
diff --git a/vm/signal.c b/vm/signal.c
index 3e59480..de65854 100644
--- a/vm/signal.c
+++ b/vm/signal.c
@@ -91,6 +91,8 @@ static void sigfpe_handler(int sig, siginfo_t *si, void *ctx)
 
 static void sigsegv_handler(int sig, siginfo_t *si, void *ctx)
 {
+       print_trace();
+
        if (signal_from_native(ctx))
                goto exit;
 
diff --git a/vm/stack-trace.c b/vm/stack-trace.c
index 404aae9..31cf218 100644
--- a/vm/stack-trace.c
+++ b/vm/stack-trace.c
@@ -729,9 +729,14 @@ static void show_mixed_stack_trace(struct stack_trace_elem 
*elem)
                        print_java_stack_trace_elem(elem);
                        trace_printf("\n");
 
-                       trace_printf("%-27s"," ");
-                       if (!show_exe_function((void *) elem->addr))
-                               trace_printf("\r");
+                       struct string *str;
+
+                       str = alloc_str();
+
+                       if (show_exe_function((void *) elem->addr, str))
+                               trace_printf("%-27s%s", " ", str->value);
+
+                       free_str(str);
 
                        continue;
                }
-- 
1.6.0.6


------------------------------------------------------------------------------
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