From dca75df926e48f2a6f3b5ab2c3077d7c21696054 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 9 Apr 2013 17:45:19 -0600 Subject: [PATCH] add vmfPrintTrace method for dumping traces to a specific stream --- src/avian/machine.h | 3 +++ src/machine.cpp | 25 ++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/avian/machine.h b/src/avian/machine.h index 5c57bc18e2..a53d4c98f2 100644 --- a/src/avian/machine.h +++ b/src/avian/machine.h @@ -2699,6 +2699,9 @@ popResources(Thread* t); JNIEXPORT void vmPrintTrace(vm::Thread* t); +JNIEXPORT void +vmfPrintTrace(vm::Thread* t, FILE* out); + namespace vm { void diff --git a/src/machine.cpp b/src/machine.cpp index 098a60130a..0f5bf55291 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -5171,11 +5171,11 @@ noop() // for debugging JNIEXPORT void -vmPrintTrace(Thread* t) +vmfPrintTrace(Thread* t, FILE* out) { class Visitor: public Processor::StackVisitor { public: - Visitor(Thread* t): t(t) { } + Visitor(Thread* t, FILE* out): t(t), out(out) { } virtual bool visit(Processor::StackWalker* walker) { const int8_t* class_ = &byteArrayBody @@ -5185,30 +5185,37 @@ vmPrintTrace(Thread* t) int line = t->m->processor->lineNumber (t, walker->method(), walker->ip()); - fprintf(stderr, " at %s.%s ", class_, method); + fprintf(out, " at %s.%s ", class_, method); switch (line) { case NativeLine: - fprintf(stderr, "(native)\n"); + fprintf(out, "(native)\n"); break; case UnknownLine: - fprintf(stderr, "(unknown line)\n"); + fprintf(out, "(unknown line)\n"); break; default: - fprintf(stderr, "(line %d)\n", line); + fprintf(out, "(line %d)\n", line); } return true; } Thread* t; - } v(t); + FILE* out; + } v(t, out); - fprintf(stderr, "debug trace for thread %p\n", t); + fprintf(out, "debug trace for thread %p\n", t); t->m->processor->walkStack(t, &v); - fflush(stderr); + fflush(out); +} + +JNIEXPORT void +vmPrintTrace(Thread* t) +{ + vmfPrintTrace(t, stderr); } // also for debugging