X-Git-Url: http://git.tdb.fi/?p=gldbg.git;a=blobdiff_plain;f=source%2Fgldbg.cpp;h=c13d5cc2fa6bbafb1b42c87b38139cf78fd58c10;hp=c37e65552a3684c5681284e5821959829d79648b;hb=a34325fadec5b2be003bf9af1f081bfc4c83e8b6;hpb=a832996c884a0e0acc9a38ba4dd258edb75ec7af diff --git a/source/gldbg.cpp b/source/gldbg.cpp index c37e655..c13d5cc 100644 --- a/source/gldbg.cpp +++ b/source/gldbg.cpp @@ -20,8 +20,10 @@ using namespace std; GlDbg *GlDbg::instance = 0; GlDbg::GlDbg(int argc, char **argv): + done(false), cmd_interp(*this), process(vector(argv+1, argv+argc)), + sock_fd(-1), buf_offset(0), flushing(false), got_sigchld(false), @@ -56,7 +58,7 @@ int GlDbg::main() printf("Copyright © 2009-2010 Mikkosoft Productions\n"); printf("Type \"help\" for a list of commands\n"); - while(1) + while(!done) tick(); return 0; @@ -79,13 +81,28 @@ void GlDbg::launch() process.launch(); close(fds[1]); - breakpoints.clear(); + for(BreakList::iterator i=breakpoints.begin(); i!=breakpoints.end(); ) + { + if(i->has_owner(0)) + { + i->owners.clear(); + i->owners.push_back(0); + send_breakpoint(i->function, i->flag, 0); + ++i; + } + else + breakpoints.erase(i++); + } + for(ToolList::iterator i=tools.begin(); i!=tools.end(); ++i) (*i)->process_started(); } void GlDbg::send(GlPacket *pkt) { + if(process.get_state()==Process::INACTIVE) + throw runtime_error("Program is not running"); + packet_send(pkt, sock_fd); } @@ -95,6 +112,15 @@ void GlDbg::hold() send(pkt); } +void GlDbg::send_breakpoint(unsigned short func, unsigned char set_flags, unsigned char clear_flags) +{ + GlPacket *pkt = packet_begin(FUNC_GLDBREAK); + packet_write_short(pkt, func); + packet_write_char(pkt, set_flags); + packet_write_char(pkt, clear_flags); + send(pkt); +} + void GlDbg::set_breakpoint(unsigned short func, unsigned char flag, Tool *owner) { Breakpoint *bp = (func ? get_breakpoint(func, flag) : 0); @@ -108,11 +134,8 @@ void GlDbg::set_breakpoint(unsigned short func, unsigned char flag, Tool *owner) breakpoints.back().add_owner(owner); } - GlPacket *pkt = packet_begin(FUNC_GLDBREAK); - packet_write_short(pkt, func); - packet_write_char(pkt, flag); - packet_write_char(pkt, 0); - send(pkt); + if(process.get_state()>=Process::RUNNING) + send_breakpoint(func, flag, 0); } } @@ -135,11 +158,8 @@ void GlDbg::clear_breakpoint(unsigned short func, unsigned char flag, Tool *owne break; } - GlPacket *pkt = packet_begin(FUNC_GLDBREAK); - packet_write_short(pkt, func); - packet_write_char(pkt, 0); - packet_write_char(pkt, flag); - send(pkt); + if(process.get_state()>=Process::RUNNING) + send_breakpoint(func, 0, flag); } } } @@ -161,7 +181,7 @@ void GlDbg::quit(bool force) { if(!force && process.get_state()!=Process::INACTIVE) throw runtime_error("Program is still running"); - exit(0); + done = true; } void GlDbg::tick() @@ -207,7 +227,7 @@ void GlDbg::tick() free(line); } else if(pstate==Process::INACTIVE) - exit(0); + done = true; } }