X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgldbg.cpp;h=4bc169fcd0079abb2f99811a87db777266e4e86f;hb=efd709c6cdac15b7823e80ed64e448003aea835d;hp=a7abf31e08ed848f205dbcc468d4b81706fd19c3;hpb=81f1ddee977603293d0c5710f2db69130dac6a96;p=gldbg.git diff --git a/source/gldbg.cpp b/source/gldbg.cpp index a7abf31..4bc169f 100644 --- a/source/gldbg.cpp +++ b/source/gldbg.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of gldbg -Copyright © 2009-2011 Mikko Rasa, Mikkosoft Productions -Distributed under the GPL -*/ - #include #include #include @@ -86,13 +79,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); } @@ -102,6 +110,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); @@ -115,11 +132,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); } } @@ -142,11 +156,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); } } }