Ejemplo n.º 1
0
        protected override BreakEventInfo OnInsertBreakEvent(BreakEvent breakEvent)
        {
            BreakEventInfo breakEventInfo;

            if (breakpoints.TryGetValue(breakEvent, out breakEventInfo))
            {
                return(breakEventInfo);
            }

            breakEventInfo = new BreakEventInfo();

            if (breakEvent is Mono.Debugging.Client.Breakpoint)
            {
                breakpoints.Add(breakEvent, breakEventInfo);
                UpdateBreakpoints();
            }
            else if (breakEvent is Catchpoint)
            {
                breakpoints.Add(breakEvent, breakEventInfo);
                UpdateExceptions();
            }
            else
            {
                throw new NotImplementedException(breakEvent.GetType().FullName);
            }

            return(breakEventInfo);
        }
Ejemplo n.º 2
0
        protected override void OnUpdateBreakEvent(BreakEventInfo binfo)
        {
            Breakpoint bp = binfo.BreakEvent as Breakpoint;

            if (bp == null)
            {
                throw new NotSupportedException();
            }

            bool ss = InternalStop();

            try {
                if (bp.HitCount > 0)
                {
                    RunCommand("-break-after", binfo.Handle.ToString(), bp.HitCount.ToString());
                    breakpointsWithHitCount.Add(binfo);
                }
                else
                {
                    breakpointsWithHitCount.Remove(binfo);
                }

                if (!string.IsNullOrEmpty(bp.ConditionExpression) && !bp.BreakIfConditionChanges)
                {
                    RunCommand("-break-condition", binfo.Handle.ToString(), bp.ConditionExpression);
                }
                else
                {
                    RunCommand("-break-condition", binfo.Handle.ToString());
                }
            } finally {
                InternalResume(ss);
            }
        }
Ejemplo n.º 3
0
 protected override void OnRemoveBreakEvent(BreakEventInfo binfo)
 {
     if (LogWriter != null)
     {
         LogWriter(false, "Break removed " + binfo.ToString());
     }
 }
Ejemplo n.º 4
0
        protected override BreakEventInfo OnInsertBreakEvent(BreakEvent be)
        {
            Breakpoint bp = be as Breakpoint;

            if (bp == null)
            {
                throw new NotSupportedException();
            }

            BreakEventInfo breakEventInfo = new BreakEventInfo();

            if (bp.HitCount > 0)
            {
                breakpointsWithHitCount.Add(breakEventInfo);
            }

            ulong address = this.SymbolResolver.GetAddressFromCodeLine(bp.FileName, (ushort)bp.Line);

            if (address != 0)
            {
                breakpointcounter++;
                debuggee.SetBreakPoint(address);
                breakpoints[address]  = new BreakPointWrapper(breakpointcounter, breakEventInfo);
                breakEventInfo.Handle = address;
                breakEventInfo.SetStatus(BreakEventStatus.Bound, null);
            }
            else
            {
                breakEventInfo.SetStatus(BreakEventStatus.BindError, null);
            }

            return(breakEventInfo);
        }
Ejemplo n.º 5
0
 protected override void OnEnableBreakEvent(BreakEventInfo binfo, bool enable)
 {
     lock (gdbLock)
     {
         if (binfo.Handle == null)
         {
             return;
         }
         bool dres = InternalStop();
         try
         {
             if (enable)
             {
                 RunCommand("-break-enable", binfo.Handle.ToString());
             }
             else
             {
                 RunCommand("-break-disable", binfo.Handle.ToString());
             }
         }
         finally
         {
             InternalResume(dres);
         }
     }
 }
Ejemplo n.º 6
0
        protected override BreakEventInfo OnInsertBreakEvent(BreakEvent be)
        {
            Breakpoint bp = be as Breakpoint;

            if (bp == null)
            {
                throw new NotSupportedException();
            }

            BreakEventInfo breakEventInfo = new BreakEventInfo();


            //bool dres = InternalStop ();
            try
            {
                string extraCmd = string.Empty;
                if (bp.HitCount > 0)
                {
                    extraCmd += "-i " + bp.HitCount;
                    breakpointsWithHitCount.Add(breakEventInfo);
                }
                if (!string.IsNullOrEmpty(bp.ConditionExpression))
                {
                    if (!bp.BreakIfConditionChanges)
                    {
                        extraCmd += " -c " + bp.ConditionExpression;
                    }
                }

                ulong bh = 0;
                DebugEngineWrapper.BreakPoint engineBreakPoint = null;
                ulong off = 0;
                if (Engine.Symbols.GetOffsetByLine(bp.FileName, (uint)bp.Line, out off))
                {
                    engineBreakPoint        = Engine.AddBreakPoint(BreakPointOptions.Enabled);
                    engineBreakPoint.Offset = off;

                    bh = engineBreakPoint.Offset;
                    breakpoints[bh]       = new BreakPointWrapper(breakEventInfo, engineBreakPoint);
                    breakEventInfo.Handle = bh;
                    breakEventInfo.SetStatus(BreakEventStatus.Bound, null);

                    //if (!be.Enabled)
                    //ToDo: tell debugger engine that breakpoint is disabled
                }
                else
                {
                    breakEventInfo.SetStatus(BreakEventStatus.BindError, null);
                }



                return(breakEventInfo);
            }
            finally
            {
                //InternalResume (dres);
            }
        }
