- all symbol information storage is now module relative, so we can
[wine/multimedia.git] / programs / winedbg / break.c
blobc78258b92baad6aad31d4c5cdd2fdbdae6f49f66
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 * is_at_func_return
32 * Determine if the instruction at current PC is an instruction that
33 * is a function return.
35 static BOOL is_at_func_return(void)
37 ADDRESS addr;
39 memory_get_current_pc(&addr);
40 return be_cpu->is_function_return(memory_to_linear_addr(&addr));
43 /***********************************************************************
44 * break_set_xpoints
46 * Set or remove all the breakpoints & watchpoints
48 void break_set_xpoints(BOOL set)
50 static BOOL last; /* = 0 = FALSE */
52 int i;
53 unsigned ret, size;
54 void* addr;
55 struct dbg_breakpoint* bp = dbg_curr_process->bp;
57 if (set == last) return;
58 last = set;
60 for (i = 0; i < dbg_curr_process->next_bp; i++)
62 if (!bp[i].refcount && !bp[i].enabled)
63 continue;
65 if (bp[i].xpoint_type == be_xpoint_break)
66 size = 0;
67 else
68 size = bp[i].w.len + 1;
69 addr = (void*)memory_to_linear_addr(&bp[i].addr);
71 if (set)
72 ret = be_cpu->insert_Xpoint(dbg_curr_process->handle, &dbg_context,
73 bp[i].xpoint_type, addr,
74 &bp[i].info, size);
75 else
76 ret = be_cpu->remove_Xpoint(dbg_curr_process->handle, &dbg_context,
77 bp[i].xpoint_type, addr,
78 bp[i].info, size);
79 if (!ret)
81 dbg_printf("Invalid address (%p) for breakpoint %d, disabling it\n",
82 addr, i);
83 bp[i].enabled = FALSE;
88 /***********************************************************************
89 * find_xpoint
91 * Find the breakpoint for a given address. Return the breakpoint
92 * number or -1 if none.
94 static int find_xpoint(const ADDRESS* addr, enum be_xpoint_type type)
96 int i;
97 void* lin = memory_to_linear_addr(addr);
98 struct dbg_breakpoint* bp = dbg_curr_process->bp;
100 for (i = 0; i < dbg_curr_process->next_bp; i++)
102 if (bp[i].refcount && bp[i].enabled && bp[i].xpoint_type == type &&
103 memory_to_linear_addr(&bp[i].addr) == lin)
104 return i;
106 return -1;
109 /***********************************************************************
110 * init_xpoint
112 * Find an empty slot in BP table to add a new break/watch point
114 static int init_xpoint(int type, const ADDRESS* addr)
116 int num;
117 struct dbg_breakpoint* bp = dbg_curr_process->bp;
119 for (num = (dbg_curr_process->next_bp < MAX_BREAKPOINTS) ?
120 dbg_curr_process->next_bp++ : 1;
121 num < MAX_BREAKPOINTS; num++)
123 if (bp[num].refcount == 0)
125 bp[num].refcount = 1;
126 bp[num].enabled = TRUE;
127 bp[num].xpoint_type = type;
128 bp[num].skipcount = 0;
129 bp[num].addr = *addr;
130 return num;
134 dbg_printf("Too many bp. Please delete some.\n");
135 return -1;
138 /***********************************************************************
139 * get_watched_value
141 * Returns the value watched by watch point 'num'.
143 static BOOL get_watched_value(int num, LPDWORD val)
145 BYTE buf[4];
147 if (!dbg_read_memory(memory_to_linear_addr(&dbg_curr_process->bp[num].addr),
148 buf, dbg_curr_process->bp[num].w.len + 1))
149 return FALSE;
151 switch (dbg_curr_process->bp[num].w.len + 1)
153 case 4: *val = *(DWORD*)buf; break;
154 case 2: *val = *(WORD*)buf; break;
155 case 1: *val = *(BYTE*)buf; break;
156 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
158 return TRUE;
161 /***********************************************************************
162 * break_add_break
164 * Add a breakpoint.
166 BOOL break_add_break(const ADDRESS* addr, BOOL verbose)
168 int num;
169 BYTE ch;
170 struct dbg_breakpoint* bp = dbg_curr_process->bp;
172 if ((num = find_xpoint(addr, be_xpoint_break)) >= 1)
174 bp[num].refcount++;
175 dbg_printf("Breakpoint %d at ", num);
176 print_address(&bp[num].addr, TRUE);
177 dbg_printf(" (refcount=%d)\n", bp[num].refcount);
178 return TRUE;
181 if (!dbg_read_memory(memory_to_linear_addr(addr), &ch, sizeof(ch)))
183 if (verbose)
185 dbg_printf("Invalid address ");
186 print_bare_address(addr);
187 dbg_printf(", can't set breakpoint\n");
189 return FALSE;
192 if ((num = init_xpoint(be_xpoint_break, addr)) == -1)
193 return FALSE;
195 dbg_printf("Breakpoint %d at ", num);
196 print_address(&bp[num].addr, TRUE);
197 dbg_printf("\n");
199 return TRUE;
202 /***********************************************************************
203 * break_add_break_from_lvalue
205 * Add a breakpoint.
207 BOOL break_add_break_from_lvalue(const struct dbg_lvalue* lvalue)
209 ADDRESS addr;
211 addr.Mode = AddrModeFlat;
212 addr.Offset = types_extract_as_integer(lvalue);
214 if (!break_add_break(&addr, TRUE))
216 if (!DBG_IVAR(CanDeferOnBPByAddr))
218 dbg_printf("Invalid address, can't set breakpoint\n"
219 "You can turn on deferring bp by address by setting $CanDeferOnBPByAddr to 1\n");
220 return FALSE;
222 dbg_printf("Unable to add breakpoint, will check again any time a new DLL is loaded\n");
223 dbg_curr_process->delayed_bp =
224 dbg_heap_realloc(dbg_curr_process->delayed_bp,
225 sizeof(struct dbg_delayed_bp) * ++dbg_curr_process->num_delayed_bp);
227 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].is_symbol = FALSE;
228 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.addr = addr;
229 return TRUE;
231 return FALSE;
234 /***********************************************************************
235 * break_add_break_from_id
237 * Add a breakpoint from a function name (and eventually a line #)
239 void break_add_break_from_id(const char *name, int lineno)
241 struct dbg_lvalue lvalue;
242 int i;
244 switch (symbol_get_lvalue(name, lineno, &lvalue, TRUE))
246 case sglv_found:
247 break_add_break(&lvalue.addr, TRUE);
248 return;
249 case sglv_unknown:
250 break;
251 case sglv_aborted: /* user aborted symbol lookup */
252 return;
255 dbg_printf("Unable to add breakpoint, will check again when a new DLL is loaded\n");
256 for (i = 0; i < dbg_curr_process->num_delayed_bp; i++)
258 if (dbg_curr_process->delayed_bp[i].is_symbol &&
259 !strcmp(name, dbg_curr_process->delayed_bp[i].u.symbol.name) &&
260 lineno == dbg_curr_process->delayed_bp[i].u.symbol.lineno)
261 return;
263 dbg_curr_process->delayed_bp = dbg_heap_realloc(dbg_curr_process->delayed_bp,
264 sizeof(struct dbg_delayed_bp) * ++dbg_curr_process->num_delayed_bp);
266 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].is_symbol = TRUE;
267 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.symbol.name = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(name) + 1), name);
268 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.symbol.lineno = lineno;
271 /***********************************************************************
272 * break_add_break_from_lineno
274 * Add a breakpoint from a line number in current file
276 void break_add_break_from_lineno(int lineno)
278 ADDRESS addr;
280 memory_get_current_pc(&addr);
282 if (lineno != -1)
284 IMAGEHLP_LINE il;
285 IMAGEHLP_LINE iil;
286 BOOL found = FALSE;
288 il.SizeOfStruct = sizeof(il);
289 if (!SymGetLineFromAddr(dbg_curr_process->handle,
290 (DWORD)memory_to_linear_addr(&addr), NULL, &il))
292 dbg_printf("Unable to add breakpoint (unknown address)\n");
293 return;
296 iil = il;
297 while (SymGetLinePrev(dbg_curr_process->handle, &iil))
299 if (lineno == iil.LineNumber && !strcmp(il.FileName, iil.FileName))
301 addr.Mode = AddrModeFlat;
302 addr.Offset = iil.Address;
303 found = TRUE;
304 break;
307 iil = il;
308 if (!found) while (SymGetLineNext(dbg_curr_process->handle, &iil))
310 if (lineno == iil.LineNumber && !strcmp(il.FileName, iil.FileName))
312 addr.Mode = AddrModeFlat;
313 addr.Offset = iil.Address;
314 found = TRUE;
315 break;
318 if (!found)
320 dbg_printf("Unknown line number\n"
321 "(either out of file, or no code at given line number)\n");
322 return;
326 break_add_break(&addr, TRUE);
329 /***********************************************************************
330 * break_check_delayed_bp
332 * Check is a registered delayed BP is now available.
334 void break_check_delayed_bp(void)
336 struct dbg_lvalue lvalue;
337 int i;
338 struct dbg_delayed_bp* dbp = dbg_curr_process->delayed_bp;
340 for (i = 0; i < dbg_curr_process->num_delayed_bp; i++)
342 if (dbp[i].is_symbol)
344 if (symbol_get_lvalue(dbp[i].u.symbol.name, dbp[i].u.symbol.lineno,
345 &lvalue, TRUE) != sglv_found)
346 continue;
347 if (lvalue.cookie != DLV_TARGET) continue;
349 else
350 lvalue.addr = dbp[i].u.addr;
351 WINE_TRACE("trying to add delayed %s-bp\n", dbp[i].is_symbol ? "S" : "A");
352 if (!dbp[i].is_symbol)
353 WINE_TRACE("\t%04x:%08lx\n",
354 dbp[i].u.addr.Segment, dbp[i].u.addr.Offset);
355 else
356 WINE_TRACE("\t'%s' @ %d\n",
357 dbp[i].u.symbol.name, dbp[i].u.symbol.lineno);
359 if (break_add_break(&lvalue.addr, FALSE))
360 memmove(&dbp[i], &dbp[i+1], (--dbg_curr_process->num_delayed_bp - i) * sizeof(*dbp));
364 /***********************************************************************
365 * break_add_watch
367 * Add a watchpoint.
369 void break_add_watch(const struct dbg_lvalue* lvalue, BOOL is_write)
371 int num;
372 DWORD l = 4;
374 num = init_xpoint((is_write) ? be_xpoint_watch_write : be_xpoint_watch_read,
375 &lvalue->addr);
376 if (num == -1) return;
378 if (lvalue->typeid != dbg_itype_none)
380 if (types_get_info((DWORD)memory_to_linear_addr(&lvalue->addr),
381 lvalue->typeid, TI_GET_LENGTH, &l))
383 switch (l)
385 case 4: case 2: case 1: break;
386 default:
387 dbg_printf("Unsupported length (%lu) for watch-points, defaulting to 4\n", l);
388 break;
391 else dbg_printf("Cannot get watch size, defaulting to 4\n");
393 dbg_curr_process->bp[num].w.len = l - 1;
395 if (!get_watched_value(num, &dbg_curr_process->bp[num].w.oldval))
397 dbg_printf("Bad address. Watchpoint not set\n");
398 dbg_curr_process->bp[num].refcount = 0;
399 return;
401 dbg_printf("Watchpoint %d at ", num);
402 print_address(&dbg_curr_process->bp[num].addr, TRUE);
403 dbg_printf("\n");
406 /***********************************************************************
407 * break_add_watch_from_id
409 * Add a watchpoint from a symbol name (and eventually a line #)
411 void break_add_watch_from_id(const char *name)
413 struct dbg_lvalue lvalue;
415 switch (symbol_get_lvalue(name, -1, &lvalue, TRUE))
417 case sglv_found:
418 break_add_watch(&lvalue, 1);
419 break;
420 case sglv_unknown:
421 dbg_printf("Unable to add watchpoint\n");
422 break;
423 case sglv_aborted: /* user aborted symbol lookup */
424 break;
428 /***********************************************************************
429 * break_delete_xpoint
431 * Delete a breakpoint.
433 void break_delete_xpoint(int num)
435 struct dbg_breakpoint* bp = dbg_curr_process->bp;
437 if ((num <= 0) || (num >= dbg_curr_process->next_bp) ||
438 bp[num].refcount == 0)
440 dbg_printf("Invalid breakpoint number %d\n", num);
441 return;
444 if (--bp[num].refcount > 0)
445 return;
447 if (bp[num].condition != NULL)
449 expr_free(bp[num].condition);
450 bp[num].condition = NULL;
453 bp[num].enabled = FALSE;
454 bp[num].refcount = 0;
455 bp[num].skipcount = 0;
458 static inline BOOL module_is_container(const IMAGEHLP_MODULE* wmod_cntnr,
459 const IMAGEHLP_MODULE* wmod_child)
461 return wmod_cntnr->BaseOfImage <= wmod_child->BaseOfImage &&
462 (DWORD)wmod_cntnr->BaseOfImage + wmod_cntnr->ImageSize >=
463 (DWORD)wmod_child->BaseOfImage + wmod_child->ImageSize;
466 /******************************************************************
467 * break_delete_xpoints_from_module
469 * Remove all Xpoints from module which base is 'base'
471 void break_delete_xpoints_from_module(unsigned long base)
473 IMAGEHLP_MODULE im, im_elf;
474 int i;
475 DWORD linear;
476 struct dbg_breakpoint* bp = dbg_curr_process->bp;
478 /* FIXME: should do it also on the ELF sibbling if any */
479 im.SizeOfStruct = sizeof(im);
480 im_elf.SizeOfStruct = sizeof(im_elf);
481 if (!SymGetModuleInfo(dbg_curr_process->handle, base, &im)) return;
483 /* try to get in fact the underlying ELF module (if any) */
484 if (SymGetModuleInfo(dbg_curr_process->handle, im.BaseOfImage - 1, &im_elf) &&
485 im_elf.BaseOfImage <= im.BaseOfImage &&
486 (DWORD)im_elf.BaseOfImage + im_elf.ImageSize >= (DWORD)im.BaseOfImage + im.ImageSize)
487 im = im_elf;
489 for (i = 0; i < dbg_curr_process->next_bp; i++)
491 linear = (DWORD)memory_to_linear_addr(&bp[i].addr);
492 if (bp[i].refcount && bp[i].enabled &&
493 im.BaseOfImage <= linear && linear < im.BaseOfImage + im.ImageSize)
495 break_delete_xpoint(i);
500 /***********************************************************************
501 * break_enable_xpoint
503 * Enable or disable a break point.
505 void break_enable_xpoint(int num, BOOL enable)
507 if ((num <= 0) || (num >= dbg_curr_process->next_bp) ||
508 dbg_curr_process->bp[num].refcount == 0)
510 dbg_printf("Invalid breakpoint number %d\n", num);
511 return;
513 dbg_curr_process->bp[num].enabled = (enable) ? TRUE : FALSE;
514 dbg_curr_process->bp[num].skipcount = 0;
518 /***********************************************************************
519 * find_triggered_watch
521 * Lookup the watchpoints to see if one has been triggered
522 * Return >= (watch point index) if one is found and *oldval is set to
523 * the value watched before the TRAP
524 * Return -1 if none found (*oldval is undetermined)
526 * Unfortunately, Linux does *NOT* (A REAL PITA) report with ptrace
527 * the DR6 register value, so we have to look with our own need the
528 * cause of the TRAP.
529 * -EP
531 static int find_triggered_watch(LPDWORD oldval)
533 int found = -1;
534 int i;
535 struct dbg_breakpoint* bp = dbg_curr_process->bp;
537 /* Method 1 => get triggered watchpoint from context (doesn't work on Linux
538 * 2.2.x). This should be fixed in >= 2.2.16
540 for (i = 0; i < dbg_curr_process->next_bp; i++)
542 DWORD val = 0;
544 if (bp[i].refcount && bp[i].enabled && bp[i].xpoint_type != be_xpoint_break &&
545 (be_cpu->is_watchpoint_set(&dbg_context, bp[i].info)))
547 be_cpu->clear_watchpoint(&dbg_context, bp[i].info);
549 *oldval = bp[i].w.oldval;
550 if (get_watched_value(i, &val))
552 bp[i].w.oldval = val;
553 return i;
558 /* Method 1 failed, trying method 2 */
560 /* Method 2 => check if value has changed among registered watchpoints
561 * this really sucks, but this is how gdb 4.18 works on my linux box
562 * -EP
564 for (i = 0; i < dbg_curr_process->next_bp; i++)
566 DWORD val = 0;
568 if (bp[i].refcount && bp[i].enabled && bp[i].xpoint_type != be_xpoint_break &&
569 get_watched_value(i, &val))
571 *oldval = bp[i].w.oldval;
572 if (val != *oldval)
574 be_cpu->clear_watchpoint(&dbg_context, bp[i].info);
575 bp[i].w.oldval = val;
576 found = i;
577 /* cannot break, because two watch points may have been triggered on
578 * the same access
579 * only one will be reported to the user (FIXME ?)
584 return found;
587 /***********************************************************************
588 * break_info
590 * Display break & watch points information.
592 void break_info(void)
594 int i;
595 int nbp = 0, nwp = 0;
596 struct dbg_delayed_bp* dbp = dbg_curr_process->delayed_bp;
597 struct dbg_breakpoint* bp = dbg_curr_process->bp;
599 for (i = 1; i < dbg_curr_process->next_bp; i++)
601 if (bp[i].refcount)
603 if (bp[i].xpoint_type == be_xpoint_break) nbp++; else nwp++;
607 if (nbp)
609 dbg_printf("Breakpoints:\n");
610 for (i = 1; i < dbg_curr_process->next_bp; i++)
612 if (!bp[i].refcount || bp[i].xpoint_type != be_xpoint_break)
613 continue;
614 dbg_printf("%d: %c ", i, bp[i].enabled ? 'y' : 'n');
615 print_address(&bp[i].addr, TRUE);
616 dbg_printf(" (%u)\n", bp[i].refcount);
617 if (bp[i].condition != NULL)
619 dbg_printf("\t\tstop when ");
620 expr_print(bp[i].condition);
621 dbg_printf("\n");
625 else dbg_printf("No breakpoints\n");
626 if (nwp)
628 dbg_printf("Watchpoints:\n");
629 for (i = 1; i < dbg_curr_process->next_bp; i++)
631 if (!bp[i].refcount || bp[i].xpoint_type == be_xpoint_break)
632 continue;
633 dbg_printf("%d: %c ", i, bp[i].enabled ? 'y' : 'n');
634 print_address(&bp[i].addr, TRUE);
635 dbg_printf(" on %d byte%s (%c)\n",
636 bp[i].w.len + 1, bp[i].w.len > 0 ? "s" : "",
637 bp[i].xpoint_type == be_xpoint_watch_write ? 'W' : 'R');
638 if (bp[i].condition != NULL)
640 dbg_printf("\t\tstop when ");
641 expr_print(bp[i].condition);
642 dbg_printf("\n");
646 else dbg_printf("No watchpoints\n");
647 if (dbg_curr_process->num_delayed_bp)
649 dbg_printf("Delayed breakpoints:\n");
650 for (i = 0; i < dbg_curr_process->num_delayed_bp; i++)
652 if (dbp[i].is_symbol)
654 dbg_printf("%d: %s", i, dbp[i].u.symbol.name);
655 if (dbp[i].u.symbol.lineno != -1)
656 dbg_printf(" at line %u", dbp[i].u.symbol.lineno);
658 else
660 dbg_printf("%d: ", i);
661 print_address(&dbp[i].u.addr, FALSE);
663 dbg_printf("\n");
668 /***********************************************************************
669 * should_stop
671 * Check whether or not the condition (bp / skipcount) of a break/watch
672 * point are met.
674 static BOOL should_stop(int bpnum)
676 struct dbg_breakpoint* bp = &dbg_curr_process->bp[bpnum];
678 if (bp->condition != NULL)
680 struct dbg_lvalue lvalue = expr_eval(bp->condition);
682 if (lvalue.typeid == dbg_itype_none)
685 * Something wrong - unable to evaluate this expression.
687 dbg_printf("Unable to evaluate expression ");
688 expr_print(bp->condition);
689 dbg_printf("\nTurning off condition\n");
690 break_add_condition(bpnum, NULL);
692 else if (!types_extract_as_integer(&lvalue))
694 return FALSE;
698 if (bp->skipcount > 0) bp->skipcount--;
699 return bp->skipcount == 0;
702 /***********************************************************************
703 * break_should_continue
705 * Determine if we should continue execution after a SIGTRAP signal when
706 * executing in the given mode.
708 BOOL break_should_continue(ADDRESS* addr, DWORD code, int* count)
710 int bpnum;
711 DWORD oldval;
712 int wpnum;
713 enum dbg_exec_mode mode = dbg_curr_thread->exec_mode;
715 /* If not single-stepping, back up to the break instruction */
716 if (code == EXCEPTION_BREAKPOINT)
717 addr->Offset += be_cpu->adjust_pc_for_break(&dbg_context, TRUE);
719 bpnum = find_xpoint(addr, be_xpoint_break);
720 dbg_curr_process->bp[0].enabled = FALSE; /* disable the step-over breakpoint */
722 if (bpnum > 0)
724 if (!should_stop(bpnum)) return TRUE;
726 dbg_printf("Stopped on breakpoint %d at ", bpnum);
727 print_address(&dbg_curr_process->bp[bpnum].addr, TRUE);
728 dbg_printf("\n");
729 source_list_from_addr(addr, 0);
730 return FALSE;
733 wpnum = find_triggered_watch(&oldval);
734 if (wpnum > 0)
736 /* If not single-stepping, do not back up over the break instruction */
737 if (code == EXCEPTION_BREAKPOINT)
738 addr->Offset += be_cpu->adjust_pc_for_break(&dbg_context, FALSE);
740 if (!should_stop(wpnum)) return TRUE;
742 dbg_printf("Stopped on watchpoint %d at ", wpnum);
743 print_address(addr, TRUE);
744 dbg_printf(" values: old=%lu new=%lu\n",
745 oldval, dbg_curr_process->bp[wpnum].w.oldval);
746 source_list_from_addr(addr, 0);
747 return FALSE;
751 * If our mode indicates that we are stepping line numbers,
752 * get the current function, and figure out if we are exactly
753 * on a line number or not.
755 if (mode == dbg_exec_step_over_line || mode == dbg_exec_step_into_line)
757 if (symbol_get_function_line_status(addr) == dbg_on_a_line_number)
759 (*count)--;
762 else if (mode == dbg_exec_step_over_insn || mode == dbg_exec_step_into_insn)
764 (*count)--;
767 if (*count > 0 || mode == dbg_exec_finish)
770 * We still need to execute more instructions.
772 return TRUE;
776 * If we are about to stop, then print out the source line if we
777 * have it.
779 if (mode != dbg_exec_cont && mode != dbg_exec_finish)
780 source_list_from_addr(addr, 0);
782 /* If there's no breakpoint and we are not single-stepping, then
783 * either we must have encountered a break insn in the Windows program
784 * or someone is trying to stop us
786 if (bpnum == -1 && code == EXCEPTION_BREAKPOINT)
788 addr->Offset += be_cpu->adjust_pc_for_break(&dbg_context, FALSE);
789 return FALSE;
792 /* no breakpoint, continue if in continuous mode */
793 return mode == dbg_exec_cont || mode == dbg_exec_finish;
796 /***********************************************************************
797 * break_suspend_execution
799 * Remove all bp before entering the debug loop
801 void break_suspend_execution(void)
803 break_set_xpoints(FALSE);
804 dbg_curr_process->bp[0] = dbg_curr_thread->step_over_bp;
807 /***********************************************************************
808 * break_restart_execution
810 * Set the bp to the correct state to restart execution
811 * in the given mode.
813 void break_restart_execution(int count)
815 ADDRESS addr;
816 int bp;
817 enum dbg_line_status status;
818 enum dbg_exec_mode mode, ret_mode;
819 ADDRESS callee;
821 memory_get_current_pc(&addr);
824 * This is the mode we will be running in after we finish. We would like
825 * to be able to modify this in certain cases.
827 ret_mode = mode = dbg_curr_thread->exec_mode;
829 bp = find_xpoint(&addr, be_xpoint_break);
830 if (bp != -1 && bp != 0)
833 * If we have set a new value, then save it in the BP number.
835 if (count != 0 && mode == dbg_exec_cont)
837 dbg_curr_process->bp[bp].skipcount = count;
839 mode = dbg_exec_step_into_insn; /* If there's a breakpoint, skip it */
841 else if (mode == dbg_exec_cont && count > 1)
843 dbg_printf("Not stopped at any breakpoint; argument ignored.\n");
846 if (mode == dbg_exec_finish && is_at_func_return())
848 mode = ret_mode = dbg_exec_step_into_insn;
852 * See if the function we are stepping into has debug info
853 * and line numbers. If not, then we step over it instead.
854 * FIXME - we need to check for things like thunks or trampolines,
855 * as the actual function may in fact have debug info.
857 if (be_cpu->is_function_call(memory_to_linear_addr(&addr), &callee))
859 status = symbol_get_function_line_status(&callee);
860 #if 0
861 /* FIXME: we need to get the thunk type */
863 * Anytime we have a trampoline, step over it.
865 if ((mode == EXEC_STEP_OVER || mode == EXEC_STEPI_OVER)
866 && status == dbg_in_a_thunk)
868 WINE_WARN("Not stepping into trampoline at %p (no lines)\n",
869 memory_to_linear_addr(&callee));
870 mode = EXEC_STEP_OVER_TRAMPOLINE;
872 #endif
873 if (mode == dbg_exec_step_into_line && status == dbg_no_line_info)
875 WINE_WARN("Not stepping into function at %p (no lines)\n",
876 memory_to_linear_addr(&callee));
877 mode = dbg_exec_step_over_line;
881 if (mode == dbg_exec_step_into_line &&
882 symbol_get_function_line_status(&addr) == dbg_no_line_info)
884 dbg_printf("Single stepping until exit from function, \n"
885 "which has no line number information.\n");
886 ret_mode = mode = dbg_exec_finish;
889 switch (mode)
891 case dbg_exec_cont: /* Continuous execution */
892 be_cpu->single_step(&dbg_context, FALSE);
893 break_set_xpoints(TRUE);
894 break;
896 #if 0
897 case EXEC_STEP_OVER_TRAMPOLINE:
899 * This is the means by which we step over our conversion stubs
900 * in callfrom*.s and callto*.s. We dig the appropriate address
901 * off the stack, and we set the breakpoint there instead of the
902 * address just after the call.
904 be_cpu->get_addr(dbg_curr_thread->handle, &dbg_context,
905 be_cpu_addr_stack, &addr);
906 /* FIXME: we assume stack grows as on a i386 */
907 addr.Offset += 2 * sizeof(unsigned int);
908 dbg_read_memory(memory_to_linear_addr(&addr),
909 &addr.Offset, sizeof(addr.Offset));
910 dbg_curr_process->bp[0].addr = addr;
911 dbg_curr_process->bp[0].enabled = TRUE;
912 dbg_curr_process->bp[0].refcount = 1;
913 dbg_curr_process->bp[0].skipcount = 0;
914 be_cpu->single_step(&dbg_context, FALSE);
915 break_set_xpoints(TRUE);
916 break;
917 #endif
919 case dbg_exec_finish:
920 case dbg_exec_step_over_insn: /* Stepping over a call */
921 case dbg_exec_step_over_line: /* Stepping over a call */
922 if (be_cpu->is_step_over_insn(memory_to_linear_addr(&addr)))
924 be_cpu->single_step(&dbg_context, FALSE);
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 be_cpu->single_step(&dbg_context, FALSE);
931 break_set_xpoints(TRUE);
932 break;
934 /* else fall through to single-stepping */
936 case dbg_exec_step_into_line: /* Single-stepping a line */
937 case dbg_exec_step_into_insn: /* Single-stepping an instruction */
938 be_cpu->single_step(&dbg_context, TRUE);
939 break;
940 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
942 dbg_curr_thread->step_over_bp = dbg_curr_process->bp[0];
943 dbg_curr_thread->exec_mode = ret_mode;
946 int break_add_condition(int num, struct expr* exp)
948 if (num <= 0 || num >= dbg_curr_process->next_bp ||
949 !dbg_curr_process->bp[num].refcount)
951 dbg_printf("Invalid breakpoint number %d\n", num);
952 return FALSE;
955 if (dbg_curr_process->bp[num].condition != NULL)
957 expr_free(dbg_curr_process->bp[num].condition);
958 dbg_curr_process->bp[num].condition = NULL;
961 if (exp != NULL) dbg_curr_process->bp[num].condition = expr_clone(exp);
963 return TRUE;