internal void SetBreakpoint(uint address, AD7BoundBreakpoint bb) { if (address >= breakPointAddresses.Count) { return; } BreakPointAddress bpa = breakPointAddresses[(int)address]; if (bpa != null) { bpa.boundbp = bb; ctx.AddBreakpoint(bpa.filectx, bpa.line, bpa.source); engineCallback.OnBreakpointBound(bb, bpa.id); } // Console.WriteLine("SetBreakpoint"); }
internal void RemoveBreakpoint(uint address, AD7BoundBreakpoint bb) { if (address >= breakPointAddresses.Count) { return; } BreakPointAddress bpa = breakPointAddresses[(int)address]; if (bpa != null) { breakPointAddresses[(int)address] = null; ctx.RemoveBreakpoint(bpa.filectx, bpa.line, bpa.source); } //Console.WriteLine("RemoveBreakpoint"); }
internal void ToggleBreakpoint(uint address, AD7BoundBreakpoint bb, bool enable) { if (address >= breakPointAddresses.Count) { return; } BreakPointAddress bpa = breakPointAddresses[(int)address]; if (bpa != null) { if (enable) { ctx.AddBreakpoint(bpa.filectx, bpa.line, bpa.source); } else { ctx.RemoveBreakpoint(bpa.filectx, bpa.line, bpa.source); } } //Console.WriteLine("RemoveBreakpoint"); }
// Initiate an x86 stack walk on this thread. /* public void DoStackWalk(DebuggedThread thread) * { * //throw new NotImplementedException(); * } * * public void WaitForAndDispatchDebugEvent(ResumeEventPumpFlags flags) * { * throw new NotImplementedException(); * }*/ /* public int PollThreadId * { * get { return 1; } * } * * public bool IsStopped * { * get * { * return false; * } * } * * public bool IsPumpingDebugEvents * { * get * { * return true; * } * }*/ #endregion void DebugContextHandler(SquirrelDebugContext ctx, DebuggerEventDesc ed) { switch (ed.EventType) { case "error": case "breakpoint": case "step": if (ed.EventType != "step") { engineCallback.OnOutputString("DEBUGGER EVENT : " + ed.EventType + "\n"); } if (thread.Id != ed.ThreadId) { DebuggedThread oldthread = thread; thread = new DebuggedThread(engine, ed.ThreadId); thread.SetContext(ctx); engineCallback.OnThreadExit(oldthread, 0); } thread.SetStackFrames(ctx.StackFrames); processState = (uint)enum_PROCESS_INFO_FLAGS.PIFLAG_PROCESS_STOPPED | (uint)enum_PROCESS_INFO_FLAGS.PIFLAG_DEBUGGER_ATTACHED; switch (ed.EventType) { case "error": //engineCallback.OnError(thread,"Unhandled exception [{0}] line = {1} source = {2} ThreadId = {3}", ed.Error, ed.Line, ed.Source, ed.ThreadId); engineCallback.OnException(thread, ed.Error, ed.Line, ed.Source); break; case "breakpoint": { BreakPointAddress bpa = FindBreakpoint((uint)ed.Line, ed.Source); if (bpa != null) { engineCallback.OnOutputString("BP " + ed.Line + " : " + ed.Source + "\n"); engineCallback.OnBreakpoint(thread, bpa.boundbp, bpa.id); } else { engineCallback.OnOutputString("DEBUGGER ERROR : Could not find breakpoint " + ed.Line + " : " + ed.Source + "\n"); Continue(thread); } } break; case "step": engineCallback.OnStepComplete(thread); break; } break; case "resumed": engineCallback.OnOutputString("DEBUGGER EVENT : resumed\n"); processState = (uint)enum_PROCESS_INFO_FLAGS.PIFLAG_PROCESS_RUNNING | (uint)enum_PROCESS_INFO_FLAGS.PIFLAG_DEBUGGER_ATTACHED; break; case "suspended": engineCallback.OnOutputString("DEBUGGER EVENT : suspended\n"); engineCallback.OnAsyncBreakComplete(thread); processState = (uint)enum_PROCESS_INFO_FLAGS.PIFLAG_PROCESS_STOPPED | (uint)enum_PROCESS_INFO_FLAGS.PIFLAG_DEBUGGER_ATTACHED; break; case "disconnected": engineCallback.OnOutputString("DEBUGGER EVENT : disconnected\n"); Terminate(); processState = (uint)enum_PROCESS_INFO_FLAGS.PIFLAG_PROCESS_STOPPED; break; case "addbreakpoint": engineCallback.OnOutputString(String.Format("DEBUGGER EVENT : {0}\n", ed.EventType)); break; default: engineCallback.OnOutputString("DEBUGGER EVENT : " + ed.EventType + "<UNHANDLED>\n"); break; } //Console.WriteLine("do things here"); }
internal uint[] GetAddressesForSourceLocation(String moduleName, String documentName, uint dwStartLine, uint dwStartCol) { string source = documentName.ToLower(); SquirrelDebugFileContext filectx = null; if (Path.IsPathRooted(source)) { foreach (SquirrelDebugFileContext sdfc in FileContexts) { if (source.StartsWith(sdfc.rootpath)) { source = source.Substring(sdfc.rootpath.Length); filectx = sdfc; break; } } //string engineDir = engine.BaseDir.ToLower(); /*string engineDir = ProjectFolder.ToLower(); * if (!engineDir.EndsWith("\\")) * { * engineDir += "\\"; * } * if (source.StartsWith(engineDir)) * { * source = source.Substring(engineDir.Length); * }*/ /*else * { * string[] srcsplits = source.Split('\\'); * string[] engsplits = engineDir.Split('\\'); * int nb = Math.Min(srcsplits.Length, engsplits.Length); * int idx = -1; * for(int i=0; i<nb; i++) * { * string ep = engsplits[i]; * string sp = srcsplits[i]; * if (ep != sp) * { * idx = i; * break; * } * } * if (idx != -1) * { * string normalizesrc = ""; * int pad = nb - idx; * normalizesrc = normalizesrc.PadLeft(pad, '-'); * for (int i = idx; i < nb; i++) * { * //string ep = engsplits[i]; * string sp = srcsplits[i]; * normalizesrc += "\\" + sp; * } * source = string.IsNullOrEmpty(normalizesrc)? source : normalizesrc; * } * }*/ } foreach (BreakPointAddress bpa in breakPointAddresses) { if (bpa != null && bpa.line == dwStartLine && bpa.source == source) { return(new uint[] { bpa.id }); } } uint emptyslot = 0; bool slotfound = false; foreach (BreakPointAddress bpa in breakPointAddresses) { if (bpa == null) { slotfound = true; break; } emptyslot++; } BreakPointAddress nbpa = new BreakPointAddress(); nbpa.id = (uint)breakPointAddresses.Count; nbpa.source = source; nbpa.line = dwStartLine; nbpa.filectx = filectx; if (slotfound) { nbpa.id = emptyslot; breakPointAddresses[(int)emptyslot] = nbpa; } else { nbpa.id = (uint)breakPointAddresses.Count; breakPointAddresses.Add(nbpa); } return(new uint[] { nbpa.id }); }