Skip to content

Commit

Permalink
Add configuration for handling of unknown breakpoints (#1351)
Browse files Browse the repository at this point in the history
* Add configuration for handling of unknown breakpoints
  • Loading branch information
benmcmorran authored Sep 9, 2022
1 parent 7983eaa commit 7ece35b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
18 changes: 18 additions & 0 deletions src/MICore/JsonLaunchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;

namespace MICore.Json.LaunchOptions
Expand Down Expand Up @@ -113,6 +115,12 @@ public abstract partial class BaseOptions
/// </summary>
[JsonProperty("hardwareBreakpoints", DefaultValueHandling = DefaultValueHandling.Ignore)]
public HardwareBreakpointInfo HardwareBreakpointInfo { get; set; }

/// <summary>
/// Controls how breakpoints set externally (usually via raw GDB commands) are handled when hit. "throw" acts as if an exception was thrown by the application and "stop" only pauses the debug session.
/// </summary>
[JsonProperty("unknownBreakpointHandling", DefaultValueHandling = DefaultValueHandling.Ignore)]
public UnknownBreakpointHandling? UnknownBreakpointHandling { get; set; }
}

public partial class AttachOptions : BaseOptions
Expand Down Expand Up @@ -265,6 +273,16 @@ public HardwareBreakpointInfo(bool require = false, int? limit = null)
#endregion
}

[JsonConverter(typeof(StringEnumConverter))]
public enum UnknownBreakpointHandling
{
[EnumMember(Value = "throw")]
Throw,

[EnumMember(Value = "stop")]
Stop
}

public partial class LaunchOptions : BaseOptions
{
#region Public Properties for Serialization
Expand Down
15 changes: 15 additions & 0 deletions src/MICore/LaunchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Text;
using MICore.Json.LaunchOptions;

namespace MICore
{
Expand Down Expand Up @@ -1202,6 +1203,18 @@ public int HardwareBreakpointLimit
}
}

private UnknownBreakpointHandling _unknownBreakpointHandling;

public UnknownBreakpointHandling UnknownBreakpointHandling
{
get { return _unknownBreakpointHandling; }
set
{
VerifyCanModifyProperty(nameof(UnknownBreakpointHandling));
_unknownBreakpointHandling = value;
}
}

public string GetOptionsString()
{
try
Expand Down Expand Up @@ -1800,6 +1813,8 @@ protected void InitializeCommonOptions(Json.LaunchOptions.BaseOptions options)
{
throw new InvalidLaunchOptionsException(String.Format(CultureInfo.InvariantCulture, MICoreResources.Error_OptionNotSupported, nameof(options.HardwareBreakpointInfo.Require), nameof(MIMode.Lldb)));
}

this.UnknownBreakpointHandling = options.UnknownBreakpointHandling ?? UnknownBreakpointHandling.Throw;
}

protected void InitializeCommonOptions(Xml.LaunchOptions.BaseLaunchOptions source)
Expand Down
21 changes: 14 additions & 7 deletions src/MIDebugEngine/Engine.Impl/DebuggedProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,13 +1234,20 @@ private async Task HandleBreakModeEvent(ResultEventArgs results, BreakRequest br
}
else
{
// This is not one of our breakpoints, so stop with a message. Possibly it
// was set by the user via "-exec break ...", so display the available
// information.
string desc = String.Format(CultureInfo.CurrentCulture,
ResourceStrings.UnknownBreakpoint,
bkptno, addr);
_callback.OnException(thread, desc, "", 0);
// This is not one of our breakpoints. Possibly it was set by the user
// via "-exec break ...", so display the available information.
switch (_launchOptions.UnknownBreakpointHandling)
{
case MICore.Json.LaunchOptions.UnknownBreakpointHandling.Throw:
string desc = String.Format(CultureInfo.CurrentCulture,
ResourceStrings.UnknownBreakpoint,
bkptno, addr);
_callback.OnException(thread, desc, "", 0);
break;
case MICore.Json.LaunchOptions.UnknownBreakpointHandling.Stop:
_callback.OnBreakpoint(thread, new ReadOnlyCollection<object>(new AD7BoundBreakpoint[] { }));
break;
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/MIDebugPackage/OpenFolderSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@
},
"hardwareBreakpoints": {
"$ref": "#/definitions/cpp_schema/definitions/hardwareBreakpointsOptions"
},
"unknownBreakpointHandling": {
"type": "string",
"enum": [
"throw",
"stop"
],
"description": "Controls how breakpoints set externally (usually via raw GDB commands) are handled when hit.\nAllowed values are \"throw\", which acts as if an exception was thrown by the application, and \"stop\", which only pauses the debug session. The default value is \"throw\"."
}
},
"definitions": {
Expand Down

0 comments on commit 7ece35b

Please sign in to comment.