winedbg: source command
Eric Pouech
eric.pouech at wanadoo.fr
Mon Jul 29 15:28:51 CDT 2002
this patch lets the winedbg user load from a file a given set of
commands by using the following (new) command
source foo
foo is searched from current directory (and can be an absolute path)
there might be one day a .winedbginit file, but there isn't for now
A+
-------------- next part --------------
Name: wdbg_source
ChangeLog: added source command
License: X11
GenDate: 2002/07/29 20:17:49 UTC
ModifiedFiles: debugger/dbg.y debugger/debug.l debugger/debugger.h debugger/winedbg.c
AddedFiles:
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/debugger/dbg.y,v
retrieving revision 1.59
diff -u -u -r1.59 dbg.y
--- debugger/dbg.y 23 Jul 2002 20:53:41 -0000 1.59
+++ debugger/dbg.y 29 Jul 2002 20:07:21 -0000
@@ -34,8 +34,6 @@
#include "expr.h"
#include "msvcrt/excpt.h"
-extern FILE * yyin;
-
static void mode_command(int);
int yylex(void);
int yyerror(char *);
@@ -55,9 +53,9 @@
%token tCONT tPASS tSTEP tLIST tNEXT tQUIT tHELP tBACKTRACE tINFO tWALK tUP tDOWN
%token tENABLE tDISABLE tBREAK tWATCH tDELETE tSET tMODE tPRINT tEXAM tABORT tVM86
%token tCLASS tMAPS tMODULE tSTACK tSEGMENTS tREGS tWND tQUEUE tLOCAL
-%token tPROCESS tTHREAD tMODREF tEOL
+%token tPROCESS tTHREAD tMODREF tEOL tEOF
%token tFRAME tSHARE tCOND tDISPLAY tUNDISPLAY tDISASSEMBLE
-%token tSTEPI tNEXTI tFINISH tSHOW tDIR tWHATIS
+%token tSTEPI tNEXTI tFINISH tSHOW tDIR tWHATIS tSOURCE
%token <string> tPATH
%token <string> tIDENTIFIER tSTRING tDEBUGSTR tINTVAR
%token <integer> tNUM tFORMAT
@@ -101,6 +99,7 @@
line: command
| tEOL
+ | tEOF { return 1; }
| error tEOL { yyerrok; }
;
@@ -145,6 +146,7 @@
| tUNDISPLAY tEOL { DEBUG_DelDisplay( -1 ); }
| tCOND tNUM tEOL { DEBUG_AddBPCondition($2, NULL); }
| tCOND tNUM expr tEOL { DEBUG_AddBPCondition($2, $3); }
+ | tSOURCE pathname tEOL { DEBUG_Parser($2); }
| tSYMBOLFILE pathname tEOL { DEBUG_ReadSymbolTable($2, 0); }
| tSYMBOLFILE pathname tNUM tEOL { DEBUG_ReadSymbolTable($2, $3); }
| tWHATIS expr_addr tEOL { DEBUG_PrintType(&$2); DEBUG_FreeExprMem(); }
@@ -412,30 +415,57 @@
return EXCEPTION_EXECUTE_HANDLER;
}
+static void set_default_channels(void)
+{
+ DEBUG_hParserOutput = GetStdHandle(STD_OUTPUT_HANDLE);
+ DEBUG_hParserInput = GetStdHandle(STD_INPUT_HANDLE);
+}
+
/***********************************************************************
* DEBUG_Parser
*
* Debugger editline parser
*/
-void DEBUG_Parser(void)
+void DEBUG_Parser(LPCSTR filename)
{
BOOL ret_ok;
#ifdef YYDEBUG
yydebug = 0;
#endif
- yyin = stdin;
ret_ok = FALSE;
- do {
- __TRY {
+
+ if (filename)
+ {
+ DEBUG_hParserOutput = 0;
+ DEBUG_hParserInput = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0L, 0);
+ if (DEBUG_hParserInput == INVALID_HANDLE_VALUE)
+ {
+ set_default_channels();
+ return;
+ }
+ }
+ else
+ set_default_channels();
+
+ do
+ {
+ __TRY
+ {
ret_ok = TRUE;
yyparse();
- } __EXCEPT(wine_dbg_cmd) {
+ }
+ __EXCEPT(wine_dbg_cmd)
+ {
ret_ok = FALSE;
}
__ENDTRY;
DEBUG_FlushSymbols();
} while (!ret_ok);
+
+ if (filename)
+ CloseHandle(DEBUG_hParserInput);
+ set_default_channels();
}
int yyerror(char* s)
Index: debugger/debug.l
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/debugger/debug.l,v
retrieving revision 1.29
diff -u -u -r1.29 debug.l
--- debugger/debug.l 22 Jul 2002 20:33:25 -0000 1.29
+++ debugger/debug.l 29 Jul 2002 20:09:27 -0000
@@ -29,13 +29,15 @@
#undef YY_INPUT
+HANDLE DEBUG_hParserInput;
+HANDLE DEBUG_hParserOutput;
+
static int DEBUG_FetchFromLine(const char* pfx, char* buf, int size);
#define YY_INPUT(buf,result,max_size) \
- if ( (result = DEBUG_FetchFromLine("Wine-dbg>", buf, max_size)) <= 0 ) \
+ if ( (result = DEBUG_FetchFromLine("Wine-dbg>", buf, max_size)) < 0 ) \
YY_FATAL_ERROR( "ReadLine() in flex scanner failed" );
-
#define YY_NO_UNPUT
static int syntax_error;
@@ -64,6 +67,7 @@
/* set to special state when no process is loaded. */
if (!DEBUG_CurrProcess && YYSTATE == INITIAL) {BEGIN(NOPROCESS);}
+<<EOF>> { return tEOF; }
<*>\n { BEGIN(INITIAL); syntax_error = 0; return tEOL; }
/* Indicates end of command. Reset state. */
@@ -128,9 +132,10 @@
<INITIAL>mode { BEGIN(MODE_CMD); return tMODE; }
<INITIAL>show|sho|sh { BEGIN(SHOW_CMD); return tSHOW; }
+<INITIAL,NOPROCESS>source|sourc|sour|src { BEGIN(PATH_EXPECTED); return tSOURCE; }
<INITIAL>symbolfile|symbols|symbol|sf { BEGIN(PATH_EXPECTED); return tSYMBOLFILE; }
<INITIAL,INFO_CMD,DEL_CMD>break|brea|bre|br|b { BEGIN(NOCMD); return tBREAK; }
<INITIAL>watch|watc|wat { BEGIN(NOCMD); return tWATCH; }
<INITIAL>whatis|whati|what { BEGIN(NOCMD); return tWHATIS; }
<INITIAL,NOPROCESS>run|ru|r { BEGIN(ASTRING_EXPECTED); return tRUN;}
@@ -216,12 +221,12 @@
/* as of today, console handles can be file handles... so better use file APIs rather than
* consoles
*/
- WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), pfx, strlen(pfx), NULL, NULL);
+ WriteFile(DEBUG_hParserOutput, pfx, strlen(pfx), NULL, NULL);
len = 0;
- do
+ do
{
- if (!ReadFile(GetStdHandle(STD_INPUT_HANDLE), buf_line, sizeof(buf_line) - 1, &nread, NULL))
+ if (!ReadFile(DEBUG_hParserInput, buf_line, sizeof(buf_line) - 1, &nread, NULL) || nread == 0)
break;
buf_line[nread] = '\0';
@@ -237,6 +242,14 @@
len += nread;
} while (nread == 0 || buf_line[nread - 1] != '\n');
+ if (!len)
+ {
+ *line = HeapReAlloc(GetProcessHeap(), 0, *line, *alloc = 1);
+ **line = '\0';
+ strcpy(*line + len, buf_line);
+ len += nread;
+ } while (nread == 0 || buf_line[nread - 1] != '\n');
+
/* Remove leading and trailing whitespace from the line */
stripwhite(*line);
return 1;
Index: debugger/debugger.h
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/debugger/debugger.h,v
retrieving revision 1.38
diff -u -u -r1.38 debugger.h
--- debugger/debugger.h 23 Jul 2002 20:53:41 -0000 1.38
+++ debugger/debugger.h 29 Jul 2002 19:35:31 -0000
@@ -243,6 +249,8 @@
extern CONTEXT DEBUG_context;
extern BOOL DEBUG_InteractiveP;
extern enum exit_mode DEBUG_ExitMode;
+extern HANDLE DEBUG_hParserInput;
+extern HANDLE DEBUG_hParserOutput;
#define DEBUG_READ_MEM(addr, buf, len) \
(ReadProcessMemory(DEBUG_CurrProcess->handle, (addr), (buf), (len), NULL))
@@ -306,8 +315,8 @@
extern void DEBUG_Disasm( DBG_ADDR *addr, int display );
/* debugger/dbg.y */
-extern void DEBUG_Parser(void);
-extern void DEBUG_Exit( DWORD );
+extern void DEBUG_Parser(LPCSTR);
+extern void DEBUG_Exit(DWORD);
/* debugger/debug.l */
extern void DEBUG_FlushSymbols(void);
@@ -320,10 +329,6 @@
extern int DEBUG_DoDisplay(void);
extern int DEBUG_DelDisplay(int displaynum);
extern int DEBUG_InfoDisplay(void);
-
- /* debugger/editline.c */
-extern char * readline(const char *);
-extern void add_history(char *);
/* debugger/expr.c */
extern void DEBUG_FreeExprMem(void);
Index: debugger/winedbg.c
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/debugger/winedbg.c,v
retrieving revision 1.60
diff -u -u -r1.60 winedbg.c
--- debugger/winedbg.c 20 Jul 2002 20:29:09 -0000 1.60
+++ debugger/winedbg.c 29 Jul 2002 20:01:45 -0000
@@ -880,7 +881,7 @@
else
{
DEBUG_InteractiveP = TRUE;
- DEBUG_Parser();
+ DEBUG_Parser(NULL);
}
DEBUG_Printf(DBG_CHN_MESG, "WineDbg terminated on pid %lx\n", DEBUG_CurrPid);
More information about the wine-patches
mailing list