From 6fd8e2dd19de59755b5531ccd7e481fd1df8967d Mon Sep 17 00:00:00 2001 From: dd86k Date: Sun, 1 Dec 2024 13:10:34 -0500 Subject: [PATCH] shell: Move process creation/attachment in main module instead --- debugger/main.d | 9 ++++++ debugger/shell.d | 83 +++++++++++++++++++++--------------------------- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/debugger/main.d b/debugger/main.d index fa6ce7c..0184bdd 100644 --- a/debugger/main.d +++ b/debugger/main.d @@ -117,5 +117,14 @@ int main(int argc, const(char)** argv) { return EXIT_FAILURE; } + // Start or attach to process if specified + if (argc > 0 && argv && shell_spawn(*argv, argc > 1 ? argv + 1 : null)) { + logerror("Could not spawn process: %s", adbg_error_message()); + return 1; + } else if (opt_pid && shell_attach(opt_pid)) { + logerror("Could not attach to process: %s", adbg_error_message()); + return 1; + } + return shell_start(argc, getoptleftovers()); } diff --git a/debugger/shell.d b/debugger/shell.d index 8d3e2bb..f5f028b 100644 --- a/debugger/shell.d +++ b/debugger/shell.d @@ -134,15 +134,6 @@ void logwrite(const(char) *pre, int color, const(char) *fmt, va_list args) { } int shell_start(int argc, const(char)** argv) { - // Start or attach to process if specified - if (argc > 0 && argv && shell_spawn(*argv, argc > 1 ? argv + 1 : null)) { - logerror("Could not spawn process: %s", adbg_error_message()); - return 1; - } else if (opt_pid && shell_attach(opt_pid)) { - logerror("Could not attach to process: %s", adbg_error_message()); - return 1; - } - Lcommand: fputs("(adbg) ", stdout); fflush(stdout); @@ -188,6 +179,43 @@ int shell_execv(int argc, const(char) **argv) { return command.entry(argc, argv); } +int shell_spawn(const(char) *exec, const(char) **argv) { + // Save for restart + last_spawn_exec = exec; + last_spawn_argv = argv; + + // Spawn process + process = adbg_debugger_spawn(exec, + AdbgSpawnOpt.argv, argv, + 0); + if (process == null) + return ShellError.alicedbg; + + printf("Process '%s' created", exec); + if (argv && *argv) { + printf(" with arguments:"); + for (int i; argv[i]; ++i) + printf(" '%s'", argv[i]); + } + putchar('\n'); + + return shell_setup(); +} + +int shell_attach(int pid) { + // Save for restart + opt_pid = pid; + + // Attach to process + process = adbg_debugger_attach(pid, 0); + if (process == null) + return ShellError.alicedbg; + + loginfo("Debugger attached."); + + return shell_setup(); +} + private: __gshared: @@ -537,43 +565,6 @@ immutable(command2_t)* shell_findcommand(const(char) *ucommand) { return null; } -int shell_spawn(const(char) *exec, const(char) **argv) { - // Save for restart - last_spawn_exec = exec; - last_spawn_argv = argv; - - // Spawn process - process = adbg_debugger_spawn(exec, - AdbgSpawnOpt.argv, argv, - 0); - if (process == null) - return ShellError.alicedbg; - - printf("Process '%s' created", exec); - if (argv && *argv) { - printf(" with arguments:"); - for (int i; argv[i]; ++i) - printf(" '%s'", argv[i]); - } - putchar('\n'); - - return shell_setup(); -} - -int shell_attach(int pid) { - // Save for restart - opt_pid = pid; - - // Attach to process - process = adbg_debugger_attach(pid, 0); - if (process == null) - return ShellError.alicedbg; - - loginfo("Debugger attached."); - - return shell_setup(); -} - // After int shell_setup() { if (adbg_debugger_on(process, AdbgEvent.exception, &shell_event_exception) ||