ncrypt/tests: Test for symmetric keys support.
[wine.git] / programs / winedbg / break.c
blob27a11a00d3337d75341a06289bdc547477b82a3a
1 /*
2 * Debugger break-points handling
4 * Copyright 1994 Martin von Loewis
5 * Copyright 1995 Alexandre Julliard
6 * Copyright 1999,2000 Eric Pouech
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "debugger.h"
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
28 static BOOL is_xpoint_break(int bpnum)
30 int type = dbg_curr_process->bp[bpnum].xpoint_type;
32 if (type == be_xpoint_break || type == be_xpoint_watch_exec) return TRUE;
33 if (type == be_xpoint_watch_read || type == be_xpoint_watch_write) return FALSE;
34 RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
35 return FALSE; /* never reached */
38 /***********************************************************************
39 * break_set_xpoints
41 * Set or remove all the breakpoints & watchpoints
43 void break_set_xpoints(BOOL set)
45 static BOOL last; /* = 0 = FALSE */
47 unsigned int i, ret, size;
48 void* addr;
49 struct dbg_breakpoint* bp = dbg_curr_process->bp;
51 if (set == last) return;
52 last = set;
54 for (i = 0; i < dbg_curr_process->next_bp; i++)
56 if (!bp[i].refcount || !bp[i].enabled) continue;
58 if (is_xpoint_break(i))
59 size = 0;
60 else
61 size = bp[i].w.len + 1;
62 addr = memory_to_linear_addr(&bp[i].addr);
64 if (set)
65 ret = dbg_curr_process->be_cpu->insert_Xpoint(dbg_curr_process->handle,
66 dbg_curr_process->process_io, &dbg_context, bp[i].xpoint_type,
67 addr, &bp[i].info, size);
68 else
69 ret = dbg_curr_process->be_cpu->remove_Xpoint(dbg_curr_process->handle,
70 dbg_curr_process->process_io, &dbg_context, bp[i].xpoint_type,
71 addr, bp[i].info, size);
72 if (!ret)
74 dbg_printf("Invalid address (");
75 print_address(&bp[i].addr, FALSE);
76 dbg_printf(") for breakpoint %d, disabling it\n", i);
77 bp[i].enabled = FALSE;
82 /***********************************************************************
83 * find_xpoint
85 * Find the breakpoint for a given address. Return the breakpoint
86 * number or -1 if none.
88 static int find_xpoint(const ADDRESS64* addr, enum be_xpoint_type type)
90 int i;
91 void* lin = memory_to_linear_addr(addr);
92 struct dbg_breakpoint* bp = dbg_curr_process->bp;
94 for (i = 0; i < dbg_curr_process->next_bp; i++)
96 if (bp[i].refcount && bp[i].enabled && bp[i].xpoint_type == type &&
97 memory_to_linear_addr(&bp[i].addr) == lin)
98 return i;
100 return -1;
103 /***********************************************************************
104 * init_xpoint
106 * Find an empty slot in BP table to add a new break/watch point
108 static int init_xpoint(int type, const ADDRESS64* addr)
110 int num;
111 struct dbg_breakpoint* bp = dbg_curr_process->bp;
113 for (num = (dbg_curr_process->next_bp < MAX_BREAKPOINTS) ?
114 dbg_curr_process->next_bp++ : 1;
115 num < MAX_BREAKPOINTS; num++)
117 if (bp[num].refcount == 0)
119 bp[num].refcount = 1;
120 bp[num].enabled = TRUE;
121 bp[num].xpoint_type = type;
122 bp[num].skipcount = 0;
123 bp[num].addr = *addr;
124 return num;
128 dbg_printf("Too many bp. Please delete some.\n");
129 return -1;
132 /***********************************************************************
133 * get_watched_value
135 * Returns the value watched by watch point 'num'.
137 static BOOL get_watched_value(int num, DWORD64* val)
139 DWORD64 buf[1];
141 if (!dbg_read_memory(memory_to_linear_addr(&dbg_curr_process->bp[num].addr),
142 buf, dbg_curr_process->bp[num].w.len + 1))
143 return FALSE;
145 switch (dbg_curr_process->bp[num].w.len + 1)
147 case 8: *val = *(DWORD64*)buf; break;
148 case 4: *val = *(DWORD*)buf; break;
149 case 2: *val = *(WORD*)buf; break;
150 case 1: *val = *(BYTE*)buf; break;
151 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
153 return TRUE;
156 /***********************************************************************
157 * break_add_break
159 * Add a breakpoint.
161 BOOL break_add_break(const ADDRESS64* addr, BOOL verbose, BOOL swbp)
163 int num;
164 BYTE ch;
165 struct dbg_breakpoint* bp = dbg_curr_process->bp;
166 int type = swbp ? be_xpoint_break : be_xpoint_watch_exec;
168 if ((num = find_xpoint(addr, type)) >= 1)
170 bp[num].refcount++;
171 dbg_printf("Breakpoint %d at ", num);
172 print_address(&bp[num].addr, TRUE);
173 dbg_printf(" (refcount=%d)\n", bp[num].refcount);
174 return TRUE;
177 if (!dbg_read_memory(memory_to_linear_addr(addr), &ch, sizeof(ch)))
179 if (verbose)
181 dbg_printf("Invalid address ");
182 print_bare_address(addr);
183 dbg_printf(", can't set breakpoint\n");
185 return FALSE;
188 if ((num = init_xpoint(type, addr)) == -1)
189 return FALSE;
191 dbg_printf("Breakpoint %d at ", num);
192 print_address(&bp[num].addr, TRUE);
193 dbg_printf("\n");
195 return TRUE;
198 /***********************************************************************
199 * break_add_break_from_lvalue
201 * Add a breakpoint.
203 BOOL break_add_break_from_lvalue(const struct dbg_lvalue* lvalue, BOOL swbp)
205 ADDRESS64 addr;
207 types_extract_as_address(lvalue, &addr);
209 if (!break_add_break(&addr, TRUE, swbp))
211 if (!DBG_IVAR(CanDeferOnBPByAddr))
213 dbg_printf("Invalid address, can't set breakpoint\n"
214 "You can turn on deferring bp by address by setting $CanDeferOnBPByAddr to 1\n");
215 return FALSE;
217 dbg_printf("Unable to add breakpoint, will check again any time a new DLL is loaded\n");
218 dbg_curr_process->delayed_bp =
219 dbg_heap_realloc(dbg_curr_process->delayed_bp,
220 sizeof(struct dbg_delayed_bp) * ++dbg_curr_process->num_delayed_bp);
222 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].is_symbol = FALSE;
223 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].software_bp = swbp;
224 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.addr = addr;
225 return TRUE;
227 return FALSE;
230 /***********************************************************************
231 * break_add_break_from_id
233 * Add a breakpoint from a function name (and eventually a line #)
235 void break_add_break_from_id(const char *name, int lineno, BOOL swbp)
237 struct dbg_lvalue lvalue;
238 int i;
240 switch (symbol_get_lvalue(name, lineno, &lvalue, TRUE))
242 case sglv_found:
243 break_add_break(&lvalue.addr, TRUE, swbp);
244 return;
245 case sglv_unknown:
246 break;
247 case sglv_aborted: /* user aborted symbol lookup */
248 return;
251 dbg_printf("Unable to add breakpoint, will check again when a new DLL is loaded\n");
252 for (i = 0; i < dbg_curr_process->num_delayed_bp; i++)
254 if (dbg_curr_process->delayed_bp[i].is_symbol &&
255 !strcmp(name, dbg_curr_process->delayed_bp[i].u.symbol.name) &&
256 lineno == dbg_curr_process->delayed_bp[i].u.symbol.lineno)
257 return;
259 dbg_curr_process->delayed_bp = dbg_heap_realloc(dbg_curr_process->delayed_bp,
260 sizeof(struct dbg_delayed_bp) * ++dbg_curr_process->num_delayed_bp);
262 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].is_symbol = TRUE;
263 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].software_bp = swbp;
264 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.symbol.name = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(name) + 1), name);
265 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.symbol.lineno = lineno;
268 struct cb_break_lineno
270 const char* filename;
271 int lineno;
272 ADDRESS64 addr;
275 static BOOL CALLBACK line_cb(SRCCODEINFO* sci, void* user)
277 struct cb_break_lineno* bkln = user;
279 if (bkln->lineno == sci->LineNumber)
281 bkln->addr.Mode = AddrModeFlat;
282 bkln->addr.Offset = sci->Address;
283 return FALSE;
285 return TRUE;
288 static BOOL CALLBACK mcb(PCWSTR module, DWORD64 base, void* user)
290 struct cb_break_lineno* bkln = user;
292 SymEnumLines(dbg_curr_process->handle, base, NULL, bkln->filename, line_cb, bkln);
293 /* continue module enum if no addr found
294 * FIXME: we don't report when several addresses match the same filename/lineno pair
296 return !bkln->addr.Offset;
299 /***********************************************************************
300 * break_add_break_from_lineno
302 * Add a breakpoint from a line number in current file
304 void break_add_break_from_lineno(const char *filename, int lineno, BOOL swbp)
306 struct cb_break_lineno bkln;
307 bkln.addr.Offset = 0;
308 bkln.lineno = lineno;
310 if (!filename)
312 DWORD disp;
313 ADDRESS64 curr;
314 IMAGEHLP_LINE64 il;
315 DWORD_PTR linear;
317 memory_get_current_pc(&curr);
318 linear = (DWORD_PTR)memory_to_linear_addr(&curr);
319 il.SizeOfStruct = sizeof(il);
320 if (!SymGetLineFromAddr64(dbg_curr_process->handle, linear, &disp, &il))
322 dbg_printf("Unable to add breakpoint (unknown address %Ix)\n", linear);
323 return;
325 filename = il.FileName;
326 SymEnumLines(dbg_curr_process->handle, linear, NULL, filename, line_cb, &bkln);
328 else
330 /* we have to enumerate across modules */
331 bkln.filename = filename;
332 SymEnumerateModulesW64(dbg_curr_process->handle, mcb, &bkln);
334 if (bkln.addr.Offset)
335 break_add_break(&bkln.addr, TRUE, swbp);
336 else
337 dbg_printf("Unknown line number\n"
338 "(either out of file, or no code at given line number)\n");
341 /***********************************************************************
342 * break_check_delayed_bp
344 * Check is a registered delayed BP is now available.
346 void break_check_delayed_bp(void)
348 struct dbg_lvalue lvalue;
349 int i;
350 struct dbg_delayed_bp* dbp = dbg_curr_process->delayed_bp;
351 char hexbuf[MAX_OFFSET_TO_STR_LEN];
353 for (i = 0; i < dbg_curr_process->num_delayed_bp; i++)
355 if (dbp[i].is_symbol)
357 if (symbol_get_lvalue(dbp[i].u.symbol.name, dbp[i].u.symbol.lineno,
358 &lvalue, TRUE) != sglv_found)
359 continue;
360 if (!lvalue.in_debuggee) continue;
362 else
363 lvalue.addr = dbp[i].u.addr;
364 WINE_TRACE("trying to add delayed %s-bp\n", dbp[i].is_symbol ? "S" : "A");
365 if (!dbp[i].is_symbol)
366 WINE_TRACE("\t%04x:%s\n",
367 dbp[i].u.addr.Segment,
368 memory_offset_to_string(hexbuf, dbp[i].u.addr.Offset, 0));
369 else
370 WINE_TRACE("\t'%s' @ %d\n",
371 dbp[i].u.symbol.name, dbp[i].u.symbol.lineno);
373 if (break_add_break(&lvalue.addr, FALSE, dbp[i].software_bp))
374 memmove(&dbp[i], &dbp[i+1], (--dbg_curr_process->num_delayed_bp - i) * sizeof(*dbp));
378 /***********************************************************************
379 * break_add_watch
381 * Add a watchpoint.
383 static void break_add_watch(const struct dbg_lvalue* lvalue, BOOL is_write)
385 int num;
386 DWORD64 l = 4;
388 if (!lvalue->in_debuggee)
390 dbg_printf("Cannot set a watch point on register or register-based variable\n");
391 return;
393 num = init_xpoint((is_write) ? be_xpoint_watch_write : be_xpoint_watch_read,
394 &lvalue->addr);
395 if (num == -1) return;
397 if (lvalue->type.id != dbg_itype_none)
399 if (types_get_info(&lvalue->type, TI_GET_LENGTH, &l))
401 switch (l)
403 case 4: case 2: case 1: break;
404 default:
405 dbg_printf("Unsupported length (%I64x) for watch-points, defaulting to 4\n", l);
406 break;
409 else dbg_printf("Cannot get watch size, defaulting to 4\n");
411 dbg_curr_process->bp[num].w.len = (DWORD)l - 1;
413 if (!get_watched_value(num, &dbg_curr_process->bp[num].w.oldval))
415 dbg_printf("Bad address. Watchpoint not set\n");
416 dbg_curr_process->bp[num].refcount = 0;
417 return;
419 dbg_printf("Watchpoint %d at ", num);
420 print_address(&dbg_curr_process->bp[num].addr, TRUE);
421 dbg_printf("\n");
424 /******************************************************************
425 * break_add_watch_from_lvalue
427 * Adds a watch point from an address (stored in a lvalue)
429 void break_add_watch_from_lvalue(const struct dbg_lvalue* lvalue,BOOL is_write)
431 struct dbg_lvalue lval;
433 types_extract_as_address(lvalue, &lval.addr);
434 lval.type.id = dbg_itype_none;
436 break_add_watch(&lval, is_write);
439 /***********************************************************************
440 * break_add_watch_from_id
442 * Add a watchpoint from a symbol name
444 void break_add_watch_from_id(const char *name, BOOL is_write)
446 struct dbg_lvalue lvalue;
448 switch (symbol_get_lvalue(name, -1, &lvalue, TRUE))
450 case sglv_found:
451 break_add_watch(&lvalue, is_write);
452 break;
453 case sglv_unknown:
454 dbg_printf("Unable to add watchpoint\n");
455 break;
456 case sglv_aborted: /* user aborted symbol lookup */
457 break;
461 /***********************************************************************
462 * break_delete_xpoint
464 * Delete a breakpoint.
466 void break_delete_xpoint(int num)
468 struct dbg_breakpoint* bp = dbg_curr_process->bp;
470 if ((num <= 0) || (num >= dbg_curr_process->next_bp) ||
471 bp[num].refcount == 0)
473 dbg_printf("Invalid breakpoint number %d\n", num);
474 return;
477 if (--bp[num].refcount > 0)
478 return;
480 if (bp[num].condition != NULL)
482 expr_free(bp[num].condition);
483 bp[num].condition = NULL;
486 bp[num].enabled = FALSE;
487 bp[num].refcount = 0;
488 bp[num].skipcount = 0;
491 /******************************************************************
492 * break_delete_xpoints_from_module
494 * Remove all Xpoints from module which base is 'base'
496 void break_delete_xpoints_from_module(DWORD64 base)
498 IMAGEHLP_MODULE64 im, im_elf;
499 int i;
500 DWORD_PTR linear;
501 struct dbg_breakpoint* bp = dbg_curr_process->bp;
503 /* FIXME: should do it also on the ELF sibling if any */
504 im.SizeOfStruct = sizeof(im);
505 im_elf.SizeOfStruct = sizeof(im_elf);
506 if (!SymGetModuleInfo64(dbg_curr_process->handle, base, &im)) return;
508 /* try to get in fact the underlying ELF module (if any) */
509 if (SymGetModuleInfo64(dbg_curr_process->handle, im.BaseOfImage - 1, &im_elf) &&
510 im_elf.BaseOfImage <= im.BaseOfImage &&
511 im_elf.BaseOfImage + im_elf.ImageSize >= im.BaseOfImage + im.ImageSize)
512 im = im_elf;
514 for (i = 0; i < dbg_curr_process->next_bp; i++)
516 if (bp[i].refcount && bp[i].enabled)
518 linear = (DWORD_PTR)memory_to_linear_addr(&bp[i].addr);
519 if (im.BaseOfImage <= linear && linear < im.BaseOfImage + im.ImageSize)
521 break_delete_xpoint(i);
527 /***********************************************************************
528 * break_enable_xpoint
530 * Enable or disable a break point.
532 void break_enable_xpoint(int num, BOOL enable)
534 if ((num <= 0) || (num >= dbg_curr_process->next_bp) ||
535 dbg_curr_process->bp[num].refcount == 0)
537 dbg_printf("Invalid breakpoint number %d\n", num);
538 return;
540 dbg_curr_process->bp[num].enabled = enable != 0;
541 dbg_curr_process->bp[num].skipcount = 0;
545 /***********************************************************************
546 * find_triggered_watch
548 * Lookup the watchpoints to see if one has been triggered
549 * Return >= (watch point index) if one is found
550 * Return -1 if none found
552 * Unfortunately, Linux used to *NOT* (A REAL PITA) report with ptrace
553 * the DR6 register value, so we have to look with our own need the
554 * cause of the TRAP.
555 * -EP
557 static int find_triggered_watch(void)
559 int found = -1;
560 int i;
561 struct dbg_breakpoint* bp = dbg_curr_process->bp;
563 /* Method 1 => get triggered watchpoint from context (doesn't work on Linux
564 * 2.2.x). This should be fixed in >= 2.2.16
566 for (i = 0; i < dbg_curr_process->next_bp; i++)
568 DWORD64 val = 0;
570 if (bp[i].refcount && bp[i].enabled && !is_xpoint_break(i) &&
571 (dbg_curr_process->be_cpu->is_watchpoint_set(&dbg_context, bp[i].info)))
573 dbg_curr_process->be_cpu->clear_watchpoint(&dbg_context, bp[i].info);
575 if (get_watched_value(i, &val))
577 bp[i].w.oldval = val;
578 return i;
583 /* Method 1 failed, trying method 2 */
585 /* Method 2 => check if value has changed among registered watchpoints
586 * this really sucks, but this is how gdb 4.18 works on my linux box
587 * -EP
589 for (i = 0; i < dbg_curr_process->next_bp; i++)
591 DWORD64 val = 0;
593 if (bp[i].refcount && bp[i].enabled && !is_xpoint_break(i) &&
594 get_watched_value(i, &val))
596 if (val != bp[i].w.oldval)
598 dbg_curr_process->be_cpu->clear_watchpoint(&dbg_context, bp[i].info);
599 bp[i].w.oldval = val;
600 found = i;
601 /* cannot break, because two watch points may have been triggered on
602 * the same access
603 * only one will be reported to the user (FIXME ?)
608 return found;
611 /***********************************************************************
612 * break_info
614 * Display break & watch points information.
616 void break_info(void)
618 int i;
619 int nbp = 0, nwp = 0;
620 struct dbg_delayed_bp* dbp = dbg_curr_process->delayed_bp;
621 struct dbg_breakpoint* bp = dbg_curr_process->bp;
623 for (i = 1; i < dbg_curr_process->next_bp; i++)
625 if (bp[i].refcount)
627 if (is_xpoint_break(i)) nbp++; else nwp++;
631 if (nbp)
633 dbg_printf("Breakpoints:\n");
634 for (i = 1; i < dbg_curr_process->next_bp; i++)
636 if (!bp[i].refcount || !is_xpoint_break(i))
637 continue;
638 dbg_printf("%d: %c ", i, bp[i].enabled ? 'y' : 'n');
639 print_address(&bp[i].addr, TRUE);
640 dbg_printf(" (%u)%s\n", bp[i].refcount,
641 bp[i].xpoint_type == be_xpoint_watch_exec ? " (hardware assisted)" : "");
642 if (bp[i].condition != NULL)
644 dbg_printf("\t\tstop when ");
645 expr_print(bp[i].condition);
646 dbg_printf("\n");
650 else dbg_printf("No breakpoints\n");
651 if (nwp)
653 dbg_printf("Watchpoints:\n");
654 for (i = 1; i < dbg_curr_process->next_bp; i++)
656 if (!bp[i].refcount || is_xpoint_break(i))
657 continue;
658 dbg_printf("%d: %c ", i, bp[i].enabled ? 'y' : 'n');
659 print_address(&bp[i].addr, TRUE);
660 dbg_printf(" on %d byte%s (%c)\n",
661 bp[i].w.len + 1, bp[i].w.len > 0 ? "s" : "",
662 bp[i].xpoint_type == be_xpoint_watch_write ? 'W' : 'R');
663 if (bp[i].condition != NULL)
665 dbg_printf("\t\tstop when ");
666 expr_print(bp[i].condition);
667 dbg_printf("\n");
671 else dbg_printf("No watchpoints\n");
672 if (dbg_curr_process->num_delayed_bp)
674 dbg_printf("Delayed breakpoints:\n");
675 for (i = 0; i < dbg_curr_process->num_delayed_bp; i++)
677 if (dbp[i].is_symbol)
679 dbg_printf("%d: %s", i, dbp[i].u.symbol.name);
680 if (dbp[i].u.symbol.lineno != -1)
681 dbg_printf(" at line %u", dbp[i].u.symbol.lineno);
683 else
685 dbg_printf("%d: ", i);
686 print_address(&dbp[i].u.addr, FALSE);
688 dbg_printf("\n");
693 /***********************************************************************
694 * should_stop
696 * Check whether or not the condition (bp / skipcount) of a break/watch
697 * point are met.
699 static BOOL should_stop(int bpnum)
701 struct dbg_breakpoint* bp = &dbg_curr_process->bp[bpnum];
703 if (bp->condition != NULL)
705 struct dbg_lvalue lvalue = expr_eval(bp->condition);
707 if (lvalue.type.id == dbg_itype_none)
710 * Something wrong - unable to evaluate this expression.
712 dbg_printf("Unable to evaluate expression ");
713 expr_print(bp->condition);
714 dbg_printf("\nTurning off condition\n");
715 break_add_condition(bpnum, NULL);
717 else if (!types_extract_as_integer(&lvalue))
719 return FALSE;
723 if (bp->skipcount > 0) bp->skipcount--;
724 return bp->skipcount == 0;
727 /***********************************************************************
728 * break_should_continue
730 * Determine if we should continue execution after a SIGTRAP signal when
731 * executing in the given mode.
733 BOOL break_should_continue(ADDRESS64* addr, DWORD code)
735 enum dbg_exec_mode mode = dbg_curr_thread->exec_mode;
738 if (dbg_curr_thread->stopped_xpoint > 0)
740 if (!should_stop(dbg_curr_thread->stopped_xpoint)) return TRUE;
742 switch (dbg_curr_process->bp[dbg_curr_thread->stopped_xpoint].xpoint_type)
744 case be_xpoint_break:
745 case be_xpoint_watch_exec:
746 dbg_printf("Stopped on breakpoint %d at ", dbg_curr_thread->stopped_xpoint);
747 print_address(&dbg_curr_process->bp[dbg_curr_thread->stopped_xpoint].addr, TRUE);
748 dbg_printf("\n");
749 break;
750 case be_xpoint_watch_read:
751 case be_xpoint_watch_write:
752 dbg_printf("Stopped on watchpoint %d at ", dbg_curr_thread->stopped_xpoint);
753 print_address(addr, TRUE);
754 dbg_printf(" new value %I64x\n",
755 dbg_curr_process->bp[dbg_curr_thread->stopped_xpoint].w.oldval);
757 return FALSE;
761 * If our mode indicates that we are stepping line numbers,
762 * get the current function, and figure out if we are exactly
763 * on a line number or not.
765 if (mode == dbg_exec_step_over_line || mode == dbg_exec_step_into_line)
767 if (symbol_get_function_line_status(addr) == dbg_on_a_line_number)
768 dbg_curr_thread->exec_count--;
770 else if (mode == dbg_exec_step_over_insn || mode == dbg_exec_step_into_insn)
771 dbg_curr_thread->exec_count--;
773 if (dbg_curr_thread->exec_count > 0 || mode == dbg_exec_finish)
776 * We still need to execute more instructions.
778 return TRUE;
781 /* no breakpoint, continue if in continuous mode */
782 return mode == dbg_exec_cont || mode == dbg_exec_finish;
785 /***********************************************************************
786 * break_adjust_pc
788 * Adjust PC to the address where the trap (if any) actually occurred
789 * Also sets dbg_curr_thread->stopped_xpoint
791 void break_adjust_pc(ADDRESS64* addr, DWORD code, BOOL first_chance, BOOL* is_break)
793 /* break / watch points are handled on first chance */
794 if ( !first_chance )
796 *is_break = TRUE;
797 dbg_curr_thread->stopped_xpoint = -1;
798 return;
800 *is_break = FALSE;
802 /* If not single-stepping, back up to the break instruction */
803 if (code == EXCEPTION_BREAKPOINT)
804 addr->Offset += dbg_curr_process->be_cpu->adjust_pc_for_break(&dbg_context, TRUE);
806 dbg_curr_thread->stopped_xpoint = find_xpoint(addr, be_xpoint_break);
807 dbg_curr_process->bp[0].enabled = FALSE; /* disable the step-over breakpoint */
809 if (dbg_curr_thread->stopped_xpoint > 0) return;
811 if (dbg_curr_thread->stopped_xpoint < 0)
813 dbg_curr_thread->stopped_xpoint = find_xpoint(addr, be_xpoint_watch_exec);
814 if (dbg_curr_thread->stopped_xpoint < 0)
815 dbg_curr_thread->stopped_xpoint = find_triggered_watch();
816 if (dbg_curr_thread->stopped_xpoint > 0)
818 /* If not single-stepping, do not back up over the break instruction */
819 if (code == EXCEPTION_BREAKPOINT)
820 addr->Offset += dbg_curr_process->be_cpu->adjust_pc_for_break(&dbg_context, FALSE);
821 return;
825 /* If there's no breakpoint and we are not single-stepping, then
826 * either we must have encountered a break insn in the Windows program
827 * or someone is trying to stop us
829 if (dbg_curr_thread->stopped_xpoint == -1 && code == EXCEPTION_BREAKPOINT)
831 *is_break = TRUE;
832 addr->Offset += dbg_curr_process->be_cpu->adjust_pc_for_break(&dbg_context, FALSE);
836 /***********************************************************************
837 * break_suspend_execution
839 * Remove all bp before entering the debug loop
841 void break_suspend_execution(void)
843 break_set_xpoints(FALSE);
844 dbg_curr_process->bp[0] = dbg_curr_thread->step_over_bp;
847 /***********************************************************************
848 * break_restart_execution
850 * Set the bp to the correct state to restart execution
851 * in the given mode.
853 void break_restart_execution(int count)
855 ADDRESS64 addr;
856 enum dbg_line_status status;
857 enum dbg_exec_mode mode, ret_mode;
858 ADDRESS64 callee;
859 void* linear;
861 memory_get_current_pc(&addr);
862 linear = memory_to_linear_addr(&addr);
865 * This is the mode we will be running in after we finish. We would like
866 * to be able to modify this in certain cases.
868 ret_mode = mode = dbg_curr_thread->exec_mode;
870 /* we've stopped on a xpoint (other than step over) */
871 if (dbg_curr_thread->stopped_xpoint > 0)
874 * If we have set a new value, then save it in the BP number.
876 if (count != 0 && mode == dbg_exec_cont)
878 dbg_curr_process->bp[dbg_curr_thread->stopped_xpoint].skipcount = count;
880 /* If we've stopped on a breakpoint, single step over it (, then run) */
881 if (is_xpoint_break(dbg_curr_thread->stopped_xpoint))
882 mode = dbg_exec_step_into_insn;
884 else if (mode == dbg_exec_cont && count > 1)
886 dbg_printf("Not stopped at any breakpoint; argument ignored.\n");
889 if (mode == dbg_exec_finish && dbg_curr_process->be_cpu->is_function_return(linear))
891 mode = ret_mode = dbg_exec_step_into_insn;
895 * See if the function we are stepping into has debug info
896 * and line numbers. If not, then we step over it instead.
897 * FIXME - we need to check for things like thunks or trampolines,
898 * as the actual function may in fact have debug info.
900 if (dbg_curr_process->be_cpu->is_function_call(linear, &callee))
902 status = symbol_get_function_line_status(&callee);
903 #if 0
904 /* FIXME: we need to get the thunk type */
906 * Anytime we have a trampoline, step over it.
908 if ((mode == EXEC_STEP_OVER || mode == EXEC_STEPI_OVER)
909 && status == dbg_in_a_thunk)
911 WINE_WARN("Not stepping into trampoline at %p (no lines)\n",
912 memory_to_linear_addr(&callee));
913 mode = EXEC_STEP_OVER_TRAMPOLINE;
915 #endif
916 if (mode == dbg_exec_step_into_line && status == dbg_no_line_info)
918 WINE_WARN("Not stepping into function at %p (no lines)\n",
919 memory_to_linear_addr(&callee));
920 mode = dbg_exec_step_over_line;
924 if (mode == dbg_exec_step_into_line &&
925 symbol_get_function_line_status(&addr) == dbg_no_line_info)
927 dbg_printf("Single stepping until exit from function,\n"
928 "which has no line number information.\n");
929 ret_mode = mode = dbg_exec_finish;
932 switch (mode)
934 case dbg_exec_cont: /* Continuous execution */
935 dbg_curr_process->be_cpu->single_step(&dbg_context, FALSE);
936 break_set_xpoints(TRUE);
937 break;
939 #if 0
940 case EXEC_STEP_OVER_TRAMPOLINE:
942 * This is the means by which we step over our conversion stubs
943 * in callfrom*.s and callto*.s. We dig the appropriate address
944 * off the stack, and we set the breakpoint there instead of the
945 * address just after the call.
947 be_cpu->get_addr(dbg_curr_thread->handle, &dbg_context,
948 be_cpu_addr_stack, &addr);
949 /* FIXME: we assume stack grows as on an i386 */
950 addr.Offset += 2 * sizeof(unsigned int);
951 dbg_read_memory(memory_to_linear_addr(&addr),
952 &addr.Offset, sizeof(addr.Offset));
953 dbg_curr_process->bp[0].addr = addr;
954 dbg_curr_process->bp[0].enabled = TRUE;
955 dbg_curr_process->bp[0].refcount = 1;
956 dbg_curr_process->bp[0].skipcount = 0;
957 dbg_curr_process->bp[0].xpoint_type = be_xpoint_break;
958 dbg_curr_process->bp[0].condition = NULL;
959 be_cpu->single_step(&dbg_context, FALSE);
960 break_set_xpoints(TRUE);
961 break;
962 #endif
964 case dbg_exec_finish:
965 case dbg_exec_step_over_insn: /* Stepping over a call */
966 case dbg_exec_step_over_line: /* Stepping over a call */
967 if (dbg_curr_process->be_cpu->is_step_over_insn(linear))
969 dbg_curr_process->be_cpu->disasm_one_insn(&addr, FALSE);
970 dbg_curr_process->bp[0].addr = addr;
971 dbg_curr_process->bp[0].enabled = TRUE;
972 dbg_curr_process->bp[0].refcount = 1;
973 dbg_curr_process->bp[0].skipcount = 0;
974 dbg_curr_process->bp[0].xpoint_type = be_xpoint_break;
975 dbg_curr_process->bp[0].condition = NULL;
976 dbg_curr_process->be_cpu->single_step(&dbg_context, FALSE);
977 break_set_xpoints(TRUE);
978 break;
980 /* else fall through to single-stepping */
982 case dbg_exec_step_into_line: /* Single-stepping a line */
983 case dbg_exec_step_into_insn: /* Single-stepping an instruction */
984 dbg_curr_process->be_cpu->single_step(&dbg_context, TRUE);
985 break;
986 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
988 dbg_curr_thread->step_over_bp = dbg_curr_process->bp[0];
989 dbg_curr_thread->exec_mode = ret_mode;
992 BOOL break_add_condition(int num, struct expr* exp)
994 if (num <= 0 || num >= dbg_curr_process->next_bp ||
995 !dbg_curr_process->bp[num].refcount)
997 dbg_printf("Invalid breakpoint number %d\n", num);
998 return FALSE;
1001 if (dbg_curr_process->bp[num].condition != NULL)
1003 expr_free(dbg_curr_process->bp[num].condition);
1004 dbg_curr_process->bp[num].condition = NULL;
1007 if (exp != NULL) dbg_curr_process->bp[num].condition = expr_clone(exp, NULL);
1009 return TRUE;