Add utility function to print stack traces from lldb/gdb.
Change-Id: I81315a1cd6900dbecfc9a39d9dc4256461163921 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
This commit is contained in:
parent
a6ffc32325
commit
3b3f3bebcd
|
@ -32,6 +32,8 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
#define LOW_LEVEL_DEBUGGING_HELPERS
|
||||
|
||||
using namespace QQmlJS;
|
||||
using namespace QQmlJS::Debugging;
|
||||
|
||||
|
@ -63,13 +65,32 @@ VM::Value *FunctionState::local(unsigned idx)
|
|||
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());
|
||||
}
|
||||
|
||||
|
@ -129,9 +150,9 @@ void Debugger::enterFunction(FunctionState *state)
|
|||
|
||||
#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
|
||||
}
|
||||
|
||||
|
@ -171,6 +192,14 @@ const char *Debugger::currentTemp(unsigned idx) const
|
|||
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) {
|
||||
|
|
|
@ -121,6 +121,7 @@ public: // debugging hooks
|
|||
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);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#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, ...)
|
||||
|
@ -154,9 +154,6 @@ VM::Value VME::operator()(QQmlJS::VM::ExecutionContext *context, const uchar *co
|
|||
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)
|
||||
|
@ -341,7 +338,7 @@ VM::Value VME::operator()(QQmlJS::VM::ExecutionContext *context, const uchar *co
|
|||
|
||||
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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue