dbg.y 27 KB

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