Ejemplo n.º 7
0
        protected override BreakEventInfo OnInsertBreakEvent(BreakEvent be)
        {
            BreakEventInfo binfo = new BreakEventInfo();

            lock (documents) {
                Breakpoint bp = be as Breakpoint;
                if (bp != null)
                {
                    DocInfo doc;
                    if (!documents.TryGetValue(System.IO.Path.GetFullPath(bp.FileName), out doc))
                    {
                        binfo.SetStatus(BreakEventStatus.NotBound, null);
                        return(binfo);
                    }

                    int line;
                    try {
                        line = doc.Document.FindClosestLine(bp.Line);
                    }
                    catch {
                        // Invalid line
                        binfo.SetStatus(BreakEventStatus.Invalid, null);
                        return(binfo);
                    }
                    ISymbolMethod met = doc.Reader.GetMethodFromDocumentPosition(doc.Document, line, 0);
                    if (met == null)
                    {
                        binfo.SetStatus(BreakEventStatus.Invalid, null);
                        return(binfo);
                    }

                    int offset = -1;
                    foreach (SequencePoint sp in met.GetSequencePoints())
                    {
                        if (sp.Line == line && sp.Document.URL == doc.Document.URL)
                        {
                            offset = sp.Offset;
                            break;
                        }
                    }
                    if (offset == -1)
                    {
                        binfo.SetStatus(BreakEventStatus.Invalid, null);
                        return(binfo);
                    }

                    CorFunction           func  = doc.Module.GetFunctionFromToken(met.Token.GetToken());
                    CorFunctionBreakpoint corBp = func.ILCode.CreateBreakpoint(offset);
                    corBp.Activate(bp.Enabled);
                    breakpoints[corBp] = binfo;

                    binfo.Handle = corBp;
                    binfo.SetStatus(BreakEventStatus.Bound, null);
                    return(binfo);
                }
            }
            return(null);
        }
Ejemplo n.º 8
0
        private BreakEventInfo OnInsertWatchPoint(BreakEvent be)
        {
            var bi = new BreakEventInfo();
            var wp = be as WatchPoint;

            lock (gdbLock)
            {
                bool dres = InternalStop();
                try
                {
                    string           errorMsg = string.Empty;
                    GdbCommandResult res      = null;

                    try
                    {
                        if (wp.TriggerOnRead && wp.TriggerOnWrite)
                        {
                            res = RunCommand("-break-watch", wp.Expression, "-a");
                        }
                        else if (wp.TriggerOnRead && !wp.TriggerOnWrite)
                        {
                            res = RunCommand("-break-watch", wp.Expression, "-r");
                        }
                        else
                        {
                            res = RunCommand("-break-watch", wp.Expression);
                        }
                    }
                    catch (Exception ex)
                    {
                        errorMsg = ex.Message;
                    }

                    if (res == null || res.Status != CommandStatus.Done)
                    {
                        bi.SetStatus(BreakEventStatus.Invalid, errorMsg);
                        return(bi);
                    }

                    int bh = res.GetObject("wpt").GetInt("number");

                    if (!be.Enabled)
                    {
                        RunCommand("-break-disable", bh.ToString());
                    }

                    breakpoints[bh] = bi;
                    bi.Handle       = bh;
                    bi.SetStatus(BreakEventStatus.Bound, null);
                    return(bi);
                }
                finally
                {
                    InternalResume(dres);
                }
            }
        }
Ejemplo n.º 9
0
        protected override void OnEnableBreakEvent(BreakEventInfo binfo, bool enable)
        {
            CorBreakpoint bp = binfo.Handle as CorFunctionBreakpoint;

            if (bp != null)
            {
                bp.Activate(enable);
            }
        }
