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
This commit is contained in:
parent
22ff946409
commit
67001a1d8b
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -180,6 +180,7 @@ STRING \"[^\n"]+\"
|
|||
<INITIAL>detach|detac|deta|det { BEGIN(NOCMD); return tDETACH; }
|
||||
<INITIAL>maintenance|maint { BEGIN(MAINT_CMD); return tMAINTENANCE; }
|
||||
<INITIAL>minidump|mdmp { BEGIN(PATH_EXPECTED); return tMINIDUMP; }
|
||||
<INITIAL>echo { BEGIN(ASTRING_EXPECTED); return tECHO; }
|
||||
<NOPROCESS>attach|attac|atta|att { BEGIN(NOCMD); return tATTACH; }
|
||||
<INFO_CMD>share|shar|sha { return tSHARE; }
|
||||
<INFO_CMD>locals|local|loca|loc { return tLOCAL; }
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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_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;
|
||||
}
|
||||
|
|
|
@ -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,32 +500,25 @@ 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);
|
||||
}
|
||||
else
|
||||
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;
|
||||
}
|
||||
}
|
||||
/* parse options */
|
||||
while (argc > 0 && argv[0][0] == '-')
|
||||
{
|
||||
if (!strcmp(argv[0], "--command"))
|
||||
{
|
||||
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);
|
||||
hFile = parser_generate_command_file(argv[0], NULL);
|
||||
if (hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
dbg_printf("Couldn't open temp file %s (%lu)\n", file, GetLastError());
|
||||
dbg_printf("Couldn't open temp file (%lu)\n", 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;
|
||||
}
|
||||
|
@ -543,21 +535,25 @@ int main(int argc, char** argv)
|
|||
argc--; argv++;
|
||||
continue;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue