/* $Id$
This file is part of gldbg
-Copyright © 2009 Mikko Rasa, Mikkosoft Productions
+Copyright © 2009, 2011 Mikko Rasa, Mikkosoft Productions
Distributed under the GPL
*/
+#include <stdexcept>
#include <cstdlib>
#include <cerrno>
#include <cstring>
#include <sys/ptrace.h>
#include <sys/wait.h>
-#include <msp/core/except.h>
#include "process.h"
+#include "strformat.h"
using namespace std;
-using namespace Msp;
Process::Process(const vector<string> &a):
args(a),
void Process::launch()
{
if(state!=INACTIVE)
- throw InvalidState("Program is already running");
+ throw logic_error("Program is already running");
pid = fork();
if(pid==0)
else if(pid>0)
state = STARTING;
else
- throw SystemError("Could not launch process", errno);
+ throw runtime_error(strformat("Could not launch process: %s", strerror(errno)));
}
int Process::check()
void Process::resume(int sig)
{
if(state!=STOPPED)
- throw InvalidState("Program is not stopped");
+ throw logic_error("Program is not stopped");
ptrace(PTRACE_CONT, 0, (void *)sig);
state = RUNNING;
}
void Process::kill()
{
if(state==INACTIVE)
- throw InvalidState("Program is not running");
+ throw logic_error("Program is not running");
ptrace(PTRACE_KILL, 0, 0);
+ // Make the debugger wait() for us
+ state = RUNNING;
}
long Process::ptrace(int req, void *addr, void *data)
{
int ret = ::ptrace((__ptrace_request)req, pid, addr, data);
if(ret==-1 && ((req!=PTRACE_PEEKTEXT && req!=PTRACE_PEEKDATA && req!=PTRACE_PEEKUSER) || errno))
- throw SystemError("ptrace error", errno);
+ throw runtime_error(strformat("ptrace error: %s", strerror(errno)));
return ret;
}