dbg.y 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. %{
  2. /*
  3. * Parser for command lines in the Wine debugger
  4. *
  5. * Copyright 1993 Eric Youngdale
  6. * Copyright 1995 Morten Welinder
  7. * Copyright 2000 Eric Pouech
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include "debugger.h"
  27. #include "wine/exception.h"
  28. #include "expr.h"
  29. int dbg_lex(void);
  30. static int dbg_error(const char*);
  31. static void parser(const char*);
  32. %}
  33. %union
  34. {
  35. struct dbg_lvalue lvalue;
  36. char* string;
  37. dbg_lgint_t integer;
  38. IMAGEHLP_LINE64 listing;
  39. struct expr* expression;
  40. struct type_expr_t type;
  41. struct list_string* strings;
  42. }
  43. %token tCONT tPASS tSTEP tLIST tNEXT tQUIT tHELP tBACKTRACE tALL tINFO tUP tDOWN
  44. %token tENABLE tDISABLE tBREAK tHBREAK tWATCH tRWATCH tDELETE tSET tPRINT tEXAM
  45. %token tABORT tECHO
  46. %token tCLASS tMAPS tSTACK tSEGMENTS tSYMBOL tREGS tALLREGS tWND tLOCAL tEXCEPTION
  47. %token tPROCESS tTHREAD tEOL tEOF
  48. %token tFRAME tSHARE tMODULE tCOND tDISPLAY tUNDISPLAY tDISASSEMBLE
  49. %token tSTEPI tNEXTI tFINISH tSHOW tDIR tWHATIS tSOURCE
  50. %token <string> tPATH tIDENTIFIER tSTRING tINTVAR
  51. %token <integer> tNUM tFORMAT
  52. %token tSYMBOLFILE tRUN tATTACH tDETACH tKILL tMAINTENANCE tTYPE tMINIDUMP
  53. %token tNOPROCESS
  54. %token tCHAR tSHORT tINT tLONG tFLOAT tDOUBLE tUNSIGNED tSIGNED
  55. %token tSTRUCT tUNION tENUM
  56. /* %left ',' */
  57. /* %left '=' OP_OR_EQUAL OP_XOR_EQUAL OP_AND_EQUAL OP_SHL_EQUAL \
  58. OP_SHR_EQUAL OP_PLUS_EQUAL OP_MINUS_EQUAL \
  59. OP_TIMES_EQUAL OP_DIVIDE_EQUAL OP_MODULO_EQUAL */
  60. /* %left OP_COND */ /* ... ? ... : ... */
  61. %left OP_LOR
  62. %left OP_LAND
  63. %left '|'
  64. %left '^'
  65. %left '&'
  66. %left OP_EQ OP_NE
  67. %left '<' '>' OP_LE OP_GE
  68. %left OP_SHL OP_SHR
  69. %left '+' '-'
  70. %left '*' '/' '%'
  71. %left OP_SIGN '!' '~' OP_DEREF /* OP_INC OP_DEC OP_ADDR */
  72. %left '.' '[' OP_DRF
  73. %nonassoc ':'
  74. %type <expression> expr lvalue
  75. %type <lvalue> expr_lvalue lvalue_addr
  76. %type <integer> expr_rvalue
  77. %type <string> pathname identifier
  78. %type <listing> list_arg
  79. %type <type> type_expr
  80. %type <strings> list_of_words
  81. %%
  82. input:
  83. line
  84. | input line
  85. ;
  86. line:
  87. command tEOL { expr_free_all(); }
  88. | tEOL
  89. | tEOF { return 1; }
  90. | error tEOL { yyerrok; expr_free_all(); }
  91. ;
  92. command:
  93. tQUIT { return 1; }
  94. | tHELP { print_help(); }
  95. | tHELP tINFO { info_help(); }
  96. | tPASS { dbg_wait_next_exception(DBG_EXCEPTION_NOT_HANDLED, 0, 0); }
  97. | tCONT { dbg_wait_next_exception(DBG_CONTINUE, 1, dbg_exec_cont); }
  98. | tCONT tNUM { dbg_wait_next_exception(DBG_CONTINUE, $2, dbg_exec_cont); }
  99. | tSTEP { dbg_wait_next_exception(DBG_CONTINUE, 1, dbg_exec_step_into_line); }
  100. | tSTEP tNUM { dbg_wait_next_exception(DBG_CONTINUE, $2, dbg_exec_step_into_line); }
  101. | tNEXT { dbg_wait_next_exception(DBG_CONTINUE, 1, dbg_exec_step_over_line); }
  102. | tNEXT tNUM { dbg_wait_next_exception(DBG_CONTINUE, $2, dbg_exec_step_over_line); }
  103. | tSTEPI { dbg_wait_next_exception(DBG_CONTINUE, 1, dbg_exec_step_into_insn); }
  104. | tSTEPI tNUM { dbg_wait_next_exception(DBG_CONTINUE, $2, dbg_exec_step_into_insn); }
  105. | tNEXTI { dbg_wait_next_exception(DBG_CONTINUE, 1, dbg_exec_step_over_insn); }
  106. | tNEXTI tNUM { dbg_wait_next_exception(DBG_CONTINUE, $2, dbg_exec_step_over_insn); }
  107. | tFINISH { dbg_wait_next_exception(DBG_CONTINUE, 0, dbg_exec_finish); }
  108. | tABORT { abort(); }
  109. | tBACKTRACE { stack_backtrace(dbg_curr_tid); }
  110. | tBACKTRACE tNUM { stack_backtrace($2); }
  111. | tBACKTRACE tALL { stack_backtrace(-1); }
  112. | tUP { stack_set_frame(dbg_curr_thread->curr_frame + 1); }
  113. | tUP tNUM { stack_set_frame(dbg_curr_thread->curr_frame + $2); }
  114. | tDOWN { stack_set_frame(dbg_curr_thread->curr_frame - 1); }
  115. | tDOWN tNUM { stack_set_frame(dbg_curr_thread->curr_frame - $2); }
  116. | tFRAME tNUM { stack_set_frame($2); }
  117. | tSHOW tDIR { source_show_path(); }
  118. | tDIR pathname { source_add_path($2); }
  119. | tDIR { source_nuke_path(dbg_curr_process); }
  120. | tCOND tNUM { break_add_condition($2, NULL); }
  121. | tCOND tNUM expr { break_add_condition($2, $3); }
  122. | tSOURCE pathname { parser($2); }
  123. | tSYMBOLFILE pathname { symbol_read_symtable($2, 0); }
  124. | tSYMBOLFILE pathname expr_rvalue { symbol_read_symtable($2, $3); }
  125. | tWHATIS expr_lvalue { dbg_printf("type = "); types_print_type(&$2.type, FALSE); dbg_printf("\n"); }
  126. | tATTACH tNUM { dbg_attach_debuggee($2); dbg_active_wait_for_first_exception(); }
  127. | tDETACH { dbg_curr_process->process_io->close_process(dbg_curr_process, FALSE); }
  128. | tTHREAD tNUM { dbg_set_curr_thread($2); }
  129. | tKILL { dbg_curr_process->process_io->close_process(dbg_curr_process, TRUE); }
  130. | tMINIDUMP pathname { minidump_write($2, (dbg_curr_thread && dbg_curr_thread->in_exception) ? &dbg_curr_thread->excpt_record : NULL);}
  131. | tECHO tSTRING { dbg_printf("%s\n", $2); }
  132. | run_command
  133. | list_command
  134. | disassemble_command
  135. | set_command
  136. | x_command
  137. | print_command
  138. | break_command
  139. | watch_command
  140. | display_command
  141. | info_command
  142. | maintenance_command
  143. | noprocess_state
  144. ;
  145. pathname:
  146. identifier { $$ = $1; }
  147. | tSTRING { $$ = $1; }
  148. | tPATH { $$ = $1; }
  149. ;
  150. identifier:
  151. tIDENTIFIER { $$ = $1; }
  152. ;
  153. list_arg:
  154. tNUM { $$.FileName = NULL; $$.LineNumber = $1; }
  155. | pathname ':' tNUM { $$.FileName = $1; $$.LineNumber = $3; }
  156. | identifier { symbol_get_line(NULL, $1, &$$); }
  157. | pathname ':' identifier { symbol_get_line($1, $3, &$$); }
  158. | '*' expr_lvalue { DWORD disp; ADDRESS64 addr; $$.SizeOfStruct = sizeof($$);
  159. types_extract_as_address(&$2, &addr);
  160. SymGetLineFromAddr64(dbg_curr_process->handle, (ULONG_PTR)memory_to_linear_addr(& addr), &disp, & $$); }
  161. ;
  162. run_command:
  163. tRUN list_of_words { dbg_run_debuggee($2); }
  164. ;
  165. list_of_words:
  166. %empty { $$ = NULL; }
  167. | tSTRING list_of_words { $$ = (struct list_string*)lexeme_alloc_size(sizeof(*$$)); $$->next = $2; $$->string = $1; }
  168. ;
  169. list_command:
  170. tLIST { source_list(NULL, NULL, 10); }
  171. | tLIST '-' { source_list(NULL, NULL, -10); }
  172. | tLIST list_arg { source_list(& $2, NULL, 10); }
  173. | tLIST ',' list_arg { source_list(NULL, & $3, -10); }
  174. | tLIST list_arg ',' list_arg { source_list(& $2, & $4, 0); }
  175. ;
  176. disassemble_command:
  177. tDISASSEMBLE { memory_disassemble(NULL, NULL, 10); }
  178. | tDISASSEMBLE expr_lvalue { memory_disassemble(&$2, NULL, 10); }
  179. | tDISASSEMBLE expr_lvalue ',' expr_lvalue { memory_disassemble(&$2, &$4, 0); }
  180. ;
  181. set_command:
  182. tSET lvalue_addr '=' expr_lvalue { types_store_value(&$2, &$4); }
  183. | tSET '+' tIDENTIFIER { info_wine_dbg_channel(TRUE, NULL, $3); }
  184. | tSET '+' tALL { info_wine_dbg_channel(TRUE, NULL, "all"); }
  185. | tSET '-' tIDENTIFIER { info_wine_dbg_channel(FALSE, NULL, $3); }
  186. | tSET '-' tALL { info_wine_dbg_channel(FALSE, NULL, "all"); }
  187. | tSET tIDENTIFIER '+' tIDENTIFIER { info_wine_dbg_channel(TRUE, $2, $4); }
  188. | tSET tIDENTIFIER '+' tALL { info_wine_dbg_channel(TRUE, $2, "all"); }
  189. | tSET tIDENTIFIER '-' tIDENTIFIER { info_wine_dbg_channel(FALSE, $2, $4); }
  190. | tSET tIDENTIFIER '-' tALL { info_wine_dbg_channel(FALSE, $2, "all"); }
  191. | tSET '!' tIDENTIFIER tIDENTIFIER { dbg_set_option($3, $4); }
  192. | tSET '!' tIDENTIFIER { dbg_set_option($3, NULL); }
  193. ;
  194. x_command:
  195. tEXAM expr_lvalue { memory_examine(&$2, 1, 'x'); }
  196. | tEXAM tFORMAT expr_lvalue { memory_examine(&$3, $2 >> 8, $2 & 0xff); }
  197. ;
  198. print_command:
  199. tPRINT expr_lvalue { print_value(&$2, 0, 0); }
  200. | tPRINT tFORMAT expr_lvalue { if (($2 >> 8) == 1) print_value(&$3, $2 & 0xff, 0); else dbg_printf("Count is meaningless in print command\n"); }
  201. ;
  202. break_command:
  203. tBREAK '*' expr_lvalue { break_add_break_from_lvalue(&$3, TRUE); }
  204. | tBREAK identifier { break_add_break_from_id($2, -1, TRUE); }
  205. | tBREAK pathname ':' tNUM { break_add_break_from_lineno($2, $4, TRUE); }
  206. | tBREAK tNUM { break_add_break_from_lineno(NULL, $2, TRUE); }
  207. | tBREAK { break_add_break_from_lineno(NULL, -1, TRUE); }
  208. | tHBREAK '*' expr_lvalue { break_add_break_from_lvalue(&$3, FALSE); }
  209. | tHBREAK identifier { break_add_break_from_id($2, -1, FALSE); }
  210. | tHBREAK pathname ':' tNUM { break_add_break_from_lineno($2, $4, FALSE); }
  211. | tHBREAK tNUM { break_add_break_from_lineno(NULL, $2, FALSE); }
  212. | tHBREAK { break_add_break_from_lineno(NULL, -1, FALSE); }
  213. | tENABLE tNUM { break_enable_xpoint($2, TRUE); }
  214. | tENABLE tBREAK tNUM { break_enable_xpoint($3, TRUE); }
  215. | tDISABLE tNUM { break_enable_xpoint($2, FALSE); }
  216. | tDISABLE tBREAK tNUM { break_enable_xpoint($3, FALSE); }
  217. | tDELETE tNUM { break_delete_xpoint($2); }
  218. | tDELETE tBREAK tNUM { break_delete_xpoint($3); }
  219. ;
  220. watch_command:
  221. tWATCH '*' expr_lvalue { break_add_watch_from_lvalue(&$3, TRUE); }
  222. | tWATCH identifier { break_add_watch_from_id($2, TRUE); }
  223. | tRWATCH '*' expr_lvalue { break_add_watch_from_lvalue(&$3, FALSE); }
  224. | tRWATCH identifier { break_add_watch_from_id($2, FALSE); }
  225. ;
  226. display_command:
  227. tDISPLAY { display_print(); }
  228. | tDISPLAY expr { display_add($2, 1, 0); }
  229. | tDISPLAY tFORMAT expr { display_add($3, $2 >> 8, $2 & 0xff); }
  230. | tENABLE tDISPLAY tNUM { display_enable($3, TRUE); }
  231. | tDISABLE tDISPLAY tNUM { display_enable($3, FALSE); }
  232. | tDELETE tDISPLAY tNUM { display_delete($3); }
  233. | tDELETE tDISPLAY { display_delete(-1); }
  234. | tUNDISPLAY tNUM { display_delete($2); }
  235. | tUNDISPLAY { display_delete(-1); }
  236. ;
  237. info_command:
  238. tINFO tBREAK { break_info(); }
  239. | tINFO tSHARE { info_win32_module(0); }
  240. | tINFO tSHARE expr_rvalue { info_win32_module($3); }
  241. | tINFO tREGS { dbg_curr_process->be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 0); }
  242. | tINFO tALLREGS { dbg_curr_process->be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 1); }
  243. | tINFO tSEGMENTS expr_rvalue { info_win32_segments($3 >> 3, 1); }
  244. | tINFO tSEGMENTS { info_win32_segments(0, -1); }
  245. | tINFO tSTACK tNUM { stack_info($3); }
  246. | tINFO tSTACK { stack_info(-1); }
  247. | tINFO tSYMBOL tSTRING { symbol_info($3); }
  248. | tINFO tLOCAL { symbol_info_locals(); }
  249. | tINFO tDISPLAY { display_info(); }
  250. | tINFO tCLASS { info_win32_class(NULL, NULL); }
  251. | tINFO tCLASS tSTRING { info_win32_class(NULL, $3); }
  252. | tINFO tWND { info_win32_window(NULL, FALSE); }
  253. | tINFO tWND expr_rvalue { info_win32_window((HWND)(DWORD_PTR)$3, FALSE); }
  254. | tINFO '*' tWND { info_win32_window(NULL, TRUE); }
  255. | tINFO '*' tWND expr_rvalue { info_win32_window((HWND)(DWORD_PTR)$4, TRUE); }
  256. | tINFO tPROCESS { info_win32_processes(); }
  257. | tINFO tTHREAD { info_win32_threads(); }
  258. | tINFO tFRAME { info_win32_frame_exceptions(dbg_curr_tid); }
  259. | tINFO tFRAME expr_rvalue { info_win32_frame_exceptions($3); }
  260. | tINFO tMAPS { info_win32_virtual(dbg_curr_pid); }
  261. | tINFO tMAPS expr_rvalue { info_win32_virtual($3); }
  262. | tINFO tEXCEPTION { info_win32_exception(); }
  263. ;
  264. maintenance_command:
  265. tMAINTENANCE tTYPE { print_types(); }
  266. | tMAINTENANCE tMODULE tSTRING { tgt_module_load($3, FALSE); }
  267. | tMAINTENANCE '*' tMODULE tSTRING { tgt_module_load($4, TRUE); }
  268. ;
  269. noprocess_state:
  270. tNOPROCESS {} /* <CR> shall not barf anything */
  271. | tNOPROCESS tBACKTRACE tALL { stack_backtrace(-1); } /* can backtrace all threads with no attached process */
  272. | tNOPROCESS tSTRING { dbg_printf("No process loaded, cannot execute '%s'\n", $2); }
  273. ;
  274. type_expr:
  275. tCHAR { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_char; }
  276. | tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_int; }
  277. | tLONG tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_long_int; }
  278. | tLONG { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_long_int; }
  279. | tUNSIGNED tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_int; }
  280. | tUNSIGNED { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_int; }
  281. | tLONG tUNSIGNED tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_long_int; }
  282. | tLONG tUNSIGNED { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_long_int; }
  283. | tSHORT tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_short_int; }
  284. | tSHORT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_short_int; }
  285. | tSHORT tUNSIGNED tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_short_int; }
  286. | tSHORT tUNSIGNED { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_short_int; }
  287. | tSIGNED tCHAR { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_char_int; }
  288. | tUNSIGNED tCHAR { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_char_int; }
  289. | tLONG tLONG tUNSIGNED tINT{ $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_longlong_int; }
  290. | tLONG tLONG tUNSIGNED { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_longlong_int; }
  291. | tLONG tLONG tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_longlong_int; }
  292. | tLONG tLONG { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_longlong_int; }
  293. | tFLOAT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_short_real; }
  294. | tDOUBLE { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_real; }
  295. | tLONG tDOUBLE { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_long_real; }
  296. | type_expr '*' { $$ = $1; $$.deref_count++; }
  297. | tCLASS identifier { $$.type = type_expr_udt_class; $$.deref_count = 0; $$.u.name = $2; }
  298. | tSTRUCT identifier { $$.type = type_expr_udt_struct; $$.deref_count = 0; $$.u.name = $2; }
  299. | tUNION identifier { $$.type = type_expr_udt_union; $$.deref_count = 0; $$.u.name = $2; }
  300. | tENUM identifier { $$.type = type_expr_enumeration; $$.deref_count = 0; $$.u.name = $2; }
  301. ;
  302. expr_lvalue:
  303. expr { $$ = expr_eval($1); }
  304. ;
  305. expr_rvalue:
  306. expr_lvalue { $$ = types_extract_as_integer(&$1); }
  307. ;
  308. /*
  309. * The expr rule builds an expression tree. When we are done, we call
  310. * EvalExpr to evaluate the value of the expression. The advantage of
  311. * the two-step approach is that it is possible to save expressions for
  312. * use in 'display' commands, and in conditional watchpoints.
  313. */
  314. expr:
  315. tNUM { $$ = expr_alloc_sconstant($1); }
  316. | tSTRING { $$ = expr_alloc_string($1); }
  317. | tINTVAR { $$ = expr_alloc_internal_var($1); }
  318. | identifier { $$ = expr_alloc_symbol($1); }
  319. | expr OP_DRF tIDENTIFIER { $$ = expr_alloc_pstruct($1, $3); }
  320. | expr '.' tIDENTIFIER { $$ = expr_alloc_struct($1, $3); }
  321. | identifier '(' ')' { $$ = expr_alloc_func_call($1, 0); }
  322. | identifier '(' expr ')' { $$ = expr_alloc_func_call($1, 1, $3); }
  323. | identifier '(' expr ',' expr ')' { $$ = expr_alloc_func_call($1, 2, $3, $5); }
  324. | identifier '(' expr ',' expr ',' expr ')' { $$ = expr_alloc_func_call($1, 3, $3, $5, $7); }
  325. | identifier '(' expr ',' expr ',' expr ',' expr ')' { $$ = expr_alloc_func_call($1, 4, $3, $5, $7, $9); }
  326. | identifier '(' expr ',' expr ',' expr ',' expr ',' expr ')' { $$ = expr_alloc_func_call($1, 5, $3, $5, $7, $9, $11); }
  327. | expr '[' expr ']' { $$ = expr_alloc_binary_op(EXP_OP_ARR, $1, $3); }
  328. | expr ':' expr { $$ = expr_alloc_binary_op(EXP_OP_SEG, $1, $3); }
  329. | expr OP_LOR expr { $$ = expr_alloc_binary_op(EXP_OP_LOR, $1, $3); }
  330. | expr OP_LAND expr { $$ = expr_alloc_binary_op(EXP_OP_LAND, $1, $3); }
  331. | expr '|' expr { $$ = expr_alloc_binary_op(EXP_OP_OR, $1, $3); }
  332. | expr '&' expr { $$ = expr_alloc_binary_op(EXP_OP_AND, $1, $3); }
  333. | expr '^' expr { $$ = expr_alloc_binary_op(EXP_OP_XOR, $1, $3); }
  334. | expr OP_EQ expr { $$ = expr_alloc_binary_op(EXP_OP_EQ, $1, $3); }
  335. | expr '>' expr { $$ = expr_alloc_binary_op(EXP_OP_GT, $1, $3); }
  336. | expr '<' expr { $$ = expr_alloc_binary_op(EXP_OP_LT, $1, $3); }
  337. | expr OP_GE expr { $$ = expr_alloc_binary_op(EXP_OP_GE, $1, $3); }
  338. | expr OP_LE expr { $$ = expr_alloc_binary_op(EXP_OP_LE, $1, $3); }
  339. | expr OP_NE expr { $$ = expr_alloc_binary_op(EXP_OP_NE, $1, $3); }
  340. | expr OP_SHL expr { $$ = expr_alloc_binary_op(EXP_OP_SHL, $1, $3); }
  341. | expr OP_SHR expr { $$ = expr_alloc_binary_op(EXP_OP_SHR, $1, $3); }
  342. | expr '+' expr { $$ = expr_alloc_binary_op(EXP_OP_ADD, $1, $3); }
  343. | expr '-' expr { $$ = expr_alloc_binary_op(EXP_OP_SUB, $1, $3); }
  344. | expr '*' expr { $$ = expr_alloc_binary_op(EXP_OP_MUL, $1, $3); }
  345. | expr '/' expr { $$ = expr_alloc_binary_op(EXP_OP_DIV, $1, $3); }
  346. | expr '%' expr { $$ = expr_alloc_binary_op(EXP_OP_REM, $1, $3); }
  347. | '-' expr %prec OP_SIGN { $$ = expr_alloc_unary_op(EXP_OP_NEG, $2); }
  348. | '+' expr %prec OP_SIGN { $$ = $2; }
  349. | '!' expr { $$ = expr_alloc_unary_op(EXP_OP_NOT, $2); }
  350. | '~' expr { $$ = expr_alloc_unary_op(EXP_OP_LNOT, $2); }
  351. | '(' expr ')' { $$ = $2; }
  352. | '*' expr %prec OP_DEREF { $$ = expr_alloc_unary_op(EXP_OP_DEREF, $2); }
  353. | '&' expr %prec OP_DEREF { $$ = expr_alloc_unary_op(EXP_OP_ADDR, $2); }
  354. | '(' type_expr ')' expr %prec OP_DEREF { $$ = expr_alloc_typecast(&$2, $4); }
  355. ;
  356. /*
  357. * The lvalue rule builds an expression tree. This is a limited form
  358. * of expression that is suitable to be used as an lvalue.
  359. */
  360. lvalue_addr:
  361. lvalue { $$ = expr_eval($1); }
  362. ;
  363. lvalue:
  364. tNUM { $$ = expr_alloc_sconstant($1); }
  365. | tINTVAR { $$ = expr_alloc_internal_var($1); }
  366. | identifier { $$ = expr_alloc_symbol($1); }
  367. | lvalue OP_DRF tIDENTIFIER { $$ = expr_alloc_pstruct($1, $3); }
  368. | lvalue '.' tIDENTIFIER { $$ = expr_alloc_struct($1, $3); }
  369. | lvalue '[' expr ']' { $$ = expr_alloc_binary_op(EXP_OP_ARR, $1, $3); }
  370. | '*' expr { $$ = expr_alloc_unary_op(EXP_OP_FORCE_DEREF, $2); }
  371. ;
  372. %%
  373. static LONG WINAPI wine_dbg_cmd(EXCEPTION_POINTERS *eptr)
  374. {
  375. switch (eptr->ExceptionRecord->ExceptionCode)
  376. {
  377. case DEBUG_STATUS_INTERNAL_ERROR:
  378. dbg_printf("\nWineDbg internal error\n");
  379. break;
  380. case DEBUG_STATUS_NO_SYMBOL:
  381. dbg_printf("\nUndefined symbol\n");
  382. break;
  383. case DEBUG_STATUS_DIV_BY_ZERO:
  384. dbg_printf("\nDivision by zero\n");
  385. break;
  386. case DEBUG_STATUS_BAD_TYPE:
  387. dbg_printf("\nNo type or type mismatch\n");
  388. break;
  389. case DEBUG_STATUS_NO_FIELD:
  390. dbg_printf("\nNo such field in structure or union\n");
  391. break;
  392. case DEBUG_STATUS_CANT_DEREF:
  393. dbg_printf("\nDereference failed (not a pointer, or out of array bounds)\n");
  394. break;
  395. case DEBUG_STATUS_ABORT:
  396. break;
  397. case DEBUG_STATUS_NOT_AN_INTEGER:
  398. dbg_printf("\nNeeding an integral value\n");
  399. break;
  400. case CONTROL_C_EXIT:
  401. /* this is generally sent by a ctrl-c when we run winedbg outside of wineconsole */
  402. /* stop the debuggee, and continue debugger execution, we will be reentered by the
  403. * debug events generated by stopping
  404. */
  405. dbg_interrupt_debuggee();
  406. return EXCEPTION_CONTINUE_EXECUTION;
  407. default:
  408. dbg_printf("\nException %x\n", eptr->ExceptionRecord->ExceptionCode);
  409. break;
  410. }
  411. return EXCEPTION_EXECUTE_HANDLER;
  412. }
  413. struct parser_context
  414. {
  415. const char* filename;
  416. HANDLE input;
  417. HANDLE output;
  418. unsigned line_no;
  419. char* last_line;
  420. size_t last_line_idx;
  421. };
  422. static struct parser_context dbg_parser = {NULL, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, 0, NULL, 0};
  423. static int input_fetch_entire_line(const char* pfx, char** line)
  424. {
  425. char* buffer;
  426. char ch;
  427. DWORD nread;
  428. size_t len, alloc;
  429. /* as of today, console handles can be file handles... so better use file APIs rather than
  430. * console's
  431. */
  432. WriteFile(dbg_parser.output, pfx, strlen(pfx), &nread, NULL);
  433. buffer = HeapAlloc(GetProcessHeap(), 0, alloc = 16);
  434. assert(buffer != NULL);
  435. dbg_parser.line_no++;
  436. len = 0;
  437. do
  438. {
  439. if (!ReadFile(dbg_parser.input, &ch, 1, &nread, NULL) || nread == 0)
  440. {
  441. HeapFree(GetProcessHeap(), 0, buffer);
  442. return -1;
  443. }
  444. if (len + 2 > alloc)
  445. {
  446. while (len + 2 > alloc) alloc *= 2;
  447. buffer = dbg_heap_realloc(buffer, alloc);
  448. }
  449. buffer[len++] = ch;
  450. }
  451. while (ch != '\n');
  452. buffer[len] = '\0';
  453. *line = buffer;
  454. return len;
  455. }
  456. size_t input_lex_read_buffer(char* buf, int size)
  457. {
  458. int len;
  459. /* try first to fetch the remaining of an existing line */
  460. if (dbg_parser.last_line_idx == 0)
  461. {
  462. char* tmp = NULL;
  463. /* no remaining chars to be read from last line, grab a brand new line up to '\n' */
  464. lexeme_flush();
  465. len = input_fetch_entire_line("Wine-dbg>", &tmp);
  466. if (len < 0) return 0; /* eof */
  467. /* remove carriage return in newline */
  468. if (len >= 2 && tmp[len - 2] == '\r')
  469. {
  470. tmp[len - 2] = '\n';
  471. tmp[len - 1] = '\0';
  472. len--;
  473. }
  474. /* recall last command when empty input buffer and not parsing a file */
  475. if (dbg_parser.last_line && (len == 0 || (len == 1 && tmp[0] == '\n')) &&
  476. dbg_parser.output != INVALID_HANDLE_VALUE)
  477. {
  478. HeapFree(GetProcessHeap(), 0, tmp);
  479. }
  480. else
  481. {
  482. HeapFree(GetProcessHeap(), 0, dbg_parser.last_line);
  483. dbg_parser.last_line = tmp;
  484. }
  485. }
  486. len = min(strlen(dbg_parser.last_line + dbg_parser.last_line_idx), size - 1);
  487. memcpy(buf, dbg_parser.last_line + dbg_parser.last_line_idx, len);
  488. buf[len] = '\0';
  489. if ((dbg_parser.last_line_idx += len) >= strlen(dbg_parser.last_line))
  490. dbg_parser.last_line_idx = 0;
  491. return len;
  492. }
  493. int input_read_line(const char* pfx, char* buf, int size)
  494. {
  495. char* line = NULL;
  496. int len = input_fetch_entire_line(pfx, &line);
  497. if (len < 0) return 0;
  498. /* remove trailing \n and \r */
  499. while (len > 0 && (line[len - 1] == '\n' || line[len - 1] == '\r')) len--;
  500. len = min(size - 1, len);
  501. memcpy(buf, line, len);
  502. buf[len] = '\0';
  503. HeapFree(GetProcessHeap(), 0, line);
  504. return 1;
  505. }
  506. /***********************************************************************
  507. * parser_handle
  508. *
  509. * Debugger command line parser
  510. */
  511. void parser_handle(const char* filename, HANDLE input)
  512. {
  513. BOOL ret_ok;
  514. struct parser_context prev = dbg_parser;
  515. ret_ok = FALSE;
  516. if (input != INVALID_HANDLE_VALUE)
  517. {
  518. dbg_parser.output = INVALID_HANDLE_VALUE;
  519. dbg_parser.input = input;
  520. }
  521. else
  522. {
  523. dbg_parser.output = GetStdHandle(STD_OUTPUT_HANDLE);
  524. dbg_parser.input = GetStdHandle(STD_INPUT_HANDLE);
  525. }
  526. dbg_parser.line_no = 0;
  527. dbg_parser.filename = filename;
  528. dbg_parser.last_line = NULL;
  529. dbg_parser.last_line_idx = 0;
  530. do
  531. {
  532. __TRY
  533. {
  534. ret_ok = TRUE;
  535. dbg_parse();
  536. }
  537. __EXCEPT(wine_dbg_cmd)
  538. {
  539. ret_ok = FALSE;
  540. }
  541. __ENDTRY;
  542. lexeme_flush();
  543. } while (!ret_ok);
  544. dbg_parser = prev;
  545. }
  546. static void parser(const char* filename)
  547. {
  548. HANDLE h = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0L, 0);
  549. if (h != INVALID_HANDLE_VALUE)
  550. {
  551. parser_handle(filename, h);
  552. CloseHandle(h);
  553. }
  554. }
  555. static int dbg_error(const char* s)
  556. {
  557. if (dbg_parser.filename)
  558. dbg_printf("%s:%d:", dbg_parser.filename, dbg_parser.line_no);
  559. dbg_printf("%s\n", s);
  560. return 0;
  561. }
  562. HANDLE WINAPIV parser_generate_command_file(const char* pmt, ...)
  563. {
  564. HANDLE hFile;
  565. char path[MAX_PATH], file[MAX_PATH];
  566. DWORD w;
  567. const char* p;
  568. GetTempPathA(sizeof(path), path);
  569. GetTempFileNameA(path, "WD", 0, file);
  570. hFile = CreateFileA(file, GENERIC_READ|GENERIC_WRITE|DELETE, FILE_SHARE_DELETE,
  571. NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, 0);
  572. if (hFile != INVALID_HANDLE_VALUE)
  573. {
  574. va_list ap;
  575. WriteFile(hFile, pmt, strlen(pmt), &w, 0);
  576. va_start(ap, pmt);
  577. while ((p = va_arg(ap, const char*)) != NULL)
  578. {
  579. WriteFile(hFile, "\n", 1, &w, 0);
  580. WriteFile(hFile, p, strlen(p), &w, 0);
  581. }
  582. va_end(ap);
  583. WriteFile(hFile, "\nquit\n", 6, &w, 0);
  584. SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
  585. }
  586. return hFile;
  587. }