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
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
29 static int is_xpoint_break(int bpnum)
31 int type = dbg_curr_process->bp[bpnum].xpoint_type;
33 if (type == be_xpoint_break || type == be_xpoint_watch_exec) return TRUE;
34 if (type == be_xpoint_watch_read || type == be_xpoint_watch_write) return FALSE;
35 RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
36 return 0; /* never reached */
39 /***********************************************************************
42 * Set or remove all the breakpoints & watchpoints
44 void break_set_xpoints(BOOL set)
46 static BOOL last; /* = 0 = FALSE */
48 unsigned int i, ret, size;
50 struct dbg_breakpoint* bp = dbg_curr_process->bp;
52 if (set == last) return;
55 for (i = 0; i < dbg_curr_process->next_bp; i++)
57 if (!bp[i].refcount || !bp[i].enabled) continue;
59 if (is_xpoint_break(i))
62 size = bp[i].w.len + 1;
63 addr = (void*)memory_to_linear_addr(&bp[i].addr);
66 ret = be_cpu->insert_Xpoint(dbg_curr_process->handle,
67 dbg_curr_process->process_io,
68 &dbg_context, bp[i].xpoint_type, addr,
71 ret = be_cpu->remove_Xpoint(dbg_curr_process->handle,
72 dbg_curr_process->process_io,
73 &dbg_context, bp[i].xpoint_type, addr,
77 dbg_printf("Invalid address (");
78 print_address(&bp[i].addr, FALSE);
79 dbg_printf(") for breakpoint %d, disabling it\n", i);
80 bp[i].enabled = FALSE;
85 /***********************************************************************
88 * Find the breakpoint for a given address. Return the breakpoint
89 * number or -1 if none.
91 static int find_xpoint(const ADDRESS64* addr, enum be_xpoint_type type)
94 void* lin = memory_to_linear_addr(addr);
95 struct dbg_breakpoint* bp = dbg_curr_process->bp;
97 for (i = 0; i < dbg_curr_process->next_bp; i++)
99 if (bp[i].refcount && bp[i].enabled && bp[i].xpoint_type == type &&
100 memory_to_linear_addr(&bp[i].addr) == lin)
106 /***********************************************************************
109 * Find an empty slot in BP table to add a new break/watch point
111 static int init_xpoint(int type, const ADDRESS64* addr)
114 struct dbg_breakpoint* bp = dbg_curr_process->bp;
116 for (num = (dbg_curr_process->next_bp < MAX_BREAKPOINTS) ?
117 dbg_curr_process->next_bp++ : 1;
118 num < MAX_BREAKPOINTS; num++)
120 if (bp[num].refcount == 0)
122 bp[num].refcount = 1;
123 bp[num].enabled = TRUE;
124 bp[num].xpoint_type = type;
125 bp[num].skipcount = 0;
126 bp[num].addr = *addr;
131 dbg_printf("Too many bp. Please delete some.\n");
135 /***********************************************************************
138 * Returns the value watched by watch point 'num'.
140 static BOOL get_watched_value(int num, LPDWORD val)
144 if (!dbg_read_memory(memory_to_linear_addr(&dbg_curr_process->bp[num].addr),
145 buf, dbg_curr_process->bp[num].w.len + 1))
148 switch (dbg_curr_process->bp[num].w.len + 1)
150 case 4: *val = *(DWORD*)buf; break;
151 case 2: *val = *(WORD*)buf; break;
152 case 1: *val = *(BYTE*)buf; break;
153 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
158 /***********************************************************************
163 BOOL break_add_break(const ADDRESS64* addr, BOOL verbose, BOOL swbp)
167 struct dbg_breakpoint* bp = dbg_curr_process->bp;
168 int type = swbp ? be_xpoint_break : be_xpoint_watch_exec;
170 if ((num = find_xpoint(addr, type)) >= 1)
173 dbg_printf("Breakpoint %d at ", num);
174 print_address(&bp[num].addr, TRUE);
175 dbg_printf(" (refcount=%d)\n", bp[num].refcount);
179 if (!dbg_read_memory(memory_to_linear_addr(addr), &ch, sizeof(ch)))
183 dbg_printf("Invalid address ");
184 print_bare_address(addr);
185 dbg_printf(", can't set breakpoint\n");
190 if ((num = init_xpoint(type, addr)) == -1)
193 dbg_printf("Breakpoint %d at ", num);
194 print_address(&bp[num].addr, TRUE);
200 /***********************************************************************
201 * break_add_break_from_lvalue
205 BOOL break_add_break_from_lvalue(const struct dbg_lvalue* lvalue, BOOL swbp)
209 types_extract_as_address(lvalue, &addr);
211 if (!break_add_break(&addr, TRUE, swbp))
213 if (!DBG_IVAR(CanDeferOnBPByAddr))
215 dbg_printf("Invalid address, can't set breakpoint\n"
216 "You can turn on deferring bp by address by setting $CanDeferOnBPByAddr to 1\n");
219 dbg_printf("Unable to add breakpoint, will check again any time a new DLL is loaded\n");
220 dbg_curr_process->delayed_bp =
221 dbg_heap_realloc(dbg_curr_process->delayed_bp,
222 sizeof(struct dbg_delayed_bp) * ++dbg_curr_process->num_delayed_bp);
224 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].is_symbol = FALSE;
225 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].software_bp = swbp;
226 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.addr = addr;
232 /***********************************************************************
233 * break_add_break_from_id
235 * Add a breakpoint from a function name (and eventually a line #)
237 void break_add_break_from_id(const char *name, int lineno, BOOL swbp)
239 struct dbg_lvalue lvalue;
242 switch (symbol_get_lvalue(name, lineno, &lvalue, TRUE))
245 break_add_break(&lvalue.addr, TRUE, swbp);
249 case sglv_aborted: /* user aborted symbol lookup */
253 dbg_printf("Unable to add breakpoint, will check again when a new DLL is loaded\n");
254 for (i = 0; i < dbg_curr_process->num_delayed_bp; i++)
256 if (dbg_curr_process->delayed_bp[i].is_symbol &&
257 !strcmp(name, dbg_curr_process->delayed_bp[i].u.symbol.name) &&
258 lineno == dbg_curr_process->delayed_bp[i].u.symbol.lineno)
261 dbg_curr_process->delayed_bp = dbg_heap_realloc(dbg_curr_process->delayed_bp,
262 sizeof(struct dbg_delayed_bp) * ++dbg_curr_process->num_delayed_bp);
264 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].is_symbol = TRUE;
265 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].software_bp = swbp;
266 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.symbol.name = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(name) + 1), name);
267 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.symbol.lineno = lineno;
270 struct cb_break_lineno
276 static BOOL CALLBACK line_cb(SRCCODEINFO* sci, void* user)
278 struct cb_break_lineno* bkln = user;
280 if (bkln->lineno == sci->LineNumber)
282 bkln->addr.Mode = AddrModeFlat;
283 bkln->addr.Offset = sci->Address;
289 /***********************************************************************
290 * break_add_break_from_lineno
292 * Add a breakpoint from a line number in current file
294 void break_add_break_from_lineno(int lineno, BOOL swbp)
296 struct cb_break_lineno bkln;
298 memory_get_current_pc(&bkln.addr);
306 DWORD linear = (DWORD)memory_to_linear_addr(&bkln.addr);
308 il.SizeOfStruct = sizeof(il);
309 if (!SymGetLineFromAddr(dbg_curr_process->handle, linear, &disp, &il))
312 dbg_printf("Unable to add breakpoint (unknown address %lx)\n", linear);
315 bkln.addr.Offset = 0;
316 bkln.lineno = lineno;
317 SymEnumLines(dbg_curr_process->handle, linear, NULL, il.FileName, line_cb, &bkln);
318 if (!bkln.addr.Offset)
320 dbg_printf("Unknown line number\n"
321 "(either out of file, or no code at given line number)\n");
326 break_add_break(&bkln.addr, TRUE, swbp);
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;
338 struct dbg_delayed_bp* dbp = dbg_curr_process->delayed_bp;
339 char hexbuf[MAX_OFFSET_TO_STR_LEN];
341 for (i = 0; i < dbg_curr_process->num_delayed_bp; i++)
343 if (dbp[i].is_symbol)
345 if (symbol_get_lvalue(dbp[i].u.symbol.name, dbp[i].u.symbol.lineno,
346 &lvalue, TRUE) != sglv_found)
348 if (lvalue.cookie != DLV_TARGET) continue;
351 lvalue.addr = dbp[i].u.addr;
352 WINE_TRACE("trying to add delayed %s-bp\n", dbp[i].is_symbol ? "S" : "A");
353 if (!dbp[i].is_symbol)
354 WINE_TRACE("\t%04x:%s\n",
355 dbp[i].u.addr.Segment,
356 memory_offset_to_string(hexbuf, dbp[i].u.addr.Offset, 0));
358 WINE_TRACE("\t'%s' @ %d\n",
359 dbp[i].u.symbol.name, dbp[i].u.symbol.lineno);
361 if (break_add_break(&lvalue.addr, FALSE, dbp[i].software_bp))
362 memmove(&dbp[i], &dbp[i+1], (--dbg_curr_process->num_delayed_bp - i) * sizeof(*dbp));
366 /***********************************************************************
371 static void break_add_watch(const struct dbg_lvalue* lvalue, BOOL is_write)
376 num = init_xpoint((is_write) ? be_xpoint_watch_write : be_xpoint_watch_read,
378 if (num == -1) return;
380 if (lvalue->type.id != dbg_itype_none)
382 if (types_get_info(&lvalue->type, TI_GET_LENGTH, &l))
386 case 4: case 2: case 1: break;
388 dbg_printf("Unsupported length (%s) for watch-points, defaulting to 4\n",
389 wine_dbgstr_longlong(l));
393 else dbg_printf("Cannot get watch size, defaulting to 4\n");
395 dbg_curr_process->bp[num].w.len = (DWORD)l - 1;
397 if (!get_watched_value(num, &dbg_curr_process->bp[num].w.oldval))
399 dbg_printf("Bad address. Watchpoint not set\n");
400 dbg_curr_process->bp[num].refcount = 0;
403 dbg_printf("Watchpoint %d at ", num);
404 print_address(&dbg_curr_process->bp[num].addr, TRUE);
408 /******************************************************************
409 * break_add_watch_from_lvalue
411 * Adds a watch point from an address (stored in a lvalue)
413 void break_add_watch_from_lvalue(const struct dbg_lvalue* lvalue)
415 struct dbg_lvalue lval;
417 types_extract_as_address(lvalue, &lval.addr);
418 lval.type.id = dbg_itype_none;
420 break_add_watch(&lval, TRUE);
423 /***********************************************************************
424 * break_add_watch_from_id
426 * Add a watchpoint from a symbol name
428 void break_add_watch_from_id(const char *name)
430 struct dbg_lvalue lvalue;
432 switch (symbol_get_lvalue(name, -1, &lvalue, TRUE))
435 break_add_watch(&lvalue, 1);
438 dbg_printf("Unable to add watchpoint\n");
440 case sglv_aborted: /* user aborted symbol lookup */
445 /***********************************************************************
446 * break_delete_xpoint
448 * Delete a breakpoint.
450 void break_delete_xpoint(int num)
452 struct dbg_breakpoint* bp = dbg_curr_process->bp;
454 if ((num <= 0) || (num >= dbg_curr_process->next_bp) ||
455 bp[num].refcount == 0)
457 dbg_printf("Invalid breakpoint number %d\n", num);
461 if (--bp[num].refcount > 0)
464 if (bp[num].condition != NULL)
466 expr_free(bp[num].condition);
467 bp[num].condition = NULL;
470 bp[num].enabled = FALSE;
471 bp[num].refcount = 0;
472 bp[num].skipcount = 0;
475 static inline BOOL module_is_container(const IMAGEHLP_MODULE* wmod_cntnr,
476 const IMAGEHLP_MODULE* wmod_child)
478 return wmod_cntnr->BaseOfImage <= wmod_child->BaseOfImage &&
479 (DWORD)wmod_cntnr->BaseOfImage + wmod_cntnr->ImageSize >=
480 (DWORD)wmod_child->BaseOfImage + wmod_child->ImageSize;
483 /******************************************************************
484 * break_delete_xpoints_from_module
486 * Remove all Xpoints from module which base is 'base'
488 void break_delete_xpoints_from_module(unsigned long base)
490 IMAGEHLP_MODULE im, im_elf;
493 struct dbg_breakpoint* bp = dbg_curr_process->bp;
495 /* FIXME: should do it also on the ELF sibbling if any */
496 im.SizeOfStruct = sizeof(im);
497 im_elf.SizeOfStruct = sizeof(im_elf);
498 if (!SymGetModuleInfo(dbg_curr_process->handle, base, &im)) return;
500 /* try to get in fact the underlying ELF module (if any) */
501 if (SymGetModuleInfo(dbg_curr_process->handle, im.BaseOfImage - 1, &im_elf) &&
502 im_elf.BaseOfImage <= im.BaseOfImage &&
503 (DWORD)im_elf.BaseOfImage + im_elf.ImageSize >= (DWORD)im.BaseOfImage + im.ImageSize)
506 for (i = 0; i < dbg_curr_process->next_bp; i++)
508 linear = (DWORD)memory_to_linear_addr(&bp[i].addr);
509 if (bp[i].refcount && bp[i].enabled &&
510 im.BaseOfImage <= linear && linear < im.BaseOfImage + im.ImageSize)
512 break_delete_xpoint(i);
517 /***********************************************************************
518 * break_enable_xpoint
520 * Enable or disable a break point.
522 void break_enable_xpoint(int num, BOOL enable)
524 if ((num <= 0) || (num >= dbg_curr_process->next_bp) ||
525 dbg_curr_process->bp[num].refcount == 0)
527 dbg_printf("Invalid breakpoint number %d\n", num);
530 dbg_curr_process->bp[num].enabled = (enable) ? TRUE : FALSE;
531 dbg_curr_process->bp[num].skipcount = 0;
535 /***********************************************************************
536 * find_triggered_watch
538 * Lookup the watchpoints to see if one has been triggered
539 * Return >= (watch point index) if one is found and *oldval is set to
540 * the value watched before the TRAP
541 * Return -1 if none found (*oldval is undetermined)
543 * Unfortunately, Linux does *NOT* (A REAL PITA) report with ptrace
544 * the DR6 register value, so we have to look with our own need the
548 static int find_triggered_watch(LPDWORD oldval)
552 struct dbg_breakpoint* bp = dbg_curr_process->bp;
554 /* Method 1 => get triggered watchpoint from context (doesn't work on Linux
555 * 2.2.x). This should be fixed in >= 2.2.16
557 for (i = 0; i < dbg_curr_process->next_bp; i++)
561 if (bp[i].refcount && bp[i].enabled && !is_xpoint_break(i) &&
562 (be_cpu->is_watchpoint_set(&dbg_context, bp[i].info)))
564 be_cpu->clear_watchpoint(&dbg_context, bp[i].info);
566 *oldval = bp[i].w.oldval;
567 if (get_watched_value(i, &val))
569 bp[i].w.oldval = val;
575 /* Method 1 failed, trying method 2 */
577 /* Method 2 => check if value has changed among registered watchpoints
578 * this really sucks, but this is how gdb 4.18 works on my linux box
581 for (i = 0; i < dbg_curr_process->next_bp; i++)
585 if (bp[i].refcount && bp[i].enabled && !is_xpoint_break(i) &&
586 get_watched_value(i, &val))
588 *oldval = bp[i].w.oldval;
591 be_cpu->clear_watchpoint(&dbg_context, bp[i].info);
592 bp[i].w.oldval = val;
594 /* cannot break, because two watch points may have been triggered on
596 * only one will be reported to the user (FIXME ?)
604 /***********************************************************************
607 * Display break & watch points information.
609 void break_info(void)
612 int nbp = 0, nwp = 0;
613 struct dbg_delayed_bp* dbp = dbg_curr_process->delayed_bp;
614 struct dbg_breakpoint* bp = dbg_curr_process->bp;
616 for (i = 1; i < dbg_curr_process->next_bp; i++)
620 if (is_xpoint_break(i)) nbp++; else nwp++;
626 dbg_printf("Breakpoints:\n");
627 for (i = 1; i < dbg_curr_process->next_bp; i++)
629 if (!bp[i].refcount || !is_xpoint_break(i))
631 dbg_printf("%d: %c ", i, bp[i].enabled ? 'y' : 'n');
632 print_address(&bp[i].addr, TRUE);
633 dbg_printf(" (%u)%s\n", bp[i].refcount,
634 bp[i].xpoint_type == be_xpoint_watch_exec ? " (hardware assisted)" : "");
635 if (bp[i].condition != NULL)
637 dbg_printf("\t\tstop when ");
638 expr_print(bp[i].condition);
643 else dbg_printf("No breakpoints\n");
646 dbg_printf("Watchpoints:\n");
647 for (i = 1; i < dbg_curr_process->next_bp; i++)
649 if (!bp[i].refcount || is_xpoint_break(i))
651 dbg_printf("%d: %c ", i, bp[i].enabled ? 'y' : 'n');
652 print_address(&bp[i].addr, TRUE);
653 dbg_printf(" on %d byte%s (%c)\n",
654 bp[i].w.len + 1, bp[i].w.len > 0 ? "s" : "",
655 bp[i].xpoint_type == be_xpoint_watch_write ? 'W' : 'R');
656 if (bp[i].condition != NULL)
658 dbg_printf("\t\tstop when ");
659 expr_print(bp[i].condition);
664 else dbg_printf("No watchpoints\n");
665 if (dbg_curr_process->num_delayed_bp)
667 dbg_printf("Delayed breakpoints:\n");
668 for (i = 0; i < dbg_curr_process->num_delayed_bp; i++)
670 if (dbp[i].is_symbol)
672 dbg_printf("%d: %s", i, dbp[i].u.symbol.name);
673 if (dbp[i].u.symbol.lineno != -1)
674 dbg_printf(" at line %u", dbp[i].u.symbol.lineno);
678 dbg_printf("%d: ", i);
679 print_address(&dbp[i].u.addr, FALSE);
686 /***********************************************************************
689 * Check whether or not the condition (bp / skipcount) of a break/watch
692 static BOOL should_stop(int bpnum)
694 struct dbg_breakpoint* bp = &dbg_curr_process->bp[bpnum];
696 if (bp->condition != NULL)
698 struct dbg_lvalue lvalue = expr_eval(bp->condition);
700 if (lvalue.type.id == dbg_itype_none)
703 * Something wrong - unable to evaluate this expression.
705 dbg_printf("Unable to evaluate expression ");
706 expr_print(bp->condition);
707 dbg_printf("\nTurning off condition\n");
708 break_add_condition(bpnum, NULL);
710 else if (!types_extract_as_integer(&lvalue))
716 if (bp->skipcount > 0) bp->skipcount--;
717 return bp->skipcount == 0;
720 /***********************************************************************
721 * break_should_continue
723 * Determine if we should continue execution after a SIGTRAP signal when
724 * executing in the given mode.
726 BOOL break_should_continue(ADDRESS64* addr, DWORD code)
729 enum dbg_exec_mode mode = dbg_curr_thread->exec_mode;
732 if (dbg_curr_thread->stopped_xpoint > 0)
734 if (!should_stop(dbg_curr_thread->stopped_xpoint)) return TRUE;
736 switch (dbg_curr_process->bp[dbg_curr_thread->stopped_xpoint].xpoint_type)
738 case be_xpoint_break:
739 case be_xpoint_watch_exec:
740 dbg_printf("Stopped on breakpoint %d at ", dbg_curr_thread->stopped_xpoint);
741 print_address(&dbg_curr_process->bp[dbg_curr_thread->stopped_xpoint].addr, TRUE);
744 case be_xpoint_watch_read:
745 case be_xpoint_watch_write:
746 dbg_printf("Stopped on watchpoint %d at ", dbg_curr_thread->stopped_xpoint);
747 print_address(addr, TRUE);
748 dbg_printf(" values: old=%lu new=%lu\n",
749 oldval, dbg_curr_process->bp[dbg_curr_thread->stopped_xpoint].w.oldval);
755 * If our mode indicates that we are stepping line numbers,
756 * get the current function, and figure out if we are exactly
757 * on a line number or not.
759 if (mode == dbg_exec_step_over_line || mode == dbg_exec_step_into_line)
761 if (symbol_get_function_line_status(addr) == dbg_on_a_line_number)
762 dbg_curr_thread->exec_count--;
764 else if (mode == dbg_exec_step_over_insn || mode == dbg_exec_step_into_insn)
765 dbg_curr_thread->exec_count--;
767 if (dbg_curr_thread->exec_count > 0 || mode == dbg_exec_finish)
770 * We still need to execute more instructions.
775 /* no breakpoint, continue if in continuous mode */
776 return mode == dbg_exec_cont || mode == dbg_exec_finish;
779 /***********************************************************************
782 * Adjust PC to the address where the trap (if any) actually occured
783 * Also sets dbg_curr_thread->stopped_xpoint
785 void break_adjust_pc(ADDRESS64* addr, DWORD code, BOOL* is_break)
791 /* If not single-stepping, back up to the break instruction */
792 if (code == EXCEPTION_BREAKPOINT)
793 addr->Offset += be_cpu->adjust_pc_for_break(&dbg_context, TRUE);
795 dbg_curr_thread->stopped_xpoint = find_xpoint(addr, be_xpoint_break);
796 dbg_curr_process->bp[0].enabled = FALSE; /* disable the step-over breakpoint */
798 if (dbg_curr_thread->stopped_xpoint > 0) return;
800 if (dbg_curr_thread->stopped_xpoint < 0)
802 dbg_curr_thread->stopped_xpoint = find_xpoint(addr, be_xpoint_watch_exec);
803 if (dbg_curr_thread->stopped_xpoint < 0)
804 dbg_curr_thread->stopped_xpoint = find_triggered_watch(&oldval);
805 if (dbg_curr_thread->stopped_xpoint > 0)
807 /* If not single-stepping, do not back up over the break instruction */
808 if (code == EXCEPTION_BREAKPOINT)
809 addr->Offset += be_cpu->adjust_pc_for_break(&dbg_context, FALSE);
814 /* If there's no breakpoint and we are not single-stepping, then
815 * either we must have encountered a break insn in the Windows program
816 * or someone is trying to stop us
818 if (dbg_curr_thread->stopped_xpoint == -1 && code == EXCEPTION_BREAKPOINT)
821 addr->Offset += be_cpu->adjust_pc_for_break(&dbg_context, FALSE);
825 /***********************************************************************
826 * break_suspend_execution
828 * Remove all bp before entering the debug loop
830 void break_suspend_execution(void)
832 break_set_xpoints(FALSE);
833 dbg_curr_process->bp[0] = dbg_curr_thread->step_over_bp;
836 /***********************************************************************
837 * break_restart_execution
839 * Set the bp to the correct state to restart execution
842 void break_restart_execution(int count)
845 enum dbg_line_status status;
846 enum dbg_exec_mode mode, ret_mode;
850 memory_get_current_pc(&addr);
851 linear = memory_to_linear_addr(&addr);
854 * This is the mode we will be running in after we finish. We would like
855 * to be able to modify this in certain cases.
857 ret_mode = mode = dbg_curr_thread->exec_mode;
859 /* we've stopped on a xpoint (other than step over) */
860 if (dbg_curr_thread->stopped_xpoint > 0)
863 * If we have set a new value, then save it in the BP number.
865 if (count != 0 && mode == dbg_exec_cont)
867 dbg_curr_process->bp[dbg_curr_thread->stopped_xpoint].skipcount = count;
869 /* If we've stopped on a breakpoint, single step over it (, then run) */
870 if (is_xpoint_break(dbg_curr_thread->stopped_xpoint))
871 mode = dbg_exec_step_into_insn;
873 else if (mode == dbg_exec_cont && count > 1)
875 dbg_printf("Not stopped at any breakpoint; argument ignored.\n");
878 if (mode == dbg_exec_finish && be_cpu->is_function_return(linear))
880 mode = ret_mode = dbg_exec_step_into_insn;
884 * See if the function we are stepping into has debug info
885 * and line numbers. If not, then we step over it instead.
886 * FIXME - we need to check for things like thunks or trampolines,
887 * as the actual function may in fact have debug info.
889 if (be_cpu->is_function_call(linear, &callee))
891 status = symbol_get_function_line_status(&callee);
893 /* FIXME: we need to get the thunk type */
895 * Anytime we have a trampoline, step over it.
897 if ((mode == EXEC_STEP_OVER || mode == EXEC_STEPI_OVER)
898 && status == dbg_in_a_thunk)
900 WINE_WARN("Not stepping into trampoline at %p (no lines)\n",
901 memory_to_linear_addr(&callee));
902 mode = EXEC_STEP_OVER_TRAMPOLINE;
905 if (mode == dbg_exec_step_into_line && status == dbg_no_line_info)
907 WINE_WARN("Not stepping into function at %p (no lines)\n",
908 memory_to_linear_addr(&callee));
909 mode = dbg_exec_step_over_line;
913 if (mode == dbg_exec_step_into_line &&
914 symbol_get_function_line_status(&addr) == dbg_no_line_info)
916 dbg_printf("Single stepping until exit from function, \n"
917 "which has no line number information.\n");
918 ret_mode = mode = dbg_exec_finish;
923 case dbg_exec_cont: /* Continuous execution */
924 be_cpu->single_step(&dbg_context, FALSE);
925 break_set_xpoints(TRUE);
929 case EXEC_STEP_OVER_TRAMPOLINE:
931 * This is the means by which we step over our conversion stubs
932 * in callfrom*.s and callto*.s. We dig the appropriate address
933 * off the stack, and we set the breakpoint there instead of the
934 * address just after the call.
936 be_cpu->get_addr(dbg_curr_thread->handle, &dbg_context,
937 be_cpu_addr_stack, &addr);
938 /* FIXME: we assume stack grows as on an i386 */
939 addr.Offset += 2 * sizeof(unsigned int);
940 dbg_read_memory(memory_to_linear_addr(&addr),
941 &addr.Offset, sizeof(addr.Offset));
942 dbg_curr_process->bp[0].addr = addr;
943 dbg_curr_process->bp[0].enabled = TRUE;
944 dbg_curr_process->bp[0].refcount = 1;
945 dbg_curr_process->bp[0].skipcount = 0;
946 dbg_curr_process->bp[0].xpoint_type = be_xpoint_break;
947 dbg_curr_process->bp[0].condition = NULL;
948 be_cpu->single_step(&dbg_context, FALSE);
949 break_set_xpoints(TRUE);
953 case dbg_exec_finish:
954 case dbg_exec_step_over_insn: /* Stepping over a call */
955 case dbg_exec_step_over_line: /* Stepping over a call */
956 if (be_cpu->is_step_over_insn(linear))
958 be_cpu->disasm_one_insn(&addr, FALSE);
959 dbg_curr_process->bp[0].addr = addr;
960 dbg_curr_process->bp[0].enabled = TRUE;
961 dbg_curr_process->bp[0].refcount = 1;
962 dbg_curr_process->bp[0].skipcount = 0;
963 dbg_curr_process->bp[0].xpoint_type = be_xpoint_break;
964 dbg_curr_process->bp[0].condition = NULL;
965 be_cpu->single_step(&dbg_context, FALSE);
966 break_set_xpoints(TRUE);
969 /* else fall through to single-stepping */
971 case dbg_exec_step_into_line: /* Single-stepping a line */
972 case dbg_exec_step_into_insn: /* Single-stepping an instruction */
973 be_cpu->single_step(&dbg_context, TRUE);
975 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
977 dbg_curr_thread->step_over_bp = dbg_curr_process->bp[0];
978 dbg_curr_thread->exec_mode = ret_mode;
981 int break_add_condition(int num, struct expr* exp)
983 if (num <= 0 || num >= dbg_curr_process->next_bp ||
984 !dbg_curr_process->bp[num].refcount)
986 dbg_printf("Invalid breakpoint number %d\n", num);
990 if (dbg_curr_process->bp[num].condition != NULL)
992 expr_free(dbg_curr_process->bp[num].condition);
993 dbg_curr_process->bp[num].condition = NULL;
996 if (exp != NULL) dbg_curr_process->bp[num].condition = expr_clone(exp, NULL);