Re: BREAKing into Euphoria
- Posted by Andy Drummond <andy at k?strel?ele.com> Sep 12, 2007
- 1952 views
Pete Lomax wrote: > > I got some "interesting" results (random crashes mainly) from this, however > enough of it works to show that something is possible (comments, Rob?): > Maybe there is a generic problem with trace in call_back routines?? > > }}} <eucode> > -- NOTE: this is probably incompatible with allow_break/check_break(). > with trace > > include misc.e > > constant CTRL_C_EVENT = 0, > CTRL_BREAK_EVENT = 1 > > function HandlerRoutine(integer event) > if event = CTRL_C_EVENT > or event = CTRL_BREAK_EVENT then > trace(1) > sleep(2) > return 1 -- handled > end if > return 0 -- not handled > end function > > atom kernel32, xSetConsoleCtrlHandler, cbHR > include dll.e > > kernel32 = open_dll("kernel32.dll") > > xSetConsoleCtrlHandler = define_c_func(kernel32,"SetConsoleCtrlHandler", > {C_POINTER, -- PHANDLER_ROUTINE pHandlerRoutine, // address of handler > function > C_INT}, -- BOOL fAdd // handler to add or remove > C_INT) -- BOOL > > cbHR = call_back(routine_id("HandlerRoutine")) > if not c_func(xSetConsoleCtrlHandler,{cbHR,1}) then ?9/0 end if > > with trace > > while 1 do > puts(1,"sleeping\n") > sleep(2) > puts(1,"awake\n") > end while > </eucode> {{{ > > I suspect that if you could somehow call the trace(1) in HandlerRoutine but > not then trace any lines in that code, it might actually work. > > When not interpreting source, or under an allow_break(False), then Ctrl Break > should not attempt to fire up the trace window, otherwise it should. > I don't think changing Ctrl C is a good idea, too easy to accidentally hit, > plus eg Edita happily uses it for Copy w/out problems as is. > > Regards, > Pete Pete, That look pretty much what I was after. I understand that it might well not be possible to trace once the break has been executed, but if I can tell where I am in the program then I can start the safer but more laborious technique of putting in trace(1) - or even trace(3) - calls. At present I have no idea where I am executing when everything dies on me. I just need to go Click! and find out which line of the program was executing at the time. We will see... Andy