From 67001a1d8b4ab6d981055a7cc0f797be0721a31e Mon Sep 17 00:00:00 2001 From: Eric Pouech Date: Mon, 27 Feb 2006 21:50:36 +0100 Subject: [PATCH] winedbg: Rewrite auto mode. - rewrote auto mode as a specific set of commands to be run in regular parser, instead of hard coding those commands - added a new function to store a set of commands to be executed in a file - added 'echo' command to the parser functions - got rid of dbg_action_mode - added support of '--' on command line --- programs/winedbg/dbg.y | 32 ++++++++++++++++- programs/winedbg/debug.l | 1 + programs/winedbg/debugger.h | 2 +- programs/winedbg/tgt_active.c | 36 +++++++------------ programs/winedbg/winedbg.c | 80 ++++++++++++++++++++----------------------- 5 files changed, 84 insertions(+), 67 deletions(-) diff --git a/programs/winedbg/dbg.y b/programs/winedbg/dbg.y index 8207d849595..abb470404ee 100644 --- a/programs/winedbg/dbg.y +++ b/programs/winedbg/dbg.y @@ -51,7 +51,7 @@ int yyerror(const char*); %token tCONT tPASS tSTEP tLIST tNEXT tQUIT tHELP tBACKTRACE tALL tINFO tUP tDOWN %token tENABLE tDISABLE tBREAK tHBREAK tWATCH tDELETE tSET tMODE tPRINT tEXAM -%token tABORT tVM86 +%token tABORT tVM86 tECHO %token tCLASS tMAPS tSTACK tSEGMENTS tSYMBOL tREGS tWND tQUEUE tLOCAL tEXCEPTION %token tPROCESS tTHREAD tMODREF tEOL tEOF %token tFRAME tSHARE tCOND tDISPLAY tUNDISPLAY tDISASSEMBLE @@ -141,6 +141,7 @@ command: | tATTACH tNUM { dbg_attach_debuggee($2, FALSE, TRUE); } | tDETACH { dbg_detach_debuggee(); } | tMINIDUMP pathname { minidump_write($2, (dbg_curr_thread && dbg_curr_thread->in_exception) ? &dbg_curr_thread->excpt_record : NULL);} + | tECHO tSTRING { dbg_printf("%s\n", $2); } | run_command | list_command | disassemble_command @@ -554,3 +555,32 @@ int yyerror(const char* s) dbg_printf("%s\n", s); return 0; } + +HANDLE parser_generate_command_file(const char* pmt, ...) +{ + HANDLE hFile; + char path[MAX_PATH], file[MAX_PATH]; + DWORD w; + const char* p; + + GetTempPath(sizeof(path), path); + GetTempFileName(path, "WD", 0, file); + hFile = CreateFileA(file, GENERIC_READ|GENERIC_WRITE|DELETE, FILE_SHARE_DELETE, + NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, 0); + if (hFile != INVALID_HANDLE_VALUE) + { + va_list ap; + + WriteFile(hFile, pmt, strlen(pmt), &w, 0); + va_start(ap, pmt); + while ((p = va_arg(ap, const char*)) != NULL) + { + WriteFile(hFile, "\n", 1, &w, 0); + WriteFile(hFile, p, strlen(p), &w, 0); + } + va_end(ap); + WriteFile(hFile, "\nquit\n", 6, &w, 0); + SetFilePointer(hFile, 0, NULL, FILE_BEGIN); + } + return hFile; +} diff --git a/programs/winedbg/debug.l b/programs/winedbg/debug.l index ad1a986f233..71d10f07fa2 100644 --- a/programs/winedbg/debug.l +++ b/programs/winedbg/debug.l @@ -180,6 +180,7 @@ STRING \"[^\n"]+\" detach|detac|deta|det { BEGIN(NOCMD); return tDETACH; } maintenance|maint { BEGIN(MAINT_CMD); return tMAINTENANCE; } minidump|mdmp { BEGIN(PATH_EXPECTED); return tMINIDUMP; } +echo { BEGIN(ASTRING_EXPECTED); return tECHO; } attach|attac|atta|att { BEGIN(NOCMD); return tATTACH; } share|shar|sha { return tSHARE; } locals|local|loca|loc { return tLOCAL; } diff --git a/programs/winedbg/debugger.h b/programs/winedbg/debugger.h index 38ad642c050..ecfe2f4f14f 100644 --- a/programs/winedbg/debugger.h +++ b/programs/winedbg/debugger.h @@ -282,6 +282,7 @@ extern void parser(const char*); extern void parser_handle(HANDLE); extern int input_read_line(const char* pfx, char* buffer, int size); extern int input_fetch_entire_line(const char* pfx, char** line); +extern HANDLE parser_generate_command_file(const char*, ...); /* debug.l */ extern void lexeme_flush(void); @@ -374,7 +375,6 @@ extern enum dbg_start dbg_active_attach(int argc, char* argv[]); extern enum dbg_start dbg_active_launch(int argc, char* argv[]); extern enum dbg_start dbg_active_auto(int argc, char* argv[]); /* temporary for tgt_active.c */ -extern enum dbg_action_mode {winedbg_mode, automatic_mode} dbg_action_mode; extern unsigned dbg_main_loop(HANDLE); /* tgt_minidump.c */ diff --git a/programs/winedbg/tgt_active.c b/programs/winedbg/tgt_active.c index 226227c348b..ac2faaa983f 100644 --- a/programs/winedbg/tgt_active.c +++ b/programs/winedbg/tgt_active.c @@ -33,7 +33,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(winedbg); static char* dbg_last_cmd_line; -/*static*/ enum dbg_action_mode dbg_action_mode; struct be_process_io be_process_active_io = { @@ -404,13 +403,6 @@ static DWORD dbg_handle_exception(const EXCEPTION_RECORD* rec, BOOL first_chance dbg_printf( ", invalid program stack" ); } - if (dbg_action_mode == automatic_mode) - { - dbg_exception_prolog(is_debug, rec); - dbg_exception_epilog(); - return 0; /* terminate execution */ - } - if (dbg_exception_prolog(is_debug, rec)) { dbg_interactiveP = TRUE; @@ -693,19 +685,8 @@ void dbg_wait_next_exception(DWORD cont, int count, int mode) { if (dbg_handle_debug_event(&de)) break; } - switch (dbg_action_mode) - { - case automatic_mode: - /* print some extra information */ - dbg_printf("Modules:\n"); - info_win32_module(0); /* print all modules */ - dbg_printf("Threads:\n"); - info_win32_threads(); - break; - default: - dbg_interactiveP = TRUE; - parser_handle(hFile); - } + dbg_interactiveP = TRUE; + parser_handle(hFile); dbg_printf("WineDbg terminated on pid 0x%lx\n", dbg_curr_pid); return 0; @@ -880,7 +861,16 @@ enum dbg_start dbg_active_launch(int argc, char* argv[]) */ enum dbg_start dbg_active_auto(int argc, char* argv[]) { + HANDLE hFile; + enum dbg_start ds = start_error_parse; + argc--; argv++; - dbg_action_mode = automatic_mode; - return dbg_active_attach(argc, argv); + hFile = parser_generate_command_file("echo Modules:", "info share", + "echo Threads:", "info threads", + NULL); + if (hFile == INVALID_HANDLE_VALUE || + (ds = dbg_active_attach(argc, argv)) != start_ok) + return ds; + dbg_main_loop(hFile); + return start_ok; } diff --git a/programs/winedbg/winedbg.c b/programs/winedbg/winedbg.c index e8678c4d8cb..40eee6c10e2 100644 --- a/programs/winedbg/winedbg.c +++ b/programs/winedbg/winedbg.c @@ -491,7 +491,6 @@ int main(int argc, char** argv) return retv; } dbg_init_console(); - dbg_action_mode = winedbg_mode; SymSetOptions((SymGetOptions() & ~(SYMOPT_UNDNAME)) | SYMOPT_LOAD_LINES | SYMOPT_DEFERRED_LOADS | SYMOPT_AUTO_PUBLICS); @@ -501,63 +500,60 @@ int main(int argc, char** argv) /* force some internal variables */ DBG_IVAR(BreakOnDllLoad) = 0; dbg_houtput = GetStdHandle(STD_ERROR_HANDLE); - ds = dbg_active_auto(argc, argv); + switch (dbg_active_auto(argc, argv)) + { + case start_ok: return 0; + case start_error_parse: return dbg_winedbg_usage(); + case start_error_init: return -1; + } } - else + /* parse options */ + while (argc > 0 && argv[0][0] == '-') { - /* parse options */ - while (argc > 0 && argv[0][0] == '-') + if (!strcmp(argv[0], "--command")) { - if (!strcmp(argv[0], "--command")) + argc--; argv++; + hFile = parser_generate_command_file(argv[0], NULL); + if (hFile == INVALID_HANDLE_VALUE) { - char path[MAX_PATH], file[MAX_PATH]; - DWORD w; - - GetTempPath(sizeof(path), path); - GetTempFileName(path, "WD", 0, file); - argc--; argv++; - hFile = CreateFileA(file, GENERIC_READ|GENERIC_WRITE|DELETE, FILE_SHARE_DELETE, - NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, 0); - if (hFile == INVALID_HANDLE_VALUE) - { - dbg_printf("Couldn't open temp file %s (%lu)\n", file, GetLastError()); - return 1; - } - WriteFile(hFile, argv[0], strlen(argv[0]), &w, 0); - WriteFile(hFile, "\nquit\n", 6, &w, 0); - SetFilePointer(hFile, 0, NULL, FILE_BEGIN); - - argc--; argv++; - continue; + dbg_printf("Couldn't open temp file (%lu)\n", GetLastError()); + return 1; } - if (!strcmp(argv[0], "--file")) + argc--; argv++; + continue; + } + if (!strcmp(argv[0], "--file")) + { + argc--; argv++; + hFile = CreateFileA(argv[0], GENERIC_READ|DELETE, 0, + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + if (hFile == INVALID_HANDLE_VALUE) { - argc--; argv++; - hFile = CreateFileA(argv[0], GENERIC_READ|DELETE, 0, - NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); - if (hFile == INVALID_HANDLE_VALUE) - { - dbg_printf("Couldn't open file %s (%lu)\n", argv[0], GetLastError()); - return 1; - } - argc--; argv++; - continue; + dbg_printf("Couldn't open file %s (%lu)\n", argv[0], GetLastError()); + return 1; } - return dbg_winedbg_usage(); + argc--; argv++; + continue; } - if (!argc) ds = start_ok; - else if ((ds = dbg_active_attach(argc, argv)) == start_error_parse) - ds = dbg_active_launch(argc, argv); + if (!strcmp(argv[0], "--")) + { + argc--; argv++; + break; + } + return dbg_winedbg_usage(); } + if (!argc) ds = start_ok; + else if ((ds = dbg_active_attach(argc, argv)) == start_error_parse) + ds = dbg_active_launch(argc, argv); switch (ds) { case start_ok: break; case start_error_parse: return dbg_winedbg_usage(); case start_error_init: return -1; } + retv = dbg_main_loop(hFile); - /* don't save modified variables in auto mode */ - if (dbg_action_mode != automatic_mode) dbg_save_internal_vars(); + dbg_save_internal_vars(); return retv; } -- 2.11.4.GIT