#include <iostream>
+#define LOW_LEVEL_DEBUGGING_HELPERS
+
using namespace QQmlJS;
using namespace QQmlJS::Debugging;
return 0;
}
+#ifdef LOW_LEVEL_DEBUGGING_HELPERS
+Debugger *globalInstance = 0;
+
+void printStackTrace()
+{
+ if (globalInstance)
+ globalInstance->printStackTrace();
+ else
+ std::cerr << "No debugger." << std::endl;
+}
+#endif // DO_TRACE_INSTR
+
Debugger::Debugger(VM::ExecutionEngine *engine)
: _engine(engine)
{
+#ifdef LOW_LEVEL_DEBUGGING_HELPERS
+ globalInstance = this;
+#endif // DO_TRACE_INSTR
}
Debugger::~Debugger()
{
+#ifdef LOW_LEVEL_DEBUGGING_HELPERS
+ globalInstance = 0;
+#endif // DO_TRACE_INSTR
+
qDeleteAll(_functionInfo.values());
}
#ifdef DO_TRACE_INSTR
QString n = name(_callStack[callIndex(state->context())].function);
- std::cerr << "*** Entering \"" << qPrintable(n) << "\" with" << state->context()->variableEnvironment->argumentCount << "args" << std::endl;
- for (unsigned i = 0; i < state->context()->variableEnvironment->argumentCount; ++i)
- std::cerr << " " << i << ": " << currentArg(i) << std::endl;
+ std::cerr << "*** Entering \"" << qPrintable(n) << "\" with " << state->context()->variableEnvironment->argumentCount << " args" << std::endl;
+// for (unsigned i = 0; i < state->context()->variableEnvironment->argumentCount; ++i)
+// std::cerr << " " << i << ": " << currentArg(i) << std::endl;
#endif // DO_TRACE_INSTR
}
return qPrintable(state->temp(idx)->toString(state->context())->toQString());
}
+void Debugger::printStackTrace() const
+{
+ for (int i = _callStack.size() - 1; i >=0; --i) {
+ QString n = name(_callStack[i].function);
+ std::cerr << "\tframe #" << i << ": " << qPrintable(n) << std::endl;
+ }
+}
+
int Debugger::callIndex(VM::ExecutionContext *context)
{
for (int idx = _callStack.size() - 1; idx >= 0; --idx) {
const char *currentArg(unsigned idx) const;
const char *currentLocal(unsigned idx) const;
const char *currentTemp(unsigned idx) const;
+ void printStackTrace() const;
private:
int callIndex(VM::ExecutionContext *context);
#ifdef DO_TRACE_INSTR
# define TRACE_INSTR(I) fprintf(stderr, "executing a %s\n", #I);
-# define TRACE(n, str, ...) { fprintf(stderr, " %s : ", #n); fprintf(stderr, str, __VA_ARGS__); fprintf(stderr, "\n"); }
+# define TRACE(n, str, ...) { char buf[4096]; snprintf(buf, 4096, str, __VA_ARGS__); fprintf(stderr, " %s : %s\n", #n, buf); }
#else
# define TRACE_INSTR(I)
# define TRACE(n, str, ...)
MOTH_BEGIN_INSTR(LoadClosure)
VM::Value c = __qmljs_init_closure(instr.value, context);
TEMP(instr.targetTempIndex) = c;
-#ifdef DO_TRACE_INSTR
- qDebug() << "loaded:" << c.toString(context)->toQString();
-#endif
MOTH_END_INSTR(LoadClosure)
MOTH_BEGIN_INSTR(LoadName)
MOTH_BEGIN_INSTR(Ret)
VM::Value result = TEMP(instr.tempIndex);
- TRACE(Ret, "returning value %s", result.toString(context)->toQString().toUtf8().constData());
+// TRACE(Ret, "returning value %s", result.toString(context)->toQString().toUtf8().constData());
return result;
MOTH_END_INSTR(Ret)