Commit d0a04935 authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

Revisited console support (got rid of old hacks and private editline

since we now have a brand new console), removed private debug heap.
parent 0b83d4cb
...@@ -9,7 +9,6 @@ C_SRCS = \ ...@@ -9,7 +9,6 @@ C_SRCS = \
break.c \ break.c \
db_disasm.c \ db_disasm.c \
display.c \ display.c \
editline.c \
expr.c \ expr.c \
ext_debugger.c \ ext_debugger.c \
hash.c \ hash.c \
......
...@@ -8,17 +8,17 @@ ...@@ -8,17 +8,17 @@
%{ %{
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "winbase.h"
#include "wincon.h"
#include "debugger.h" #include "debugger.h"
#include "y.tab.h" #include "y.tab.h"
#ifndef DONT_USE_READLINE #ifndef DONT_USE_READLINE
#undef YY_INPUT #undef YY_INPUT
#define YY_INPUT(buf,result,max_size) \ #define YY_INPUT(buf,result,max_size) \
if ( (result = dbg_read((char *) buf, max_size )) < 0 ) \ if ( (result = DEBUG_ReadLine("Wine-dbg>", (char *) buf, max_size, TRUE )) < 0 ) \
YY_FATAL_ERROR( "read() in flex scanner failed" ); YY_FATAL_ERROR( "read() in flex scanner failed" );
static int dbg_read(char * buf, int size);
#endif /* DONT_USE_READLINE */ #endif /* DONT_USE_READLINE */
#define YY_NO_UNPUT #define YY_NO_UNPUT
...@@ -195,52 +195,61 @@ static void stripwhite (char *string) ...@@ -195,52 +195,61 @@ static void stripwhite (char *string)
string[++i] = '\0'; string[++i] = '\0';
} }
static int dbg_read(char * buf, int size) int DEBUG_ReadLine(const char* pfx, char * buf, int size, int remind)
{ {
static char last_line[256] = ""; char buf_line[256];
char * line; char* ptr;
int len; int len;
DWORD nread;
for (;;) for (;;)
{ {
DEBUG_FlushSymbols(); DEBUG_FlushSymbols();
line = readline ("Wine-dbg>"); WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), pfx, strlen(pfx), NULL, NULL);
if (!line)
{
DEBUG_Printf( DBG_CHN_MESG, "\n" );
DEBUG_Exit(0);
}
/* Remove leading and trailing whitespace from the line */
stripwhite (line); if (!ReadConsole(GetStdHandle(STD_INPUT_HANDLE), buf_line, sizeof(buf_line), &nread, NULL))
break;
/* FIXME: should be rewritten not to remove and then add the trailing '\n' */
if (nread > 0 && buf_line[nread - 1] == '\n') nread--;
buf_line[nread] = 0;
/* If there is anything left, add it to the history list /* Remove leading and trailing whitespace from the line */
and execute it. Otherwise, re-execute last command. */ stripwhite (buf_line);
if (*line) if (remind)
{ {
add_history( line ); static char last_line[256] = "";
strncpy( last_line, line, 255 ); /* If there is anything left, add it to the history list
last_line[255] = '\0'; and execute it. Otherwise, re-execute last command. */
}
if (*buf_line)
free( line ); {
line = last_line; strncpy( last_line, buf_line, sizeof(last_line) - 1 );
last_line[sizeof(last_line) - 1] = '\0';
if ((len = strlen(line)) > 0) }
ptr = last_line;
}
else
{
/* I could also tweak with the undoc functions to remove this line from the console
* history... */
ptr = buf_line;
}
if ((len = strlen(ptr)) > 0)
{ {
if (size < len + 1) if (size < len + 1)
{ {
DEBUG_Printf(DBG_CHN_MESG,"Fatal readline goof.\n"); DEBUG_Printf(DBG_CHN_MESG, "Fatal readline goof.\n");
DEBUG_Exit(0); DEBUG_Exit(0);
} }
strcpy(buf, line); strcpy(buf, ptr);
buf[len] = '\n'; buf[len] = '\n';
buf[len+1] = 0; buf[len+1] = 0;
return len + 1; return len + 1;
} }
} }
return 0;
} }
static char *local_symbols[30]; static char *local_symbols[30];
......
...@@ -287,6 +287,7 @@ extern void DEBUG_Exit( DWORD ); ...@@ -287,6 +287,7 @@ extern void DEBUG_Exit( DWORD );
/* debugger/debug.l */ /* debugger/debug.l */
extern void DEBUG_FlushSymbols(void); extern void DEBUG_FlushSymbols(void);
extern char*DEBUG_MakeSymbol(const char*); extern char*DEBUG_MakeSymbol(const char*);
extern int DEBUG_ReadLine(const char* pfx, char* buffer, int size, int remind);
/* debugger/display.c */ /* debugger/display.c */
extern int DEBUG_DoDisplay(void); extern int DEBUG_DoDisplay(void);
...@@ -512,13 +513,11 @@ extern char* DEBUG_XStrDup(const char *str); ...@@ -512,13 +513,11 @@ extern char* DEBUG_XStrDup(const char *str);
#define DBG_strdup(x) DEBUG_XStrDup(x) #define DBG_strdup(x) DEBUG_XStrDup(x)
#else #else
/* this one is slow (takes 5 minutes to load the debugger on my machine), /* this one is slow (takes 5 minutes to load the debugger on my machine),
but is pretty crash-proof (can step through malloc() without problems, if someone could make optimized routines so it wouldn't
malloc() arena (and other heaps) can be totally wasted and it'll still
work, etc... if someone could make optimized routines so it wouldn't
take so long to load, it could be made default) */ take so long to load, it could be made default) */
#define DBG_alloc(x) HeapAlloc(dbg_heap,0,x) #define DBG_alloc(x) HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,x)
#define DBG_realloc(x,y) HeapRealloc(dbg_heap,0,x,y) #define DBG_realloc(x,y) HeapReAlloc(GetProcessHeap(),0,x,y)
#define DBG_free(x) HeapFree(dbg_heap,0,x) #define DBG_free(x) HeapFree(GetProcessHeap(),0,x)
inline static LPSTR DBG_strdup( LPCSTR str ) inline static LPSTR DBG_strdup( LPCSTR str )
{ {
INT len = strlen(str) + 1; INT len = strlen(str) + 1;
...@@ -526,8 +525,6 @@ inline static LPSTR DBG_strdup( LPCSTR str ) ...@@ -526,8 +525,6 @@ inline static LPSTR DBG_strdup( LPCSTR str )
if (p) memcpy( p, str, len ); if (p) memcpy( p, str, len );
return p; return p;
} }
#define DBG_need_heap
extern HANDLE dbg_heap;
#endif #endif
#define DEBUG_STATUS_OFFSET 0x80003000 #define DEBUG_STATUS_OFFSET 0x80003000
......
...@@ -387,7 +387,8 @@ BOOL DEBUG_GetSymbolValue( const char * name, const int lineno, ...@@ -387,7 +387,8 @@ BOOL DEBUG_GetSymbolValue( const char * name, const int lineno,
} else if (!DEBUG_interactiveP || num == 1) { } else if (!DEBUG_interactiveP || num == 1) {
i = 0; i = 0;
} else { } else {
char* ptr; char buffer[256];
if (num == NUMDBGV+1) { if (num == NUMDBGV+1) {
DEBUG_Printf(DBG_CHN_MESG, "Too many addresses for symbol '%s', limiting the first %d\n", name, NUMDBGV); DEBUG_Printf(DBG_CHN_MESG, "Too many addresses for symbol '%s', limiting the first %d\n", name, NUMDBGV);
num = NUMDBGV; num = NUMDBGV;
...@@ -399,11 +400,13 @@ BOOL DEBUG_GetSymbolValue( const char * name, const int lineno, ...@@ -399,11 +400,13 @@ BOOL DEBUG_GetSymbolValue( const char * name, const int lineno,
DEBUG_Printf(DBG_CHN_MESG, "\n"); DEBUG_Printf(DBG_CHN_MESG, "\n");
} }
do { do {
ptr = readline("=> "); i = 0;
if (!*ptr) return FALSE; if (DEBUG_ReadLine("=> ", buffer, sizeof(buffer), FALSE))
i = atoi(ptr); {
if (i < 1 || i > num) i = atoi(buffer);
DEBUG_Printf(DBG_CHN_MESG, "Invalid choice %d\n", i); if (i < 1 || i > num)
DEBUG_Printf(DBG_CHN_MESG, "Invalid choice %d\n", i);
}
} while (i < 1 || i > num); } while (i < 1 || i > num);
/* The array is 0-based, but the choices are 1..n, so we have to subtract one before returning. */ /* The array is 0-based, but the choices are 1..n, so we have to subtract one before returning. */
......
...@@ -188,7 +188,7 @@ DEBUG_DisplaySource(char * sourcefile, int start, int end) ...@@ -188,7 +188,7 @@ DEBUG_DisplaySource(char * sourcefile, int start, int end)
* Still couldn't find it. Ask user for path to add. * Still couldn't find it. Ask user for path to add.
*/ */
sprintf(zbuf, "Enter path to file '%s': ", sourcefile); sprintf(zbuf, "Enter path to file '%s': ", sourcefile);
lstrcpynA(tmppath, readline(zbuf), sizeof(tmppath)); DEBUG_ReadLine(zbuf, tmppath, sizeof(tmppath), FALSE);
if( tmppath[strlen(tmppath)-1] == '\n' ) if( tmppath[strlen(tmppath)-1] == '\n' )
{ {
......
...@@ -19,10 +19,6 @@ ...@@ -19,10 +19,6 @@
#include "winreg.h" #include "winreg.h"
#ifdef DBG_need_heap
HANDLE dbg_heap = 0;
#endif
DBG_PROCESS* DEBUG_CurrProcess = NULL; DBG_PROCESS* DEBUG_CurrProcess = NULL;
DBG_THREAD* DEBUG_CurrThread = NULL; DBG_THREAD* DEBUG_CurrThread = NULL;
DWORD DEBUG_CurrTid; DWORD DEBUG_CurrTid;
...@@ -464,6 +460,9 @@ static BOOL DEBUG_HandleException(EXCEPTION_RECORD *rec, BOOL first_chance, BOOL ...@@ -464,6 +460,9 @@ static BOOL DEBUG_HandleException(EXCEPTION_RECORD *rec, BOOL first_chance, BOOL
case EXCEPTION_DATATYPE_MISALIGNMENT: case EXCEPTION_DATATYPE_MISALIGNMENT:
DEBUG_Printf(DBG_CHN_MESG, "Alignment"); DEBUG_Printf(DBG_CHN_MESG, "Alignment");
break; break;
case DBG_CONTROL_C:
DEBUG_Printf(DBG_CHN_MESG, "^C");
break;
case CONTROL_C_EXIT: case CONTROL_C_EXIT:
DEBUG_Printf(DBG_CHN_MESG, "^C"); DEBUG_Printf(DBG_CHN_MESG, "^C");
break; break;
...@@ -863,7 +862,7 @@ static BOOL DEBUG_Start(LPSTR cmdLine) ...@@ -863,7 +862,7 @@ static BOOL DEBUG_Start(LPSTR cmdLine)
startup.wShowWindow = SW_SHOWNORMAL; startup.wShowWindow = SW_SHOWNORMAL;
if (!CreateProcess(NULL, cmdLine, NULL, NULL, if (!CreateProcess(NULL, cmdLine, NULL, NULL,
FALSE, DEBUG_PROCESS, NULL, NULL, &startup, &info)) { FALSE, DEBUG_PROCESS|DETACHED_PROCESS, NULL, NULL, &startup, &info)) {
DEBUG_Printf(DBG_CHN_MESG, "Couldn't start process '%s'\n", cmdLine); DEBUG_Printf(DBG_CHN_MESG, "Couldn't start process '%s'\n", cmdLine);
return FALSE; return FALSE;
} }
...@@ -889,15 +888,41 @@ void DEBUG_Run(const char* args) ...@@ -889,15 +888,41 @@ void DEBUG_Run(const char* args)
} }
} }
static void DEBUG_InitConsole(void)
{
COORD c;
SMALL_RECT sr;
DWORD mode;
/* keep it as a cuiexe for now, so that Wine won't touch the Unix stdin,
* stdout and stderr streams
*/
if (DBG_IVAR(UseXTerm))
{
FreeConsole();
AllocConsole();
}
/* this would be nicer for output */
c.X = 132;
c.Y = 500;
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), c);
/* sets the console's window width accordingly */
sr.Left = 0;
sr.Top = 0;
sr.Right = c.X - 1;
sr.Bottom = 50;
SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), TRUE, &sr);
/* put the line editing mode with the nice emacs features (FIXME: could be triggered by a IVAR) */
if (GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &mode))
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), mode | WINE_ENABLE_LINE_INPUT_EMACS);
}
int DEBUG_main(int argc, char** argv) int DEBUG_main(int argc, char** argv)
{ {
DWORD retv = 0; DWORD retv = 0;
#ifdef DBG_need_heap
/* Initialize the debugger heap. */
dbg_heap = HeapCreate(HEAP_NO_SERIALIZE, 0x1000, 0x8000000); /* 128MB */
#endif
/* Initialize the type handling stuff. */ /* Initialize the type handling stuff. */
DEBUG_InitTypes(); DEBUG_InitTypes();
DEBUG_InitCVDataTypes(); DEBUG_InitCVDataTypes();
...@@ -917,17 +942,8 @@ int DEBUG_main(int argc, char** argv) ...@@ -917,17 +942,8 @@ int DEBUG_main(int argc, char** argv)
DBG_IVAR(StdChannelMask) = DBG_CHN_MESG; DBG_IVAR(StdChannelMask) = DBG_CHN_MESG;
} }
/* keep it as a guiexe for now, so that Wine won't touch the Unix stdin, DEBUG_InitConsole();
* stdout and stderr streams
*/
if (DBG_IVAR(UseXTerm)) {
COORD pos;
/* This is a hack: it forces creation of an xterm, not done by default */
pos.X = 0; pos.Y = 1;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
DEBUG_Printf(DBG_CHN_MESG, "WineDbg starting... "); DEBUG_Printf(DBG_CHN_MESG, "WineDbg starting... ");
if (argc == 3) { if (argc == 3) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment