diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp index 7c3a23d2195..5012012ca65 100644 --- a/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -27,10 +27,12 @@ CachedWriter CW; // Object to accellerate printing of LLVM sigjmp_buf SignalRecoverBuffer; +static bool InInstruction = false; extern "C" { static void SigHandler(int Signal) { - siglongjmp(SignalRecoverBuffer, Signal); + if (InInstruction) + siglongjmp(SignalRecoverBuffer, Signal); } } @@ -41,6 +43,7 @@ static void initializeSignalHandlers() { sigemptyset(&Action.sa_mask); sigaction(SIGSEGV, &Action, 0); sigaction(SIGBUS, &Action, 0); + sigaction(SIGINT, &Action, 0); //sigaction(SIGFP, &Action, 0); } @@ -193,7 +196,7 @@ static void InitializeMemory(ConstPoolVal *Init, char *Addr) { return; default: - cout << "Bad Type: " << Init->getType()->getDescription() << endl; + CW << "Bad Type: " << Init->getType() << endl; assert(0 && "Unknown constant type to initialize memory with!"); } } @@ -982,11 +985,17 @@ bool Interpreter::executeInstruction() { // if (int SigNo = sigsetjmp(SignalRecoverBuffer, 1)) { --SF.CurInst; // Back up to erroring instruction - cout << "EXCEPTION OCCURRED [Signal " << _sys_siglistp[SigNo] << "]:\n"; - printStackTrace(); + if (SigNo != SIGINT) { + cout << "EXCEPTION OCCURRED [Signal " << _sys_siglistp[SigNo] << "]:\n"; + printStackTrace(); + } else { + cout << "CTRL-C Detected, execution halted.\n"; + } + InInstruction = false; return true; } + InInstruction = true; if (I->isBinaryOp()) { executeBinaryInst(cast(I), SF); } else { @@ -1013,6 +1022,7 @@ bool Interpreter::executeInstruction() { cout << "Don't know how to execute this instruction!\n-->" << I; } } + InInstruction = false; // Reset the current frame location to the top of stack CurFrame = ECStack.size()-1; @@ -1161,7 +1171,6 @@ void Interpreter::print(const string &Name) { getOperandValue(PickedVal, ECStack[CurFrame])); cout << endl; } - } void Interpreter::infoValue(const string &Name) { @@ -1175,22 +1184,25 @@ void Interpreter::infoValue(const string &Name) { printOperandInfo(PickedVal, ECStack[CurFrame]); } -void Interpreter::list() { - if (ECStack.empty()) - cout << "Error: No program executing!\n"; - else - CW << ECStack[CurFrame].CurMethod; // Just print the method out... -} - -void Interpreter::printStackTrace() { - if (ECStack.empty()) cout << "No program executing!\n"; - - for (unsigned i = 0; i < ECStack.size(); ++i) { - cout << (((int)i == CurFrame) ? '>' : '-'); - CW << "#" << i << ". " << ECStack[i].CurMethod->getType() << " \"" - << ECStack[i].CurMethod->getName() << "\"("; - // TODO: Print Args - cout << ")" << endl; - CW << *ECStack[i].CurInst; +// printStackFrame - Print information about the specified stack frame, or -1 +// for the default one. +// +void Interpreter::printStackFrame(int FrameNo = -1) { + if (FrameNo == -1) FrameNo = CurFrame; + cout << ((FrameNo == CurFrame) ? '>' : '-'); + Method *Meth = ECStack[FrameNo].CurMethod; + CW << "#" << FrameNo << ". " << (Value*)Meth->getType() << " \"" + << Meth->getName() << "\"("; + + Method::ArgumentListType &Args = Meth->getArgumentList(); + for (unsigned i = 0; i < Args.size(); ++i) { + if (i != 0) cout << ", "; + CW << (Value*)Args[i] << "="; + + printValue(Args[i]->getType(), getOperandValue(Args[i], ECStack[FrameNo])); } + + cout << ")" << endl; + CW << *(ECStack[FrameNo].CurInst-(FrameNo != int(ECStack.size()-1))); } + diff --git a/lib/ExecutionEngine/Interpreter/Interpreter.h b/lib/ExecutionEngine/Interpreter/Interpreter.h index 23354e38184..791419d4ad9 100644 --- a/lib/ExecutionEngine/Interpreter/Interpreter.h +++ b/lib/ExecutionEngine/Interpreter/Interpreter.h @@ -136,6 +136,11 @@ private: // Helper functions // void printCurrentInstruction(); + // printStackFrame - Print information about the specified stack frame, or -1 + // for the default one. + // + void printStackFrame(int FrameNo = -1); + // LookupMatchingNames - Search the current method namespace, then the global // namespace looking for values that match the specified name. Return ALL // matches to that name. This is obviously slow, and should only be used for diff --git a/lib/ExecutionEngine/Interpreter/UserInput.cpp b/lib/ExecutionEngine/Interpreter/UserInput.cpp index a1518d413e0..7ece7bc54b9 100644 --- a/lib/ExecutionEngine/Interpreter/UserInput.cpp +++ b/lib/ExecutionEngine/Interpreter/UserInput.cpp @@ -105,12 +105,15 @@ void Interpreter::handleUserInput() { case List: list(); break; case StackTrace: printStackTrace(); break; case Up: - if (CurFrame > 0) --CurFrame; + if (CurFrame > 0) { --CurFrame; printStackFrame(); } else cout << "Error: Already at root of stack!\n"; break; case Down: - if ((unsigned)CurFrame < ECStack.size()-1) ++CurFrame; - else cout << "Error: Already at bottom of stack!\n"; + if ((unsigned)CurFrame < ECStack.size()-1) { + ++CurFrame; + printStackFrame(); + } else + cout << "Error: Already at bottom of stack!\n"; break; case Next: nextInstruction(); break; case Step: stepInstruction(); break; @@ -277,8 +280,8 @@ bool Interpreter::callMainMethod(const string &Name, case 2: { PointerType *SPP = PointerType::get(PointerType::get(Type::SByteTy)); if (MT->getParamTypes()[1] != SPP) { - cout << "Second argument of '" << Name << "' should have type: '" - << SPP->getDescription() << "'!\n"; + CW << "Second argument of '" << Name << "' should have type: '" + << SPP << "'!\n"; return true; } @@ -306,3 +309,20 @@ bool Interpreter::callMainMethod(const string &Name, return false; } + + + +void Interpreter::list() { + if (ECStack.empty()) + cout << "Error: No program executing!\n"; + else + CW << ECStack[CurFrame].CurMethod; // Just print the method out... +} + +void Interpreter::printStackTrace() { + if (ECStack.empty()) cout << "No program executing!\n"; + + for (unsigned i = 0; i < ECStack.size(); ++i) { + printStackFrame((int)i); + } +}