winedbg: Added a more decent scheme for handling segmented addresses.
[wine/multimedia.git] / programs / winedbg / break.c
blob086d1e5ef4d08153d04765e4322301646dc5aa4b
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 types_extract_as_address(lvalue, &addr);
200 if (!break_add_break(&addr, TRUE))
202 if (!DBG_IVAR(CanDeferOnBPByAddr))
204 dbg_printf("Invalid address, can't set breakpoint\n"
205 "You can turn on deferring bp by address by setting $CanDeferOnBPByAddr to 1\n");
206 return FALSE;
208 dbg_printf("Unable to add breakpoint, will check again any time a new DLL is loaded\n");
209 dbg_curr_process->delayed_bp =
210 dbg_heap_realloc(dbg_curr_process->delayed_bp,
211 sizeof(struct dbg_delayed_bp) * ++dbg_curr_process->num_delayed_bp);
213 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].is_symbol = FALSE;
214 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.addr = addr;
215 return TRUE;
217 return FALSE;
220 /***********************************************************************
221 * break_add_break_from_id
223 * Add a breakpoint from a function name (and eventually a line #)
225 void break_add_break_from_id(const char *name, int lineno)
227 struct dbg_lvalue lvalue;
228 int i;
230 switch (symbol_get_lvalue(name, lineno, &lvalue, TRUE))
232 case sglv_found:
233 break_add_break(&lvalue.addr, TRUE);
234 return;
235 case sglv_unknown:
236 break;
237 case sglv_aborted: /* user aborted symbol lookup */
238 return;
241 dbg_printf("Unable to add breakpoint, will check again when a new DLL is loaded\n");
242 for (i = 0; i < dbg_curr_process->num_delayed_bp; i++)
244 if (dbg_curr_process->delayed_bp[i].is_symbol &&
245 !strcmp(name, dbg_curr_process->delayed_bp[i].u.symbol.name) &&
246 lineno == dbg_curr_process->delayed_bp[i].u.symbol.lineno)
247 return;
249 dbg_curr_process->delayed_bp = dbg_heap_realloc(dbg_curr_process->delayed_bp,
250 sizeof(struct dbg_delayed_bp) * ++dbg_curr_process->num_delayed_bp);
252 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].is_symbol = TRUE;
253 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.symbol.name = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(name) + 1), name);
254 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.symbol.lineno = lineno;
257 struct cb_break_lineno
259 int lineno;
260 ADDRESS addr;
263 static BOOL CALLBACK line_cb(SRCCODEINFO* sci, void* user)
265 struct cb_break_lineno* bkln = user;
267 if (bkln->lineno == sci->LineNumber)
269 bkln->addr.Mode = AddrModeFlat;
270 bkln->addr.Offset = sci->Address;
271 return FALSE;
273 return TRUE;
276 /***********************************************************************
277 * break_add_break_from_lineno
279 * Add a breakpoint from a line number in current file
281 void break_add_break_from_lineno(int lineno)
283 struct cb_break_lineno bkln;
285 memory_get_current_pc(&bkln.addr);
287 if (lineno != -1)
289 IMAGEHLP_LINE il;
292 DWORD disp;
293 DWORD linear = (DWORD)memory_to_linear_addr(&bkln.addr);
295 il.SizeOfStruct = sizeof(il);
296 if (!SymGetLineFromAddr(dbg_curr_process->handle, linear, &disp, &il))
299 dbg_printf("Unable to add breakpoint (unknown address %lx)\n", linear);
300 return;
302 bkln.addr.Offset = 0;
303 bkln.lineno = lineno;
304 SymEnumLines(dbg_curr_process->handle, linear, NULL, il.FileName, line_cb, &bkln);
305 if (!bkln.addr.Offset)
307 dbg_printf("Unknown line number\n"
308 "(either out of file, or no code at given line number)\n");
309 return;
313 break_add_break(&bkln.addr, TRUE);
316 /***********************************************************************
317 * break_check_delayed_bp
319 * Check is a registered delayed BP is now available.
321 void break_check_delayed_bp(void)
323 struct dbg_lvalue lvalue;
324 int i;
325 struct dbg_delayed_bp* dbp = dbg_curr_process->delayed_bp;
327 for (i = 0; i < dbg_curr_process->num_delayed_bp; i++)
329 if (dbp[i].is_symbol)
331 if (symbol_get_lvalue(dbp[i].u.symbol.name, dbp[i].u.symbol.lineno,
332 &lvalue, TRUE) != sglv_found)
333 continue;
334 if (lvalue.cookie != DLV_TARGET) continue;
336 else
337 lvalue.addr = dbp[i].u.addr;
338 WINE_TRACE("trying to add delayed %s-bp\n", dbp[i].is_symbol ? "S" : "A");
339 if (!dbp[i].is_symbol)
340 WINE_TRACE("\t%04x:%08lx\n",
341 dbp[i].u.addr.Segment, dbp[i].u.addr.Offset);
342 else
343 WINE_TRACE("\t'%s' @ %d\n",
344 dbp[i].u.symbol.name, dbp[i].u.symbol.lineno);
346 if (break_add_break(&lvalue.addr, FALSE))
347 memmove(&dbp[i], &dbp[i+1], (--dbg_curr_process->num_delayed_bp - i) * sizeof(*dbp));
351 /***********************************************************************
352 * break_add_watch
354 * Add a watchpoint.
356 static void break_add_watch(const struct dbg_lvalue* lvalue, BOOL is_write)
358 int num;
359 DWORD64 l = 4;
361 num = init_xpoint((is_write) ? be_xpoint_watch_write : be_xpoint_watch_read,
362 &lvalue->addr);
363 if (num == -1) return;
365 if (lvalue->type.id != dbg_itype_none)
367 if (types_get_info(&lvalue->type, TI_GET_LENGTH, &l))
369 switch (l)
371 case 4: case 2: case 1: break;
372 default:
373 dbg_printf("Unsupported length (%s) for watch-points, defaulting to 4\n",
374 wine_dbgstr_longlong(l));
375 break;
378 else dbg_printf("Cannot get watch size, defaulting to 4\n");
380 dbg_curr_process->bp[num].w.len = (DWORD)l - 1;
382 if (!get_watched_value(num, &dbg_curr_process->bp[num].w.oldval))
384 dbg_printf("Bad address. Watchpoint not set\n");
385 dbg_curr_process->bp[num].refcount = 0;
386 return;
388 dbg_printf("Watchpoint %d at ", num);
389 print_address(&dbg_curr_process->bp[num].addr, TRUE);
390 dbg_printf("\n");
393 /******************************************************************
394 * break_add_watch_from_lvalue
396 * Adds a watch point from an address (stored in a lvalue)
398 void break_add_watch_from_lvalue(const struct dbg_lvalue* lvalue)
400 struct dbg_lvalue lval;
402 types_extract_as_address(lvalue, &lval.addr);
403 lval.type.id = dbg_itype_none;
405 break_add_watch(&lval, TRUE);
408 /***********************************************************************
409 * break_add_watch_from_id
411 * Add a watchpoint from a symbol name
413 void break_add_watch_from_id(const char *name)
415 struct dbg_lvalue lvalue;
417 switch (symbol_get_lvalue(name, -1, &lvalue, TRUE))
419 case sglv_found:
420 break_add_watch(&lvalue, 1);
421 break;
422 case sglv_unknown:
423 dbg_printf("Unable to add watchpoint\n");
424 break;
425 case sglv_aborted: /* user aborted symbol lookup */
426 break;
430 /***********************************************************************
431 * break_delete_xpoint
433 * Delete a breakpoint.
435 void break_delete_xpoint(int num)
437 struct dbg_breakpoint* bp = dbg_curr_process->bp;
439 if ((num <= 0) || (num >= dbg_curr_process->next_bp) ||
440 bp[num].refcount == 0)
442 dbg_printf("Invalid breakpoint number %d\n", num);
443 return;
446 if (--bp[num].refcount > 0)
447 return;
449 if (bp[num].condition != NULL)
451 expr_free(bp[num].condition);
452 bp[num].condition = NULL;
455 bp[num].enabled = FALSE;
456 bp[num].refcount = 0;
457 bp[num].skipcount = 0;
460 static inline BOOL module_is_container(const IMAGEHLP_MODULE* wmod_cntnr,
461 const IMAGEHLP_MODULE* wmod_child)
463 return wmod_cntnr->BaseOfImage <= wmod_child->BaseOfImage &&
464 (DWORD)wmod_cntnr->BaseOfImage + wmod_cntnr->ImageSize >=
465 (DWORD)wmod_child->BaseOfImage + wmod_child->ImageSize;
468 /******************************************************************
469 * break_delete_xpoints_from_module
471 * Remove all Xpoints from module which base is 'base'
473 void break_delete_xpoints_from_module(unsigned long base)
475 IMAGEHLP_MODULE im, im_elf;
476 int i;
477 DWORD linear;
478 struct dbg_breakpoint* bp = dbg_curr_process->bp;
480 /* FIXME: should do it also on the ELF sibbling if any */
481 im.SizeOfStruct = sizeof(im);
482 im_elf.SizeOfStruct = sizeof(im_elf);
483 if (!SymGetModuleInfo(dbg_curr_process->handle, base, &im)) return;
485 /* try to get in fact the underlying ELF module (if any) */
486 if (SymGetModuleInfo(dbg_curr_process->handle, im.BaseOfImage - 1, &im_elf) &&
487 im_elf.BaseOfImage <= im.BaseOfImage &&
488 (DWORD)im_elf.BaseOfImage + im_elf.ImageSize >= (DWORD)im.BaseOfImage + im.ImageSize)
489 im = im_elf;
491 for (i = 0; i < dbg_curr_process->next_bp; i++)
493 linear = (DWORD)memory_to_linear_addr(&bp[i].addr);
494 if (bp[i].refcount && bp[i].enabled &&
495 im.BaseOfImage <= linear && linear < im.BaseOfImage + im.ImageSize)
497 break_delete_xpoint(i);
502 /***********************************************************************
503 * break_enable_xpoint
505 * Enable or disable a break point.
507 void break_enable_xpoint(int num, BOOL enable)
509 if ((num <= 0) || (num >= dbg_curr_process->next_bp) ||
510 dbg_curr_process->bp[num].refcount == 0)
512 dbg_printf("Invalid breakpoint number %d\n", num);
513 return;
515 dbg_curr_process->bp[num].enabled = (enable) ? TRUE : FALSE;
516 dbg_curr_process->bp[num].skipcount = 0;
520 /***********************************************************************
521 * find_triggered_watch
523 * Lookup the watchpoints to see if one has been triggered
524 * Return >= (watch point index) if one is found and *oldval is set to
525 * the value watched before the TRAP
526 * Return -1 if none found (*oldval is undetermined)
528 * Unfortunately, Linux does *NOT* (A REAL PITA) report with ptrace
529 * the DR6 register value, so we have to look with our own need the
530 * cause of the TRAP.
531 * -EP
533 static int find_triggered_watch(LPDWORD oldval)
535 int found = -1;
536 int i;
537 struct dbg_breakpoint* bp = dbg_curr_process->bp;
539 /* Method 1 => get triggered watchpoint from context (doesn't work on Linux
540 * 2.2.x). This should be fixed in >= 2.2.16
542 for (i = 0; i < dbg_curr_process->next_bp; i++)
544 DWORD val = 0;
546 if (bp[i].refcount && bp[i].enabled && bp[i].xpoint_type != be_xpoint_break &&
547 (be_cpu->is_watchpoint_set(&dbg_context, bp[i].info)))
549 be_cpu->clear_watchpoint(&dbg_context, bp[i].info);
551 *oldval = bp[i].w.oldval;
552 if (get_watched_value(i, &val))
554 bp[i].w.oldval = val;
555 return i;
560 /* Method 1 failed, trying method 2 */
562 /* Method 2 => check if value has changed among registered watchpoints
563 * this really sucks, but this is how gdb 4.18 works on my linux box
564 * -EP
566 for (i = 0; i < dbg_curr_process->next_bp; i++)
568 DWORD val = 0;
570 if (bp[i].refcount && bp[i].enabled && bp[i].xpoint_type != be_xpoint_break &&
571 get_watched_value(i, &val))
573 *oldval = bp[i].w.oldval;
574 if (val != *oldval)
576 be_cpu->clear_watchpoint(&dbg_context, bp[i].info);
577 bp[i].w.oldval = val;
578 found = i;
579 /* cannot break, because two watch points may have been triggered on
580 * the same access
581 * only one will be reported to the user (FIXME ?)
586 return found;
589 /***********************************************************************
590 * break_info
592 * Display break & watch points information.
594 void break_info(void)
596 int i;
597 int nbp = 0, nwp = 0;
598 struct dbg_delayed_bp* dbp = dbg_curr_process->delayed_bp;
599 struct dbg_breakpoint* bp = dbg_curr_process->bp;
601 for (i = 1; i < dbg_curr_process->next_bp; i++)
603 if (bp[i].refcount)
605 if (bp[i].xpoint_type == be_xpoint_break) nbp++; else nwp++;
609 if (nbp)
611 dbg_printf("Breakpoints:\n");
612 for (i = 1; i < dbg_curr_process->next_bp; i++)
614 if (!bp[i].refcount || bp[i].xpoint_type != be_xpoint_break)
615 continue;
616 dbg_printf("%d: %c ", i, bp[i].enabled ? 'y' : 'n');
617 print_address(&bp[i].addr, TRUE);
618 dbg_printf(" (%u)\n", bp[i].refcount);
619 if (bp[i].condition != NULL)
621 dbg_printf("\t\tstop when ");
622 expr_print(bp[i].condition);
623 dbg_printf("\n");
627 else dbg_printf("No breakpoints\n");
628 if (nwp)
630 dbg_printf("Watchpoints:\n");
631 for (i = 1; i < dbg_curr_process->next_bp; i++)
633 if (!bp[i].refcount || bp[i].xpoint_type == be_xpoint_break)
634 continue;
635 dbg_printf("%d: %c ", i, bp[i].enabled ? 'y' : 'n');
636 print_address(&bp[i].addr, TRUE);
637 dbg_printf(" on %d byte%s (%c)\n",
638 bp[i].w.len + 1, bp[i].w.len > 0 ? "s" : "",
639 bp[i].xpoint_type == be_xpoint_watch_write ? 'W' : 'R');
640 if (bp[i].condition != NULL)
642 dbg_printf("\t\tstop when ");
643 expr_print(bp[i].condition);
644 dbg_printf("\n");
648 else dbg_printf("No watchpoints\n");
649 if (dbg_curr_process->num_delayed_bp)
651 dbg_printf("Delayed breakpoints:\n");
652 for (i = 0; i < dbg_curr_process->num_delayed_bp; i++)
654 if (dbp[i].is_symbol)
656 dbg_printf("%d: %s", i, dbp[i].u.symbol.name);
657 if (dbp[i].u.symbol.lineno != -1)
658 dbg_printf(" at line %u", dbp[i].u.symbol.lineno);
660 else
662 dbg_printf("%d: ", i);
663 print_address(&dbp[i].u.addr, FALSE);
665 dbg_printf("\n");
670 /***********************************************************************
671 * should_stop
673 * Check whether or not the condition (bp / skipcount) of a break/watch
674 * point are met.
676 static BOOL should_stop(int bpnum)
678 struct dbg_breakpoint* bp = &dbg_curr_process->bp[bpnum];
680 if (bp->condition != NULL)
682 struct dbg_lvalue lvalue = expr_eval(bp->condition);
684 if (lvalue.type.id == dbg_itype_none)
687 * Something wrong - unable to evaluate this expression.
689 dbg_printf("Unable to evaluate expression ");
690 expr_print(bp->condition);
691 dbg_printf("\nTurning off condition\n");
692 break_add_condition(bpnum, NULL);
694 else if (!types_extract_as_integer(&lvalue))
696 return FALSE;
700 if (bp->skipcount > 0) bp->skipcount--;
701 return bp->skipcount == 0;
704 /***********************************************************************
705 * break_should_continue
707 * Determine if we should continue execution after a SIGTRAP signal when
708 * executing in the given mode.
710 BOOL break_should_continue(ADDRESS* addr, DWORD code, int* count, BOOL* is_break)
712 int bpnum;
713 DWORD oldval = 0;
714 int wpnum;
715 enum dbg_exec_mode mode = dbg_curr_thread->exec_mode;
717 *is_break = FALSE;
718 /* If not single-stepping, back up to the break instruction */
719 if (code == EXCEPTION_BREAKPOINT)
720 addr->Offset += be_cpu->adjust_pc_for_break(&dbg_context, TRUE);
722 bpnum = find_xpoint(addr, be_xpoint_break);
723 dbg_curr_process->bp[0].enabled = FALSE; /* disable the step-over breakpoint */
725 if (bpnum > 0)
727 if (!should_stop(bpnum)) return TRUE;
729 dbg_printf("Stopped on breakpoint %d at ", bpnum);
730 print_address(&dbg_curr_process->bp[bpnum].addr, TRUE);
731 dbg_printf("\n");
732 return FALSE;
735 wpnum = find_triggered_watch(&oldval);
736 if (wpnum > 0)
738 /* If not single-stepping, do not back up over the break instruction */
739 if (code == EXCEPTION_BREAKPOINT)
740 addr->Offset += be_cpu->adjust_pc_for_break(&dbg_context, FALSE);
742 if (!should_stop(wpnum)) return TRUE;
744 dbg_printf("Stopped on watchpoint %d at ", wpnum);
745 print_address(addr, TRUE);
746 dbg_printf(" values: old=%lu new=%lu\n",
747 oldval, dbg_curr_process->bp[wpnum].w.oldval);
748 return FALSE;
752 * If our mode indicates that we are stepping line numbers,
753 * get the current function, and figure out if we are exactly
754 * on a line number or not.
756 if (mode == dbg_exec_step_over_line || mode == dbg_exec_step_into_line)
758 if (symbol_get_function_line_status(addr) == dbg_on_a_line_number)
760 (*count)--;
763 else if (mode == dbg_exec_step_over_insn || mode == dbg_exec_step_into_insn)
765 (*count)--;
768 if (*count > 0 || mode == dbg_exec_finish)
771 * We still need to execute more instructions.
773 return TRUE;
776 /* If there's no breakpoint and we are not single-stepping, then
777 * either we must have encountered a break insn in the Windows program
778 * or someone is trying to stop us
780 if (bpnum == -1 && code == EXCEPTION_BREAKPOINT)
782 *is_break = TRUE;
783 addr->Offset += be_cpu->adjust_pc_for_break(&dbg_context, FALSE);
784 return FALSE;
787 /* no breakpoint, continue if in continuous mode */
788 return mode == dbg_exec_cont || mode == dbg_exec_finish;
791 /***********************************************************************
792 * break_suspend_execution
794 * Remove all bp before entering the debug loop
796 void break_suspend_execution(void)
798 break_set_xpoints(FALSE);
799 dbg_curr_process->bp[0] = dbg_curr_thread->step_over_bp;
802 /***********************************************************************
803 * break_restart_execution
805 * Set the bp to the correct state to restart execution
806 * in the given mode.
808 void break_restart_execution(int count)
810 ADDRESS addr;
811 int bp;
812 enum dbg_line_status status;
813 enum dbg_exec_mode mode, ret_mode;
814 ADDRESS callee;
815 void* linear;
817 memory_get_current_pc(&addr);
818 linear = memory_to_linear_addr(&addr);
821 * This is the mode we will be running in after we finish. We would like
822 * to be able to modify this in certain cases.
824 ret_mode = mode = dbg_curr_thread->exec_mode;
826 bp = find_xpoint(&addr, be_xpoint_break);
827 if (bp != -1 && bp != 0)
830 * If we have set a new value, then save it in the BP number.
832 if (count != 0 && mode == dbg_exec_cont)
834 dbg_curr_process->bp[bp].skipcount = count;
836 mode = dbg_exec_step_into_insn; /* If there's a breakpoint, skip it */
838 else if (mode == dbg_exec_cont && count > 1)
840 dbg_printf("Not stopped at any breakpoint; argument ignored.\n");
843 if (mode == dbg_exec_finish && be_cpu->is_function_return(linear))
845 mode = ret_mode = dbg_exec_step_into_insn;
849 * See if the function we are stepping into has debug info
850 * and line numbers. If not, then we step over it instead.
851 * FIXME - we need to check for things like thunks or trampolines,
852 * as the actual function may in fact have debug info.
854 if (be_cpu->is_function_call(linear, &callee))
856 status = symbol_get_function_line_status(&callee);
857 #if 0
858 /* FIXME: we need to get the thunk type */
860 * Anytime we have a trampoline, step over it.
862 if ((mode == EXEC_STEP_OVER || mode == EXEC_STEPI_OVER)
863 && status == dbg_in_a_thunk)
865 WINE_WARN("Not stepping into trampoline at %p (no lines)\n",
866 memory_to_linear_addr(&callee));
867 mode = EXEC_STEP_OVER_TRAMPOLINE;
869 #endif
870 if (mode == dbg_exec_step_into_line && status == dbg_no_line_info)
872 WINE_WARN("Not stepping into function at %p (no lines)\n",
873 memory_to_linear_addr(&callee));
874 mode = dbg_exec_step_over_line;
878 if (mode == dbg_exec_step_into_line &&
879 symbol_get_function_line_status(&addr) == dbg_no_line_info)
881 dbg_printf("Single stepping until exit from function, \n"
882 "which has no line number information.\n");
883 ret_mode = mode = dbg_exec_finish;
886 switch (mode)
888 case dbg_exec_cont: /* Continuous execution */
889 be_cpu->single_step(&dbg_context, FALSE);
890 break_set_xpoints(TRUE);
891 break;
893 #if 0
894 case EXEC_STEP_OVER_TRAMPOLINE:
896 * This is the means by which we step over our conversion stubs
897 * in callfrom*.s and callto*.s. We dig the appropriate address
898 * off the stack, and we set the breakpoint there instead of the
899 * address just after the call.
901 be_cpu->get_addr(dbg_curr_thread->handle, &dbg_context,
902 be_cpu_addr_stack, &addr);
903 /* FIXME: we assume stack grows as on an i386 */
904 addr.Offset += 2 * sizeof(unsigned int);
905 dbg_read_memory(memory_to_linear_addr(&addr),
906 &addr.Offset, sizeof(addr.Offset));
907 dbg_curr_process->bp[0].addr = addr;
908 dbg_curr_process->bp[0].enabled = TRUE;
909 dbg_curr_process->bp[0].refcount = 1;
910 dbg_curr_process->bp[0].skipcount = 0;
911 dbg_curr_process->bp[0].xpoint_type = be_xpoint_break;
912 dbg_curr_process->bp[0].condition = NULL;
913 be_cpu->single_step(&dbg_context, FALSE);
914 break_set_xpoints(TRUE);
915 break;
916 #endif
918 case dbg_exec_finish:
919 case dbg_exec_step_over_insn: /* Stepping over a call */
920 case dbg_exec_step_over_line: /* Stepping over a call */
921 if (be_cpu->is_step_over_insn(linear))
923 be_cpu->disasm_one_insn(&addr, FALSE);
924 dbg_curr_process->bp[0].addr = addr;
925 dbg_curr_process->bp[0].enabled = TRUE;
926 dbg_curr_process->bp[0].refcount = 1;
927 dbg_curr_process->bp[0].skipcount = 0;
928 dbg_curr_process->bp[0].xpoint_type = be_xpoint_break;
929 dbg_curr_process->bp[0].condition = NULL;
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, NULL);
963 return TRUE;