Skip to content

Commit

Permalink
Reused the /launchdebugger argument for both launch and attach
Browse files Browse the repository at this point in the history
  • Loading branch information
dellis1972 committed Jun 7, 2024
1 parent 8a3b0e9 commit ffbd412
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
10 changes: 2 additions & 8 deletions Tools/MonoGame.Content.Builder/BuildContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@ class BuildContent
[CommandLineParameter(
Name = "launchdebugger",
Flag = "d",
Description = "Launch the debugger before building content.")]
Description = "Launch/Attach the debugger before building content.")]
public bool LaunchDebugger = false;

[CommandLineParameter(
Name = "waitfordebugger",
Flag = "a",
Description = "Wait for debugger to attach before building content.")]
public bool WaitForDebuggerToAttach = false;

[CommandLineParameter(
Name = "quiet",
Flag = "q",
Expand Down Expand Up @@ -305,7 +299,7 @@ public void Build(out int successCount, out int errorCount)

// If the intent is to debug build, break at the original location
// of any exception, eg, within the actual importer/processor.
if (LaunchDebugger || WaitForDebuggerToAttach)
if (LaunchDebugger)
_manager.RethrowExceptions = false;

// Feed all the assembly references to the pipeline manager
Expand Down
26 changes: 12 additions & 14 deletions Tools/MonoGame.Content.Builder/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,23 @@ static int Main(string[] args)
if (!parser.Parse(args))
return -1;

// Launch debugger if requested.
// Launch or wait for the debugger to attach if requested.
if (content.LaunchDebugger)
{
try {
if (Environment.OSVersion.Platform != PlatformID.Unix)
{
System.Diagnostics.Debugger.Launch();
} catch (NotImplementedException) {
// not implemented under Mono
Console.Error.WriteLine("The debugger is not implemented under Mono and thus is not supported on your platform.");
}
}
if (content.WaitForDebuggerToAttach)
{
var currentProcess = Process.GetCurrentProcess();
Console.WriteLine($"Waiting for debugger to attach ({currentProcess.MainModule.FileName} PID {currentProcess.Id}). Press any key to continue without debugger.");
while (!Debugger.IsAttached) {
if (Console.KeyAvailable) {
break;
else
{
var currentProcess = Process.GetCurrentProcess();
Console.WriteLine($"Waiting for debugger to attach ({currentProcess.MainModule.FileName} PID {currentProcess.Id}). Press any key to continue without debugger.");
while (!Debugger.IsAttached)
{
if (Console.KeyAvailable)
break;
Thread.Sleep(100);
}
Thread.Sleep(100);
}
}

Expand Down

0 comments on commit ffbd412

Please sign in to comment.