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 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 /***********************************************************************
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
= 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
, DWORD64
* 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 8: *val
= *(DWORD64
*)buf
; break;
151 case 4: *val
= *(DWORD
*)buf
; break;
152 case 2: *val
= *(WORD
*)buf
; break;
153 case 1: *val
= *(BYTE
*)buf
; break;
154 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
159 /***********************************************************************
164 BOOL
break_add_break(const ADDRESS64
* addr
, BOOL verbose
, BOOL swbp
)
168 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
169 int type
= swbp
? be_xpoint_break
: be_xpoint_watch_exec
;
171 if ((num
= find_xpoint(addr
, type
)) >= 1)
174 dbg_printf("Breakpoint %d at ", num
);
175 print_address(&bp
[num
].addr
, TRUE
);
176 dbg_printf(" (refcount=%d)\n", bp
[num
].refcount
);
180 if (!dbg_read_memory(memory_to_linear_addr(addr
), &ch
, sizeof(ch
)))
184 dbg_printf("Invalid address ");
185 print_bare_address(addr
);
186 dbg_printf(", can't set breakpoint\n");
191 if ((num
= init_xpoint(type
, addr
)) == -1)
194 dbg_printf("Breakpoint %d at ", num
);
195 print_address(&bp
[num
].addr
, TRUE
);
201 /***********************************************************************
202 * break_add_break_from_lvalue
206 BOOL
break_add_break_from_lvalue(const struct dbg_lvalue
* lvalue
, BOOL swbp
)
210 types_extract_as_address(lvalue
, &addr
);
212 if (!break_add_break(&addr
, TRUE
, swbp
))
214 if (!DBG_IVAR(CanDeferOnBPByAddr
))
216 dbg_printf("Invalid address, can't set breakpoint\n"
217 "You can turn on deferring bp by address by setting $CanDeferOnBPByAddr to 1\n");
220 dbg_printf("Unable to add breakpoint, will check again any time a new DLL is loaded\n");
221 dbg_curr_process
->delayed_bp
=
222 dbg_heap_realloc(dbg_curr_process
->delayed_bp
,
223 sizeof(struct dbg_delayed_bp
) * ++dbg_curr_process
->num_delayed_bp
);
225 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].is_symbol
= FALSE
;
226 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].software_bp
= swbp
;
227 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].u
.addr
= addr
;
233 /***********************************************************************
234 * break_add_break_from_id
236 * Add a breakpoint from a function name (and eventually a line #)
238 void break_add_break_from_id(const char *name
, int lineno
, BOOL swbp
)
240 struct dbg_lvalue lvalue
;
243 switch (symbol_get_lvalue(name
, lineno
, &lvalue
, TRUE
))
246 break_add_break(&lvalue
.addr
, TRUE
, swbp
);
250 case sglv_aborted
: /* user aborted symbol lookup */
254 dbg_printf("Unable to add breakpoint, will check again when a new DLL is loaded\n");
255 for (i
= 0; i
< dbg_curr_process
->num_delayed_bp
; i
++)
257 if (dbg_curr_process
->delayed_bp
[i
].is_symbol
&&
258 !strcmp(name
, dbg_curr_process
->delayed_bp
[i
].u
.symbol
.name
) &&
259 lineno
== dbg_curr_process
->delayed_bp
[i
].u
.symbol
.lineno
)
262 dbg_curr_process
->delayed_bp
= dbg_heap_realloc(dbg_curr_process
->delayed_bp
,
263 sizeof(struct dbg_delayed_bp
) * ++dbg_curr_process
->num_delayed_bp
);
265 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].is_symbol
= TRUE
;
266 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].software_bp
= swbp
;
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 struct cb_break_lineno
273 const char* filename
;
278 static BOOL CALLBACK
line_cb(SRCCODEINFO
* sci
, void* user
)
280 struct cb_break_lineno
* bkln
= user
;
282 if (bkln
->lineno
== sci
->LineNumber
)
284 bkln
->addr
.Mode
= AddrModeFlat
;
285 bkln
->addr
.Offset
= sci
->Address
;
291 static BOOL CALLBACK
mcb(PCWSTR module
, DWORD64 base
, void* user
)
293 struct cb_break_lineno
* bkln
= user
;
295 SymEnumLines(dbg_curr_process
->handle
, base
, NULL
, bkln
->filename
, line_cb
, bkln
);
296 /* continue module enum if no addr found
297 * FIXME: we don't report when several addresses match the same filename/lineno pair
299 return !bkln
->addr
.Offset
;
302 /***********************************************************************
303 * break_add_break_from_lineno
305 * Add a breakpoint from a line number in current file
307 void break_add_break_from_lineno(const char *filename
, int lineno
, BOOL swbp
)
309 struct cb_break_lineno bkln
;
310 bkln
.addr
.Offset
= 0;
311 bkln
.lineno
= lineno
;
320 memory_get_current_pc(&curr
);
321 linear
= (DWORD_PTR
)memory_to_linear_addr(&curr
);
322 il
.SizeOfStruct
= sizeof(il
);
323 if (!SymGetLineFromAddr64(dbg_curr_process
->handle
, linear
, &disp
, &il
))
325 dbg_printf("Unable to add breakpoint (unknown address %lx)\n", linear
);
328 filename
= il
.FileName
;
329 SymEnumLines(dbg_curr_process
->handle
, linear
, NULL
, filename
, line_cb
, &bkln
);
333 /* we have to enumerate across modules */
334 bkln
.filename
= filename
;
335 SymEnumerateModulesW64(dbg_curr_process
->handle
, mcb
, &bkln
);
337 if (bkln
.addr
.Offset
)
338 break_add_break(&bkln
.addr
, TRUE
, swbp
);
340 dbg_printf("Unknown line number\n"
341 "(either out of file, or no code at given line number)\n");
344 /***********************************************************************
345 * break_check_delayed_bp
347 * Check is a registered delayed BP is now available.
349 void break_check_delayed_bp(void)
351 struct dbg_lvalue lvalue
;
353 struct dbg_delayed_bp
* dbp
= dbg_curr_process
->delayed_bp
;
354 char hexbuf
[MAX_OFFSET_TO_STR_LEN
];
356 for (i
= 0; i
< dbg_curr_process
->num_delayed_bp
; i
++)
358 if (dbp
[i
].is_symbol
)
360 if (symbol_get_lvalue(dbp
[i
].u
.symbol
.name
, dbp
[i
].u
.symbol
.lineno
,
361 &lvalue
, TRUE
) != sglv_found
)
363 if (lvalue
.cookie
!= DLV_TARGET
) continue;
366 lvalue
.addr
= dbp
[i
].u
.addr
;
367 WINE_TRACE("trying to add delayed %s-bp\n", dbp
[i
].is_symbol
? "S" : "A");
368 if (!dbp
[i
].is_symbol
)
369 WINE_TRACE("\t%04x:%s\n",
370 dbp
[i
].u
.addr
.Segment
,
371 memory_offset_to_string(hexbuf
, dbp
[i
].u
.addr
.Offset
, 0));
373 WINE_TRACE("\t'%s' @ %d\n",
374 dbp
[i
].u
.symbol
.name
, dbp
[i
].u
.symbol
.lineno
);
376 if (break_add_break(&lvalue
.addr
, FALSE
, dbp
[i
].software_bp
))
377 memmove(&dbp
[i
], &dbp
[i
+1], (--dbg_curr_process
->num_delayed_bp
- i
) * sizeof(*dbp
));
381 /***********************************************************************
386 static void break_add_watch(const struct dbg_lvalue
* lvalue
, BOOL is_write
)
391 if (lvalue
->cookie
== DLV_HOST
)
393 dbg_printf("Cannot set a watch point on register or register-based variable\n");
396 num
= init_xpoint((is_write
) ? be_xpoint_watch_write
: be_xpoint_watch_read
,
398 if (num
== -1) return;
400 if (lvalue
->type
.id
!= dbg_itype_none
)
402 if (types_get_info(&lvalue
->type
, TI_GET_LENGTH
, &l
))
406 case 4: case 2: case 1: break;
408 dbg_printf("Unsupported length (%s) for watch-points, defaulting to 4\n",
409 wine_dbgstr_longlong(l
));
413 else dbg_printf("Cannot get watch size, defaulting to 4\n");
415 dbg_curr_process
->bp
[num
].w
.len
= (DWORD
)l
- 1;
417 if (!get_watched_value(num
, &dbg_curr_process
->bp
[num
].w
.oldval
))
419 dbg_printf("Bad address. Watchpoint not set\n");
420 dbg_curr_process
->bp
[num
].refcount
= 0;
423 dbg_printf("Watchpoint %d at ", num
);
424 print_address(&dbg_curr_process
->bp
[num
].addr
, TRUE
);
428 /******************************************************************
429 * break_add_watch_from_lvalue
431 * Adds a watch point from an address (stored in a lvalue)
433 void break_add_watch_from_lvalue(const struct dbg_lvalue
* lvalue
,BOOL is_write
)
435 struct dbg_lvalue lval
;
437 types_extract_as_address(lvalue
, &lval
.addr
);
438 lval
.type
.id
= dbg_itype_none
;
440 break_add_watch(&lval
, is_write
);
443 /***********************************************************************
444 * break_add_watch_from_id
446 * Add a watchpoint from a symbol name
448 void break_add_watch_from_id(const char *name
, BOOL is_write
)
450 struct dbg_lvalue lvalue
;
452 switch (symbol_get_lvalue(name
, -1, &lvalue
, TRUE
))
455 break_add_watch(&lvalue
, is_write
);
458 dbg_printf("Unable to add watchpoint\n");
460 case sglv_aborted
: /* user aborted symbol lookup */
465 /***********************************************************************
466 * break_delete_xpoint
468 * Delete a breakpoint.
470 void break_delete_xpoint(int num
)
472 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
474 if ((num
<= 0) || (num
>= dbg_curr_process
->next_bp
) ||
475 bp
[num
].refcount
== 0)
477 dbg_printf("Invalid breakpoint number %d\n", num
);
481 if (--bp
[num
].refcount
> 0)
484 if (bp
[num
].condition
!= NULL
)
486 expr_free(bp
[num
].condition
);
487 bp
[num
].condition
= NULL
;
490 bp
[num
].enabled
= FALSE
;
491 bp
[num
].refcount
= 0;
492 bp
[num
].skipcount
= 0;
495 /******************************************************************
496 * break_delete_xpoints_from_module
498 * Remove all Xpoints from module which base is 'base'
500 void break_delete_xpoints_from_module(DWORD64 base
)
502 IMAGEHLP_MODULE64 im
, im_elf
;
505 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
507 /* FIXME: should do it also on the ELF sibling if any */
508 im
.SizeOfStruct
= sizeof(im
);
509 im_elf
.SizeOfStruct
= sizeof(im_elf
);
510 if (!SymGetModuleInfo64(dbg_curr_process
->handle
, base
, &im
)) return;
512 /* try to get in fact the underlying ELF module (if any) */
513 if (SymGetModuleInfo64(dbg_curr_process
->handle
, im
.BaseOfImage
- 1, &im_elf
) &&
514 im_elf
.BaseOfImage
<= im
.BaseOfImage
&&
515 im_elf
.BaseOfImage
+ im_elf
.ImageSize
>= im
.BaseOfImage
+ im
.ImageSize
)
518 for (i
= 0; i
< dbg_curr_process
->next_bp
; i
++)
520 if (bp
[i
].refcount
&& bp
[i
].enabled
)
522 linear
= (DWORD_PTR
)memory_to_linear_addr(&bp
[i
].addr
);
523 if (im
.BaseOfImage
<= linear
&& linear
< im
.BaseOfImage
+ im
.ImageSize
)
525 break_delete_xpoint(i
);
531 /***********************************************************************
532 * break_enable_xpoint
534 * Enable or disable a break point.
536 void break_enable_xpoint(int num
, BOOL enable
)
538 if ((num
<= 0) || (num
>= dbg_curr_process
->next_bp
) ||
539 dbg_curr_process
->bp
[num
].refcount
== 0)
541 dbg_printf("Invalid breakpoint number %d\n", num
);
544 dbg_curr_process
->bp
[num
].enabled
= enable
!= 0;
545 dbg_curr_process
->bp
[num
].skipcount
= 0;
549 /***********************************************************************
550 * find_triggered_watch
552 * Lookup the watchpoints to see if one has been triggered
553 * Return >= (watch point index) if one is found
554 * Return -1 if none found
556 * Unfortunately, Linux used to *NOT* (A REAL PITA) report with ptrace
557 * the DR6 register value, so we have to look with our own need the
561 static int find_triggered_watch(void)
565 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
567 /* Method 1 => get triggered watchpoint from context (doesn't work on Linux
568 * 2.2.x). This should be fixed in >= 2.2.16
570 for (i
= 0; i
< dbg_curr_process
->next_bp
; i
++)
574 if (bp
[i
].refcount
&& bp
[i
].enabled
&& !is_xpoint_break(i
) &&
575 (be_cpu
->is_watchpoint_set(&dbg_context
, bp
[i
].info
)))
577 be_cpu
->clear_watchpoint(&dbg_context
, bp
[i
].info
);
579 if (get_watched_value(i
, &val
))
581 bp
[i
].w
.oldval
= val
;
587 /* Method 1 failed, trying method 2 */
589 /* Method 2 => check if value has changed among registered watchpoints
590 * this really sucks, but this is how gdb 4.18 works on my linux box
593 for (i
= 0; i
< dbg_curr_process
->next_bp
; i
++)
597 if (bp
[i
].refcount
&& bp
[i
].enabled
&& !is_xpoint_break(i
) &&
598 get_watched_value(i
, &val
))
600 if (val
!= bp
[i
].w
.oldval
)
602 be_cpu
->clear_watchpoint(&dbg_context
, bp
[i
].info
);
603 bp
[i
].w
.oldval
= val
;
605 /* cannot break, because two watch points may have been triggered on
607 * only one will be reported to the user (FIXME ?)
615 /***********************************************************************
618 * Display break & watch points information.
620 void break_info(void)
623 int nbp
= 0, nwp
= 0;
624 struct dbg_delayed_bp
* dbp
= dbg_curr_process
->delayed_bp
;
625 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
627 for (i
= 1; i
< dbg_curr_process
->next_bp
; i
++)
631 if (is_xpoint_break(i
)) nbp
++; else nwp
++;
637 dbg_printf("Breakpoints:\n");
638 for (i
= 1; i
< dbg_curr_process
->next_bp
; i
++)
640 if (!bp
[i
].refcount
|| !is_xpoint_break(i
))
642 dbg_printf("%d: %c ", i
, bp
[i
].enabled
? 'y' : 'n');
643 print_address(&bp
[i
].addr
, TRUE
);
644 dbg_printf(" (%u)%s\n", bp
[i
].refcount
,
645 bp
[i
].xpoint_type
== be_xpoint_watch_exec
? " (hardware assisted)" : "");
646 if (bp
[i
].condition
!= NULL
)
648 dbg_printf("\t\tstop when ");
649 expr_print(bp
[i
].condition
);
654 else dbg_printf("No breakpoints\n");
657 dbg_printf("Watchpoints:\n");
658 for (i
= 1; i
< dbg_curr_process
->next_bp
; i
++)
660 if (!bp
[i
].refcount
|| is_xpoint_break(i
))
662 dbg_printf("%d: %c ", i
, bp
[i
].enabled
? 'y' : 'n');
663 print_address(&bp
[i
].addr
, TRUE
);
664 dbg_printf(" on %d byte%s (%c)\n",
665 bp
[i
].w
.len
+ 1, bp
[i
].w
.len
> 0 ? "s" : "",
666 bp
[i
].xpoint_type
== be_xpoint_watch_write
? 'W' : 'R');
667 if (bp
[i
].condition
!= NULL
)
669 dbg_printf("\t\tstop when ");
670 expr_print(bp
[i
].condition
);
675 else dbg_printf("No watchpoints\n");
676 if (dbg_curr_process
->num_delayed_bp
)
678 dbg_printf("Delayed breakpoints:\n");
679 for (i
= 0; i
< dbg_curr_process
->num_delayed_bp
; i
++)
681 if (dbp
[i
].is_symbol
)
683 dbg_printf("%d: %s", i
, dbp
[i
].u
.symbol
.name
);
684 if (dbp
[i
].u
.symbol
.lineno
!= -1)
685 dbg_printf(" at line %u", dbp
[i
].u
.symbol
.lineno
);
689 dbg_printf("%d: ", i
);
690 print_address(&dbp
[i
].u
.addr
, FALSE
);
697 /***********************************************************************
700 * Check whether or not the condition (bp / skipcount) of a break/watch
703 static BOOL
should_stop(int bpnum
)
705 struct dbg_breakpoint
* bp
= &dbg_curr_process
->bp
[bpnum
];
707 if (bp
->condition
!= NULL
)
709 struct dbg_lvalue lvalue
= expr_eval(bp
->condition
);
711 if (lvalue
.type
.id
== dbg_itype_none
)
714 * Something wrong - unable to evaluate this expression.
716 dbg_printf("Unable to evaluate expression ");
717 expr_print(bp
->condition
);
718 dbg_printf("\nTurning off condition\n");
719 break_add_condition(bpnum
, NULL
);
721 else if (!types_extract_as_integer(&lvalue
))
727 if (bp
->skipcount
> 0) bp
->skipcount
--;
728 return bp
->skipcount
== 0;
731 /***********************************************************************
732 * break_should_continue
734 * Determine if we should continue execution after a SIGTRAP signal when
735 * executing in the given mode.
737 BOOL
break_should_continue(ADDRESS64
* addr
, DWORD code
)
739 enum dbg_exec_mode mode
= dbg_curr_thread
->exec_mode
;
742 if (dbg_curr_thread
->stopped_xpoint
> 0)
744 if (!should_stop(dbg_curr_thread
->stopped_xpoint
)) return TRUE
;
746 switch (dbg_curr_process
->bp
[dbg_curr_thread
->stopped_xpoint
].xpoint_type
)
748 case be_xpoint_break
:
749 case be_xpoint_watch_exec
:
750 dbg_printf("Stopped on breakpoint %d at ", dbg_curr_thread
->stopped_xpoint
);
751 print_address(&dbg_curr_process
->bp
[dbg_curr_thread
->stopped_xpoint
].addr
, TRUE
);
754 case be_xpoint_watch_read
:
755 case be_xpoint_watch_write
:
756 dbg_printf("Stopped on watchpoint %d at ", dbg_curr_thread
->stopped_xpoint
);
757 print_address(addr
, TRUE
);
758 dbg_printf(" new value %s\n",
759 wine_dbgstr_longlong(dbg_curr_process
->bp
[dbg_curr_thread
->stopped_xpoint
].w
.oldval
));
765 * If our mode indicates that we are stepping line numbers,
766 * get the current function, and figure out if we are exactly
767 * on a line number or not.
769 if (mode
== dbg_exec_step_over_line
|| mode
== dbg_exec_step_into_line
)
771 if (symbol_get_function_line_status(addr
) == dbg_on_a_line_number
)
772 dbg_curr_thread
->exec_count
--;
774 else if (mode
== dbg_exec_step_over_insn
|| mode
== dbg_exec_step_into_insn
)
775 dbg_curr_thread
->exec_count
--;
777 if (dbg_curr_thread
->exec_count
> 0 || mode
== dbg_exec_finish
)
780 * We still need to execute more instructions.
785 /* no breakpoint, continue if in continuous mode */
786 return mode
== dbg_exec_cont
|| mode
== dbg_exec_finish
;
789 /***********************************************************************
792 * Adjust PC to the address where the trap (if any) actually occurred
793 * Also sets dbg_curr_thread->stopped_xpoint
795 void break_adjust_pc(ADDRESS64
* addr
, DWORD code
, BOOL first_chance
, BOOL
* is_break
)
797 /* break / watch points are handled on first chance */
801 dbg_curr_thread
->stopped_xpoint
= -1;
806 /* If not single-stepping, back up to the break instruction */
807 if (code
== EXCEPTION_BREAKPOINT
)
808 addr
->Offset
+= be_cpu
->adjust_pc_for_break(&dbg_context
, TRUE
);
810 dbg_curr_thread
->stopped_xpoint
= find_xpoint(addr
, be_xpoint_break
);
811 dbg_curr_process
->bp
[0].enabled
= FALSE
; /* disable the step-over breakpoint */
813 if (dbg_curr_thread
->stopped_xpoint
> 0) return;
815 if (dbg_curr_thread
->stopped_xpoint
< 0)
817 dbg_curr_thread
->stopped_xpoint
= find_xpoint(addr
, be_xpoint_watch_exec
);
818 if (dbg_curr_thread
->stopped_xpoint
< 0)
819 dbg_curr_thread
->stopped_xpoint
= find_triggered_watch();
820 if (dbg_curr_thread
->stopped_xpoint
> 0)
822 /* If not single-stepping, do not back up over the break instruction */
823 if (code
== EXCEPTION_BREAKPOINT
)
824 addr
->Offset
+= be_cpu
->adjust_pc_for_break(&dbg_context
, FALSE
);
829 /* If there's no breakpoint and we are not single-stepping, then
830 * either we must have encountered a break insn in the Windows program
831 * or someone is trying to stop us
833 if (dbg_curr_thread
->stopped_xpoint
== -1 && code
== EXCEPTION_BREAKPOINT
)
836 addr
->Offset
+= be_cpu
->adjust_pc_for_break(&dbg_context
, FALSE
);
840 /***********************************************************************
841 * break_suspend_execution
843 * Remove all bp before entering the debug loop
845 void break_suspend_execution(void)
847 break_set_xpoints(FALSE
);
848 dbg_curr_process
->bp
[0] = dbg_curr_thread
->step_over_bp
;
851 /***********************************************************************
852 * break_restart_execution
854 * Set the bp to the correct state to restart execution
857 void break_restart_execution(int count
)
860 enum dbg_line_status status
;
861 enum dbg_exec_mode mode
, ret_mode
;
865 memory_get_current_pc(&addr
);
866 linear
= memory_to_linear_addr(&addr
);
869 * This is the mode we will be running in after we finish. We would like
870 * to be able to modify this in certain cases.
872 ret_mode
= mode
= dbg_curr_thread
->exec_mode
;
874 /* we've stopped on a xpoint (other than step over) */
875 if (dbg_curr_thread
->stopped_xpoint
> 0)
878 * If we have set a new value, then save it in the BP number.
880 if (count
!= 0 && mode
== dbg_exec_cont
)
882 dbg_curr_process
->bp
[dbg_curr_thread
->stopped_xpoint
].skipcount
= count
;
884 /* If we've stopped on a breakpoint, single step over it (, then run) */
885 if (is_xpoint_break(dbg_curr_thread
->stopped_xpoint
))
886 mode
= dbg_exec_step_into_insn
;
888 else if (mode
== dbg_exec_cont
&& count
> 1)
890 dbg_printf("Not stopped at any breakpoint; argument ignored.\n");
893 if (mode
== dbg_exec_finish
&& be_cpu
->is_function_return(linear
))
895 mode
= ret_mode
= dbg_exec_step_into_insn
;
899 * See if the function we are stepping into has debug info
900 * and line numbers. If not, then we step over it instead.
901 * FIXME - we need to check for things like thunks or trampolines,
902 * as the actual function may in fact have debug info.
904 if (be_cpu
->is_function_call(linear
, &callee
))
906 status
= symbol_get_function_line_status(&callee
);
908 /* FIXME: we need to get the thunk type */
910 * Anytime we have a trampoline, step over it.
912 if ((mode
== EXEC_STEP_OVER
|| mode
== EXEC_STEPI_OVER
)
913 && status
== dbg_in_a_thunk
)
915 WINE_WARN("Not stepping into trampoline at %p (no lines)\n",
916 memory_to_linear_addr(&callee
));
917 mode
= EXEC_STEP_OVER_TRAMPOLINE
;
920 if (mode
== dbg_exec_step_into_line
&& status
== dbg_no_line_info
)
922 WINE_WARN("Not stepping into function at %p (no lines)\n",
923 memory_to_linear_addr(&callee
));
924 mode
= dbg_exec_step_over_line
;
928 if (mode
== dbg_exec_step_into_line
&&
929 symbol_get_function_line_status(&addr
) == dbg_no_line_info
)
931 dbg_printf("Single stepping until exit from function,\n"
932 "which has no line number information.\n");
933 ret_mode
= mode
= dbg_exec_finish
;
938 case dbg_exec_cont
: /* Continuous execution */
939 be_cpu
->single_step(&dbg_context
, FALSE
);
940 break_set_xpoints(TRUE
);
944 case EXEC_STEP_OVER_TRAMPOLINE
:
946 * This is the means by which we step over our conversion stubs
947 * in callfrom*.s and callto*.s. We dig the appropriate address
948 * off the stack, and we set the breakpoint there instead of the
949 * address just after the call.
951 be_cpu
->get_addr(dbg_curr_thread
->handle
, &dbg_context
,
952 be_cpu_addr_stack
, &addr
);
953 /* FIXME: we assume stack grows as on an i386 */
954 addr
.Offset
+= 2 * sizeof(unsigned int);
955 dbg_read_memory(memory_to_linear_addr(&addr
),
956 &addr
.Offset
, sizeof(addr
.Offset
));
957 dbg_curr_process
->bp
[0].addr
= addr
;
958 dbg_curr_process
->bp
[0].enabled
= TRUE
;
959 dbg_curr_process
->bp
[0].refcount
= 1;
960 dbg_curr_process
->bp
[0].skipcount
= 0;
961 dbg_curr_process
->bp
[0].xpoint_type
= be_xpoint_break
;
962 dbg_curr_process
->bp
[0].condition
= NULL
;
963 be_cpu
->single_step(&dbg_context
, FALSE
);
964 break_set_xpoints(TRUE
);
968 case dbg_exec_finish
:
969 case dbg_exec_step_over_insn
: /* Stepping over a call */
970 case dbg_exec_step_over_line
: /* Stepping over a call */
971 if (be_cpu
->is_step_over_insn(linear
))
973 be_cpu
->disasm_one_insn(&addr
, FALSE
);
974 dbg_curr_process
->bp
[0].addr
= addr
;
975 dbg_curr_process
->bp
[0].enabled
= TRUE
;
976 dbg_curr_process
->bp
[0].refcount
= 1;
977 dbg_curr_process
->bp
[0].skipcount
= 0;
978 dbg_curr_process
->bp
[0].xpoint_type
= be_xpoint_break
;
979 dbg_curr_process
->bp
[0].condition
= NULL
;
980 be_cpu
->single_step(&dbg_context
, FALSE
);
981 break_set_xpoints(TRUE
);
984 /* else fall through to single-stepping */
986 case dbg_exec_step_into_line
: /* Single-stepping a line */
987 case dbg_exec_step_into_insn
: /* Single-stepping an instruction */
988 be_cpu
->single_step(&dbg_context
, TRUE
);
990 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
992 dbg_curr_thread
->step_over_bp
= dbg_curr_process
->bp
[0];
993 dbg_curr_thread
->exec_mode
= ret_mode
;
996 BOOL
break_add_condition(int num
, struct expr
* exp
)
998 if (num
<= 0 || num
>= dbg_curr_process
->next_bp
||
999 !dbg_curr_process
->bp
[num
].refcount
)
1001 dbg_printf("Invalid breakpoint number %d\n", num
);
1005 if (dbg_curr_process
->bp
[num
].condition
!= NULL
)
1007 expr_free(dbg_curr_process
->bp
[num
].condition
);
1008 dbg_curr_process
->bp
[num
].condition
= NULL
;
1011 if (exp
!= NULL
) dbg_curr_process
->bp
[num
].condition
= expr_clone(exp
, NULL
);