X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fgldbg.cpp;fp=source%2Fgldbg.cpp;h=a7abf31e08ed848f205dbcc468d4b81706fd19c3;hb=81f1ddee977603293d0c5710f2db69130dac6a96;hp=001742d39599b85942702f797d8e8ed383d7a16d;hpb=a51c2557622ea93944e24f58845609526eb46ec1;p=gldbg.git diff --git a/source/gldbg.cpp b/source/gldbg.cpp index 001742d..a7abf31 100644 --- a/source/gldbg.cpp +++ b/source/gldbg.cpp @@ -1,31 +1,30 @@ /* $Id$ This file is part of gldbg -Copyright © 2009-2010 Mikko Rasa, Mikkosoft Productions +Copyright © 2009-2011 Mikko Rasa, Mikkosoft Productions Distributed under the GPL */ #include +#include #include +#include #include #include +#include #include #include #include -#include -#include -#include -#include #include "functions.h" #include "gldbg.h" #include "gldecoder.h" #include "packet.h" +#include "strformat.h" #include "tool.h" using namespace std; -using namespace Msp; -Application::RegApp GlDbg::reg; +GlDbg *GlDbg::instance = 0; GlDbg::GlDbg(int argc, char **argv): cmd_interp(*this), @@ -36,8 +35,13 @@ GlDbg::GlDbg(int argc, char **argv): stop_reason(0), current_break(0) { - FS::Path libdir = FS::get_sys_lib_dir(argv[0], "gldbg"); - process.setenv("LD_PRELOAD", (libdir/"glwrap.so").str().c_str()); + instance = this; + + char buf[PATH_MAX]; + unsigned len = readlink("/proc/self/exe", buf, sizeof(buf)); + string exe(buf, len); + string::size_type slash = exe.rfind('/'); + process.setenv("LD_PRELOAD", (exe.substr(0, slash+1)+"glwrap.so")); const list &factories = Tool::get_factories(); for(list::const_iterator i=factories.begin(); i!=factories.end(); ++i) @@ -52,15 +56,15 @@ GlDbg::~GlDbg() int GlDbg::main() { - catch_signal(SIGINT); - catch_signal(SIGCHLD); - set_loop_mode(TICK_BUSY); + signal(SIGINT, &sighandler); + signal(SIGCHLD, &sighandler); - IO::print("GLdbg 0.0\n"); - IO::print("Copyright © 2009-2010 Mikkosoft Productions\n"); - IO::print("Type \"help\" for a list of commands\n"); + printf("GLdbg 0.0\n"); + printf("Copyright © 2009-2010 Mikkosoft Productions\n"); + printf("Type \"help\" for a list of commands\n"); - Application::main(); + while(1) + tick(); return 0; } @@ -68,7 +72,7 @@ int GlDbg::main() void GlDbg::launch() { if(process.get_state()!=Process::INACTIVE) - throw InvalidState("Program is already running"); + throw runtime_error("Program is already running"); int fds[2]; socketpair(AF_UNIX, SOCK_STREAM, 0, fds); @@ -77,8 +81,8 @@ void GlDbg::launch() int flags = fcntl(sock_fd, F_GETFD); fcntl(sock_fd, F_SETFD, flags|FD_CLOEXEC); - process.setenv("GLWRAP_FD", lexical_cast(fds[1])); - process.setenv("GLWRAP_CTRL_FD", lexical_cast(fds[1])); + process.setenv("GLWRAP_FD", strformat("%d", fds[1])); + process.setenv("GLWRAP_CTRL_FD", strformat("%d", fds[1])); process.launch(); close(fds[1]); @@ -163,7 +167,7 @@ void GlDbg::resume_from_break(Tool *tool) void GlDbg::quit(bool force) { if(!force && process.get_state()!=Process::INACTIVE) - throw InvalidState("Program is still running"); + throw runtime_error("Program is still running"); exit(0); } @@ -185,13 +189,13 @@ void GlDbg::tick() if(stop_reason) { if(stop_reason==0x100) - IO::print("Target process exited normally\n"); + printf("Target process exited normally\n"); else if((stop_reason>>8)==1) - IO::print("Target process exited with status %d\n", stop_reason&0xFF); + printf("Target process exited with status %d\n", stop_reason&0xFF); else if((stop_reason>>8)==2) - IO::print("Target process terminated with signal %d\n", stop_reason&0xFF); + printf("Target process terminated with signal %d\n", stop_reason&0xFF); else if((stop_reason>>8)==3) - IO::print("Target process stopped by signal %d\n", stop_reason&0xFF); + printf("Target process stopped by signal %d\n", stop_reason&0xFF); stop_reason = 0; } @@ -203,9 +207,9 @@ void GlDbg::tick() { cmd_interp.execute(line); } - catch(const Exception &e) + catch(const exception &e) { - IO::print("%s\n", e.what()); + printf("%s\n", e.what()); } free(line); } @@ -250,7 +254,7 @@ void GlDbg::read_stream() } if(announce) - IO::print("Breakpoint: %s\n", get_function_name(func)); + printf("Breakpoint: %s\n", get_function_name(func)); } for(ToolList::iterator i=tools.begin(); i!=tools.end(); ++i) @@ -291,7 +295,7 @@ GlDbg::Breakpoint *GlDbg::get_breakpoint(unsigned short func, unsigned char flag void GlDbg::sighandler(int sig) { if(sig==SIGCHLD) - got_sigchld = true; + instance->got_sigchld = true; }