-
Notifications
You must be signed in to change notification settings - Fork 0
/
Debugger.cs
64 lines (56 loc) · 1.67 KB
/
Debugger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
using System.Linq;
namespace MsBuildDebugger
{
public class Debugger
{
private ConsoleUI ui;
private readonly HashSet<BreakpointLocation> breakpoints = new HashSet<BreakpointLocation>();
public Debugger(string projectFile, IEnumerable<string> targets)
{
Analyzer = new ProjectAnalyzer(projectFile);
var breakTargets = targets;
if (!breakTargets.Any())
{
breakTargets = Analyzer.GetDefaultTargets();
}
foreach (var target in breakTargets)
{
SetBreakpoint(target, BreakpointPosition.Start);
}
}
public ProjectAnalyzer Analyzer { get; }
public void SetUI(ConsoleUI ui)
{
this.ui = ui;
}
public void SetBreakpoint(string target, BreakpointPosition pos)
{
breakpoints.Add(new BreakpointLocation(target, pos));
}
public void RemoveAllBreakpoints()
{
breakpoints.Clear();
}
public void OnTargetEnter(string name)
{
ui.OnTargetEnter(name);
var loc = new BreakpointLocation(name, BreakpointPosition.Start);
if (breakpoints.Contains(loc))
{
ui.OnHitBreakpoint(loc);
}
}
public void OnTargetLeave(string name)
{
var loc = new BreakpointLocation(name, BreakpointPosition.End);
if (breakpoints.Contains(loc))
{
ui.OnHitBreakpoint(loc);
}
ui.OnTargetLeave(name);
}
}
}