wined3d: Return the map pitch in wined3d_device_context_map().
[wine.git] / programs / winedbg / break.c
blob2896c179067a45ff7808f77faad53b469578f1ad
1 /*
2 * Debugger break-points handling
4 * Copyright 1994 Martin von Loewis
5 * Copyright 1995 Alexandre Julliard
6 * Copyright 1999,2000 Eric Pouech
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
24 #include "debugger.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
29 static BOOL 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 FALSE; /* never reached */
39 /***********************************************************************
40 * break_set_xpoints
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;
49 void* addr;
50 struct dbg_breakpoint* bp = dbg_curr_process->bp;
52 if (set == last) return;
53 last = set;
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))
60 size = 0;
61 else
62 size = bp[i].w.len + 1;
63 addr = memory_to_linear_addr(&bp[i].addr);
65 if (set)
66 ret = dbg_curr_process->be_cpu->insert_Xpoint(dbg_curr_process->handle,
67 dbg_curr_process->process_io, &dbg_context, bp[i].xpoint_type,
68 addr, &bp[i].info, size);
69 else
70 ret = dbg_curr_process->be_cpu->remove_Xpoint(dbg_curr_process->handle,
71 dbg_curr_process->process_io, &dbg_context, bp[i].xpoint_type,
72 addr, bp[i].info, size);
73 if (!ret)
75 dbg_printf("Invalid address (");
76 print_address(&bp[i].addr, FALSE);
77 dbg_printf(") for breakpoint %d, disabling it\n", i);
78 bp[i].enabled = FALSE;
83 /***********************************************************************
84 * find_xpoint
86 * Find the breakpoint for a given address. Return the breakpoint
87 * number or -1 if none.
89 static int find_xpoint(const ADDRESS64* addr, enum be_xpoint_type type)
91 int i;
92 void* lin = memory_to_linear_addr(addr);
93 struct dbg_breakpoint* bp = dbg_curr_process->bp;
95 for (i = 0; i < dbg_curr_process->next_bp; i++)
97 if (bp[i].refcount && bp[i].enabled && bp[i].xpoint_type == type &&
98 memory_to_linear_addr(&bp[i].addr) == lin)
99 return i;
101 return -1;
104 /***********************************************************************
105 * init_xpoint
107 * Find an empty slot in BP table to add a new break/watch point
109 static int init_xpoint(int type, const ADDRESS64* addr)
111 int num;
112 struct dbg_breakpoint* bp = dbg_curr_process->bp;
114 for (num = (dbg_curr_process->next_bp < MAX_BREAKPOINTS) ?
115 dbg_curr_process->next_bp++ : 1;
116 num < MAX_BREAKPOINTS; num++)
118 if (bp[num].refcount == 0)
120 bp[num].refcount = 1;
121 bp[num].enabled = TRUE;
122 bp[num].xpoint_type = type;
123 bp[num].skipcount = 0;
124 bp[num].addr = *addr;
125 return num;
129 dbg_printf("Too many bp. Please delete some.\n");
130 return -1;
133 /***********************************************************************
134 * get_watched_value
136 * Returns the value watched by watch point 'num'.
138 static BOOL get_watched_value(int num, DWORD64* val)
140 DWORD64 buf[1];
142 if (!dbg_read_memory(memory_to_linear_addr(&dbg_curr_process->bp[num].addr),
143 buf, dbg_curr_process->bp[num].w.len + 1))
144 return FALSE;
146 switch (dbg_curr_process->bp[num].w.len + 1)
148 case 8: *val = *(DWORD64*)buf; break;
149 case 4: *val = *(DWORD*)buf; break;
150 case 2: *val = *(WORD*)buf; break;
151 case 1: *val = *(BYTE*)buf; break;
152 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
154 return TRUE;
157 /***********************************************************************
158 * break_add_break
160 * Add a breakpoint.
162 BOOL break_add_break(const ADDRESS64* addr, BOOL verbose, BOOL swbp)
164 int num;
165 BYTE ch;
166 struct dbg_breakpoint* bp = dbg_curr_process->bp;
167 int type = swbp ? be_xpoint_break : be_xpoint_watch_exec;
169 if ((num = find_xpoint(addr, type)) >= 1)
171 bp[num].refcount++;
172 dbg_printf("Breakpoint %d at ", num);
173 print_address(&bp[num].addr, TRUE);
174 dbg_printf(" (refcount=%d)\n", bp[num].refcount);
175 return TRUE;
178 if (!dbg_read_memory(memory_to_linear_addr(addr), &ch, sizeof(ch)))
180 if (verbose)
182 dbg_printf("Invalid address ");
183 print_bare_address(addr);
184 dbg_printf(", can't set breakpoint\n");
186 return FALSE;
189 if ((num = init_xpoint(type, addr)) == -1)
190 return FALSE;
192 dbg_printf("Breakpoint %d at ", num);
193 print_address(&bp[num].addr, TRUE);
194 dbg_printf("\n");
196 return TRUE;
199 /***********************************************************************
200 * break_add_break_from_lvalue
202 * Add a breakpoint.
204 BOOL break_add_break_from_lvalue(const struct dbg_lvalue* lvalue, BOOL swbp)
206 ADDRESS64 addr;
208 types_extract_as_address(lvalue, &addr);
210 if (!break_add_break(&addr, TRUE, swbp))
212 if (!DBG_IVAR(CanDeferOnBPByAddr))
214 dbg_printf("Invalid address, can't set breakpoint\n"
215 "You can turn on deferring bp by address by setting $CanDeferOnBPByAddr to 1\n");
216 return FALSE;
218 dbg_printf("Unable to add breakpoint, will check again any time a new DLL is loaded\n");
219 dbg_curr_process->delayed_bp =
220 dbg_heap_realloc(dbg_curr_process->delayed_bp,
221 sizeof(struct dbg_delayed_bp) * ++dbg_curr_process->num_delayed_bp);
223 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].is_symbol = FALSE;
224 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].software_bp = swbp;
225 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.addr = addr;
226 return TRUE;
228 return FALSE;
231 /***********************************************************************
232 * break_add_break_from_id
234 * Add a breakpoint from a function name (and eventually a line #)
236 void break_add_break_from_id(const char *name, int lineno, BOOL swbp)
238 struct dbg_lvalue lvalue;
239 int i;
241 switch (symbol_get_lvalue(name, lineno, &lvalue, TRUE))
243 case sglv_found:
244 break_add_break(&lvalue.addr, TRUE, swbp);
245 return;
246 case sglv_unknown:
247 break;
248 case sglv_aborted: /* user aborted symbol lookup */
249 return;
252 dbg_printf("Unable to add breakpoint, will check again when a new DLL is loaded\n");
253 for (i = 0; i < dbg_curr_process->num_delayed_bp; i++)
255 if (dbg_curr_process->delayed_bp[i].is_symbol &&
256 !strcmp(name, dbg_curr_process->delayed_bp[i].u.symbol.name) &&
257 lineno == dbg_curr_process->delayed_bp[i].u.symbol.lineno)
258 return;
260 dbg_curr_process->delayed_bp = dbg_heap_realloc(dbg_curr_process->delayed_bp,
261 sizeof(struct dbg_delayed_bp) * ++dbg_curr_process->num_delayed_bp);
263 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].is_symbol = TRUE;
264 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].software_bp = swbp;
265 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.symbol.name = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(name) + 1), name);
266 dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.symbol.lineno = lineno;
269 struct cb_break_lineno
271 const char* filename;
272 int lineno;
273 ADDRESS64 addr;
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;
284 return FALSE;
286 return TRUE;
289 static BOOL CALLBACK mcb(PCWSTR module, DWORD64 base, void* user)
291 struct cb_break_lineno* bkln = user;
293 SymEnumLines(dbg_curr_process->handle, base, NULL, bkln->filename, line_cb, bkln);
294 /* continue module enum if no addr found
295 * FIXME: we don't report when several addresses match the same filename/lineno pair
297 return !bkln->addr.Offset;
300 /***********************************************************************
301 * break_add_break_from_lineno
303 * Add a breakpoint from a line number in current file
305 void break_add_break_from_lineno(const char *filename, int lineno, BOOL swbp)
307 struct cb_break_lineno bkln;
308 bkln.addr.Offset = 0;
309 bkln.lineno = lineno;
311 if (!filename)
313 DWORD disp;
314 ADDRESS64 curr;
315 IMAGEHLP_LINE64 il;
316 DWORD_PTR linear;
318 memory_get_current_pc(&curr);
319 linear = (DWORD_PTR)memory_to_linear_addr(&curr);
320 il.SizeOfStruct = sizeof(il);
321 if (!SymGetLineFromAddr64(dbg_curr_process->handle, linear, &disp, &il))
323 dbg_printf("Unable to add breakpoint (unknown address %lx)\n", linear);
324 return;
326 filename = il.FileName;
327 SymEnumLines(dbg_curr_process->handle, linear, NULL, filename, line_cb, &bkln);
329 else
331 /* we have to enumerate across modules */
332 bkln.filename = filename;
333 SymEnumerateModulesW64(dbg_curr_process->handle, mcb, &bkln);
335 if (bkln.addr.Offset)
336 break_add_break(&bkln.addr, TRUE, swbp);
337 else
338 dbg_printf("Unknown line number\n"
339 "(either out of file, or no code at given line number)\n");
342 /***********************************************************************
343 * break_check_delayed_bp
345 * Check is a registered delayed BP is now available.
347 void break_check_delayed_bp(void)
349 struct dbg_lvalue lvalue;
350 int i;
351 struct dbg_delayed_bp* dbp = dbg_curr_process->delayed_bp;
352 char hexbuf[MAX_OFFSET_TO_STR_LEN];
354 for (i = 0; i < dbg_curr_process->num_delayed_bp; i++)
356 if (dbp[i].is_symbol)
358 if (symbol_get_lvalue(dbp[i].u.symbol.name, dbp[i].u.symbol.lineno,
359 &lvalue, TRUE) != sglv_found)
360 continue;
361 if (lvalue.cookie != DLV_TARGET) continue;
363 else
364 lvalue.addr = dbp[i].u.addr;
365 WINE_TRACE("trying to add delayed %s-bp\n", dbp[i].is_symbol ? "S" : "A");
366 if (!dbp[i].is_symbol)
367 WINE_TRACE("\t%04x:%s\n",
368 dbp[i].u.addr.Segment,
369 memory_offset_to_string(hexbuf, dbp[i].u.addr.Offset, 0));
370 else
371 WINE_TRACE("\t'%s' @ %d\n",
372 dbp[i].u.symbol.name, dbp[i].u.symbol.lineno);
374 if (break_add_break(&lvalue.addr, FALSE, dbp[i].software_bp))
375 memmove(&dbp[i], &dbp[i+1], (--dbg_curr_process->num_delayed_bp - i) * sizeof(*dbp));
379 /***********************************************************************
380 * break_add_watch
382 * Add a watchpoint.
384 static void break_add_watch(const struct dbg_lvalue* lvalue, BOOL is_write)
386 int num;
387 DWORD64 l = 4;
389 if (lvalue->cookie == DLV_HOST)
391 dbg_printf("Cannot set a watch point on register or register-based variable\n");
392 return;
394 num = init_xpoint((is_write) ? be_xpoint_watch_write : be_xpoint_watch_read,
395 &lvalue->addr);
396 if (num == -1) return;
398 if (lvalue->type.id != dbg_itype_none)
400 if (types_get_info(&lvalue->type, TI_GET_LENGTH, &l))
402 switch (l)
404 case 4: case 2: case 1: break;
405 default:
406 dbg_printf("Unsupported length (%s) for watch-points, defaulting to 4\n",
407 wine_dbgstr_longlong(l));
408 break;
411 else dbg_printf("Cannot get watch size, defaulting to 4\n");
413 dbg_curr_process->bp[num].w.len = (DWORD)l - 1;
415 if (!get_watched_value(num, &dbg_curr_process->bp[num].w.oldval))
417 dbg_printf("Bad address. Watchpoint not set\n");
418 dbg_curr_process->bp[num].refcount = 0;
419 return;
421 dbg_printf("Watchpoint %d at ", num);
422 print_address(&dbg_curr_process->bp[num].addr, TRUE);
423 dbg_printf("\n");
426 /******************************************************************
427 * break_add_watch_from_lvalue
429 * Adds a watch point from an address (stored in a lvalue)
431 void break_add_watch_from_lvalue(const struct dbg_lvalue* lvalue,BOOL is_write)
433 struct dbg_lvalue lval;
435 types_extract_as_address(lvalue, &lval.addr);
436 lval.type.id = dbg_itype_none;
438 break_add_watch(&lval, is_write);
441 /***********************************************************************
442 * break_add_watch_from_id
444 * Add a watchpoint from a symbol name
446 void break_add_watch_from_id(const char *name, BOOL is_write)
448 struct dbg_lvalue lvalue;
450 switch (symbol_get_lvalue(name, -1, &lvalue, TRUE))
452 case sglv_found:
453 break_add_watch(&lvalue, is_write);
454 break;
455 case sglv_unknown:
456 dbg_printf("Unable to add watchpoint\n");
457 break;
458 case sglv_aborted: /* user aborted symbol lookup */
459 break;
463 /***********************************************************************
464 * break_delete_xpoint
466 * Delete a breakpoint.
468 void break_delete_xpoint(int num)
470 struct dbg_breakpoint* bp = dbg_curr_process->bp;
472 if ((num <= 0) || (num >= dbg_curr_process->next_bp) ||
473 bp[num].refcount == 0)
475 dbg_printf("Invalid breakpoint number %d\n", num);
476 return;
479 if (--bp[num].refcount > 0)
480 return;
482 if (bp[num].condition != NULL)
484 expr_free(bp[num].condition);
485 bp[num].condition = NULL;
488 bp[num].enabled = FALSE;
489 bp[num].refcount = 0;
490 bp[num].skipcount = 0;
493 /******************************************************************
494 * break_delete_xpoints_from_module
496 * Remove all Xpoints from module which base is 'base'
498 void break_delete_xpoints_from_module(DWORD64 base)
500 IMAGEHLP_MODULE64 im, im_elf;
501 int i;
502 DWORD_PTR linear;
503 struct dbg_breakpoint* bp = dbg_curr_process->bp;
505 /* FIXME: should do it also on the ELF sibling if any */
506 im.SizeOfStruct = sizeof(im);
507 im_elf.SizeOfStruct = sizeof(im_elf);
508 if (!SymGetModuleInfo64(dbg_curr_process->handle, base, &im)) return;
510 /* try to get in fact the underlying ELF module (if any) */
511 if (SymGetModuleInfo64(dbg_curr_process->handle, im.BaseOfImage - 1, &im_elf) &&
512 im_elf.BaseOfImage <= im.BaseOfImage &&
513 im_elf.BaseOfImage + im_elf.ImageSize >= im.BaseOfImage + im.ImageSize)
514 im = im_elf;
516 for (i = 0; i < dbg_curr_process->next_bp; i++)
518 if (bp[i].refcount && bp[i].enabled)
520 linear = (DWORD_PTR)memory_to_linear_addr(&bp[i].addr);
521 if (im.BaseOfImage <= linear && linear < im.BaseOfImage + im.ImageSize)
523 break_delete_xpoint(i);
529 /***********************************************************************
530 * break_enable_xpoint
532 * Enable or disable a break point.
534 void break_enable_xpoint(int num, BOOL enable)
536 if ((num <= 0) || (num >= dbg_curr_process->next_bp) ||
537 dbg_curr_process->bp[num].refcount == 0)
539 dbg_printf("Invalid breakpoint number %d\n", num);
540 return;
542 dbg_curr_process->bp[num].enabled = enable != 0;
543 dbg_curr_process->bp[num].skipcount = 0;
547 /***********************************************************************
548 * find_triggered_watch
550 * Lookup the watchpoints to see if one has been triggered
551 * Return >= (watch point index) if one is found
552 * Return -1 if none found
554 * Unfortunately, Linux used to *NOT* (A REAL PITA) report with ptrace
555 * the DR6 register value, so we have to look with our own need the
556 * cause of the TRAP.
557 * -EP
559 static int find_triggered_watch(void)
561 int found = -1;
562 int i;
563 struct dbg_breakpoint* bp = dbg_curr_process->bp;
565 /* Method 1 => get triggered watchpoint from context (doesn't work on Linux
566 * 2.2.x). This should be fixed in >= 2.2.16
568 for (i = 0; i < dbg_curr_process->next_bp; i++)
570 DWORD64 val = 0;
572 if (bp[i].refcount && bp[i].enabled && !is_xpoint_break(i) &&
573 (dbg_curr_process->be_cpu->is_watchpoint_set(&dbg_context, bp[i].info)))
575 dbg_curr_process->be_cpu->clear_watchpoint(&dbg_context, bp[i].info);
577 if (get_watched_value(i, &val))
579 bp[i].w.oldval = val;
580 return i;
585 /* Method 1 failed, trying method 2 */
587 /* Method 2 => check if value has changed among registered watchpoints
588 * this really sucks, but this is how gdb 4.18 works on my linux box
589 * -EP
591 for (i = 0; i < dbg_curr_process->next_bp; i++)
593 DWORD64 val = 0;
595 if (bp[i].refcount && bp[i].enabled && !is_xpoint_break(i) &&
596 get_watched_value(i, &val))
598 if (val != bp[i].w.oldval)
600 dbg_curr_process->be_cpu->clear_watchpoint(&dbg_context, bp[i].info);
601 bp[i].w.oldval = val;
602 found = i;
603 /* cannot break, because two watch points may have been triggered on
604 * the same access
605 * only one will be reported to the user (FIXME ?)
610 return found;
613 /***********************************************************************
614 * break_info
616 * Display break & watch points information.
618 void break_info(void)
620 int i;
621 int nbp = 0, nwp = 0;
622 struct dbg_delayed_bp* dbp = dbg_curr_process->delayed_bp;
623 struct dbg_breakpoint* bp = dbg_curr_process->bp;
625 for (i = 1; i < dbg_curr_process->next_bp; i++)
627 if (bp[i].refcount)
629 if (is_xpoint_break(i)) nbp++; else nwp++;
633 if (nbp)
635 dbg_printf("Breakpoints:\n");
636 for (i = 1; i < dbg_curr_process->next_bp; i++)
638 if (!bp[i].refcount || !is_xpoint_break(i))
639 continue;
640 dbg_printf("%d: %c ", i, bp[i].enabled ? 'y' : 'n');
641 print_address(&bp[i].addr, TRUE);
642 dbg_printf(" (%u)%s\n", bp[i].refcount,
643 bp[i].xpoint_type == be_xpoint_watch_exec ? " (hardware assisted)" : "");
644 if (bp[i].condition != NULL)
646 dbg_printf("\t\tstop when ");
647 expr_print(bp[i].condition);
648 dbg_printf("\n");
652 else dbg_printf("No breakpoints\n");
653 if (nwp)
655 dbg_printf("Watchpoints:\n");
656 for (i = 1; i < dbg_curr_process->next_bp; i++)
658 if (!bp[i].refcount || is_xpoint_break(i))
659 continue;
660 dbg_printf("%d: %c ", i, bp[i].enabled ? 'y' : 'n');
661 print_address(&bp[i].addr, TRUE);
662 dbg_printf(" on %d byte%s (%c)\n",
663 bp[i].w.len + 1, bp[i].w.len > 0 ? "s" : "",
664 bp[i].xpoint_type == be_xpoint_watch_write ? 'W' : 'R');
665 if (bp[i].condition != NULL)
667 dbg_printf("\t\tstop when ");
668 expr_print(bp[i].condition);
669 dbg_printf("\n");
673 else dbg_printf("No watchpoints\n");
674 if (dbg_curr_process->num_delayed_bp)
676 dbg_printf("Delayed breakpoints:\n");
677 for (i = 0; i < dbg_curr_process->num_delayed_bp; i++)
679 if (dbp[i].is_symbol)
681 dbg_printf("%d: %s", i, dbp[i].u.symbol.name);
682 if (dbp[i].u.symbol.lineno != -1)
683 dbg_printf(" at line %u", dbp[i].u.symbol.lineno);
685 else
687 dbg_printf("%d: ", i);
688 print_address(&dbp[i].u.addr, FALSE);
690 dbg_printf("\n");
695 /***********************************************************************
696 * should_stop
698 * Check whether or not the condition (bp / skipcount) of a break/watch
699 * point are met.
701 static BOOL should_stop(int bpnum)
703 struct dbg_breakpoint* bp = &dbg_curr_process->bp[bpnum];
705 if (bp->condition != NULL)
707 struct dbg_lvalue lvalue = expr_eval(bp->condition);
709 if (lvalue.type.id == dbg_itype_none)
712 * Something wrong - unable to evaluate this expression.
714 dbg_printf("Unable to evaluate expression ");
715 expr_print(bp->condition);
716 dbg_printf("\nTurning off condition\n");
717 break_add_condition(bpnum, NULL);
719 else if (!types_extract_as_integer(&lvalue))
721 return FALSE;
725 if (bp->skipcount > 0) bp->skipcount--;
726 return bp->skipcount == 0;
729 /***********************************************************************
730 * break_should_continue
732 * Determine if we should continue execution after a SIGTRAP signal when
733 * executing in the given mode.
735 BOOL break_should_continue(ADDRESS64* addr, DWORD code)
737 enum dbg_exec_mode mode = dbg_curr_thread->exec_mode;
740 if (dbg_curr_thread->stopped_xpoint > 0)
742 if (!should_stop(dbg_curr_thread->stopped_xpoint)) return TRUE;
744 switch (dbg_curr_process->bp[dbg_curr_thread->stopped_xpoint].xpoint_type)
746 case be_xpoint_break:
747 case be_xpoint_watch_exec:
748 dbg_printf("Stopped on breakpoint %d at ", dbg_curr_thread->stopped_xpoint);
749 print_address(&dbg_curr_process->bp[dbg_curr_thread->stopped_xpoint].addr, TRUE);
750 dbg_printf("\n");
751 break;
752 case be_xpoint_watch_read:
753 case be_xpoint_watch_write:
754 dbg_printf("Stopped on watchpoint %d at ", dbg_curr_thread->stopped_xpoint);
755 print_address(addr, TRUE);
756 dbg_printf(" new value %s\n",
757 wine_dbgstr_longlong(dbg_curr_process->bp[dbg_curr_thread->stopped_xpoint].w.oldval));
759 return FALSE;
763 * If our mode indicates that we are stepping line numbers,
764 * get the current function, and figure out if we are exactly
765 * on a line number or not.
767 if (mode == dbg_exec_step_over_line || mode == dbg_exec_step_into_line)
769 if (symbol_get_function_line_status(addr) == dbg_on_a_line_number)
770 dbg_curr_thread->exec_count--;
772 else if (mode == dbg_exec_step_over_insn || mode == dbg_exec_step_into_insn)
773 dbg_curr_thread->exec_count--;
775 if (dbg_curr_thread->exec_count > 0 || mode == dbg_exec_finish)
778 * We still need to execute more instructions.
780 return TRUE;
783 /* no breakpoint, continue if in continuous mode */
784 return mode == dbg_exec_cont || mode == dbg_exec_finish;
787 /***********************************************************************
788 * break_adjust_pc
790 * Adjust PC to the address where the trap (if any) actually occurred
791 * Also sets dbg_curr_thread->stopped_xpoint
793 void break_adjust_pc(ADDRESS64* addr, DWORD code, BOOL first_chance, BOOL* is_break)
795 /* break / watch points are handled on first chance */
796 if ( !first_chance )
798 *is_break = TRUE;
799 dbg_curr_thread->stopped_xpoint = -1;
800 return;
802 *is_break = FALSE;
804 /* If not single-stepping, back up to the break instruction */
805 if (code == EXCEPTION_BREAKPOINT)
806 addr->Offset += dbg_curr_process->be_cpu->adjust_pc_for_break(&dbg_context, TRUE);
808 dbg_curr_thread->stopped_xpoint = find_xpoint(addr, be_xpoint_break);
809 dbg_curr_process->bp[0].enabled = FALSE; /* disable the step-over breakpoint */
811 if (dbg_curr_thread->stopped_xpoint > 0) return;
813 if (dbg_curr_thread->stopped_xpoint < 0)
815 dbg_curr_thread->stopped_xpoint = find_xpoint(addr, be_xpoint_watch_exec);
816 if (dbg_curr_thread->stopped_xpoint < 0)
817 dbg_curr_thread->stopped_xpoint = find_triggered_watch();
818 if (dbg_curr_thread->stopped_xpoint > 0)
820 /* If not single-stepping, do not back up over the break instruction */
821 if (code == EXCEPTION_BREAKPOINT)
822 addr->Offset += dbg_curr_process->be_cpu->adjust_pc_for_break(&dbg_context, FALSE);
823 return;
827 /* If there's no breakpoint and we are not single-stepping, then
828 * either we must have encountered a break insn in the Windows program
829 * or someone is trying to stop us
831 if (dbg_curr_thread->stopped_xpoint == -1 && code == EXCEPTION_BREAKPOINT)
833 *is_break = TRUE;
834 addr->Offset += dbg_curr_process->be_cpu->adjust_pc_for_break(&dbg_context, FALSE);
838 /***********************************************************************
839 * break_suspend_execution
841 * Remove all bp before entering the debug loop
843 void break_suspend_execution(void)
845 break_set_xpoints(FALSE);
846 dbg_curr_process->bp[0] = dbg_curr_thread->step_over_bp;
849 /***********************************************************************
850 * break_restart_execution
852 * Set the bp to the correct state to restart execution
853 * in the given mode.
855 void break_restart_execution(int count)
857 ADDRESS64 addr;
858 enum dbg_line_status status;
859 enum dbg_exec_mode mode, ret_mode;
860 ADDRESS64 callee;
861 void* linear;
863 memory_get_current_pc(&addr);
864 linear = memory_to_linear_addr(&addr);
867 * This is the mode we will be running in after we finish. We would like
868 * to be able to modify this in certain cases.
870 ret_mode = mode = dbg_curr_thread->exec_mode;
872 /* we've stopped on a xpoint (other than step over) */
873 if (dbg_curr_thread->stopped_xpoint > 0)
876 * If we have set a new value, then save it in the BP number.
878 if (count != 0 && mode == dbg_exec_cont)
880 dbg_curr_process->bp[dbg_curr_thread->stopped_xpoint].skipcount = count;
882 /* If we've stopped on a breakpoint, single step over it (, then run) */
883 if (is_xpoint_break(dbg_curr_thread->stopped_xpoint))
884 mode = dbg_exec_step_into_insn;
886 else if (mode == dbg_exec_cont && count > 1)
888 dbg_printf("Not stopped at any breakpoint; argument ignored.\n");
891 if (mode == dbg_exec_finish && dbg_curr_process->be_cpu->is_function_return(linear))
893 mode = ret_mode = dbg_exec_step_into_insn;
897 * See if the function we are stepping into has debug info
898 * and line numbers. If not, then we step over it instead.
899 * FIXME - we need to check for things like thunks or trampolines,
900 * as the actual function may in fact have debug info.
902 if (dbg_curr_process->be_cpu->is_function_call(linear, &callee))
904 status = symbol_get_function_line_status(&callee);
905 #if 0
906 /* FIXME: we need to get the thunk type */
908 * Anytime we have a trampoline, step over it.
910 if ((mode == EXEC_STEP_OVER || mode == EXEC_STEPI_OVER)
911 && status == dbg_in_a_thunk)
913 WINE_WARN("Not stepping into trampoline at %p (no lines)\n",
914 memory_to_linear_addr(&callee));
915 mode = EXEC_STEP_OVER_TRAMPOLINE;
917 #endif
918 if (mode == dbg_exec_step_into_line && status == dbg_no_line_info)
920 WINE_WARN("Not stepping into function at %p (no lines)\n",
921 memory_to_linear_addr(&callee));
922 mode = dbg_exec_step_over_line;
926 if (mode == dbg_exec_step_into_line &&
927 symbol_get_function_line_status(&addr) == dbg_no_line_info)
929 dbg_printf("Single stepping until exit from function,\n"
930 "which has no line number information.\n");
931 ret_mode = mode = dbg_exec_finish;
934 switch (mode)
936 case dbg_exec_cont: /* Continuous execution */
937 dbg_curr_process->be_cpu->single_step(&dbg_context, FALSE);
938 break_set_xpoints(TRUE);
939 break;
941 #if 0
942 case EXEC_STEP_OVER_TRAMPOLINE:
944 * This is the means by which we step over our conversion stubs
945 * in callfrom*.s and callto*.s. We dig the appropriate address
946 * off the stack, and we set the breakpoint there instead of the
947 * address just after the call.
949 be_cpu->get_addr(dbg_curr_thread->handle, &dbg_context,
950 be_cpu_addr_stack, &addr);
951 /* FIXME: we assume stack grows as on an i386 */
952 addr.Offset += 2 * sizeof(unsigned int);
953 dbg_read_memory(memory_to_linear_addr(&addr),
954 &addr.Offset, sizeof(addr.Offset));
955 dbg_curr_process->bp[0].addr = addr;
956 dbg_curr_process->bp[0].enabled = TRUE;
957 dbg_curr_process->bp[0].refcount = 1;
958 dbg_curr_process->bp[0].skipcount = 0;
959 dbg_curr_process->bp[0].xpoint_type = be_xpoint_break;
960 dbg_curr_process->bp[0].condition = NULL;
961 be_cpu->single_step(&dbg_context, FALSE);
962 break_set_xpoints(TRUE);
963 break;
964 #endif
966 case dbg_exec_finish:
967 case dbg_exec_step_over_insn: /* Stepping over a call */
968 case dbg_exec_step_over_line: /* Stepping over a call */
969 if (dbg_curr_process->be_cpu->is_step_over_insn(linear))
971 dbg_curr_process->be_cpu->disasm_one_insn(&addr, FALSE);
972 dbg_curr_process->bp[0].addr = addr;
973 dbg_curr_process->bp[0].enabled = TRUE;
974 dbg_curr_process->bp[0].refcount = 1;
975 dbg_curr_process->bp[0].skipcount = 0;
976 dbg_curr_process->bp[0].xpoint_type = be_xpoint_break;
977 dbg_curr_process->bp[0].condition = NULL;
978 dbg_curr_process->be_cpu->single_step(&dbg_context, FALSE);
979 break_set_xpoints(TRUE);
980 break;
982 /* else fall through to single-stepping */
984 case dbg_exec_step_into_line: /* Single-stepping a line */
985 case dbg_exec_step_into_insn: /* Single-stepping an instruction */
986 dbg_curr_process->be_cpu->single_step(&dbg_context, TRUE);
987 break;
988 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
990 dbg_curr_thread->step_over_bp = dbg_curr_process->bp[0];
991 dbg_curr_thread->exec_mode = ret_mode;
994 BOOL break_add_condition(int num, struct expr* exp)
996 if (num <= 0 || num >= dbg_curr_process->next_bp ||
997 !dbg_curr_process->bp[num].refcount)
999 dbg_printf("Invalid breakpoint number %d\n", num);
1000 return FALSE;
1003 if (dbg_curr_process->bp[num].condition != NULL)
1005 expr_free(dbg_curr_process->bp[num].condition);
1006 dbg_curr_process->bp[num].condition = NULL;
1009 if (exp != NULL) dbg_curr_process->bp[num].condition = expr_clone(exp, NULL);
1011 return TRUE;