Fix breakpoint provider
This commit is contained in:
Родитель
127aa2028c
Коммит
5d61cdfa3a
|
@ -117,6 +117,9 @@ namespace Debugger
|
|||
File.Delete ("console.log");
|
||||
|
||||
session.TraceCallback += s => File.AppendAllText ("console.log", s + "\n");
|
||||
session.BreakpointProvider.BreakpointBound += (breakpoint, location) => Console.WriteLine("breakpoint {0} bound at {1}", session.BreakpointProvider.IndexOf (breakpoint), location.LineNumber);
|
||||
session.BreakpointProvider.BreakpointUnbound += (breakpoint, location) => Console.WriteLine("breakpoint {0} unbound from {1}", session.BreakpointProvider.IndexOf (breakpoint), location.LineNumber);
|
||||
|
||||
session.ExecutionProvider.Break += () => {
|
||||
var location = session.ExecutionProvider.Location;
|
||||
Console.WriteLine ();
|
||||
|
@ -290,8 +293,8 @@ namespace Debugger
|
|||
|
||||
private bool ListBreakpoints (string command, Stack<string> commands, Dictionary<string, CommandHandler> calls)
|
||||
{
|
||||
var bps = session.BreakpointProvider.Breakpoints.Keys.ToArray ();
|
||||
for (int i = 0; i < bps.Length; i++)
|
||||
var bps = session.BreakpointProvider.Breakpoints;
|
||||
for (int i = 0; i < bps.Count; i++)
|
||||
{
|
||||
var l = bps[i].Location;
|
||||
Console.WriteLine ("breakpoint {0} on {1}:{2}", i + 1, l.SourceFile, l.LineNumber);
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using CodeEditor.Composition;
|
||||
|
@ -12,9 +13,13 @@ namespace Debugger
|
|||
{
|
||||
private readonly ITypeProvider typeProvider;
|
||||
private readonly Dictionary<IBreakpoint, IBreakpoint> breakpoints = new Dictionary<IBreakpoint, IBreakpoint> ();
|
||||
public IDictionary<IBreakpoint, IBreakpoint> Breakpoints { get { return breakpoints; }}
|
||||
public IList<IBreakpoint> Breakpoints { get { return new ReadOnlyCollection<IBreakpoint> (breakpoints.Keys.ToList ());}}
|
||||
|
||||
public event Action<IBreakpoint> BreakpointBound;
|
||||
public event Action<IBreakpoint, ILocation> BreakpointBound;
|
||||
public event Action<IBreakpoint, ILocation> BreakpointUnbound;
|
||||
|
||||
|
||||
public IBreakpoint this[int index] { get { return breakpoints.Keys.ElementAt (index); } }
|
||||
|
||||
[ImportingConstructor]
|
||||
public BreakpointProvider (ITypeProvider typeProvider)
|
||||
|
@ -24,7 +29,17 @@ namespace Debugger
|
|||
typeProvider.TypeUnloaded += OnTypeUnloaded;
|
||||
}
|
||||
|
||||
public IBreakpoint this[int index] { get { return breakpoints.Keys.ElementAt (index); } }
|
||||
public IEnumerable<ILocation> GetBoundLocations (IBreakpoint breakpoint)
|
||||
{
|
||||
return breakpoints.Where (x => x.Key == breakpoint).Select (b => b.Value.Location as ILocation);
|
||||
}
|
||||
|
||||
public IEnumerable<IBreakpoint> GetBreakpoints (bool bound)
|
||||
{
|
||||
if (bound)
|
||||
return breakpoints.Where (x => x.Value != null).Select (b => b.Key);
|
||||
return breakpoints.Keys;
|
||||
}
|
||||
|
||||
public IBreakpoint GetBreakpointAt (string file, int line)
|
||||
{
|
||||
|
@ -32,6 +47,16 @@ namespace Debugger
|
|||
return breakpoints.Keys.FirstOrDefault (bp => bp.Location.SourceFile == file && bp.Location.LineNumber == line);
|
||||
}
|
||||
|
||||
public int IndexOf (IBreakpoint breakpoint)
|
||||
{
|
||||
int i = 0;
|
||||
var keys = breakpoints.Keys.ToArray ();
|
||||
for (i = 0; i < keys.Length; i++)
|
||||
if (keys[i] == breakpoint)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void ToggleBreakpointAt (string file, int line)
|
||||
{
|
||||
LogProvider.Log ("Toggling breakpoint at line: " + line);
|
||||
|
@ -73,6 +98,18 @@ namespace Debugger
|
|||
return true;
|
||||
}
|
||||
|
||||
public bool IsBound (IBreakpoint breakpoint)
|
||||
{
|
||||
IBreakpoint val = null;
|
||||
return breakpoints.TryGetValue (breakpoint, out val) && val != null;
|
||||
}
|
||||
|
||||
public ILocation GetBoundLocation (IBreakpoint breakpoint)
|
||||
{
|
||||
IBreakpoint val = null;
|
||||
return breakpoints.TryGetValue (breakpoint, out val) && val != null ? val.Location : null;
|
||||
}
|
||||
|
||||
public bool RemoveBreakpoint (string file, int line)
|
||||
{
|
||||
file = typeProvider.MapFile (file);
|
||||
|
@ -100,7 +137,7 @@ namespace Debugger
|
|||
breakpoints[bp.Key] = b;
|
||||
b.Enable ();
|
||||
if (BreakpointBound != null)
|
||||
BreakpointBound (b);
|
||||
BreakpointBound (bp.Key, b.Location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -109,14 +146,16 @@ namespace Debugger
|
|||
private void OnTypeUnloaded (ITypeMirror typeMirror)
|
||||
{
|
||||
var bps = breakpoints.Where (x => typeMirror.SourceFiles.Contains(x.Value.Location.SourceFile)).ToArray ();
|
||||
foreach (var bp in bps)
|
||||
foreach (var bp in bps) {
|
||||
if (BreakpointUnbound != null)
|
||||
BreakpointUnbound (bp.Key, bp.Value.Location);
|
||||
breakpoints.Remove (bp.Key);
|
||||
}
|
||||
}
|
||||
|
||||
private ILocation BestLocationIn (IMethodMirror method, IBreakpoint bp)
|
||||
{
|
||||
return method.Locations.FirstOrDefault (l => l.SourceFile == bp.Location.SourceFile && l.LineNumber == bp.Location.LineNumber);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,14 +6,59 @@ namespace Debugger
|
|||
{
|
||||
public interface IBreakpointProvider
|
||||
{
|
||||
IDictionary<IBreakpoint, IBreakpoint> Breakpoints { get; }
|
||||
IBreakpoint GetBreakpointAt(string file, int line);
|
||||
void ToggleBreakpointAt(string file, int line);
|
||||
IBreakpoint AddBreakpoint (string file, int line);
|
||||
bool RemoveBreakpoint (IBreakpoint breakpoint);
|
||||
bool RemoveBreakpoint (string file, int line);
|
||||
IList<IBreakpoint> Breakpoints { get; }
|
||||
|
||||
IBreakpoint this [int index] { get; }
|
||||
event Action<IBreakpoint> BreakpointBound;
|
||||
/// <summary>
|
||||
/// Returns the list of existing breakpoints.
|
||||
/// If bound is true, then returns the list of
|
||||
/// breakpoints which have been successfully bound
|
||||
/// in the VM.
|
||||
/// </summary>
|
||||
/// <param name="bound"></param>
|
||||
/// <returns></returns>
|
||||
IEnumerable<IBreakpoint> GetBreakpoints (bool bound);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the breakpoint set at the provided user location.
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <param name="line"></param>
|
||||
/// <returns></returns>
|
||||
IBreakpoint GetBreakpointAt (string file, int line);
|
||||
void ToggleBreakpointAt (string file, int line);
|
||||
|
||||
IBreakpoint AddBreakpoint (string file, int line);
|
||||
bool RemoveBreakpoint (string file, int line);
|
||||
bool RemoveBreakpoint (IBreakpoint breakpoint);
|
||||
|
||||
bool IsBound (IBreakpoint breakpoint);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the actual runtime location for this breakpoint. If
|
||||
/// this breakpoint represents more than one location (if the runtime supports it),
|
||||
/// returns the first location.
|
||||
/// </summary>
|
||||
/// <param name="breakpoint"></param>
|
||||
/// <returns></returns>
|
||||
ILocation GetBoundLocation (IBreakpoint breakpoint);
|
||||
|
||||
/// <summary>
|
||||
/// Returns all the actual runtime locations for this breakpoint.
|
||||
/// </summary>
|
||||
/// <param name="breakpoint"></param>
|
||||
/// <returns></returns>
|
||||
IEnumerable<ILocation> GetBoundLocations (IBreakpoint breakpoint);
|
||||
|
||||
/// <summary>
|
||||
/// Handy accessor for accessing breakpoints by index.
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
IBreakpoint this[int index] { get; }
|
||||
|
||||
int IndexOf (IBreakpoint breakpoint);
|
||||
|
||||
event Action<IBreakpoint, ILocation> BreakpointBound;
|
||||
event Action<IBreakpoint, ILocation> BreakpointUnbound;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
@ -24,6 +24,7 @@ namespace Debugger.DummyProviders
|
|||
}
|
||||
|
||||
public IBreakpoint this[int index] { get { return breakpoints.Keys.ElementAt (index); } }
|
||||
public event Action<IBreakpoint> BreakpointBound;
|
||||
|
||||
public IBreakpoint GetBreakpointAt (string file, int line)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче