Skip to content

Commit d00fc34

Browse files
committed
Fix spurious exception on entry and add stopAtConnect
1 parent 05acc46 commit d00fc34

3 files changed

Lines changed: 55 additions & 5 deletions

File tree

src/MICore/JsonLaunchOptions.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ public abstract partial class BaseOptions
9595
/// </summary>
9696
[JsonProperty("setupCommands", DefaultValueHandling = DefaultValueHandling.Ignore)]
9797
public List<SetupCommand> SetupCommands { get; protected set; }
98+
99+
/// <summary>
100+
/// Optional parameter. If true, the debugger should stop after connecting to the target.
101+
/// </summary>
102+
[JsonProperty("stopAtConnect", DefaultValueHandling = DefaultValueHandling.Ignore)]
103+
public bool? StopAtConnect { get; set; }
98104
}
99105

100106
public partial class AttachOptions : BaseOptions
@@ -127,7 +133,8 @@ public AttachOptions(
127133
string miDebuggerServerAddress = null,
128134
Dictionary<string, object> sourceFileMap = null,
129135
PipeTransport pipeTransport = null,
130-
SymbolLoadInfo symbolLoadInfo = null)
136+
SymbolLoadInfo symbolLoadInfo = null,
137+
bool? stopAtConnect = null)
131138
{
132139
this.Program = program;
133140
this.Type = type;
@@ -143,6 +150,7 @@ public AttachOptions(
143150
this.SourceFileMap = sourceFileMap;
144151
this.PipeTransport = pipeTransport;
145152
this.SymbolLoadInfo = symbolLoadInfo;
153+
this.StopAtConnect = stopAtConnect;
146154
}
147155

148156
#endregion
@@ -345,7 +353,8 @@ public LaunchOptions(
345353
string coreDumpPath = null,
346354
bool? externalConsole = null,
347355
Dictionary<string, object> sourceFileMap = null,
348-
PipeTransport pipeTransport = null)
356+
PipeTransport pipeTransport = null,
357+
bool? stopAtConnect = null)
349358
{
350359
this.Program = program;
351360
this.Args = args;
@@ -374,6 +383,7 @@ public LaunchOptions(
374383
this.ExternalConsole = externalConsole;
375384
this.SourceFileMap = sourceFileMap;
376385
this.PipeTransport = pipeTransport;
386+
this.StopAtConnect = stopAtConnect;
377387
}
378388

379389
#endregion

src/MICore/LaunchOptions.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,21 @@ public ReadOnlyCollection<EnvironmentEntry> Environment
11261126
}
11271127
}
11281128

1129+
private bool _stopAtConnect;
1130+
1131+
/// <summary>
1132+
/// Optional parameter. If true, the debugger should stop after connecting to the target.
1133+
/// </summary>
1134+
public bool StopAtConnect
1135+
{
1136+
get { return _stopAtConnect; }
1137+
set
1138+
{
1139+
VerifyCanModifyProperty(nameof(StopAtConnect));
1140+
_stopAtConnect = value;
1141+
}
1142+
}
1143+
11291144
public string GetOptionsString()
11301145
{
11311146
try
@@ -1714,7 +1729,7 @@ protected void InitializeCommonOptions(Json.LaunchOptions.BaseOptions options)
17141729
}
17151730

17161731
this.SetupCommands = LaunchCommand.CreateCollection(options.SetupCommands);
1717-
1732+
this.StopAtConnect = options.StopAtConnect ?? false;
17181733
}
17191734

17201735
protected void InitializeCommonOptions(Xml.LaunchOptions.BaseLaunchOptions source)

src/MIDebugEngine/Engine.Impl/DebuggedProcess.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,24 +1103,41 @@ private async Task HandleBreakModeEvent(ResultEventArgs results, BreakRequest br
11031103
if (String.IsNullOrWhiteSpace(reason) && !this.EntrypointHit)
11041104
{
11051105
breakRequest = BreakRequest.None; // don't let stopping interfere with launch processing
1106+
bool shouldContinue = true;
11061107

1108+
if (_launchOptions.StopAtConnect)
1109+
{
1110+
this.EntrypointHit = true;
1111+
await this.ClearEntrypointBreakpoint();
1112+
1113+
// Send a breakpoint event to force the client to stop (entry point may not stop depending on how the user started debugging)
1114+
_callback.OnBreakpoint(thread, new ReadOnlyCollection<object>(new AD7BoundBreakpoint[] { }));
1115+
shouldContinue = false;
1116+
}
11071117
// MinGW sends a stopped event on attach. gdb<->gdbserver also sends a stopped event when first attached.
11081118
// If this is a gdb<->gdbserver connection, ignore this as the entryPoint
1109-
if (IsLocalLaunchUsingServer())
1119+
else if (IsLocalLaunchUsingServer())
11101120
{
11111121
// If the stopped event occurs on gdbserver, ignore it unless it contains a filename.
11121122
TupleValue frame = results.Results.TryFind<TupleValue>("frame");
11131123
if (frame.Contains("file"))
11141124
{
11151125
this.EntrypointHit = true;
1126+
await this.ClearEntrypointBreakpoint();
1127+
_callback.OnEntryPoint(thread);
1128+
shouldContinue = false;
11161129
}
11171130
}
11181131
else
11191132
{
11201133
this.EntrypointHit = true;
1134+
await this.ClearEntrypointBreakpoint();
11211135
}
11221136

1123-
CmdContinueAsync();
1137+
if (shouldContinue)
1138+
{
1139+
CmdContinueAsync();
1140+
}
11241141
FireDeviceAppLauncherResume();
11251142
}
11261143
else if (reason == "entry-point-hit")
@@ -1315,6 +1332,14 @@ private async Task OnEntrypointHit()
13151332
await ConsoleCmdAsync("process handle --pass true --stop false --notify false SIGHUP", allowWhileRunning: false, ignoreFailures: true);
13161333
}
13171334

1335+
await this.ClearEntrypointBreakpoint();
1336+
}
1337+
1338+
/// <summary>
1339+
/// Attempts to remove the breakpoint automatically set at the entrypoint of the application.
1340+
/// </summary>
1341+
private async Task ClearEntrypointBreakpoint()
1342+
{
13181343
if (this._deleteEntryPointBreakpoint && !String.IsNullOrWhiteSpace(this._entryPointBreakpoint))
13191344
{
13201345
// Try and delete the entrypoint breakpoint. We only try this once but in some cases this won't succeed

0 commit comments

Comments
 (0)