Module: wine Branch: refs/heads/master Commit: a67f8e862eac26b7e1d07530f0ed461e7f7a05c3 URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=a67f8e862eac26b7e1d07530...
Author: Eric Pouech eric.pouech@wanadoo.fr Date: Fri Feb 24 22:14:36 2006 +0100
winedbg: Move gdb command line handling.
- moves gdb command line handling to gdbproxy.c - using manifest constants to make code more readable
---
programs/winedbg/debugger.h | 4 ++-- programs/winedbg/gdbproxy.c | 35 ++++++++++++++++++++++++++++++++--- programs/winedbg/winedbg.c | 35 +++++++++-------------------------- 3 files changed, 43 insertions(+), 31 deletions(-)
diff --git a/programs/winedbg/debugger.h b/programs/winedbg/debugger.h index fbe8ea2..91b4b70 100644 --- a/programs/winedbg/debugger.h +++ b/programs/winedbg/debugger.h @@ -373,7 +373,7 @@ extern void dbg_wait_next_ex extern enum dbg_start dbg_active_attach(int argc, char* argv[]); extern enum dbg_start dbg_active_launch(int argc, char* argv[]); /* temporary for tgt_active.c */ -extern enum dbg_action_mode {none_mode = 0, winedbg_mode, automatic_mode, gdb_mode} dbg_action_mode; +extern enum dbg_action_mode {none_mode = 0, winedbg_mode, automatic_mode} dbg_action_mode; extern unsigned dbg_main_loop(HANDLE);
/* tgt_minidump.c */ @@ -414,7 +414,7 @@ extern void dbg_del_thread(s extern BOOL dbg_get_debuggee_info(HANDLE hProcess, IMAGEHLP_MODULE* imh_mod);
/* gdbproxy.c */ -extern BOOL gdb_remote(unsigned int); +extern int gdb_main(int argc, char* argv[]);
static inline BOOL dbg_read_memory(const void* addr, void* buffer, size_t len) { diff --git a/programs/winedbg/gdbproxy.c b/programs/winedbg/gdbproxy.c index 6a448d3..3d5a9cc 100644 --- a/programs/winedbg/gdbproxy.c +++ b/programs/winedbg/gdbproxy.c @@ -2042,6 +2042,9 @@ static int fetch_data(struct gdb_context return gdbctx->in_len - in_len; }
+#define FLAG_NO_START 1 +#define FLAG_WITH_XTERM 2 + static BOOL gdb_exec(const char* wine_path, unsigned port, unsigned flags) { char buf[MAX_PATH]; @@ -2071,7 +2074,7 @@ static BOOL gdb_exec(const char* wine_pa /* tell gdb to delete this file when done handling it... */ fprintf(f, "shell rm -f "%s"\n", buf); fclose(f); - if (flags & 2) + if (flags & FLAG_WITH_XTERM) execlp("xterm", "xterm", "-e", gdb_path, "-x", buf, NULL); else execlp(gdb_path, gdb_path, "-x", buf, NULL); @@ -2106,7 +2109,7 @@ static BOOL gdb_startup(struct gdb_conte if (!dbg_get_debuggee_info(gdbctx->process->handle, &imh_mod)) return FALSE;
/* step 4: fire up gdb (if requested) */ - if (flags & 1) + if (flags & FLAG_NO_START) fprintf(stderr, "target remote localhost:%d\n", ntohs(s_addrs.sin_port)); else switch (fork()) @@ -2205,7 +2208,7 @@ static BOOL gdb_init_context(struct gdb_ return TRUE; }
-BOOL gdb_remote(unsigned flags) +static int gdb_remote(unsigned flags) { struct pollfd pollfd; struct gdb_context gdbctx; @@ -2248,3 +2251,29 @@ BOOL gdb_remote(unsigned flags) wait(NULL); return 0; } + +int gdb_main(int argc, char* argv[]) +{ + unsigned gdb_flags = 0; + + argc--; argv++; + while (argc > 0 && argv[0][0] == '-') + { + if (strcmp(argv[0], "--no-start") == 0) + { + gdb_flags |= FLAG_NO_START; + argc--; argv++; + continue; + } + if (strcmp(argv[0], "--with-xterm") == 0) + { + gdb_flags |= FLAG_WITH_XTERM; + argc--; argv++; + continue; + } + return -1; + } + if (dbg_active_attach(argc, argv) || dbg_active_launch(argc, argv)) + return gdb_remote(gdb_flags); + return -1; +} diff --git a/programs/winedbg/winedbg.c b/programs/winedbg/winedbg.c index e1ffe60..1978d37 100644 --- a/programs/winedbg/winedbg.c +++ b/programs/winedbg/winedbg.c @@ -446,7 +446,7 @@ static void dbg_init_console(void) static int dbg_winedbg_usage(void) { dbg_printf("Usage: winedbg [--command cmd|--file file|--auto] [--gdb [--no-start] [--with-xterm]] cmdline\n"); - return 1; + return -1; }
struct backend_cpu* be_cpu; @@ -462,8 +462,7 @@ extern struct backend_cpu be_alpha;
int main(int argc, char** argv) { - DWORD retv = 0; - unsigned gdb_flags = 0; + int retv = 0; HANDLE hFile = INVALID_HANDLE_VALUE;
#ifdef __i386__ @@ -484,6 +483,13 @@ int main(int argc, char** argv) /* as we don't care about exec name */ argc--; argv++;
+ if (argc && !strcmp(argv[0], "--gdb")) + { + retv = gdb_main(argc, argv); + if (retv == -1) dbg_winedbg_usage(); + return retv; + } + /* parse options */ while (argc > 0 && argv[0][0] == '-') { @@ -532,25 +538,6 @@ int main(int argc, char** argv) dbg_houtput = GetStdHandle(STD_ERROR_HANDLE); continue; } - if (!strcmp(argv[0], "--gdb")) - { - if (dbg_action_mode != none_mode) return dbg_winedbg_usage(); - dbg_action_mode = gdb_mode; - argc--; argv++; - continue; - } - if (strcmp(argv[0], "--no-start") == 0 && dbg_action_mode == gdb_mode) - { - gdb_flags |= 1; - argc--; argv++; - continue; - } - if (strcmp(argv[0], "--with-xterm") == 0 && dbg_action_mode == gdb_mode) - { - gdb_flags |= 2; - argc--; argv++; - continue; - } return dbg_winedbg_usage(); }
@@ -558,10 +545,6 @@ int main(int argc, char** argv) if (!argc || dbg_active_attach(argc, argv) == start_ok || dbg_active_launch(argc, argv) == start_ok) { - /* don't save local vars in gdb mode */ - if (dbg_action_mode == gdb_mode && dbg_curr_pid) - return gdb_remote(gdb_flags); - dbg_init_console();
SymSetOptions((SymGetOptions() & ~(SYMOPT_UNDNAME)) |