kernel: Documentation cleanups.
[wine/multimedia.git] / programs / winedbg / break.c
blob8f502b5e4f607b597fd2e14f8eab2f425fe96005
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "config.h"
24 #include "debugger.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
29 /***********************************************************************
30 * break_set_xpoints
32 * Set or remove all the breakpoints & watchpoints
34 void break_set_xpoints(BOOL set)
36 static BOOL last; /* = 0 = FALSE */
38 unsigned int i, ret, size;
39 void* addr;
40 struct dbg_breakpoint* bp = dbg_curr_process->bp;
42 if (set == last) return;
43 last = set;
45 for (i = 0; i < dbg_curr_process->next_bp; i++)
47 if (!bp[i].refcount || !bp[i].enabled) continue;
49 if (bp[i].xpoint_type == be_xpoint_break)
50 size = 0;
51 else
52 size = bp[i].w.len + 1;
53 addr = (void*)memory_to_linear_addr(&bp[i].addr);
55 if (set)
56 ret = be_cpu->insert_Xpoint(dbg_curr_process->handle,
57 dbg_curr_process->process_io,
58 &dbg_context, bp[i].xpoint_type, addr,
59 &bp[i].info, size);
60 else
61 ret = be_cpu->remove_Xpoint(dbg_curr_process->handle,
62 dbg_curr_process->process_io,
63 &dbg_context, bp[i].xpoint_type, addr,
64 bp[i].info, size);
65 if (!ret)
67 dbg_printf("Invalid address (");
68 print_address(&bp[i].addr, FALSE);
69 dbg_printf(") for breakpoint %d, disabling it\n", i);
70 bp[i].enabled = FALSE;
75 /***********************************************************************
76 * find_xpoint
78 * Find the breakpoint for a given address. Return the breakpoint
79 * number or -1 if none.
81 static int find_xpoint(const ADDRESS* addr, enum be_xpoint_type type)
83 int i;
84 void* lin = memory_to_linear_addr(addr);
85 struct dbg_breakpoint* bp = dbg_curr_process->bp;
87 for (i = 0; i < dbg_curr_process->next_bp; i++)
89 if (bp[i].refcount && bp[i].enabled && bp[i].xpoint_type == type &&
90 memory_to_linear_addr(&bp[i].addr) == lin)
91 return i;
93 return -1;
96 /***********************************************************************
97 * init_xpoint
99 * Find an empty slot in BP table to add a new break/watch point
101 static int init_xpoint(int type, const ADDRESS* addr)
103 int num;
104 struct dbg_breakpoint* bp = dbg_curr_process->bp;
106 for (num = (dbg_curr_process->next_bp < MAX_BREAKPOINTS) ?
107 dbg_curr_process->next_bp++ : 1;
108 num < MAX_BREAKPOINTS; num++)
110 if (bp[num].refcount == 0)
112 bp[num].refcount = 1;
113 bp[num].enabled = TRUE;
114 bp[num].xpoint_type = type;
115 bp[num].skipcount = 0;
116 bp[num].addr = *addr;
117 return num;
121 dbg_printf("Too many bp. Please delete some.\n");
122 return -1;
125 /***********************************************************************
126 * get_watched_value
128 * Returns the value watched by watch point 'num'.
130 static BOOL get_watched_value(int num, LPDWORD val)
132 BYTE buf[4];
134 if (!dbg_read_memory(memory_to_linear_addr(&dbg_curr_process->bp[num].addr),
135 buf, dbg_curr_process->bp[num].w.len + 1))
136 return FALSE;
138 switch (dbg_curr_process->bp[num].w.len + 1)
140 case 4: *val = *(DWORD*)buf; break;
141 case 2: *val = *(WORD*)buf; break;
142 case 1: *val = *(BYTE*)buf; break;
143 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
145 return TRUE;
148 /***********************************************************************
149 * break_add_break
151 * Add a breakpoint.
153 BOOL break_add_break(const ADDRESS* addr, BOOL verbose)
155 int num;
156 BYTE ch;
157 struct dbg_breakpoint* bp = dbg_curr_process->bp;
159 if ((num = find_xpoint(addr, be_xpoint_break)) >= 1)
161 bp[num].refcount++;
162 dbg_printf("Breakpoint %d at ", num);
163 print_address(&bp[num].addr, TRUE);
164 dbg_printf(" (refcount=%d)\n", bp[num].refcount);
165 return TRUE;
168 if (!dbg_read_memory(memory_to_linear_addr(addr), &ch, sizeof(ch)))
170 if (verbose)
172 dbg_printf("Invalid address ");
173 print_bare_address(addr);
174 dbg_printf(", can't set breakpoint\n");
176 return FALSE;
179 if ((num = init_xpoint(be_xpoint_break, addr)) == -1)
180 return FALSE;
182 dbg_printf("Breakpoint %d at ", num);
183 print_address(&bp[num].addr, TRUE);
184 dbg_printf("\n");
186 return TRUE;
189 /***********************************************************************
190 * break_add_break_from_lvalue
192 * Add a breakpoint.
194 BOOL break_add_break_from_lvalue(const struct dbg_lvalue* lvalue)
196 ADDRESS addr;
198 addr.Mode = AddrModeFlat;
199 addr.Offset = types_extract_as_integer(lvalue);
201 if (!break_add_break(&addr, TRUE))
203 if (!DBG_IVAR(CanDeferOnBPByAddr))
205 dbg_printf("Invalid address, can't set breakpoint\n"
206 "You can turn on deferring bp by address by setting $CanDeferOnBPByAddr to 1\n");
207 return FALSE;
209 dbg_printf("Unable to add breakpoint, will check again any time a new DLL is loaded\n");
210 dbg_curr_process->delayed_bp =
211 dbg_heap_realloc(dbg_curr_process->delayed_bp,
212 sizeof(struct dbg_delayed_bp) * ++dbg_curr_process->num_delayed_bp);
214 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].is_symbol = FALSE;
215 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.addr = addr;
216 return TRUE;
218 return FALSE;
221 /***********************************************************************
222 * break_add_break_from_id
224 * Add a breakpoint from a function name (and eventually a line #)
226 void break_add_break_from_id(const char *name, int lineno)
228 struct dbg_lvalue lvalue;
229 int i;
231 switch (symbol_get_lvalue(name, lineno, &lvalue, TRUE))
233 case sglv_found:
234 break_add_break(&lvalue.addr, TRUE);
235 return;
236 case sglv_unknown:
237 break;
238 case sglv_aborted: /* user aborted symbol lookup */
239 return;
242 dbg_printf("Unable to add breakpoint, will check again when a new DLL is loaded\n");
243 for (i = 0; i < dbg_curr_process->num_delayed_bp; i++)
245 if (dbg_curr_process->delayed_bp[i].is_symbol &&
246 !strcmp(name, dbg_curr_process->delayed_bp[i].u.symbol.name) &&
247 lineno == dbg_curr_process->delayed_bp[i].u.symbol.lineno)
248 return;
250 dbg_curr_process->delayed_bp = dbg_heap_realloc(dbg_curr_process->delayed_bp,
251 sizeof(struct dbg_delayed_bp) * ++dbg_curr_process->num_delayed_bp);
253 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].is_symbol = TRUE;
254 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.symbol.name = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(name) + 1), name);
255 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.symbol.lineno = lineno;
258 struct cb_break_lineno
260 int lineno;
261 ADDRESS addr;
264 static BOOL CALLBACK line_cb(SRCCODEINFO* sci, void* user)
266 struct cb_break_lineno* bkln = user;
268 if (bkln->lineno == sci->LineNumber)
270 bkln->addr.Mode = AddrModeFlat;
271 bkln->addr.Offset = sci->Address;
272 return FALSE;
274 return TRUE;
277 /***********************************************************************
278 * break_add_break_from_lineno
280 * Add a breakpoint from a line number in current file
282 void break_add_break_from_lineno(int lineno)
284 struct cb_break_lineno bkln;
286 memory_get_current_pc(&bkln.addr);
288 if (lineno != -1)
290 IMAGEHLP_LINE il;
293 DWORD disp;
294 DWORD linear = (DWORD)memory_to_linear_addr(&bkln.addr);
296 il.SizeOfStruct = sizeof(il);
297 if (!SymGetLineFromAddr(dbg_curr_process->handle, linear, &disp, &il))
300 dbg_printf("Unable to add breakpoint (unknown address %lx)\n", linear);
301 return;
303 bkln.addr.Offset = 0;
304 bkln.lineno = lineno;
305 SymEnumLines(dbg_curr_process->handle, linear, NULL, il.FileName, line_cb, &bkln);
306 if (!bkln.addr.Offset)
308 dbg_printf("Unknown line number\n"
309 "(either out of file, or no code at given line number)\n");
310 return;
314 break_add_break(&bkln.addr, TRUE);
317 /***********************************************************************
318 * break_check_delayed_bp
320 * Check is a registered delayed BP is now available.
322 void break_check_delayed_bp(void)
324 struct dbg_lvalue lvalue;
325 int i;
326 struct dbg_delayed_bp* dbp = dbg_curr_process->delayed_bp;
328 for (i = 0; i < dbg_curr_process->num_delayed_bp; i++)
330 if (dbp[i].is_symbol)
332 if (symbol_get_lvalue(dbp[i].u.symbol.name, dbp[i].u.symbol.lineno,
333 &lvalue, TRUE) != sglv_found)
334 continue;
335 if (lvalue.cookie != DLV_TARGET) continue;
337 else
338 lvalue.addr = dbp[i].u.addr;
339 WINE_TRACE("trying to add delayed %s-bp\n", dbp[i].is_symbol ? "S" : "A");
340 if (!dbp[i].is_symbol)
341 WINE_TRACE("\t%04x:%08lx\n",
342 dbp[i].u.addr.Segment, dbp[i].u.addr.Offset);
343 else
344 WINE_TRACE("\t'%s' @ %d\n",
345 dbp[i].u.symbol.name, dbp[i].u.symbol.lineno);
347 if (break_add_break(&lvalue.addr, FALSE))
348 memmove(&dbp[i], &dbp[i+1], (--dbg_curr_process->num_delayed_bp - i) * sizeof(*dbp));
352 /***********************************************************************
353 * break_add_watch
355 * Add a watchpoint.
357 static void break_add_watch(const struct dbg_lvalue* lvalue, BOOL is_write)
359 int num;
360 DWORD64 l = 4;
362 num = init_xpoint((is_write) ? be_xpoint_watch_write : be_xpoint_watch_read,
363 &lvalue->addr);
364 if (num == -1) return;
366 if (lvalue->type.id != dbg_itype_none)
368 if (types_get_info(&lvalue->type, TI_GET_LENGTH, &l))
370 switch (l)
372 case 4: case 2: case 1: break;
373 default:
374 dbg_printf("Unsupported length (%s) for watch-points, defaulting to 4\n",
375 wine_dbgstr_longlong(l));
376 break;
379 else dbg_printf("Cannot get watch size, defaulting to 4\n");
381 dbg_curr_process->bp[num].w.len = (DWORD)l - 1;
383 if (!get_watched_value(num, &dbg_curr_process->bp[num].w.oldval))
385 dbg_printf("Bad address. Watchpoint not set\n");
386 dbg_curr_process->bp[num].refcount = 0;
387 return;
389 dbg_printf("Watchpoint %d at ", num);
390 print_address(&dbg_curr_process->bp[num].addr, TRUE);
391 dbg_printf("\n");
394 /******************************************************************
395 * break_add_watch_from_lvalue
397 * Adds a watch point from an address (stored in a lvalue)
399 void break_add_watch_from_lvalue(const struct dbg_lvalue* lvalue)
401 struct dbg_lvalue lval;
403 lval.addr.Mode = AddrModeFlat;
404 lval.addr.Offset = types_extract_as_integer(lvalue);
405 lval.type.id = dbg_itype_none;
407 break_add_watch(&lval, TRUE);
410 /***********************************************************************
411 * break_add_watch_from_id
413 * Add a watchpoint from a symbol name
415 void break_add_watch_from_id(const char *name)
417 struct dbg_lvalue lvalue;
419 switch (symbol_get_lvalue(name, -1, &lvalue, TRUE))
421 case sglv_found:
422 break_add_watch(&lvalue, 1);
423 break;
424 case sglv_unknown:
425 dbg_printf("Unable to add watchpoint\n");
426 break;
427 case sglv_aborted: /* user aborted symbol lookup */
428 break;
432 /***********************************************************************
433 * break_delete_xpoint
435 * Delete a breakpoint.
437 void break_delete_xpoint(int num)
439 struct dbg_breakpoint* bp = dbg_curr_process->bp;
441 if ((num <= 0) || (num >= dbg_curr_process->next_bp) ||
442 bp[num].refcount == 0)
444 dbg_printf("Invalid breakpoint number %d\n", num);
445 return;
448 if (--bp[num].refcount > 0)
449 return;
451 if (bp[num].condition != NULL)
453 expr_free(bp[num].condition);
454 bp[num].condition = NULL;
457 bp[num].enabled = FALSE;
458 bp[num].refcount = 0;
459 bp[num].skipcount = 0;
462 static inline BOOL module_is_container(const IMAGEHLP_MODULE* wmod_cntnr,
463 const IMAGEHLP_MODULE* wmod_child)
465 return wmod_cntnr->BaseOfImage <= wmod_child->BaseOfImage &&
466 (DWORD)wmod_cntnr->BaseOfImage + wmod_cntnr->ImageSize >=
467 (DWORD)wmod_child->BaseOfImage + wmod_child->ImageSize;
470 /******************************************************************
471 * break_delete_xpoints_from_module
473 * Remove all Xpoints from module which base is 'base'
475 void break_delete_xpoints_from_module(unsigned long base)
477 IMAGEHLP_MODULE im, im_elf;
478 int i;
479 DWORD linear;
480 struct dbg_breakpoint* bp = dbg_curr_process->bp;
482 /* FIXME: should do it also on the ELF sibbling if any */
483 im.SizeOfStruct = sizeof(im);
484 im_elf.SizeOfStruct = sizeof(im_elf);
485 if (!SymGetModuleInfo(dbg_curr_process->handle, base, &im)) return;
487 /* try to get in fact the underlying ELF module (if any) */
488 if (SymGetModuleInfo(dbg_curr_process->handle, im.BaseOfImage - 1, &im_elf) &&
489 im_elf.BaseOfImage <= im.BaseOfImage &&
490 (DWORD)im_elf.BaseOfImage + im_elf.ImageSize >= (DWORD)im.BaseOfImage + im.ImageSize)
491 im = im_elf;
493 for (i = 0; i < dbg_curr_process->next_bp; i++)
495 linear = (DWORD)memory_to_linear_addr(&bp[i].addr);
496 if (bp[i].refcount && bp[i].enabled &&
497 im.BaseOfImage <= linear && linear < im.BaseOfImage + im.ImageSize)
499 break_delete_xpoint(i);
504 /***********************************************************************
505 * break_enable_xpoint
507 * Enable or disable a break point.
509 void break_enable_xpoint(int num, BOOL enable)
511 if ((num <= 0) || (num >= dbg_curr_process->next_bp) ||
512 dbg_curr_process->bp[num].refcount == 0)
514 dbg_printf("Invalid breakpoint number %d\n", num);
515 return;
517 dbg_curr_process->bp[num].enabled = (enable) ? TRUE : FALSE;
518 dbg_curr_process->bp[num].skipcount = 0;
522 /***********************************************************************
523 * find_triggered_watch
525 * Lookup the watchpoints to see if one has been triggered
526 * Return >= (watch point index) if one is found and *oldval is set to
527 * the value watched before the TRAP
528 * Return -1 if none found (*oldval is undetermined)
530 * Unfortunately, Linux does *NOT* (A REAL PITA) report with ptrace
531 * the DR6 register value, so we have to look with our own need the
532 * cause of the TRAP.
533 * -EP
535 static int find_triggered_watch(LPDWORD oldval)
537 int found = -1;
538 int i;
539 struct dbg_breakpoint* bp = dbg_curr_process->bp;
541 /* Method 1 => get triggered watchpoint from context (doesn't work on Linux
542 * 2.2.x). This should be fixed in >= 2.2.16
544 for (i = 0; i < dbg_curr_process->next_bp; i++)
546 DWORD val = 0;
548 if (bp[i].refcount && bp[i].enabled && bp[i].xpoint_type != be_xpoint_break &&
549 (be_cpu->is_watchpoint_set(&dbg_context, bp[i].info)))
551 be_cpu->clear_watchpoint(&dbg_context, bp[i].info);
553 *oldval = bp[i].w.oldval;
554 if (get_watched_value(i, &val))
556 bp[i].w.oldval = val;
557 return i;
562 /* Method 1 failed, trying method 2 */
564 /* Method 2 => check if value has changed among registered watchpoints
565 * this really sucks, but this is how gdb 4.18 works on my linux box
566 * -EP
568 for (i = 0; i < dbg_curr_process->next_bp; i++)
570 DWORD val = 0;
572 if (bp[i].refcount && bp[i].enabled && bp[i].xpoint_type != be_xpoint_break &&
573 get_watched_value(i, &val))
575 *oldval = bp[i].w.oldval;
576 if (val != *oldval)
578 be_cpu->clear_watchpoint(&dbg_context, bp[i].info);
579 bp[i].w.oldval = val;
580 found = i;
581 /* cannot break, because two watch points may have been triggered on
582 * the same access
583 * only one will be reported to the user (FIXME ?)
588 return found;
591 /***********************************************************************
592 * break_info
594 * Display break & watch points information.
596 void break_info(void)
598 int i;
599 int nbp = 0, nwp = 0;
600 struct dbg_delayed_bp* dbp = dbg_curr_process->delayed_bp;
601 struct dbg_breakpoint* bp = dbg_curr_process->bp;
603 for (i = 1; i < dbg_curr_process->next_bp; i++)
605 if (bp[i].refcount)
607 if (bp[i].xpoint_type == be_xpoint_break) nbp++; else nwp++;
611 if (nbp)
613 dbg_printf("Breakpoints:\n");
614 for (i = 1; i < dbg_curr_process->next_bp; i++)
616 if (!bp[i].refcount || bp[i].xpoint_type != be_xpoint_break)
617 continue;
618 dbg_printf("%d: %c ", i, bp[i].enabled ? 'y' : 'n');
619 print_address(&bp[i].addr, TRUE);
620 dbg_printf(" (%u)\n", bp[i].refcount);
621 if (bp[i].condition != NULL)
623 dbg_printf("\t\tstop when ");
624 expr_print(bp[i].condition);
625 dbg_printf("\n");
629 else dbg_printf("No breakpoints\n");
630 if (nwp)
632 dbg_printf("Watchpoints:\n");
633 for (i = 1; i < dbg_curr_process->next_bp; i++)
635 if (!bp[i].refcount || bp[i].xpoint_type == be_xpoint_break)
636 continue;
637 dbg_printf("%d: %c ", i, bp[i].enabled ? 'y' : 'n');
638 print_address(&bp[i].addr, TRUE);
639 dbg_printf(" on %d byte%s (%c)\n",
640 bp[i].w.len + 1, bp[i].w.len > 0 ? "s" : "",
641 bp[i].xpoint_type == be_xpoint_watch_write ? 'W' : 'R');
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 watchpoints\n");
651 if (dbg_curr_process->num_delayed_bp)
653 dbg_printf("Delayed breakpoints:\n");
654 for (i = 0; i < dbg_curr_process->num_delayed_bp; i++)
656 if (dbp[i].is_symbol)
658 dbg_printf("%d: %s", i, dbp[i].u.symbol.name);
659 if (dbp[i].u.symbol.lineno != -1)
660 dbg_printf(" at line %u", dbp[i].u.symbol.lineno);
662 else
664 dbg_printf("%d: ", i);
665 print_address(&dbp[i].u.addr, FALSE);
667 dbg_printf("\n");
672 /***********************************************************************
673 * should_stop
675 * Check whether or not the condition (bp / skipcount) of a break/watch
676 * point are met.
678 static BOOL should_stop(int bpnum)
680 struct dbg_breakpoint* bp = &dbg_curr_process->bp[bpnum];
682 if (bp->condition != NULL)
684 struct dbg_lvalue lvalue = expr_eval(bp->condition);
686 if (lvalue.type.id == dbg_itype_none)
689 * Something wrong - unable to evaluate this expression.
691 dbg_printf("Unable to evaluate expression ");
692 expr_print(bp->condition);
693 dbg_printf("\nTurning off condition\n");
694 break_add_condition(bpnum, NULL);
696 else if (!types_extract_as_integer(&lvalue))
698 return FALSE;
702 if (bp->skipcount > 0) bp->skipcount--;
703 return bp->skipcount == 0;
706 /***********************************************************************
707 * break_should_continue
709 * Determine if we should continue execution after a SIGTRAP signal when
710 * executing in the given mode.
712 BOOL break_should_continue(ADDRESS* addr, DWORD code, int* count, BOOL* is_break)
714 int bpnum;
715 DWORD oldval = 0;
716 int wpnum;
717 enum dbg_exec_mode mode = dbg_curr_thread->exec_mode;
719 *is_break = FALSE;
720 /* If not single-stepping, back up to the break instruction */
721 if (code == EXCEPTION_BREAKPOINT)
722 addr->Offset += be_cpu->adjust_pc_for_break(&dbg_context, TRUE);
724 bpnum = find_xpoint(addr, be_xpoint_break);
725 dbg_curr_process->bp[0].enabled = FALSE; /* disable the step-over breakpoint */
727 if (bpnum > 0)
729 if (!should_stop(bpnum)) return TRUE;
731 dbg_printf("Stopped on breakpoint %d at ", bpnum);
732 print_address(&dbg_curr_process->bp[bpnum].addr, TRUE);
733 dbg_printf("\n");
734 return FALSE;
737 wpnum = find_triggered_watch(&oldval);
738 if (wpnum > 0)
740 /* If not single-stepping, do not back up over the break instruction */
741 if (code == EXCEPTION_BREAKPOINT)
742 addr->Offset += be_cpu->adjust_pc_for_break(&dbg_context, FALSE);
744 if (!should_stop(wpnum)) return TRUE;
746 dbg_printf("Stopped on watchpoint %d at ", wpnum);
747 print_address(addr, TRUE);
748 dbg_printf(" values: old=%lu new=%lu\n",
749 oldval, dbg_curr_process->bp[wpnum].w.oldval);
750 return FALSE;
754 * If our mode indicates that we are stepping line numbers,
755 * get the current function, and figure out if we are exactly
756 * on a line number or not.
758 if (mode == dbg_exec_step_over_line || mode == dbg_exec_step_into_line)
760 if (symbol_get_function_line_status(addr) == dbg_on_a_line_number)
762 (*count)--;
765 else if (mode == dbg_exec_step_over_insn || mode == dbg_exec_step_into_insn)
767 (*count)--;
770 if (*count > 0 || mode == dbg_exec_finish)
773 * We still need to execute more instructions.
775 return TRUE;
778 /* If there's no breakpoint and we are not single-stepping, then
779 * either we must have encountered a break insn in the Windows program
780 * or someone is trying to stop us
782 if (bpnum == -1 && code == EXCEPTION_BREAKPOINT)
784 *is_break = TRUE;
785 addr->Offset += be_cpu->adjust_pc_for_break(&dbg_context, FALSE);
786 return FALSE;
789 /* no breakpoint, continue if in continuous mode */
790 return mode == dbg_exec_cont || mode == dbg_exec_finish;
793 /***********************************************************************
794 * break_suspend_execution
796 * Remove all bp before entering the debug loop
798 void break_suspend_execution(void)
800 break_set_xpoints(FALSE);
801 dbg_curr_process->bp[0] = dbg_curr_thread->step_over_bp;
804 /***********************************************************************
805 * break_restart_execution
807 * Set the bp to the correct state to restart execution
808 * in the given mode.
810 void break_restart_execution(int count)
812 ADDRESS addr;
813 int bp;
814 enum dbg_line_status status;
815 enum dbg_exec_mode mode, ret_mode;
816 ADDRESS callee;
817 void* linear;
819 memory_get_current_pc(&addr);
820 linear = memory_to_linear_addr(&addr);
823 * This is the mode we will be running in after we finish. We would like
824 * to be able to modify this in certain cases.
826 ret_mode = mode = dbg_curr_thread->exec_mode;
828 bp = find_xpoint(&addr, be_xpoint_break);
829 if (bp != -1 && bp != 0)
832 * If we have set a new value, then save it in the BP number.
834 if (count != 0 && mode == dbg_exec_cont)
836 dbg_curr_process->bp[bp].skipcount = count;
838 mode = dbg_exec_step_into_insn; /* If there's a breakpoint, skip it */
840 else if (mode == dbg_exec_cont && count > 1)
842 dbg_printf("Not stopped at any breakpoint; argument ignored.\n");
845 if (mode == dbg_exec_finish && be_cpu->is_function_return(linear))
847 mode = ret_mode = dbg_exec_step_into_insn;
851 * See if the function we are stepping into has debug info
852 * and line numbers. If not, then we step over it instead.
853 * FIXME - we need to check for things like thunks or trampolines,
854 * as the actual function may in fact have debug info.
856 if (be_cpu->is_function_call(linear, &callee))
858 status = symbol_get_function_line_status(&callee);
859 #if 0
860 /* FIXME: we need to get the thunk type */
862 * Anytime we have a trampoline, step over it.
864 if ((mode == EXEC_STEP_OVER || mode == EXEC_STEPI_OVER)
865 && status == dbg_in_a_thunk)
867 WINE_WARN("Not stepping into trampoline at %p (no lines)\n",
868 memory_to_linear_addr(&callee));
869 mode = EXEC_STEP_OVER_TRAMPOLINE;
871 #endif
872 if (mode == dbg_exec_step_into_line && status == dbg_no_line_info)
874 WINE_WARN("Not stepping into function at %p (no lines)\n",
875 memory_to_linear_addr(&callee));
876 mode = dbg_exec_step_over_line;
880 if (mode == dbg_exec_step_into_line &&
881 symbol_get_function_line_status(&addr) == dbg_no_line_info)
883 dbg_printf("Single stepping until exit from function, \n"
884 "which has no line number information.\n");
885 ret_mode = mode = dbg_exec_finish;
888 switch (mode)
890 case dbg_exec_cont: /* Continuous execution */
891 be_cpu->single_step(&dbg_context, FALSE);
892 break_set_xpoints(TRUE);
893 break;
895 #if 0
896 case EXEC_STEP_OVER_TRAMPOLINE:
898 * This is the means by which we step over our conversion stubs
899 * in callfrom*.s and callto*.s. We dig the appropriate address
900 * off the stack, and we set the breakpoint there instead of the
901 * address just after the call.
903 be_cpu->get_addr(dbg_curr_thread->handle, &dbg_context,
904 be_cpu_addr_stack, &addr);
905 /* FIXME: we assume stack grows as on an i386 */
906 addr.Offset += 2 * sizeof(unsigned int);
907 dbg_read_memory(memory_to_linear_addr(&addr),
908 &addr.Offset, sizeof(addr.Offset));
909 dbg_curr_process->bp[0].addr = addr;
910 dbg_curr_process->bp[0].enabled = TRUE;
911 dbg_curr_process->bp[0].refcount = 1;
912 dbg_curr_process->bp[0].skipcount = 0;
913 dbg_curr_process->bp[0].xpoint_type = be_xpoint_break;
914 dbg_curr_process->bp[0].condition = NULL;
915 be_cpu->single_step(&dbg_context, FALSE);
916 break_set_xpoints(TRUE);
917 break;
918 #endif
920 case dbg_exec_finish:
921 case dbg_exec_step_over_insn: /* Stepping over a call */
922 case dbg_exec_step_over_line: /* Stepping over a call */
923 if (be_cpu->is_step_over_insn(linear))
925 be_cpu->disasm_one_insn(&addr, FALSE);
926 dbg_curr_process->bp[0].addr = addr;
927 dbg_curr_process->bp[0].enabled = TRUE;
928 dbg_curr_process->bp[0].refcount = 1;
929 dbg_curr_process->bp[0].skipcount = 0;
930 dbg_curr_process->bp[0].xpoint_type = be_xpoint_break;
931 dbg_curr_process->bp[0].condition = NULL;
932 be_cpu->single_step(&dbg_context, FALSE);
933 break_set_xpoints(TRUE);
934 break;
936 /* else fall through to single-stepping */
938 case dbg_exec_step_into_line: /* Single-stepping a line */
939 case dbg_exec_step_into_insn: /* Single-stepping an instruction */
940 be_cpu->single_step(&dbg_context, TRUE);
941 break;
942 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
944 dbg_curr_thread->step_over_bp = dbg_curr_process->bp[0];
945 dbg_curr_thread->exec_mode = ret_mode;
948 int break_add_condition(int num, struct expr* exp)
950 if (num <= 0 || num >= dbg_curr_process->next_bp ||
951 !dbg_curr_process->bp[num].refcount)
953 dbg_printf("Invalid breakpoint number %d\n", num);
954 return FALSE;
957 if (dbg_curr_process->bp[num].condition != NULL)
959 expr_free(dbg_curr_process->bp[num].condition);
960 dbg_curr_process->bp[num].condition = NULL;
963 if (exp != NULL) dbg_curr_process->bp[num].condition = expr_clone(exp, NULL);
965 return TRUE;