-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[gh-4] Initial version of breakpoint persister.
- Loading branch information
Showing
17 changed files
with
245 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace ExceptionBreaker.Breakpoints { | ||
public class BreakpointExtraData { | ||
public BreakpointExtraData() { | ||
Version = 1; // for serialization tracking | ||
} | ||
|
||
public int Version { get; set; } | ||
public ExceptionBreakChange ExceptionBreakChange { get; set; } | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
ExceptionBreaker/Breakpoints/BreakpointExtraDataProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using AshMind.Extensions; | ||
using EnvDTE80; | ||
using ExceptionBreaker.Core; | ||
using JetBrains.Annotations; | ||
using Microsoft.VisualStudio.Debugger.Interop; | ||
using Newtonsoft.Json; | ||
|
||
namespace ExceptionBreaker.Breakpoints { | ||
public class BreakpointExtraDataProvider : ISolutionDataPersister { | ||
private readonly BreakpointKeyProvider _keyProvider; | ||
private readonly BreakpointFinder _finder; | ||
private readonly JsonSerializer _jsonSerializer; | ||
private readonly IDiagnosticLogger _logger; | ||
private readonly ConcurrentDictionary<string, BreakpointExtraData> _store = new ConcurrentDictionary<string, BreakpointExtraData>(StringComparer.InvariantCultureIgnoreCase); | ||
|
||
public BreakpointExtraDataProvider(BreakpointKeyProvider keyProvider, BreakpointFinder finder, JsonSerializer jsonSerializer, IDiagnosticLogger logger) { | ||
_keyProvider = keyProvider; | ||
_finder = finder; | ||
_jsonSerializer = jsonSerializer; | ||
_logger = logger; | ||
} | ||
|
||
[NotNull] | ||
public BreakpointExtraData GetData([NotNull] Breakpoint2 breakpoint) { | ||
return GetData(_keyProvider.GetKey(breakpoint)); | ||
} | ||
|
||
[CanBeNull] | ||
public BreakpointExtraData GetData([NotNull] IDebugBoundBreakpoint2 breakpoint) { | ||
var key = _keyProvider.GetKey(breakpoint); | ||
if (key == null) | ||
return null; | ||
|
||
return GetData(key); | ||
} | ||
|
||
[NotNull] | ||
private BreakpointExtraData GetData([NotNull] string key) { | ||
return _store.GetOrAdd(key, k => new BreakpointExtraData()); | ||
} | ||
|
||
#region ISolutionDataPersister Members | ||
|
||
string ISolutionDataPersister.Key { | ||
// due to VS limitation, this has to be shorted than 31 char and contain no '.' | ||
get { return "XB-BreakpointExtraData"; } | ||
} | ||
|
||
void ISolutionDataPersister.SaveTo(Stream stream) { | ||
_logger.WriteLine("Breakpoints: saving extra data."); | ||
var existingBreakpointKeys = _finder.GetAllBreakpoints().Select(b => _keyProvider.GetKey(b)); | ||
foreach (var key in _store.Keys.Except(existingBreakpointKeys).ToArray()) { | ||
BreakpointExtraData _; | ||
_store.TryRemove(key, out _); | ||
_logger.WriteLine(" Skipped '{0}' — no corresponding breakpoint.", key); | ||
} | ||
|
||
using (var writer = new StreamWriter(stream)) { | ||
_jsonSerializer.Serialize(writer, _store); | ||
} | ||
_logger.WriteLine(" Saved {0} extra data entries to the solution.", _store.Count); | ||
} | ||
|
||
void ISolutionDataPersister.LoadFrom(Stream stream) { | ||
using (var reader = new StreamReader(stream)) | ||
using (var jsonReader = new JsonTextReader(reader)) { | ||
var loaded = _jsonSerializer.Deserialize<IDictionary<string, BreakpointExtraData>>(jsonReader); | ||
_store.Clear(); | ||
_logger.WriteLine("Breakpoints: loading extra data."); | ||
foreach (var pair in loaded) { | ||
_store[pair.Key] = pair.Value; | ||
_logger.WriteLine(" Loaded '{0}': change = {1}.", pair.Key, pair.Value.ExceptionBreakChange); | ||
} | ||
} | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using EnvDTE80; | ||
using ExceptionBreaker.Core; | ||
using JetBrains.Annotations; | ||
using Microsoft.VisualStudio.Debugger.Interop; | ||
|
||
namespace ExceptionBreaker.Breakpoints { | ||
public class BreakpointKeyProvider { | ||
[NotNull] | ||
public string GetKey(Breakpoint2 breakpoint) { | ||
return string.Intern(breakpoint.File + ":" + breakpoint.FileLine + ":" + breakpoint.FileColumn); | ||
} | ||
|
||
[CanBeNull] | ||
public string GetKey(IDebugBoundBreakpoint2 breakpoint) { | ||
var resolution = breakpoint.GetBreakpointResolutionSafe(); | ||
var resolutionInfo = resolution.GetResolutionInfoSafe((int)enum_BPRESI_FIELDS.BPRESI_BPRESLOCATION); | ||
var location = resolutionInfo.bpResLocation; | ||
if (location.bpType != (uint)enum_BP_TYPE.BPT_CODE) | ||
return null; | ||
|
||
var context = (IDebugCodeContext2)Marshal.GetObjectForIUnknown(location.unionmember1); | ||
var documentContext = context.GetDocumentContextSafe(); | ||
var fileName = documentContext.GetNameSafe((uint)enum_GETNAME_TYPE.GN_FILENAME); | ||
|
||
var position = new TEXT_POSITION[1]; | ||
var hr = documentContext.GetStatementRange(position, null); | ||
VSInteropHelper.Validate(hr); | ||
|
||
return string.Intern(fileName + ":" + (position[0].dwLine + 1) + ":" + (position[0].dwColumn + 1)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace ExceptionBreaker.Core { | ||
public interface ISolutionDataPersister { | ||
string Key { get; } | ||
void SaveTo(Stream stream); | ||
void LoadFrom(Stream stream); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.