diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2013-05-25 15:31:23 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@digia.com> | 2013-05-27 16:59:53 +0200 |
commit | 8a822866b68f5f425b2e1f5c793fe36acf291f4d (patch) | |
tree | 259a3e3bc3a504e900778901b88d8682dfe11a38 /tools | |
parent | 68827e982f685e13fe4a8d5143931621eb82fbb5 (diff) |
Add support for line numbers in stack traces (Linux/Mac OS X only at this point)
* Add support for debug annotations on statement boundaries to the
IR, to get accurate line/column information
* Use binary search to retrieve the function and line number for a given
program counter
* Save the stack trace in the exception class and print it in v4
* Fix initial line number in QV4::Script to start a 1, just like the initial column
in QQmlJS::Lexer also starts at 1
The native stack frame tracing is currently only implemented on Linux and Mac OS X.
The implementation for Windows using StackWalk64 is still missing.
Change-Id: I771fe44816397e29c69952772a772bf0d985236f
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/v4/main.cpp | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/tools/v4/main.cpp b/tools/v4/main.cpp index 56ec2da7af..ead057c86a 100644 --- a/tools/v4/main.cpp +++ b/tools/v4/main.cpp @@ -120,26 +120,32 @@ DEFINE_MANAGED_VTABLE(GC); } // builtins -static void showException(QV4::ExecutionContext *ctx, const QV4::Value &exception) +static void showException(QV4::ExecutionContext *ctx, const QV4::Exception &exception) { - QV4::ErrorObject *e = exception.asErrorObject(); + QV4::ErrorObject *e = exception.value().asErrorObject(); if (!e) { - std::cerr << "Uncaught exception: " << qPrintable(exception.toString(ctx)->toQString()) << std::endl; - return; - } + std::cerr << "Uncaught exception: " << qPrintable(exception.value().toString(ctx)->toQString()) << std::endl; + } else { + if (QV4::SyntaxErrorObject *err = e->asSyntaxError()) { + QV4::DiagnosticMessage *msg = err->message(); + if (!msg) { + std::cerr << "Uncaught exception: Syntax error" << std::endl; + return; + } - if (QV4::SyntaxErrorObject *err = e->asSyntaxError()) { - QV4::DiagnosticMessage *msg = err->message(); - if (!msg) { - std::cerr << "Uncaught exception: Syntax error" << std::endl; - return; + for (; msg; msg = msg->next) { + std::cerr << qPrintable(msg->buildFullMessage(ctx)->toQString()) << std::endl; + } + } else { + std::cerr << "Uncaught exception: " << qPrintable(e->get(ctx, ctx->engine->newString(QStringLiteral("message")), 0).toString(ctx)->toQString()) << std::endl; } + } - for (; msg; msg = msg->next) { - std::cerr << qPrintable(msg->buildFullMessage(ctx)->toQString()) << std::endl; - } - } else { - std::cerr << "Uncaught exception: " << qPrintable(e->get(ctx, ctx->engine->newString(QStringLiteral("message")), 0).toString(ctx)->toQString()) << std::endl; + foreach (const QV4::ExecutionEngine::StackFrame &frame, exception.stackTrace()) { + std::cerr << " at " << qPrintable(frame.function) << " (" << qPrintable(frame.source.toLocalFile()); + if (frame.line >= 0) + std::cerr << ":" << frame.line; + std::cerr << ")" << std::endl; } } @@ -390,7 +396,7 @@ int main(int argc, char *argv[]) } } catch (QV4::Exception& ex) { ex.accept(ctx); - showException(ctx, ex.value()); + showException(ctx, ex); return EXIT_FAILURE; } |