3 This file is part of gldbg
4 Copyright © 2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the GPL
8 #include <msp/core/except.h>
9 #include <msp/io/file.h>
10 #include <msp/io/print.h>
11 #include <msp/strings/lexicalcast.h>
12 #include "commandinterpreter.h"
19 CommandInterpreter::CommandInterpreter(GlDbg &d):
22 commands["run"] = &CommandInterpreter::cmd_run;
23 commands["continue"] = &CommandInterpreter::cmd_continue;
24 commands["c"] = &CommandInterpreter::cmd_continue;
25 commands["kill"] = &CommandInterpreter::cmd_kill;
26 commands["signal"] = &CommandInterpreter::cmd_signal;
27 commands["exit"] = &CommandInterpreter::cmd_exit;
28 commands["quit"] = &CommandInterpreter::cmd_exit;
29 commands["trace"] = &CommandInterpreter::cmd_trace;
32 void CommandInterpreter::execute(const string &cmd)
34 unsigned space = cmd.find(' ');
35 string name = cmd.substr(0, space);
36 CommandMap::const_iterator i = commands.lower_bound(name);
37 if(i==commands.end() || i->first.compare(0, name.size(), name))
38 throw KeyError("Unknown command", name);
41 CommandMap::const_iterator j = i;
42 if((++j)!=commands.end() && !j->first.compare(0, name.size(), name))
43 throw KeyError("Ambiguous command", name);
47 if(space!=string::npos)
48 args = cmd.substr(space+1);
50 (this->*(i->second))(args);
54 void CommandInterpreter::cmd_run(const string &)
59 void CommandInterpreter::cmd_continue(const string &)
61 gldbg.get_process().resume();
64 void CommandInterpreter::cmd_signal(const string &args)
66 gldbg.get_process().resume(lexical_cast<unsigned>(args));
69 void CommandInterpreter::cmd_kill(const string &)
71 gldbg.get_process().kill();
74 void CommandInterpreter::cmd_exit(const string &)
79 void CommandInterpreter::cmd_trace(const string &args)
81 Tracer &tracer = gldbg.get_tracer();
84 string fn = args.substr(1);
87 tracer.set_output(IO::cout);
88 IO::print("Tracing to stdout\n");
92 tracer.set_output(new IO::File(fn, IO::M_WRITE));
93 IO::print("Tracing to %s\n", fn);
101 IO::print("Tracing enabled\n");
106 IO::print("Tracing disabled\n");
110 tracer.set_output(0);
111 IO::print("Tracing terminated\n");