arch,sim: Convert clone to GuestABI and define a cloneBackwardsFunc.
[gem5.git] / src / sim / debug.cc
index b82219f7d76a6932bee22ef9402cfd1fb8e63f72..bf46a51b26a270e4c6fa5dcb20584ec255fc4b6c 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 "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 +66,65 @@ 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");
-
-VectorParam<Tick> break_cycles(&debugParams, "break_cycles",
-                                 "cycle(s) to create breakpoint events");
+    new DebugBreakEvent(when);
+    warn("need to stop all queues");
+}
 
 void
-DebugContext::checkParams()
+schedRelBreak(Tick delta)
 {
-    if (break_cycles.isValid()) {
-        vector<Tick> &cycles = break_cycles;
+    schedBreak(curTick() + delta);
+}
 
-        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)
-//
-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;
 }