Ejemplo n.º 10
0
        private void NotifyBreakEventUpdate(BreakEventInfo binfo, int hitCount, string lastTrace)
        {
            bool notify = false;

            WaitCallback nc = delegate
            {
                if (hitCount != -1)
                {
                    binfo.IncrementHitCount();
                }
                if (lastTrace != null)
                {
                    binfo.UpdateLastTraceValue(lastTrace);
                }
            };

            lock (breakUpdates)
            {
                int span = (int)(DateTime.Now - lastBreakEventUpdate).TotalMilliseconds;
                if (span >= BreakEventUpdateNotifyDelay && !breakUpdateEventsQueued)
                {
                    // Last update was more than 0.5s ago. The update can be sent.
                    lastBreakEventUpdate = DateTime.Now;
                    notify = true;
                }
                else
                {
                    // Queue the event notifications to avoid wasting too much time
                    breakUpdates[(int)binfo.Handle] = nc;
                    if (!breakUpdateEventsQueued)
                    {
                        breakUpdateEventsQueued = true;

                        ThreadPool.QueueUserWorkItem(delegate
                        {
                            Thread.Sleep(BreakEventUpdateNotifyDelay - span);
                            List <WaitCallback> copy;
                            lock (breakUpdates)
                            {
                                copy = new List <WaitCallback>(breakUpdates.Values);
                                breakUpdates.Clear();
                                breakUpdateEventsQueued = false;
                                lastBreakEventUpdate    = DateTime.Now;
                            }
                            foreach (WaitCallback wc in copy)
                            {
                                wc(null);
                            }
                        });
                    }
                }
            }
            if (notify)
            {
                nc(null);
            }
        }
Ejemplo n.º 11
0
        protected override void OnRemoveBreakEvent(BreakEventInfo bi)
        {
            if (terminated)
            {
                return;
            }
            CorFunctionBreakpoint corBp = (CorFunctionBreakpoint)bi.Handle;

            corBp.Activate(false);
        }
Ejemplo n.º 12
0
        protected override void OnEnableBreakEvent(BreakEventInfo binfo, bool enable)
        {
            if (binfo.Handle == null)
            {
                return;
            }

            breakpoints[(ulong)binfo.Handle].Breakpoint.Flags = enable ? BreakPointOptions.Enabled : BreakPointOptions.Deferred;

            //ToDo: tell engine we enabled a break point
        }
Ejemplo n.º 13
0
 protected override void OnRemoveBreakEvent(BreakEventInfo binfo)
 {
     lock (gdbLock) {
         bool dres = InternalStop();
         breakpointsWithHitCount.Remove(binfo);
         breakpoints.Remove((int)binfo.Handle);
         try {
             RunCommand("-break-delete", binfo.Handle.ToString());
         } finally {
             InternalResume(dres);
         }
     }
 }
Ejemplo n.º 14
0
        protected override void OnRemoveBreakEvent(BreakEventInfo binfo)
        {
            if (binfo == null)
            {
                return;
            }

            breakpointsWithHitCount.Remove(binfo);
            if (breakpoints.ContainsKey((ulong)binfo.Handle))
            {
                ulong key = breakpoints[(ulong)binfo.Handle].Key;
                breakpoints.Remove((ulong)binfo.Handle);
                debuggee.RemoveBreakPoint((ulong)binfo.Handle);
            }
        }
Ejemplo n.º 15
0
        protected override void OnRemoveBreakEvent(BreakEventInfo eventInfo)
        {
            if (process == null)
            {
                return;
            }

            if (eventInfo.Status != BreakEventStatus.Bound || eventInfo.Handle == null)
            {
                return;
            }

            var corBp = (CorDebugFunctionBreakpoint)eventInfo.Handle;

            corBp.Active = false;
        }
        protected override void OnRemoveBreakEvent(BreakEventInfo bi)
        {
            if (terminated)
            {
                return;
            }

            if (bi.Status != BreakEventStatus.Bound || bi.Handle == null)
            {
                return;
            }

            CorFunctionBreakpoint corBp = (CorFunctionBreakpoint)bi.Handle;

            corBp.Activate(false);
        }
Ejemplo n.º 17
0
        protected override BreakEventInfo OnInsertBreakEvent(BreakEvent breakEvent)
        {
            var bp = breakEvent as Breakpoint;

            if (bp == null)
            {
                throw new NotImplementedException();
            }

            unityDebugProtocol.AddBreakpoint(bp.FileName, bp.Line);

            var eventInfo = new BreakEventInfo();

            eventInfo.SetStatus(BreakEventStatus.Bound, null);
            return(eventInfo);
        }
