]> git.tdb.fi Git - gldbg.git/commitdiff
Add help
authorMikko Rasa <tdb@tdb.fi>
Wed, 4 Nov 2009 10:58:59 +0000 (10:58 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 4 Nov 2009 10:58:59 +0000 (10:58 +0000)
source/commandinterpreter.cpp
source/commandinterpreter.h
source/gldbg.cpp

index 71e8ee7a001b7eafc14b1ec4f014ff47a48bac84..c51d0a2b223a326ff297be9d37e6fb46df573eae 100644 (file)
@@ -5,10 +5,12 @@ Copyright © 2009  Mikko Rasa, Mikkosoft Productions
 Distributed under the GPL
 */
 
+#include <signal.h>
 #include <msp/core/except.h>
 #include <msp/io/file.h>
 #include <msp/io/print.h>
 #include <msp/strings/lexicalcast.h>
+#include <msp/strings/utils.h>
 #include "commandinterpreter.h"
 #include "gldbg.h"
 #include "tracer.h"
@@ -19,14 +21,37 @@ using namespace Msp;
 CommandInterpreter::CommandInterpreter(GlDbg &d):
        gldbg(d)
 {
-       commands["run"] = &CommandInterpreter::cmd_run;
-       commands["continue"] = &CommandInterpreter::cmd_continue;
-       commands["c"] = &CommandInterpreter::cmd_continue;
-       commands["kill"] = &CommandInterpreter::cmd_kill;
-       commands["signal"] = &CommandInterpreter::cmd_signal;
-       commands["exit"] = &CommandInterpreter::cmd_exit;
-       commands["quit"] = &CommandInterpreter::cmd_exit;
-       commands["trace"] = &CommandInterpreter::cmd_trace;
+       commands["help"] = Command(&CommandInterpreter::cmd_help,
+               "Provides help on commands",
+               "help\n"
+               "  Displays a list of commands\n\n"
+               "help COMMAND\n"
+               "  Gives detailed information on a command\n");
+       commands["exit"] = Command(&CommandInterpreter::cmd_exit,
+               "Ends the debugging session");
+
+       commands["run"] = Command(&CommandInterpreter::cmd_run,
+               "Starts the program");
+       commands["continue"] = Command(&CommandInterpreter::cmd_continue,
+               "Resumes program execution");
+       commands["kill"] = Command(&CommandInterpreter::cmd_kill,
+               "Terminates the program immediately");
+       commands["signal"] = Command(&CommandInterpreter::cmd_signal,
+               "Resumes execution with a signal",
+               "signal NUM\n"
+               "signal NAME\n"
+               "  Sends the signal identified by NUM or NAME to the program and resumes\n"
+               "  execution.  Currently recognized signal names are HUP, INT, TERM, SEGV\n"
+               "  and TERM.\n");
+
+       commands["trace"] = Command(&CommandInterpreter::cmd_trace,
+               "Traces GL function calls",
+               "trace >FILE\n"
+               "  Send trace output to FILE.  As a special case, - means stdout.\n\n"
+               "trace {off|on}\n"
+               "  Temporarily suspend or resume trace without closing the file.\n\n"
+               "trace end\n"
+               "  Terminate trace, closing the file.\n");
 }
 
 void CommandInterpreter::execute(const string &cmd)
@@ -47,9 +72,26 @@ void CommandInterpreter::execute(const string &cmd)
        if(space!=string::npos)
                args = cmd.substr(space+1);
 
-       (this->*(i->second))(args);
+       (this->*(i->second.func))(args);
 }
 
+void CommandInterpreter::cmd_help(const string &args)
+{
+       if(args.empty())
+       {
+               for(map<string, Command>::const_iterator i=commands.begin(); i!=commands.end(); ++i)
+                       IO::print("%-10s : %s\n", i->first, i->second.description);
+       }
+       else
+       {
+               map<string, Command>::const_iterator i = commands.find(args);
+               if(i==commands.end())
+                       throw KeyError("Unknown command", args);
+               IO::print("%s : %s\n", i->first, i->second.description);
+               if(!i->second.help.empty())
+                       IO::print("\n%s", i->second.help);
+       }
+}
 
 void CommandInterpreter::cmd_run(const string &)
 {
@@ -63,7 +105,22 @@ void CommandInterpreter::cmd_continue(const string &)
 
 void CommandInterpreter::cmd_signal(const string &args)
 {
-       gldbg.get_process().resume(lexical_cast<unsigned>(args));
+       unsigned sig = 0;
+       if(args=="HUP" || args=="SIGHUP")
+               sig = SIGHUP;
+       else if(args=="INT" || args=="SIGINT")
+               sig = SIGINT;
+       else if(args=="ILL" || args=="SIGILL")
+               sig = SIGILL;
+       else if(args=="SEGV" || args=="SIGSEGV")
+               sig = SIGSEGV;
+       else if(args=="TERM" || args=="SIGTERM")
+               sig = SIGTERM;
+       else if(isnumrc(args))
+               sig = lexical_cast<unsigned>(args);
+       else
+               throw InvalidParameterValue("Invalid signal specification");
+       gldbg.get_process().resume(sig);
 }
 
 void CommandInterpreter::cmd_kill(const string &)
@@ -112,3 +169,19 @@ void CommandInterpreter::cmd_trace(const string &args)
                }
        }
 }
+
+
+CommandInterpreter::Command::Command():
+       func(0)
+{ }
+
+CommandInterpreter::Command::Command(Func f, const string &d):
+       func(f),
+       description(d)
+{ }
+
+CommandInterpreter::Command::Command(Func f, const string &d, const string &h):
+       func(f),
+       description(d),
+       help(h)
+{ }
index 8ce59d0a85fc02343908bf3001c21050227ea6f6..bdd3c174b2d993a2a34c694e1d6be279d627e7d3 100644 (file)
@@ -16,8 +16,20 @@ class GlDbg;
 class CommandInterpreter
 {
 private:
-       typedef void (CommandInterpreter::*CommandFunc)(const std::string &);
-       typedef std::map<std::string, CommandFunc> CommandMap;
+       struct Command
+       {
+               typedef void (CommandInterpreter::*Func)(const std::string &);
+
+               Func func;
+               std::string description;
+               std::string help;
+
+               Command();
+               Command(Func, const std::string &);
+               Command(Func, const std::string &, const std::string &);
+       };
+
+       typedef std::map<std::string, Command> CommandMap;
 
        GlDbg &gldbg;
        CommandMap commands;
@@ -27,6 +39,7 @@ public:
        void execute(const std::string &);
 
 private:
+       void cmd_help(const std::string &);
        void cmd_run(const std::string &);
        void cmd_continue(const std::string &);
        void cmd_signal(const std::string &);
index 5a4ad191f65c29a6c760deae5c329657b44b21b0..c91e00a79ec8171dd6672fbc8a1b9333209fa7e4 100644 (file)
@@ -39,6 +39,10 @@ int GlDbg::main()
        catch_signal(SIGCHLD);
        set_loop_mode(TICK_BUSY);
 
+       IO::print("GLdbg 0.0\n");
+       IO::print("Copyright © 2009 Mikkosoft Productions\n");
+       IO::print("Type \"help\" for a list of commands\n");
+
        Application::main();
 }