sim, arch, base: Refactor the base remote GDB class.
[gem5.git] / src / sim / debug.cc
index be9566836feca90a0a864128e1a1dfd084eb111c..b8291c86205c495160301b7bb0bdde9c62360fdd 100644 (file)
  *          Steve Reinhardt
  */
 
-#include <sys/types.h>
-#include <signal.h>
-#include <unistd.h>
+#include "sim/debug.hh"
 
 #include <string>
 #include <vector>
 
-#include "sim/debug.hh"
-#include "sim/eventq.hh"
-#include "sim/param.hh"
+#include "base/debug.hh"
+#include "cpu/pc_event.hh"
+#include "sim/eventq_impl.hh"
+#include "sim/global_event.hh"
 #include "sim/sim_events.hh"
+#include "sim/sim_exit.hh"
+#include "sim/system.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 GlobalEvent
 {
-  public:
-
-    DebugBreakEvent(EventQueue *q, Tick _when);
-
-    void process();    // process event
-    virtual const char *description();
+    DebugBreakEvent(Tick when);
+    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(Tick when)
+    : GlobalEvent(when, Debug_Break_Pri, AutoDelete)
 {
-    setFlags(AutoDelete);
-    schedule(_when);
 }
 
 //
@@ -83,57 +69,73 @@ DebugBreakEvent::DebugBreakEvent(EventQueue *q, Tick _when)
 void
 DebugBreakEvent::process()
 {
-    debug_break();
+    Debug::breakpoint();
 }
 
 
 const char *
-DebugBreakEvent::description()
+DebugBreakEvent::description() const
 {
-    return "debug break";
+    return "debug breakpoint";
 }
 
 //
-// Parameter context for global debug options
+// handy function to schedule DebugBreakEvent on main event queue
+// (callable from debugger)
 //
-class DebugContext : public ParamContext
+void
+schedBreak(Tick when)
 {
-  public:
-    DebugContext(const string &_iniSection)
-        : ParamContext(_iniSection) {}
-    void checkParams();
-};
-
-DebugContext debugParams("debug");
+    new DebugBreakEvent(when);
+    warn("need to stop all queues");
+}
 
-VectorParam<Tick> break_cycles(&debugParams, "break_cycles",
-                                 "cycle(s) to create breakpoint events");
+void
+schedRelBreak(Tick delta)
+{
+    schedBreak(curTick() + delta);
+}
 
 void
-DebugContext::checkParams()
+breakAtKernelFunction(const char* funcName)
 {
-    if (break_cycles.isValid()) {
-        vector<Tick> &cycles = break_cycles;
+    System* curSystem = System::systemList[0];
+    curSystem->addKernelFuncEvent<BreakPCEvent>(funcName,
+                                                "GDB scheduled break", true);
+}
 
-        vector<Tick>::iterator i = cycles.begin();
-        vector<Tick>::iterator end = cycles.end();
+///
+/// Function to cause the simulator to take a checkpoint from the debugger
+///
+void
+takeCheckpoint(Tick when)
+{
+    if (!when)
+        when = curTick() + 1;
+    exitSimLoop("checkpoint", 0, when, 0);
+}
 
-        for (; i < end; ++i)
-            new DebugBreakEvent(&mainEventQueue, *i);
+void
+eventqDump()
+{
+    for (uint32_t i = 0; i < numMainEventQueues; ++i) {
+        mainEventQueue[i]->dump();
     }
 }
 
-//
-// handy function to schedule DebugBreakEvent on main event queue
-// (callable from debugger)
-//
-void sched_break_cycle(Tick when)
+int remote_gdb_base_port = 7000;
+
+int
+getRemoteGDBPort()
 {
-    new DebugBreakEvent(&mainEventQueue, when);
+    return remote_gdb_base_port;
 }
 
-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;
 }