Ejemplo n.º 18
0
        void FireBreakPoint(ulong offset)
        {
            TargetEventArgs args = new TargetEventArgs(TargetEventType.TargetHitBreakpoint);

            ulong tempoff = (ulong)offset;

            if (breakpoints.ContainsKey(tempoff))
            {
                breakpoints[(ulong)tempoff].EventInfo.BreakEvent.HitCount = (int)breakpoints[(ulong)tempoff].Breakpoint.HitCount;
                args.BreakEvent = breakpoints[(ulong)tempoff].EventInfo.BreakEvent;
            }
            else
            {
                args = new TargetEventArgs(TargetEventType.TargetStopped);
                BreakEventInfo breakInfo = new BreakEventInfo();
                breakInfo.Handle = tempoff;
                breakInfo.SetStatus(BreakEventStatus.Bound, null);
                string fn;
                uint   ln;
                if (Engine.Symbols.GetLineByOffset(offset, out fn, out ln))
                {
                    //breakInfo.BreakEvent = new Breakpoint(fn, (int)ln);
                    args.BreakEvent = breakInfo.BreakEvent;
                }
            }

            ProcessInfo process = OnGetProcesses()[0];

            args.Process = new ProcessInfo(process.Id, process.Name);

            args.Backtrace = new Backtrace(new PlainDbgEngBasedBacktrace(this, activeThread, Engine));

            ThreadPool.QueueUserWorkItem(delegate(object data)
            {
                try
                {
                    OnTargetEvent((TargetEventArgs)data);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }, args);
        }
Ejemplo n.º 19
0
        protected override void OnRemoveBreakEvent(BreakEventInfo binfo)
        {
            if (binfo == null)
            {
                return;
            }

            breakpointsWithHitCount.Remove(binfo);

            DebugEngineWrapper.BreakPoint breakpoint = breakpoints[(ulong)binfo.Handle].Breakpoint;

            if (IsDebugging /*&& bpw.IsExisting*/)
            {
                Engine.RemoveBreakPoint(breakpoint);
            }

            breakpointsWithHitCount.Remove(binfo);
            breakpoints.Remove((ulong)binfo.Handle);
        }
Ejemplo n.º 20
0
        protected override BreakEventInfo OnInsertBreakEvent(BreakEvent be)
        {
            if (be is Breakpoint)
            {
                return(OnInsertBreakPoint(be as Breakpoint));
            }
            else if (be is WatchPoint)
            {
                return(OnInsertWatchPoint(be as WatchPoint));
            }
            else
            {
                var bi = new BreakEventInfo();

                bi.SetStatus(BreakEventStatus.NotBound, "BreakEvent type not supported.");

                return(bi);
            }
        }
Ejemplo n.º 21
0
        void FireBreakPoint(ulong address)
        {
            TargetEventArgs args = new TargetEventArgs(TargetEventType.TargetHitBreakpoint);

            ulong tempAddress = address;

            if (breakpoints.ContainsKey(tempAddress))
            {
                //breakpoints[(ulong)tempoff].EventInfo.UpdateHitCount((int)breakpoints[(ulong)tempoff].Breakpoint.HitCount);
                args.BreakEvent = breakpoints[tempAddress].EventInfo.BreakEvent;
            }
            else
            {
                args = new TargetEventArgs(TargetEventType.TargetStopped);
                BreakEventInfo breakInfo = new BreakEventInfo();
                breakInfo.Handle = tempAddress;
                breakInfo.SetStatus(BreakEventStatus.Bound, null);
                string filename;
                uint   line;
                if (this.SymbolResolver.GetCodeLineFromAddress(address, out filename, out line))
                {
                    args.BreakEvent = breakInfo.BreakEvent;
                }
            }

            ProcessInfo process = OnGetProcesses()[0];

            args.Process   = new ProcessInfo(process.Id, process.Name);
            args.Backtrace = new Backtrace(new DDebugBacktrace(this, activeThread, this.debuggee));//, Engine));
            args.Thread    = GetThread(activeThread);

            ThreadPool.QueueUserWorkItem(delegate(object data)
            {
                try
                {
                    OnTargetEvent((TargetEventArgs)data);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }, args);
        }
Ejemplo n.º 22
0
 protected override BreakEventInfo OnInsertBreakEvent(BreakEvent breakEvent)
 {
     if (breakEvent is Mono.Debugging.Client.Breakpoint)
     {
         var breakEventInfo = new BreakEventInfo();
         breakpoints.Add((Mono.Debugging.Client.Breakpoint)breakEvent, breakEventInfo);
         UpdateBreakpoints();
         return(breakEventInfo);
     }
     else if (breakEvent is Catchpoint)
     {
         var catchpoint     = (Catchpoint)breakEvent;
         var breakEventInfo = new BreakEventInfo();
         breakpoints.Add(breakEvent, breakEventInfo);
         UpdateExceptions();
         return(breakEventInfo);
     }
     throw new NotImplementedException(breakEvent.GetType().FullName);
 }
Ejemplo n.º 23
0
        protected override BreakEventInfo OnInsertBreakEvent(BreakEvent be)
        {
            LogWriter(false, "Break inserted\n");
            Breakpoint bp = be as Breakpoint;

            if (bp == null)
            {
                throw new NotSupportedException();
            }

            BreakEventInfo bi = new BreakEventInfo();

            //lock (debuggerLock) {
            LogWriter(false, "Location is " + PathHelper.CutOffClassPath(classPathes, bp.FileName) + ":" + bp.Line + '\n');
            breaks.Add(new Break(PathHelper.CutOffClassPath(classPathes, bp.FileName), bp.Line));
            //}

            //bi.Handle = TODO: add returned success value (break count etc)
            bi.SetStatus(BreakEventStatus.Bound, null);
            return(bi);
        }
Ejemplo n.º 24
0
        private BreakEventInfo OnInsertBreakPoint(BreakEvent be)
        {
            var bi = new BreakEventInfo();
            var bp = be as Breakpoint;

            lock (gdbLock)
            {
                bool dres = InternalStop();
                try
                {
                    string extraCmd = string.Empty;
                    if (bp.HitCount > 0)
                    {
                        extraCmd += "-i " + bp.HitCount;
                        breakpointsWithHitCount.Add(bi);
                    }
                    if (!string.IsNullOrEmpty(bp.ConditionExpression))
                    {
                        if (!bp.BreakIfConditionChanges)
                        {
                            extraCmd += " -c " + bp.ConditionExpression;
                        }
                    }

                    GdbCommandResult res      = null;
                    string           errorMsg = null;

                    if (bp is FunctionBreakpoint)
                    {
                        try
                        {
                            res = RunCommand("-break-insert", extraCmd.Trim(), ((FunctionBreakpoint)bp).FunctionName);
                        }
                        catch (Exception ex)
                        {
                            errorMsg = ex.Message;
                        }
                    }
                    else
                    {
                        // Breakpoint locations must be double-quoted if files contain spaces.
                        // For example: -break-insert "\"C:/Documents and Settings/foo.c\":17"
                        RunCommand("-environment-directory", Escape(Path.GetDirectoryName(bp.FileName).ToAvalonPath()));

                        try
                        {
                            res = RunCommand("-break-insert", extraCmd.Trim(), Escape(Escape(bp.FileName.ToAvalonPath()) + ":" + bp.Line));
                        }
                        catch (Exception ex)
                        {
                            errorMsg = ex.Message;
                        }

                        if (res == null)
                        {
                            try
                            {
                                res = RunCommand("-break-insert", extraCmd.Trim(), Escape(Escape(Path.GetFileName(bp.FileName)) + ":" + bp.Line));
                            }
                            catch
                            {
                                // Ignore
                            }
                        }
                    }

                    if (res == null || res.Status != CommandStatus.Done)
                    {
                        bi.SetStatus(BreakEventStatus.Invalid, errorMsg);
                        return(bi);
                    }
                    int bh = res.GetObject("bkpt").GetInt("number");
                    if (!be.Enabled)
                    {
                        RunCommand("-break-disable", bh.ToString());
                    }
                    breakpoints[bh] = bi;
                    bi.Handle       = bh;
                    bi.SetStatus(BreakEventStatus.Bound, null);
                    return(bi);
                }
                finally
                {
                    InternalResume(dres);
                }
            }
        }
Ejemplo n.º 25
0
 protected override void OnUpdateBreakEvent(BreakEventInfo eventInfo)
 {
     breakpoints [breakpoints.Single(b => b.Value == eventInfo).Key] = eventInfo;
     UpdateBreakpoints();
     UpdateExceptions();
 }
Ejemplo n.º 26
0
 protected override void OnEnableBreakEvent(BreakEventInfo eventInfo, bool enable)
 {
     UpdateExceptions();
     UpdateBreakpoints();
 }
 protected override void OnRemoveBreakEvent(BreakEventInfo eventInfo)
 {
 }
 protected override void OnEnableBreakEvent(BreakEventInfo eventInfo, bool enable)
 {
 }
 protected override void OnUpdateBreakEvent(BreakEventInfo eventInfo)
 {
 }
Ejemplo n.º 30
0
 protected override void OnUpdateBreakEvent(BreakEventInfo binfo)
 {
     return;
 }