4 * Parser for command lines in the Wine debugger
6 * Copyright 1993 Eric Youngdale
16 unsigned int dbg_mode
= 0;
18 static enum exec_mode dbg_exec_mode
= EXEC_CONT
;
20 void issue_prompt
(void);
21 void mode_command
(int);
22 void flush_symbols
(void);
36 %token CONT STEP NEXT QUIT HELP BACKTRACE INFO STACK SEGMENTS REGS
37 %token ENABLE DISABLE BREAK DELETE SET MODE PRINT EXAM DEFINE ABORT
41 %token
<string> IDENTIFIER
42 %token
<integer
> NUM FORMAT
46 %type
<address
> addr symbol
51 | input line
{ issue_prompt
(); }
54 |
error '\n' { yyerrok; }
55 | QUIT
'\n' { exit
(0); }
56 | HELP
'\n' { DEBUG_Help
(); }
57 | CONT
'\n' { dbg_exec_mode
= EXEC_CONT
; return
0; }
58 | STEP
'\n' { dbg_exec_mode
= EXEC_STEP_INSTR
; return
0; }
59 | NEXT
'\n' { dbg_exec_mode
= EXEC_STEP_OVER
; return
0; }
60 | ABORT
'\n' { kill
(getpid
(), SIGABRT
); }
61 | SYMBOLFILE IDENTIFIER
'\n' { DEBUG_ReadSymbolTable
( $2 ); }
62 | DEFINE IDENTIFIER addr
'\n' { DEBUG_AddSymbol
( $2, &$3 ); }
63 | MODE NUM
'\n' { mode_command
($2); }
64 | ENABLE NUM
'\n' { DEBUG_EnableBreakpoint
( $2, TRUE
); }
65 | DISABLE NUM
'\n' { DEBUG_EnableBreakpoint
( $2, FALSE
); }
66 | BREAK
'*' addr
'\n' { DEBUG_AddBreakpoint
( &$3 ); }
67 | BREAK symbol
'\n' { DEBUG_AddBreakpoint
( &$2 ); }
68 | BREAK
'\n' { DBG_ADDR addr
= { CS_reg
(DEBUG_context
),
69 EIP_reg
(DEBUG_context
) };
70 DEBUG_AddBreakpoint
( &addr
);
72 | DELETE BREAK NUM
'\n' { DEBUG_DelBreakpoint
( $3 ); }
73 | BACKTRACE
'\n' { DEBUG_BackTrace
(); }
80 SET REG
'=' expr
'\n' { DEBUG_SetRegister
( $2, $4 ); }
81 | SET
'*' addr
'=' expr
'\n' { DEBUG_WriteMemory
( &$3, $5 ); }
82 | SET IDENTIFIER
'=' addr
'\n' { if
(!DEBUG_SetSymbolValue
( $2, &$4 ))
84 fprintf
( stderr
, "Symbol %s not found\n", $2 );
91 EXAM addr
'\n' { DEBUG_ExamineMemory
( &$2, 1, 'x'); }
92 | EXAM FORMAT addr
'\n' { DEBUG_ExamineMemory
( &$3, $2>>8, $2&0xff ); }
95 PRINT addr
'\n' { DEBUG_Print
( &$2, 1, 'x' ); }
96 | PRINT FORMAT addr
'\n' { DEBUG_Print
( &$3, $2 >> 8, $2 & 0xff ); }
98 symbol
: IDENTIFIER
{ if
(!DEBUG_GetSymbolValue
( $1, &$$
))
100 fprintf
( stderr
, "Symbol %s not found\n", $1 );
105 addr
: expr
{ $$.seg
= 0xffffffff; $$.off
= $1; }
106 | expr
':' expr
{ $$.seg
= $1; $$.off
= $3; }
107 | symbol
{ $$
= $1; }
109 expr
: NUM
{ $$
= $1; }
110 | REG
{ $$
= DEBUG_GetRegister
($1); }
111 | expr
'+' NUM
{ $$
= $1 + $3; }
112 | expr
'-' NUM
{ $$
= $1 - $3; }
113 |
'(' expr
')' { $$
= $2; }
114 |
'*' addr
{ $$
= DEBUG_ReadMemory
( &$2 ); }
116 infocmd
: INFO REGS
'\n' { DEBUG_InfoRegisters
(); }
117 | INFO STACK
'\n' { DEBUG_InfoStack
(); }
118 | INFO BREAK
'\n' { DEBUG_InfoBreakpoints
(); }
119 | INFO SEGMENTS
'\n' { LDT_Print
( 0, -1 ); }
120 | INFO SEGMENTS expr
'\n' { LDT_Print
( SELECTOR_TO_ENTRY
($3), 1 ); }
128 fprintf
(stderr
,"Wine-dbg>");
132 void mode_command
(int newmode
)
134 if
((newmode
== 16) ||
(newmode
== 32)) dbg_mode
= newmode
;
135 else fprintf
(stderr
,"Invalid mode (use 16 or 32)\n");
139 void wine_debug
( int signal
, struct sigcontext_struct
*regs
)
141 static int loaded_symbols
= 0;
142 char SymbolTableFile
[256];
143 int instr_len
= 0, newmode
;
149 DEBUG_context
= (struct sigcontext_struct
*)regs
;
151 DEBUG_SetBreakpoints
( FALSE
);
156 GetPrivateProfileString
("wine", "SymbolTableFile", "wine.sym",
157 SymbolTableFile
, sizeof
(SymbolTableFile
), WINE_INI
);
158 DEBUG_ReadSymbolTable
( SymbolTableFile
);
159 DEBUG_LoadEntryPoints
();
162 if
((signal
!= SIGTRAP
) ||
!DEBUG_ShouldContinue
( regs
, dbg_exec_mode
))
166 addr.seg
= CS_reg
(DEBUG_context
);
167 addr.off
= EIP_reg
(DEBUG_context
);
168 DBG_FIX_ADDR_SEG
( &addr
, 0 );
170 if
(!addr.seg
) newmode
= 32;
171 else newmode
= (GET_SEL_FLAGS
(addr.seg
) & LDT_FLAGS_32BIT
) ?
32 : 16;
173 if
(newmode
!= dbg_mode
)
174 fprintf
(stderr
,"In %d bit mode.\n", dbg_mode
= newmode
);
176 /* Show where we crashed */
177 DEBUG_PrintAddress
( &addr
, dbg_mode
);
178 fprintf
(stderr
,": ");
179 if
(DBG_CHECK_READ_PTR
( &addr
, 1 ))
181 DEBUG_Disasm
( &addr
);
182 fprintf
(stderr
,"\n");
183 instr_len
= addr.off
- EIP_reg
(DEBUG_context
);
191 addr.seg
= CS_reg
(DEBUG_context
);
192 addr.off
= EIP_reg
(DEBUG_context
);
193 DBG_FIX_ADDR_SEG
( &addr
, 0 );
194 } while
(!DBG_CHECK_READ_PTR
( &addr
, 1 ));
197 DEBUG_RestartExecution
( regs
, dbg_exec_mode
, instr_len
);
201 int yyerror(char * s
)
203 fprintf
(stderr
,"%s\n", s
);