]> git.tdb.fi Git - gldbg.git/blobdiff - source/commandinterpreter.cpp
Enable bidirectional communication between gldbg and glwrap.so
[gldbg.git] / source / commandinterpreter.cpp
index 2a28f69acd6e06a2dc8c523ef2e58a388a62124d..25f004ef32a639497437eaf5709c0b87c64465d5 100644 (file)
@@ -11,8 +11,10 @@ Distributed under the GPL
 #include <msp/io/print.h>
 #include <msp/strings/lexicalcast.h>
 #include <msp/strings/utils.h>
+#include "breakpoint.h"
 #include "commandinterpreter.h"
 #include "enums.h"
+#include "functions.h"
 #include "gldbg.h"
 #include "tracer.h"
 
@@ -34,6 +36,19 @@ CommandInterpreter::CommandInterpreter(GlDbg &d):
 
        register_command("run", this, &CommandInterpreter::cmd_run)
                .set_help("Starts the program");
+       register_command("break", this, &CommandInterpreter::cmd_break)
+               .set_help("Sets a breakpoint",
+                       "break FUNC\n"
+                       "  Makes program execution stop at FUNC\n");
+       register_command("unbreak", this, &CommandInterpreter::cmd_unbreak)
+               .set_help("Removes a breakpoint",
+                       "unbreak FUNC\n"
+                       "  Makes program execution no longer stop at FUNC\n");
+       register_command("next", this, &CommandInterpreter::cmd_next)
+               .set_help("Resumes program execution until the next function call");
+       commands["step"] = new CommandAlias(commands["next"]);
+       register_command("finish", this, &CommandInterpreter::cmd_finish)
+               .set_help("Resumes program execution until the next function return");
        register_command("continue", this, &CommandInterpreter::cmd_continue)
                .set_help("Resumes program execution");
        register_command("kill", this, &CommandInterpreter::cmd_kill)
@@ -98,6 +113,36 @@ void CommandInterpreter::cmd_run(const string &)
        gldbg.launch();
 }
 
+void CommandInterpreter::cmd_break(const string &args)
+{
+       unsigned short func = get_function(args.c_str());
+       if(!func)
+               throw InvalidParameterValue("Unknown function");
+
+       gldbg.set_breakpoint(func, BREAK_CALL);
+}
+
+void CommandInterpreter::cmd_unbreak(const string &args)
+{
+       unsigned short func = get_function(args.c_str());
+       if(!func)
+               throw InvalidParameterValue("Unknown function");
+
+       gldbg.clear_breakpoint(func, BREAK_CALL);
+}
+
+void CommandInterpreter::cmd_next(const string &)
+{
+       gldbg.set_breakpoint(0, BREAK_CALL);
+       gldbg.get_process().resume();
+}
+
+void CommandInterpreter::cmd_finish(const string &)
+{
+       gldbg.set_breakpoint(0, BREAK_RETURN);
+       gldbg.get_process().resume();
+}
+
 void CommandInterpreter::cmd_continue(const string &)
 {
        IO::print("Continuing.\n");