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 Issue #844 where pause does not work on Linux and Mac when using gdbservers #855

Merged
merged 9 commits into from
May 14, 2019
32 changes: 18 additions & 14 deletions src/MICore/Debugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public Task AddInternalBreakAction(Func<Task> func)
// When using signals to stop the process, do not kick off another break attempt. The debug break injection and
// signal based models are reliable so no retries are needed. Cygwin can't currently async-break reliably, so
// use retries there.
if (!IsLocalGdb() && !this.IsCygwin)
if (!IsLocalGdbTarget() && !this.IsCygwin)
{
_breakTimer = new Timer(RetryBreak, null, BREAK_DELTA, BREAK_DELTA);
}
Expand Down Expand Up @@ -578,20 +578,24 @@ public Task CmdBreak(BreakRequest request)
return CmdBreakInternal();
}

internal bool IsLocalGdb()
protected bool IsLocalLaunchUsingServer()
{
return (this.MICommandFactory.Mode == MIMode.Gdb &&
this._launchOptions is LocalLaunchOptions &&
String.IsNullOrEmpty(((LocalLaunchOptions)this._launchOptions).MIDebuggerServerAddress));
return (_launchOptions is LocalLaunchOptions localLaunchOptions &&
(!String.IsNullOrWhiteSpace(localLaunchOptions.MIDebuggerServerAddress) ||
!String.IsNullOrWhiteSpace(localLaunchOptions.DebugServer)));
}

internal bool IsLocalGdbTarget()
{
return (MICommandFactory.Mode == MIMode.Gdb &&
_launchOptions is LocalLaunchOptions && !IsLocalLaunchUsingServer());
}

private bool IsRemoteGdb()
private bool IsRemoteGdbTarget()
{
return this.MICommandFactory.Mode == MIMode.Gdb &&
(this._launchOptions is PipeLaunchOptions || this._launchOptions is UnixShellPortLaunchOptions ||
(this._launchOptions is LocalLaunchOptions
&& !String.IsNullOrEmpty(((LocalLaunchOptions)this._launchOptions).MIDebuggerServerAddress)));
return MICommandFactory.Mode == MIMode.Gdb &&
(_launchOptions is PipeLaunchOptions || _launchOptions is UnixShellPortLaunchOptions ||
IsLocalLaunchUsingServer());
}

protected bool IsCoreDump
Expand All @@ -614,7 +618,7 @@ public async Task<Results> CmdTerminate()
// the normal path of sending an internal async break so we can exit doesn't work.
// Therefore, we will call TerminateProcess on the debuggee with the exit code of 0
// to terminate debugging.
if (this.IsLocalGdb() &&
if (this.IsLocalGdbTarget() &&
(this.IsCygwin || this.IsMinGW) &&
_debuggeePids.Count > 0)
{
Expand Down Expand Up @@ -704,7 +708,7 @@ public Task CmdBreakInternal()

// Note that interrupt doesn't work on OS X with gdb:
// https://sourceware.org/bugzilla/show_bug.cgi?id=20035
if (IsLocalGdb())
if (IsLocalGdbTarget())
{
bool useSignal = false;
int debuggeePid = 0;
Expand All @@ -729,15 +733,15 @@ public Task CmdBreakInternal()
}
}
}
else if (IsRemoteGdb() && _transport is PipeTransport)
else if (IsRemoteGdbTarget() && _transport is PipeTransport)
{
int pid = PidByInferior("i1");
if (pid != 0 && ((PipeTransport)_transport).Interrupt(pid))
{
return Task.FromResult<Results>(new Results(ResultClass.done));
}
}
else if (IsRemoteGdb() && _transport is UnixShellPortTransport)
else if (IsRemoteGdbTarget() && _transport is UnixShellPortTransport)
{
int pid = PidByInferior("i1");
if (pid != 0 && ((UnixShellPortTransport)_transport).Interrupt(pid))
Expand Down
7 changes: 3 additions & 4 deletions src/MIDebugEngine/Engine.Impl/DebuggedProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ private List<LaunchCommand> GetInitializeCommands()

// check for remote
string destination = localLaunchOptions?.MIDebuggerServerAddress;
if (!string.IsNullOrEmpty(destination))
if (!string.IsNullOrWhiteSpace(destination))
{
commands.Add(new LaunchCommand("-target-select remote " + destination, string.Format(CultureInfo.CurrentCulture, ResourceStrings.ConnectingMessage, destination)));
}
Expand Down Expand Up @@ -839,7 +839,7 @@ private List<LaunchCommand> GetInitializeCommands()
if (null != localLaunchOptions)
{
string destination = localLaunchOptions.MIDebuggerServerAddress;
if (!string.IsNullOrEmpty(destination))
if (!string.IsNullOrWhiteSpace(destination))
{
commands.Add(new LaunchCommand("-target-select remote " + destination, string.Format(CultureInfo.CurrentCulture, ResourceStrings.ConnectingMessage, destination)));
}
Expand Down Expand Up @@ -1133,8 +1133,7 @@ private async Task HandleBreakModeEvent(ResultEventArgs results, BreakRequest br

// MinGW sends a stopped event on attach. gdb<->gdbserver also sends a stopped event when first attached.
// If this is a gdb<->gdbserver connection, ignore this as the entryPoint
if (this._launchOptions is LocalLaunchOptions &&
!String.IsNullOrWhiteSpace(((LocalLaunchOptions)this._launchOptions).MIDebuggerServerAddress))
if (IsLocalLaunchUsingServer())
{
// If the stopped event occurs on gdbserver, ignore it unless it contains a filename.
TupleValue frame = results.Results.TryFind<TupleValue>("frame");
Expand Down