X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprocess.cpp;h=88cb0fac533ebf3521c1f5e0139cb1eabb550961;hb=HEAD;hp=ebc0b955e1b64b13680d621fafe16a0ee9e89aca;hpb=c6b2f7585d51164dc32f4dd2a05855913e464c58;p=gldbg.git diff --git a/source/process.cpp b/source/process.cpp index ebc0b95..88cb0fa 100644 --- a/source/process.cpp +++ b/source/process.cpp @@ -1,20 +1,14 @@ -/* $Id$ - -This file is part of gldbg -Copyright © 2009 Mikko Rasa, Mikkosoft Productions -Distributed under the GPL -*/ - +#include #include #include #include +#include #include #include -#include #include "process.h" +#include "strformat.h" using namespace std; -using namespace Msp; Process::Process(const vector &a): args(a), @@ -30,7 +24,7 @@ void Process::setenv(const string &key, const string &value) void Process::launch() { if(state!=INACTIVE) - throw InvalidState("Program is already running"); + throw logic_error("Program is already running"); pid = fork(); if(pid==0) @@ -48,7 +42,7 @@ void Process::launch() 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() @@ -90,7 +84,7 @@ 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; } @@ -98,14 +92,16 @@ void Process::resume(int sig) 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; }