Skip to content

Commit

Permalink
Add 'All Exceptions' for ExceptionFilter in OpenDebugAD7 (#1251)
Browse files Browse the repository at this point in the history
* Add 'All Exceptions' for ExceptionFilter in ODA7

This PR adds an exception filter in the VS Code window "All Exceptions".

When checked, any exception thrown will be stopped at as a breakpoint.

This PR also updates the exception description for the AD7Exception
event. The description will indicate the address and function that it
was thrown.

* Disable Condition Exception for MinGW
  • Loading branch information
WardenGnaw authored Dec 17, 2021
1 parent 876f815 commit 46a905b
Show file tree
Hide file tree
Showing 15 changed files with 398 additions and 43 deletions.
2 changes: 1 addition & 1 deletion build/package_versions.settings.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Microsoft_VisualStudio_Debugger_Interop_Portable_Version>1.0.1</Microsoft_VisualStudio_Debugger_Interop_Portable_Version>
<Microsoft_VisualStudio_Interop_Version>17.0.0-previews-1-31410-258</Microsoft_VisualStudio_Interop_Version>
<Newtonsoft_Json_Version>12.0.2</Newtonsoft_Json_Version>
<Microsoft_VisualStudio_Shared_VSCodeDebugProtocol_Version>16.9.50204.1</Microsoft_VisualStudio_Shared_VSCodeDebugProtocol_Version>
<Microsoft_VisualStudio_Shared_VSCodeDebugProtocol_Version>17.0.50801.1</Microsoft_VisualStudio_Shared_VSCodeDebugProtocol_Version>

<!-- Test Packages -->
<Microsoft_NET_Test_Sdk_Version>16.7.1</Microsoft_NET_Test_Sdk_Version>
Expand Down
24 changes: 15 additions & 9 deletions src/DebugEngineHost.VSCode/VSCode/ExceptionBreakpointFilter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.VisualStudio.Debugger.Interop;
using Newtonsoft.Json;
using System;
using System.Diagnostics;
Expand All @@ -13,9 +14,6 @@ namespace Microsoft.DebugEngineHost.VSCode
/// </summary>
sealed public class ExceptionBreakpointFilter
{
public const string Filter_All = "all";
public const string Filter_UserUnhandled = "user-unhandled";

private string _filter;

/// <summary>
Expand All @@ -25,7 +23,7 @@ sealed public class ExceptionBreakpointFilter
public string label { get; set; }

/// <summary>
/// The identifier for this filter. Currently this should be 'all' or 'user-unhandled'
/// The identifier for this filter.
/// </summary>
[JsonRequired]
public string filter
Expand All @@ -37,18 +35,26 @@ public string filter

set
{
if (value != Filter_All && value != Filter_UserUnhandled)
{
Debug.Fail("Invalid ExceptionBreakpointFilter");
throw new ArgumentOutOfRangeException("filter");
}
_filter = value;
}
}

[JsonRequired]
public bool supportsCondition { get; set; }

[JsonRequired]
public string conditionDescription { get; set; }

[JsonRequired]
public Guid categoryId { get; set; }

/// <summary>
/// The default state for the button
/// </summary>
public bool @default { get; set; }

[JsonIgnore]
public enum_EXCEPTION_STATE State { get; set; } = enum_EXCEPTION_STATE.EXCEPTION_STOP_SECOND_CHANCE | enum_EXCEPTION_STATE.EXCEPTION_STOP_FIRST_CHANCE | enum_EXCEPTION_STATE.EXCEPTION_STOP_USER_FIRST_CHANCE;

}
}
20 changes: 20 additions & 0 deletions src/DebugEngineHost.VSCode/VSCode/ExceptionSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;

