SVN commit 1121538 by orlovich: Some low-level tracing improvements. M +22 -22 bytecode/opcodes.cpp.in M +50 -3 function.cpp M +5 -5 nodes.cpp --- trunk/KDE/kdelibs/kjs/bytecode/opcodes.cpp.in #1121537:1121538 @@ -148,7 +148,7 @@ break; default: - printf("Unable to emit conversion:%s, in:%c, out:%c\n", ConvOpVals[convType], + fprintf(stderr, "Unable to emit conversion:%s, in:%c, out:%c\n", ConvOpVals[convType], original->immediate ? 'I' : 'R', outImm ? 'I' : 'R'); CRASH(); }; @@ -204,13 +204,13 @@ emitOp(comp, Op_RegPutNumber, 0, regNum, val); break; default: - printf("Don't know how to store type to register:%s\n", OpTypeVals[val->type]); + fprintf(stderr, "Don't know how to store type to register:%s\n", OpTypeVals[val->type]); CRASH(); } } static void printType(const char* prefix, int pos, OpValue* v) { - printf("%s%d:%s/imm:%d\n", prefix, pos, OpTypeVals[v->type], v->immediate); + fprintf(stderr, "%s%d:%s/imm:%d\n", prefix, pos, OpTypeVals[v->type], v->immediate); } Addr CodeGen::emitOp(CompileState* comp, OpName baseInstr, @@ -247,7 +247,7 @@ ++numArgs; #ifdef TRACE_INSTR_SELECT - printf("\n\nTrying to select variant for:%s\n", OpNameVals[baseInstr]); + fprintf(stderr, "\n\nTrying to select variant for:%s\n", OpNameVals[baseInstr]); for (int i = 0; i < numArgs; ++i) printType("\targ", i, args[i]); #endif @@ -275,9 +275,9 @@ } #ifdef TRACE_INSTR_SELECT - printf("Candidate:%s, totalCost:%d, variant cost:%d\n", OpByteCodeVals[cand->opCode], totalCost, cand->cost); + fprintf(stderr, "Candidate:%s, totalCost:%d, variant cost:%d\n", OpByteCodeVals[cand->opCode], totalCost, cand->cost); for (int i = 0; i < numArgs; ++i) { - printf("\tconv:%s, costs:%d\n", ConvOpVals[convOps[i]], costs[i]); + fprintf(stderr, "\tconv:%s, costs:%d\n", ConvOpVals[convOps[i]], costs[i]); } #endif @@ -295,7 +295,7 @@ } if (!cheapest) { - printf("Unable to find an acceptable conversion for:%s\n", OpNameVals[baseInstr]); + fprintf(stderr, "Unable to find an acceptable conversion for:%s\n", OpNameVals[baseInstr]); for (int i = 0; i < numArgs; ++i) printType("\ta", i, args[i]); CRASH(); // Should never happen! @@ -374,43 +374,43 @@ switch (type) { case OpType_bool: if (reinterpret_cast(block.data() + offset)->boolVal) - std::printf("true"); + std::fprintf(stderr, "true"); else - std::printf("false"); + std::fprintf(stderr, "false"); break; case OpType_int32: - std::printf("%d", reinterpret_cast(block.data() + offset)->int32Val); + std::fprintf(stderr, "%d", reinterpret_cast(block.data() + offset)->int32Val); break; case OpType_value: // Immediate value -- should go through JSImmediate stuff.. - std::printf("", reinterpret_cast(block.data() + offset)->valueVal->toString(0).ascii()); + std::fprintf(stderr, "", reinterpret_cast(block.data() + offset)->valueVal->toString(0).ascii()); break; case OpType_ident: - std::printf("%s", reinterpret_cast(block.data() + offset)->identVal->ustring().ascii()); + std::fprintf(stderr, "%s", reinterpret_cast(block.data() + offset)->identVal->ustring().ascii()); break; case OpType_string: - std::printf("\"%s\"", reinterpret_cast(block.data() + offset)->stringVal->ascii()); + std::fprintf(stderr, "\"%s\"", reinterpret_cast(block.data() + offset)->stringVal->ascii()); break; case OpType_number: - std::printf("%f", reinterpret_cast(block.data() + offset)->numberVal); + std::fprintf(stderr, "%f", reinterpret_cast(block.data() + offset)->numberVal); break; case OpType_addr: - std::printf("A%08x", reinterpret_cast(block.data() + offset)->addrVal); + std::fprintf(stderr, "A%08x", reinterpret_cast(block.data() + offset)->addrVal); break; case OpType_reg: - std::printf("r%lu", reinterpret_cast(block.data() + offset)->regVal / (wasImm ? + std::fprintf(stderr, "r%lu", reinterpret_cast(block.data() + offset)->regVal / (wasImm ? 1lu : sizeof(LocalStorageEntry))); break; case OpType_node: - std::printf("N%p", (void*)(reinterpret_cast(block.data() + offset)->nodeVal)); + std::fprintf(stderr,"N%p", (void*)(reinterpret_cast(block.data() + offset)->nodeVal)); break; case OpType_cstr: - std::printf("c\"%s\"", reinterpret_cast(block.data() + offset)->cstrVal); + std::fprintf(stderr, "c\"%s\"", reinterpret_cast(block.data() + offset)->cstrVal); break; default: - std::printf("???:%s", OpTypeVals[type]); + std::fprintf(stderr, "???:%s", OpTypeVals[type]); }; - std::printf(" "); + std::fprintf(stderr, " "); } void CodeGen::disassembleBlock(CodeBlock& block) @@ -420,13 +420,13 @@ OpByteCode opCode = *reinterpret_cast(block.data() + pc); const Op& opDescr = opsForOpCodes[opCode]; - std::printf("%08lx %s ", pc, OpNameVals[opDescr.baseInstr]); + std::fprintf(stderr, "%08lx %s ", pc, OpNameVals[opDescr.baseInstr]); for (int p = 0; p < opDescr.numParams; ++p) { dumpParam(block, pc + opDescr.paramOffsets[p], opDescr.immediateParams[p] ? opDescr.paramTypes[p] : OpType_reg, opDescr.immediateParams[p]); } - std::printf("\t\t// %s\n", OpByteCodeVals[opCode]); + std::fprintf(stderr, "\t\t// %s\n", OpByteCodeVals[opCode]); pc += opDescr.length; } } --- trunk/KDE/kdelibs/kjs/function.cpp #1121537:1121538 @@ -44,9 +44,12 @@ #include "wtf/DisallowCType.h" #include "wtf/ASCIICType.h" #include "bytecode/machine.h" +#include using namespace WTF; +//#define KJS_VERBOSE + namespace KJS { // ----------------------------- FunctionImp ---------------------------------- @@ -93,10 +96,41 @@ body->compile(FunctionCode, newExec->dynamicInterpreter()->debugger() ? Debug : Release); } + +#ifdef KJS_VERBOSE +static int callDepth; +static std::string callIndent; + +static const char* ind() +{ + callIndent = ""; + for (int i = 0; i < callDepth; ++i) + callIndent += " "; + return callIndent.c_str(); +} + +// Multiline print adding indentation +static void printInd(const char* str) +{ + fprintf(stderr, "%s", ind()); + for (const char* c = str; *c; ++c) { + if (*c != '\n') + fprintf(stderr, "%c", *c); + else + fprintf(stderr, "\n%s", ind()); + } +} + +#endif + JSValue* FunctionImp::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) { assert(thisObj); +#ifdef KJS_VERBOSE + ++callDepth; +#endif + Debugger* dbg = exec->dynamicInterpreter()->debugger(); // enter a new execution context @@ -160,10 +194,13 @@ exec->dynamicInterpreter()->stackFree(stackSize); #ifdef KJS_VERBOSE + fprintf(stderr, "%s", ind()); if (exec->exception()) printInfo(exec,"throwing", exec->exception()); else printInfo(exec,"returning", result); + + --callDepth; #endif // The debugger may have been deallocated by now if the WebFrame @@ -488,8 +525,8 @@ // Pass in the parameters (ECMA 10.1.3q) #ifdef KJS_VERBOSE - fprintf(stderr, "---------------------------------------------------\n" - "processing parameters for %s call\n", + fprintf(stderr, "%s---------------------------------------------------\n" + "%sprocessing parameters for %s call\n", ind(), ind(), function->functionName().isEmpty() ? "(internal)" : function->functionName().ascii()); #endif size_t numParams = body->numParams(); @@ -500,11 +537,19 @@ entries[symNum].val.valueVal = v; #ifdef KJS_VERBOSE - fprintf(stderr, "setting parameter %s", body->paramName(pos).ascii()); + fprintf(stderr, "%s setting parameter %s", ind(), body->paramName(pos).ascii()); printInfo(exec, "to", v); #endif } +#ifdef KJS_VERBOSE + fprintf(stderr, "\n%s---------------------------------\n", ind()); + fprintf(stderr, "%sBody:\n", ind()); + fprintf(stderr, "%s---------------------------------\n", ind()); + printInd(body->toString().ascii()); + fprintf(stderr, "\n%s---------------------------------\n\n", ind()); +#endif + // Initialize the rest of the locals to 'undefined' for (size_t pos = numParams + ActivationImp::NumReservedSlots; pos < total; ++pos) entries[pos].val.valueVal = jsUndefined(); @@ -1013,3 +1058,5 @@ } } // namespace + +// kate: indent-width 4; replace-tabs on; tab-width 4; space-indent on; --- trunk/KDE/kdelibs/kjs/nodes.cpp #1121537:1121538 @@ -948,12 +948,12 @@ m_tearOffAtEnd = comp.needsClosures(); #if 0 - printf("\n\n"); - printf("\n---------------------------------\n\n"); - printf("%s", toString().ascii()); - printf("\n---------------------------------\n\n"); + fprintf(stderr, "\n\n"); + fprintf(stderr, "\n---------------------------------\n\n"); + fprintf(stderr, "%s", toString().ascii()); + fprintf(stderr, "\n---------------------------------\n\n"); CodeGen::disassembleBlock(m_compiledCode); - printf("\n---------------------------------\n\n"); + fprintf(stderr, "\n---------------------------------\n\n"); #endif }