Skip to content

Commit

Permalink
Merge pull request #1193 from microsoft/main
Browse files Browse the repository at this point in the history
Added PostRemoteConnectCommands (#1181)
  • Loading branch information
WardenGnaw authored Aug 11, 2021
2 parents c462d94 + d3b2415 commit 9e738ca
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/MICore/JsonLaunchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ public abstract partial class BaseOptions
[JsonProperty("setupCommands", DefaultValueHandling = DefaultValueHandling.Ignore)]
public List<SetupCommand> SetupCommands { get; protected set; }

/// <summary>
/// One or more commands to execute in order to setup underlying debugger after debugger has been attached. i.e. flashing and resetting the board
/// </summary>
[JsonProperty("postRemoteConnectCommands", DefaultValueHandling = DefaultValueHandling.Ignore)]
public List<SetupCommand> PostRemoteConnectCommands { get; protected set; }

/// <summary>
/// Explicitly control whether hardware breakpoints are used. If an optional limit is provided, additionally restrict the number of hardware breakpoints for remote targets. Example: "hardwareBreakpoints": { "require": true, "limit": 5 }.
/// </summary>
Expand Down Expand Up @@ -360,6 +366,7 @@ public LaunchOptions()
{
this.Args = new List<string>();
this.SetupCommands = new List<SetupCommand>();
this.PostRemoteConnectCommands = new List<SetupCommand>();
this.CustomLaunchSetupCommands = new List<SetupCommand>();
this.Environment = new List<Environment>();
this.SourceFileMap = new Dictionary<string, object>();
Expand All @@ -372,6 +379,7 @@ public LaunchOptions(
string targetArchitecture = null,
string cwd = null,
List<SetupCommand> setupCommands = null,
List<SetupCommand> postRemoteConnectCommands = null,
List<SetupCommand> customLaunchSetupCommands = null,
LaunchCompleteCommand? launchCompleteCommand = null,
string visualizerFile = null,
Expand Down Expand Up @@ -402,6 +410,7 @@ public LaunchOptions(
this.TargetArchitecture = targetArchitecture;
this.Cwd = cwd;
this.SetupCommands = setupCommands;
this.PostRemoteConnectCommands = postRemoteConnectCommands;
this.CustomLaunchSetupCommands = customLaunchSetupCommands;
this.LaunchCompleteCommand = launchCompleteCommand;
this.VisualizerFile = visualizerFile;
Expand Down
20 changes: 20 additions & 0 deletions src/MICore/LaunchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,24 @@ public ReadOnlyCollection<LaunchCommand> SetupCommands
}
}

private ReadOnlyCollection<LaunchCommand> _postRemoteConnectCommands;

/// <summary>
/// [Required] Additional commands used to setup debugging once the remote connection has been made. May be an empty collection
/// </summary>
public ReadOnlyCollection<LaunchCommand> PostRemoteConnectCommands
{
get { return _postRemoteConnectCommands; }
set
{
if (value == null)
throw new ArgumentNullException("PostRemoteConnectCommands");

VerifyCanModifyProperty(nameof(PostRemoteConnectCommands));
_postRemoteConnectCommands = value;
}
}


private ReadOnlyCollection<LaunchCommand> _customLaunchSetupCommands;

Expand Down Expand Up @@ -1416,6 +1434,7 @@ public static LaunchOptions CreateForAttachRequest(Microsoft.VisualStudio.Debugg

options.ProcessId = processId;
options.SetupCommands = new ReadOnlyCollection<LaunchCommand>(new LaunchCommand[] { });
options.PostRemoteConnectCommands = new ReadOnlyCollection<LaunchCommand>(new LaunchCommand[] { });
if (attachOptions != null)
{
options.Merge(attachOptions);
Expand Down Expand Up @@ -1753,6 +1772,7 @@ protected void InitializeCommonOptions(Json.LaunchOptions.BaseOptions options)
}

this.SetupCommands = LaunchCommand.CreateCollection(options.SetupCommands);
this.PostRemoteConnectCommands = LaunchCommand.CreateCollection(options.PostRemoteConnectCommands);

this.RequireHardwareBreakpoints = options.HardwareBreakpointInfo?.Require ?? false;
this.HardwareBreakpointLimit = options.HardwareBreakpointInfo?.Limit ?? 0;
Expand Down
4 changes: 3 additions & 1 deletion src/MIDebugEngine/Engine.Impl/DebuggedProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,8 @@ private async Task<List<LaunchCommand>> GetInitializeCommands()
commands.Add(new LaunchCommand("-target-attach " + _launchOptions.ProcessId.Value.ToString(CultureInfo.InvariantCulture), ignoreFailures: false, failureHandler: failureHandler));
}

commands.AddRange(_launchOptions.PostRemoteConnectCommands);

if (this.MICommandFactory.Mode == MIMode.Lldb)
{
// LLDB finishes attach in break mode. Gdb does finishes in run mode. Issue a continue in lldb to match the gdb behavior
Expand Down Expand Up @@ -824,13 +826,13 @@ private async Task<List<LaunchCommand>> GetInitializeCommands()
if (!string.IsNullOrWhiteSpace(destination))
{
commands.Add(new LaunchCommand("-target-select remote " + destination, string.Format(CultureInfo.CurrentCulture, ResourceStrings.ConnectingMessage, destination)));

if (localLaunchOptions.RequireHardwareBreakpoints && localLaunchOptions.HardwareBreakpointLimit > 0) {
commands.Add(new LaunchCommand(string.Format(CultureInfo.InvariantCulture, "-interpreter-exec console \"set remote hardware-breakpoint-limit {0}\"", localLaunchOptions.HardwareBreakpointLimit.ToString(CultureInfo.InvariantCulture))));
}
}

}
commands.AddRange(_launchOptions.PostRemoteConnectCommands);

// Environment variables are set for the debuggee only with the modes that support that
foreach (EnvironmentEntry envEntry in _launchOptions.Environment)
Expand Down
4 changes: 4 additions & 0 deletions src/MIDebugPackage/OpenFolderSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@
"$ref": "#/definitions/cpp_schema/definitions/launchSetupCommands"
}
},
"postRemoteConnectCommands": {
"type": "array",
"description": "One or more commands to execute after the connection has been made, in order to set up the remote connection."
},
"customLaunchSetupCommands": {
"type": "array",
"description": "If provided, this replaces the default commands used to launch a target with some other commands. \nFor example, this can be \"-target-attach\" in order to attach to a target process. \nAn empty command list replaces the launch commands with nothing, which can be useful if the debugger is being provided launch options as command line options. \nExample: \"customLaunchSetupCommands\": [ { \"text\": \"target-run\", \"description\": \"run target\", \"ignoreFailures\": false }].",
Expand Down

0 comments on commit 9e738ca

Please sign in to comment.