Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for -break-insert main returning multiple bind points #729

Merged
merged 2 commits into from
Jun 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
39 changes: 24 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,33 @@ 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) // Used when main breakpoint binds in more than one location
{
this._entryPointBreakpoint = dict["number"];
// Grab the first one as this is usually the <MULTIPLE> one that we can unbind them all with.
// This is usually "1" when the children manifest as "1.1", "1.2", etc
bkpt = (b as ValueListValue).Content[0] as TupleValue;
}

if (bkpt != null)
{
this._entryPointBreakpoint = bkpt.FindString("number");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does GDB do the .1 thing with number in the multiple bind case? If so, do we need to do anything else to pre-process the number before we send it to breakpoint delete?

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