Skip to content

Commit

Permalink
Fix for -break-insert main returning multiple bind points
Browse files Browse the repository at this point in the history
This fix is to support -break-insert main returning multiple bind
points, which was causing a dictionary error on multiple keys.
  • Loading branch information
pieandcakes committed Jun 11, 2018
1 parent 5ef9fb6 commit 34f85fa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/MICore/LaunchCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public class LaunchCommand
public readonly bool IsMICommand;
public /*OPTIONAL*/ Action<string> FailureHandler { get; private set; }
public /*OPTIONAL*/ Func<string, Task> SuccessHandler { get; private set; }
public /*Optional*/ Func<Results, Task> SuccessResultsHandler { get; private set; }

public LaunchCommand(string commandText, string description = null, bool ignoreFailures = false, Action<string> failureHandler = null, Func<string, Task> successHandler = null)
public LaunchCommand(string commandText, string description = null, bool ignoreFailures = false, Action<string> failureHandler = null, Func<string, Task> successHandler = null, Func<Results, Task> successResultsHandler = null)
{
if (commandText == null)
throw new ArgumentNullException("commandText");
Expand All @@ -40,6 +41,7 @@ public LaunchCommand(string commandText, string description = null, bool ignoreF
this.IgnoreFailures = ignoreFailures;
this.FailureHandler = failureHandler;
this.SuccessHandler = successHandler;
this.SuccessResultsHandler = successResultsHandler;
}

public static ReadOnlyCollection<LaunchCommand> CreateCollection(List<Json.LaunchOptions.SetupCommand> source)
Expand Down
37 changes: 22 additions & 15 deletions src/MIDebugEngine/Engine.Impl/DebuggedProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal class DebuggedProcess : MICore.Debugger
private HashSet<Tuple<string, string>> _fileTimestampWarnings;
private ProcessSequence _childProcessHandler;
private bool _deleteEntryPointBreakpoint;
private string _entryPointBreakpoint = String.Empty;
private string _entryPointBreakpoint = string.Empty;

public DebuggedProcess(bool bLaunched, LaunchOptions launchOptions, ISampleEngineCallback callback, WorkerThread worker, BreakpointManager bpman, AD7Engine engine, HostConfigurationStore configStore, HostWaitLoop waitLoop = null) : base(launchOptions, engine.Logger)
{
Expand Down Expand Up @@ -549,6 +549,11 @@ public async Task Initialize(HostWaitLoop waitLoop, CancellationToken token)
{
await command.SuccessHandler(results.ToString());
}

if (command.SuccessResultsHandler != null)
{
await command.SuccessResultsHandler(results);
}
}
}
else
Expand Down Expand Up @@ -752,29 +757,31 @@ private List<LaunchCommand> GetInitializeCommands()
commands.Add(new LaunchCommand("-exec-arguments " + _launchOptions.ExeArguments));
}

Func<string, Task> breakMainSuccessHandler = (string bkptResult) =>
Func<Results, Task> breakMainSuccessResultsHandler = (Results bkptResult) =>
{
int index = bkptResult.IndexOf("number=", StringComparison.Ordinal);
if (index > 0)
if (bkptResult.Contains("bkpt"))
{
string trimmedInnerText = bkptResult.Substring(index).Trim('\r', '\n', '{', '}');
Dictionary<string, string> dict = trimmedInnerText
.Split(',')
.Select(value => value.Split('='))
.Where(x => x.Length == 2)
.ToDictionary(x => x.First(), x => x.Last());
if (dict.Keys.Contains("number"))
ResultValue b = bkptResult.Find("bkpt");
TupleValue bkpt = null;
if (b is TupleValue)
{
bkpt = b as TupleValue;
}
else if (b is ValueListValue)
{
this._entryPointBreakpoint = dict["number"];
bkpt = (b as ValueListValue).Content[0] as TupleValue;
}
if (bkpt != null)
{
this._entryPointBreakpoint = bkpt.FindString("number");
this._deleteEntryPointBreakpoint = true;
}
}
return Task.FromResult(0);
};

commands.Add(new LaunchCommand("-break-insert main", ignoreFailures: true, successHandler: breakMainSuccessHandler));
commands.Add(new LaunchCommand("-break-insert main", ignoreFailures: true, successResultsHandler: breakMainSuccessResultsHandler));

if (null != localLaunchOptions)
{
Expand Down

0 comments on commit 34f85fa

Please sign in to comment.