*Print Stack traces better.
* Use the cache writer for all it's problems.
* print arguments to methods in stack traces.
*Print the current stack from for up/down commands.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1170 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp
index 7c3a23d..5012012 100644
--- a/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -27,10 +27,12 @@
 
 
 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 @@
   sigemptyset(&Action.sa_mask);
   sigaction(SIGSEGV, &Action, 0);
   sigaction(SIGBUS, &Action, 0);
+  sigaction(SIGINT, &Action, 0);
   //sigaction(SIGFP, &Action, 0);
 }
 
@@ -193,7 +196,7 @@
     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 @@
   //
   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<BinaryOperator>(I), SF);
   } else {
@@ -1013,6 +1022,7 @@
       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 @@
           getOperandValue(PickedVal, ECStack[CurFrame]));
     cout << endl;
   }
-    
 }
 
 void Interpreter::infoValue(const string &Name) {
@@ -1175,22 +1184,25 @@
   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 23354e3..791419d 100644
--- a/lib/ExecutionEngine/Interpreter/Interpreter.h
+++ b/lib/ExecutionEngine/Interpreter/Interpreter.h
@@ -136,6 +136,11 @@
   //
   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 a1518d4..7ece7bc 100644
--- a/lib/ExecutionEngine/Interpreter/UserInput.cpp
+++ b/lib/ExecutionEngine/Interpreter/UserInput.cpp
@@ -105,12 +105,15 @@
     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 @@
   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 @@
 
   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);
+  }
+}