ARM: Add minimal ARM_SE support for m5threads.
[gem5.git] / src / sim / debug.cc
index 09e5346a83697859c0bf7b278c477f3e57566e30..f8a3215d0dceb4562e95399799b428410a4fc64a 100644 (file)
  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Nathan Binkert
+ *          Steve Reinhardt
  */
 
-#include <sys/types.h>
-#include <signal.h>
-#include <unistd.h>
+#include <Python.h>
 
 #include <string>
 #include <vector>
 
+#include "base/debug.hh"
 #include "sim/debug.hh"
 #include "sim/eventq.hh"
-#include "sim/param.hh"
 #include "sim/sim_events.hh"
 
 using namespace std;
 
-void
-debug_break()
-{
-#ifndef NDEBUG
-    kill(getpid(), SIGTRAP);
-#else
-    cprintf("debug_break suppressed, compiled with NDEBUG\n");
-#endif
-}
-
 //
 // Debug event: place a breakpoint on the process function and
 // schedule the event to break at a particular cycle
 //
-class DebugBreakEvent : public Event
+struct DebugBreakEvent : public Event
 {
-  public:
-
-    DebugBreakEvent(EventQueue *q, Tick _when);
-
-    void process();    // process event
-    virtual const char *description();
+    DebugBreakEvent();
+    void process();     // process event
+    virtual const char *description() const;
 };
 
 //
 // constructor: schedule at specified time
 //
-DebugBreakEvent::DebugBreakEvent(EventQueue *q, Tick _when)
-    : Event(q, Debug_Break_Pri)
+DebugBreakEvent::DebugBreakEvent()
+    : Event(Debug_Break_Pri)
 {
     setFlags(AutoDelete);
-    schedule(_when);
 }
 
 //
@@ -85,52 +72,58 @@ DebugBreakEvent::process()
 
 
 const char *
-DebugBreakEvent::description()
+DebugBreakEvent::description() const
 {
     return "debug break";
 }
 
 //
-// Parameter context for global debug options
+// handy function to schedule DebugBreakEvent on main event queue
+// (callable from debugger)
 //
-class DebugContext : public ParamContext
+void
+schedBreakCycle(Tick when)
 {
-  public:
-    DebugContext(const string &_iniSection)
-        : ParamContext(_iniSection) {}
-    void checkParams();
-};
-
-DebugContext debugParams("debug");
-
-VectorParam<Tick> break_cycles(&debugParams, "break_cycles",
-                                 "cycle(s) to create breakpoint events");
+    mainEventQueue.schedule(new DebugBreakEvent, when);
+    warn("need to stop all queues");
+}
 
 void
-DebugContext::checkParams()
+eventqDump()
 {
-    if (break_cycles.isValid()) {
-        vector<Tick> &cycles = break_cycles;
-
-        vector<Tick>::iterator i = cycles.begin();
-        vector<Tick>::iterator end = cycles.end();
+    mainEventQueue.dump();
+    warn("need to dump all queues");
+}
 
-        for (; i < end; ++i)
-            new DebugBreakEvent(&mainEventQueue, *i);
-    }
+void
+py_interact()
+{
+    PyObject *globals;
+    PyObject *locals;
+
+    globals = PyEval_GetGlobals();
+    Py_INCREF(globals);
+    locals = PyDict_New();
+    PyRun_String("import code", Py_file_input, globals, locals);
+    PyRun_String("code.interact(local=globals())", Py_file_input,
+                 globals, locals);
+    Py_DECREF(globals);
+    Py_DECREF(locals);
 }
 
-//
-// handy function to schedule DebugBreakEvent on main event queue
-// (callable from debugger)
-//
-extern "C" void sched_break_cycle(Tick when)
+int remote_gdb_base_port = 7000;
+
+int
+getRemoteGDBPort()
 {
-    new DebugBreakEvent(&mainEventQueue, when);
+    return remote_gdb_base_port;
 }
 
-extern "C" void eventq_dump()
+// Set remote GDB base port.  0 means disable remote GDB.
+// Callable from python.
+void
+setRemoteGDBPort(int port)
 {
-    mainEventQueue.dump();
+    remote_gdb_base_port = port;
 }