Fixed the launch argument processing done by the debugger

This commit is contained in:
x1nixmzeng 2020-09-25 20:41:28 +01:00
parent 44f1e0937c
commit 2c16a3f1b6
2 changed files with 28 additions and 27 deletions

View File

@ -71,30 +71,29 @@ namespace CxbxDebugger
Init();
}
public Debugger(string[] x_args)
public Debugger(string[] launchArgs)
{
Init();
if (x_args == null)
return;
// Copy all arguments
args = x_args;
// Keep quotes for any strings that may contain spaces
int scratch;
for (int i = 0; i < args.Length; ++i)
// Copy XBE path without the quotes
var loadArg = Array.FindIndex(launchArgs, x => x == "/load");
if (loadArg != -1)
{
if (int.TryParse(args[i], out scratch) == false)
{
args[i] = string.Format("\"{0}\"", args[i]);
}
Target = launchArgs[loadArg + 1].Trim(new char[] { '"' });
}
// Copy XBE path without the quotes
if(x_args.Length > 2)
args = new string[launchArgs.Length];
for (int i = 0; i < launchArgs.Length; ++i)
{
Target = x_args[2].Trim(new char[] { '"' });
var arg = launchArgs[i];
if (arg.Contains(" "))
{
arg = string.Format($"\"{arg}\"");
}
args[i] = arg;
}
}
@ -176,11 +175,13 @@ namespace CxbxDebugger
var DebugCreationFlags =
WinProcesses.ProcessCreationFlags.DEBUG_ONLY_THIS_PROCESS |
WinProcesses.ProcessCreationFlags.CREATE_NEW_CONSOLE;
var launchArgs = new StringBuilder(string.Join(" ", args));
bool bRet = WinProcesses.NativeMethods.CreateProcess
(
null,
new StringBuilder(string.Join(" ", args)),
launchArgs,
null,
null,
false,
@ -201,6 +202,10 @@ namespace CxbxDebugger
State = RunState.Running;
}
else
{
throw new Exception($"Failed to launch loader '{launchArgs}'");
}
return bRet;
}

View File

@ -15,7 +15,7 @@ namespace CxbxDebugger
{
Thread DebuggerWorkerThread;
Debugger DebuggerInst;
string[] CachedArgs;
string[] StartupArgs;
string CachedTitle = "";
bool SuspendedOnBp = false;
@ -45,13 +45,9 @@ namespace CxbxDebugger
throw new Exception("Incorrect usage");
}
var items = new List<string>(args.Length - 1);
for (int i = 1; i < args.Length; ++i)
{
items.Add(args[i]);
}
CachedArgs = items.ToArray();
StartupArgs = new string[args.Length - 1];
Array.Copy(args, 1, StartupArgs, 0, args.Length - 1);
DebugEvents = new DebuggerFormEvents(this);
@ -104,7 +100,7 @@ namespace CxbxDebugger
if (Create)
{
// Create debugger instance
DebuggerInst = new Debugger(CachedArgs);
DebuggerInst = new Debugger(StartupArgs);
DebuggerInst.RegisterEventInterfaces(DebugEvents);
DebuggerInst.RegisterEventInterfaces(patchMan);