namespace Microsoft.DebugEngineHost.VSCode
{
Expand Down Expand Up @@ -52,8 +55,25 @@ internal ExceptionSettings()
{
}

#if DEBUG
internal void ValidateExceptionFilters()
{
foreach (ExceptionBreakpointFilter filter in _exceptionFilters)
{
// Make sure that the category GUID was listed in the config file.
if (!_categories.Where(c => c.Id == filter.categoryId).Any())
{
Debug.Fail(string.Format(CultureInfo.InvariantCulture, "Missing category '{0}' from configuration file.", filter.categoryId));
}
}
}
#endif

internal void MakeReadOnly()
{
#if DEBUG
ValidateExceptionFilters();
#endif
_categories = new ReadOnlyCollection<CategoryConfiguration>(_categories);
_exceptionFilters = new ReadOnlyCollection<ExceptionBreakpointFilter>(_exceptionFilters);
}
Expand Down
4 changes: 2 additions & 2 deletions src/MIDebugEngine/Engine.Impl/DebuggedProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,9 +1189,9 @@ private async Task HandleBreakModeEvent(ResultEventArgs results, BreakRequest br
bplist.AddRange(bkpt);
_callback.OnBreakpoint(thread, bplist.AsReadOnly());
}
else if (ExceptionManager.TryGetExceptionBreakpoint(bkptno, out string exceptionName, out Guid exceptionCategoryGuid)) // exception breakpoint hit
else if (ExceptionManager.TryGetExceptionBreakpoint(bkptno, addr, frame, out string exceptionName, out string description, out Guid exceptionCategoryGuid)) // exception breakpoint hit
{
_callback.OnException(thread, exceptionName, "", 0, exceptionCategoryGuid, ExceptionBreakpointStates.BreakThrown);
_callback.OnException(thread, exceptionName, description, 0, exceptionCategoryGuid, ExceptionBreakpointStates.BreakThrown);
}
else if (!this.EntrypointHit)
{
Expand Down
24 changes: 22 additions & 2 deletions src/MIDebugEngine/Engine.Impl/ExceptionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,10 @@ public void SetAllExceptions(enum_EXCEPTION_STATE dwState)
}
}

public bool TryGetExceptionBreakpoint(string bkptno, out string exceptionName, out Guid exceptionCategoryGuid)
public bool TryGetExceptionBreakpoint(string bkptno, ulong address, TupleValue frame, out string exceptionName, out string exceptionDescription, out Guid exceptionCategoryGuid)
{
exceptionName = null;
exceptionName = string.Empty;
exceptionDescription = string.Empty;
exceptionCategoryGuid = Guid.Empty;
ExceptionCategorySettings categorySettings;
if (_categoryMap.TryGetValue(CppExceptionCategoryGuid, out categorySettings))
Expand All @@ -307,10 +308,29 @@ public bool TryGetExceptionBreakpoint(string bkptno, out string exceptionName, o
exceptionName = categorySettings.CurrentRules.FirstOrDefault(pair => pair.Value == breakpointNumber).Key;
if (exceptionName != null)
{
// The string to use when displaying which exception caused the breakpoint to hit.
// It is empty if it uses the category name
string displayException = string.Empty;

if (exceptionName.Length < 1 || exceptionName == "*") // if exceptionName is "*", the exceptions category is selected
{
exceptionName = categorySettings.CategoryName;
}
else
{
displayException = string.Format(CultureInfo.InvariantCulture, " '{0}'", exceptionName);
}

string functionName = frame?.TryFindString("func");
if (string.IsNullOrWhiteSpace(functionName))
{
exceptionDescription = string.Format(CultureInfo.CurrentCulture, ResourceStrings.Exception_Thrown, displayException, address);
}
else
{
exceptionDescription = string.Format(CultureInfo.CurrentCulture, ResourceStrings.Exception_Thrown_with_Source, displayException, address, functionName);
}

exceptionCategoryGuid = CppExceptionCategoryGuid;
return true;

Expand Down
18 changes: 18 additions & 0 deletions src/MIDebugEngine/ResourceStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/MIDebugEngine/ResourceStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,12 @@ See https://aka.ms/miengine-gdb-troubleshooting for details.</value>
<value>Warning: Exceptions are not supported in this scenario.
</value>
</data>
<data name="Exception_Thrown" xml:space="preserve">
<value>Exception{0} thrown at 0x{1:X}.</value>
<comment>0 = optional exception name, 1 = address</comment>
</data>
<data name="Exception_Thrown_with_Source" xml:space="preserve">
<value>Exception{0} thrown at 0x{1:X} in {2}.</value>
<comment>0 = optional exception name, 1 = address, 2 = exception file</comment>
</data>
</root>
Loading

0 comments on commit 46a905b

Please sign in to comment.