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
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(winedbg
);
28 static BOOL
is_xpoint_break(int bpnum
)
30 int type
= dbg_curr_process
->bp
[bpnum
].xpoint_type
;
32 if (type
== be_xpoint_break
|| type
== be_xpoint_watch_exec
) return TRUE
;
33 if (type
== be_xpoint_watch_read
|| type
== be_xpoint_watch_write
) return FALSE
;
34 RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
35 return FALSE
; /* never reached */
38 /***********************************************************************
41 * Set or remove all the breakpoints & watchpoints
43 void break_set_xpoints(BOOL set
)
45 static BOOL last
; /* = 0 = FALSE */
47 unsigned int i
, ret
, size
;
49 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
51 if (set
== last
) return;
54 for (i
= 0; i
< dbg_curr_process
->next_bp
; i
++)
56 if (!bp
[i
].refcount
|| !bp
[i
].enabled
) continue;
58 if (is_xpoint_break(i
))
61 size
= bp
[i
].w
.len
+ 1;
62 addr
= memory_to_linear_addr(&bp
[i
].addr
);
65 ret
= dbg_curr_process
->be_cpu
->insert_Xpoint(dbg_curr_process
->handle
,
66 dbg_curr_process
->process_io
, &dbg_context
, bp
[i
].xpoint_type
,
67 addr
, &bp
[i
].info
, size
);
69 ret
= dbg_curr_process
->be_cpu
->remove_Xpoint(dbg_curr_process
->handle
,
70 dbg_curr_process
->process_io
, &dbg_context
, bp
[i
].xpoint_type
,
71 addr
, bp
[i
].info
, size
);
74 dbg_printf("Invalid address (");
75 print_address(&bp
[i
].addr
, FALSE
);
76 dbg_printf(") for breakpoint %d, disabling it\n", i
);
77 bp
[i
].enabled
= FALSE
;
82 /***********************************************************************
85 * Find the breakpoint for a given address. Return the breakpoint
86 * number or -1 if none.
88 static int find_xpoint(const ADDRESS64
* addr
, enum be_xpoint_type type
)
91 void* lin
= memory_to_linear_addr(addr
);
92 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
94 for (i
= 0; i
< dbg_curr_process
->next_bp
; i
++)
96 if (bp
[i
].refcount
&& bp
[i
].enabled
&& bp
[i
].xpoint_type
== type
&&
97 memory_to_linear_addr(&bp
[i
].addr
) == lin
)
103 /***********************************************************************
106 * Find an empty slot in BP table to add a new break/watch point
108 static int init_xpoint(int type
, const ADDRESS64
* addr
)
111 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
113 for (num
= (dbg_curr_process
->next_bp
< MAX_BREAKPOINTS
) ?
114 dbg_curr_process
->next_bp
++ : 1;
115 num
< MAX_BREAKPOINTS
; num
++)
117 if (bp
[num
].refcount
== 0)
119 bp
[num
].refcount
= 1;
120 bp
[num
].enabled
= TRUE
;
121 bp
[num
].xpoint_type
= type
;
122 bp
[num
].skipcount
= 0;
123 bp
[num
].addr
= *addr
;
128 dbg_printf("Too many bp. Please delete some.\n");
132 /***********************************************************************
135 * Returns the value watched by watch point 'num'.
137 static BOOL
get_watched_value(int num
, DWORD64
* val
)
141 if (!dbg_read_memory(memory_to_linear_addr(&dbg_curr_process
->bp
[num
].addr
),
142 buf
, dbg_curr_process
->bp
[num
].w
.len
+ 1))
145 switch (dbg_curr_process
->bp
[num
].w
.len
+ 1)
147 case 8: *val
= *(DWORD64
*)buf
; break;
148 case 4: *val
= *(DWORD
*)buf
; break;
149 case 2: *val
= *(WORD
*)buf
; break;
150 case 1: *val
= *(BYTE
*)buf
; break;
151 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
156 /***********************************************************************
161 BOOL
break_add_break(const ADDRESS64
* addr
, BOOL verbose
, BOOL swbp
)
165 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
166 int type
= swbp
? be_xpoint_break
: be_xpoint_watch_exec
;
168 if ((num
= find_xpoint(addr
, type
)) >= 1)
171 dbg_printf("Breakpoint %d at ", num
);
172 print_address(&bp
[num
].addr
, TRUE
);
173 dbg_printf(" (refcount=%d)\n", bp
[num
].refcount
);
177 if (!dbg_read_memory(memory_to_linear_addr(addr
), &ch
, sizeof(ch
)))
181 dbg_printf("Invalid address ");
182 print_bare_address(addr
);
183 dbg_printf(", can't set breakpoint\n");
188 if ((num
= init_xpoint(type
, addr
)) == -1)
191 dbg_printf("Breakpoint %d at ", num
);
192 print_address(&bp
[num
].addr
, TRUE
);
198 /***********************************************************************
199 * break_add_break_from_lvalue
203 BOOL
break_add_break_from_lvalue(const struct dbg_lvalue
* lvalue
, BOOL swbp
)
207 types_extract_as_address(lvalue
, &addr
);
209 if (!break_add_break(&addr
, TRUE
, swbp
))
211 if (!DBG_IVAR(CanDeferOnBPByAddr
))
213 dbg_printf("Invalid address, can't set breakpoint\n"
214 "You can turn on deferring bp by address by setting $CanDeferOnBPByAddr to 1\n");
217 dbg_printf("Unable to add breakpoint, will check again any time a new DLL is loaded\n");
218 dbg_curr_process
->delayed_bp
=
219 dbg_heap_realloc(dbg_curr_process
->delayed_bp
,
220 sizeof(struct dbg_delayed_bp
) * ++dbg_curr_process
->num_delayed_bp
);
222 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].is_symbol
= FALSE
;
223 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].software_bp
= swbp
;
224 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].u
.addr
= addr
;
230 /***********************************************************************
231 * break_add_break_from_id
233 * Add a breakpoint from a function name (and eventually a line #)
235 void break_add_break_from_id(const char *name
, int lineno
, BOOL swbp
)
237 struct dbg_lvalue lvalue
;
240 switch (symbol_get_lvalue(name
, lineno
, &lvalue
, TRUE
))
243 break_add_break(&lvalue
.addr
, TRUE
, swbp
);
247 case sglv_aborted
: /* user aborted symbol lookup */
251 dbg_printf("Unable to add breakpoint, will check again when a new DLL is loaded\n");
252 for (i
= 0; i
< dbg_curr_process
->num_delayed_bp
; i
++)
254 if (dbg_curr_process
->delayed_bp
[i
].is_symbol
&&
255 !strcmp(name
, dbg_curr_process
->delayed_bp
[i
].u
.symbol
.name
) &&
256 lineno
== dbg_curr_process
->delayed_bp
[i
].u
.symbol
.lineno
)
259 dbg_curr_process
->delayed_bp
= dbg_heap_realloc(dbg_curr_process
->delayed_bp
,
260 sizeof(struct dbg_delayed_bp
) * ++dbg_curr_process
->num_delayed_bp
);
262 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].is_symbol
= TRUE
;
263 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].software_bp
= swbp
;
264 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].u
.symbol
.name
= strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(name
) + 1), name
);
265 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].u
.symbol
.lineno
= lineno
;
268 struct cb_break_lineno
270 const char* filename
;
275 static BOOL CALLBACK
line_cb(SRCCODEINFO
* sci
, void* user
)
277 struct cb_break_lineno
* bkln
= user
;
279 if (bkln
->lineno
== sci
->LineNumber
)
281 bkln
->addr
.Mode
= AddrModeFlat
;
282 bkln
->addr
.Offset
= sci
->Address
;
288 static BOOL CALLBACK
mcb(PCWSTR module
, DWORD64 base
, void* user
)
290 struct cb_break_lineno
* bkln
= user
;
292 SymEnumLines(dbg_curr_process
->handle
, base
, NULL
, bkln
->filename
, line_cb
, bkln
);
293 /* continue module enum if no addr found
294 * FIXME: we don't report when several addresses match the same filename/lineno pair
296 return !bkln
->addr
.Offset
;
299 /***********************************************************************
300 * break_add_break_from_lineno
302 * Add a breakpoint from a line number in current file
304 void break_add_break_from_lineno(const char *filename
, int lineno
, BOOL swbp
)
306 struct cb_break_lineno bkln
;
307 bkln
.addr
.Offset
= 0;
308 bkln
.lineno
= lineno
;
317 memory_get_current_pc(&curr
);
318 linear
= (DWORD_PTR
)memory_to_linear_addr(&curr
);
319 il
.SizeOfStruct
= sizeof(il
);
320 if (!SymGetLineFromAddr64(dbg_curr_process
->handle
, linear
, &disp
, &il
))
322 dbg_printf("Unable to add breakpoint (unknown address %Ix)\n", linear
);
325 filename
= il
.FileName
;
326 SymEnumLines(dbg_curr_process
->handle
, linear
, NULL
, filename
, line_cb
, &bkln
);
330 /* we have to enumerate across modules */
331 bkln
.filename
= filename
;
332 SymEnumerateModulesW64(dbg_curr_process
->handle
, mcb
, &bkln
);
334 if (bkln
.addr
.Offset
)
335 break_add_break(&bkln
.addr
, TRUE
, swbp
);
337 dbg_printf("Unknown line number\n"
338 "(either out of file, or no code at given line number)\n");
341 /***********************************************************************
342 * break_check_delayed_bp
344 * Check is a registered delayed BP is now available.
346 void break_check_delayed_bp(void)
348 struct dbg_lvalue lvalue
;
350 struct dbg_delayed_bp
* dbp
= dbg_curr_process
->delayed_bp
;
351 char hexbuf
[MAX_OFFSET_TO_STR_LEN
];
353 for (i
= 0; i
< dbg_curr_process
->num_delayed_bp
; i
++)
355 if (dbp
[i
].is_symbol
)
357 if (symbol_get_lvalue(dbp
[i
].u
.symbol
.name
, dbp
[i
].u
.symbol
.lineno
,
358 &lvalue
, TRUE
) != sglv_found
)
360 if (!lvalue
.in_debuggee
) continue;
363 lvalue
.addr
= dbp
[i
].u
.addr
;
364 WINE_TRACE("trying to add delayed %s-bp\n", dbp
[i
].is_symbol
? "S" : "A");
365 if (!dbp
[i
].is_symbol
)
366 WINE_TRACE("\t%04x:%s\n",
367 dbp
[i
].u
.addr
.Segment
,
368 memory_offset_to_string(hexbuf
, dbp
[i
].u
.addr
.Offset
, 0));
370 WINE_TRACE("\t'%s' @ %d\n",
371 dbp
[i
].u
.symbol
.name
, dbp
[i
].u
.symbol
.lineno
);
373 if (break_add_break(&lvalue
.addr
, FALSE
, dbp
[i
].software_bp
))
374 memmove(&dbp
[i
], &dbp
[i
+1], (--dbg_curr_process
->num_delayed_bp
- i
) * sizeof(*dbp
));
378 /***********************************************************************
383 static void break_add_watch(const struct dbg_lvalue
* lvalue
, BOOL is_write
)
388 if (!lvalue
->in_debuggee
)
390 dbg_printf("Cannot set a watch point on register or register-based variable\n");
393 num
= init_xpoint((is_write
) ? be_xpoint_watch_write
: be_xpoint_watch_read
,
395 if (num
== -1) return;
397 if (lvalue
->type
.id
!= dbg_itype_none
)
399 if (types_get_info(&lvalue
->type
, TI_GET_LENGTH
, &l
))
403 case 4: case 2: case 1: break;
405 dbg_printf("Unsupported length (%I64x) for watch-points, defaulting to 4\n", l
);
409 else dbg_printf("Cannot get watch size, defaulting to 4\n");
411 dbg_curr_process
->bp
[num
].w
.len
= (DWORD
)l
- 1;
413 if (!get_watched_value(num
, &dbg_curr_process
->bp
[num
].w
.oldval
))
415 dbg_printf("Bad address. Watchpoint not set\n");
416 dbg_curr_process
->bp
[num
].refcount
= 0;
419 dbg_printf("Watchpoint %d at ", num
);
420 print_address(&dbg_curr_process
->bp
[num
].addr
, TRUE
);
424 /******************************************************************
425 * break_add_watch_from_lvalue
427 * Adds a watch point from an address (stored in a lvalue)
429 void break_add_watch_from_lvalue(const struct dbg_lvalue
* lvalue
,BOOL is_write
)
431 struct dbg_lvalue lval
;
433 types_extract_as_address(lvalue
, &lval
.addr
);
434 lval
.type
.id
= dbg_itype_none
;
436 break_add_watch(&lval
, is_write
);
439 /***********************************************************************
440 * break_add_watch_from_id
442 * Add a watchpoint from a symbol name
444 void break_add_watch_from_id(const char *name
, BOOL is_write
)
446 struct dbg_lvalue lvalue
;
448 switch (symbol_get_lvalue(name
, -1, &lvalue
, TRUE
))
451 break_add_watch(&lvalue
, is_write
);
454 dbg_printf("Unable to add watchpoint\n");
456 case sglv_aborted
: /* user aborted symbol lookup */
461 /***********************************************************************
462 * break_delete_xpoint
464 * Delete a breakpoint.
466 void break_delete_xpoint(int num
)
468 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
470 if ((num
<= 0) || (num
>= dbg_curr_process
->next_bp
) ||
471 bp
[num
].refcount
== 0)
473 dbg_printf("Invalid breakpoint number %d\n", num
);
477 if (--bp
[num
].refcount
> 0)
480 if (bp
[num
].condition
!= NULL
)
482 expr_free(bp
[num
].condition
);
483 bp
[num
].condition
= NULL
;
486 bp
[num
].enabled
= FALSE
;
487 bp
[num
].refcount
= 0;
488 bp
[num
].skipcount
= 0;
491 /******************************************************************
492 * break_delete_xpoints_from_module
494 * Remove all Xpoints from module which base is 'base'
496 void break_delete_xpoints_from_module(DWORD64 base
)
498 IMAGEHLP_MODULE64 im
, im_elf
;
501 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
503 /* FIXME: should do it also on the ELF sibling if any */
504 im
.SizeOfStruct
= sizeof(im
);
505 im_elf
.SizeOfStruct
= sizeof(im_elf
);
506 if (!SymGetModuleInfo64(dbg_curr_process
->handle
, base
, &im
)) return;
508 /* try to get in fact the underlying ELF module (if any) */
509 if (SymGetModuleInfo64(dbg_curr_process
->handle
, im
.BaseOfImage
- 1, &im_elf
) &&
510 im_elf
.BaseOfImage
<= im
.BaseOfImage
&&
511 im_elf
.BaseOfImage
+ im_elf
.ImageSize
>= im
.BaseOfImage
+ im
.ImageSize
)
514 for (i
= 0; i
< dbg_curr_process
->next_bp
; i
++)
516 if (bp
[i
].refcount
&& bp
[i
].enabled
)
518 linear
= (DWORD_PTR
)memory_to_linear_addr(&bp
[i
].addr
);
519 if (im
.BaseOfImage
<= linear
&& linear
< im
.BaseOfImage
+ im
.ImageSize
)
521 break_delete_xpoint(i
);
527 /***********************************************************************
528 * break_enable_xpoint
530 * Enable or disable a break point.
532 void break_enable_xpoint(int num
, BOOL enable
)
534 if ((num
<= 0) || (num
>= dbg_curr_process
->next_bp
) ||
535 dbg_curr_process
->bp
[num
].refcount
== 0)
537 dbg_printf("Invalid breakpoint number %d\n", num
);
540 dbg_curr_process
->bp
[num
].enabled
= enable
!= 0;
541 dbg_curr_process
->bp
[num
].skipcount
= 0;
545 /***********************************************************************
546 * find_triggered_watch
548 * Lookup the watchpoints to see if one has been triggered
549 * Return >= (watch point index) if one is found
550 * Return -1 if none found
552 * Unfortunately, Linux used to *NOT* (A REAL PITA) report with ptrace
553 * the DR6 register value, so we have to look with our own need the
557 static int find_triggered_watch(void)
561 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
563 /* Method 1 => get triggered watchpoint from context (doesn't work on Linux
564 * 2.2.x). This should be fixed in >= 2.2.16
566 for (i
= 0; i
< dbg_curr_process
->next_bp
; i
++)
570 if (bp
[i
].refcount
&& bp
[i
].enabled
&& !is_xpoint_break(i
) &&
571 (dbg_curr_process
->be_cpu
->is_watchpoint_set(&dbg_context
, bp
[i
].info
)))
573 dbg_curr_process
->be_cpu
->clear_watchpoint(&dbg_context
, bp
[i
].info
);
575 if (get_watched_value(i
, &val
))
577 bp
[i
].w
.oldval
= val
;
583 /* Method 1 failed, trying method 2 */
585 /* Method 2 => check if value has changed among registered watchpoints
586 * this really sucks, but this is how gdb 4.18 works on my linux box
589 for (i
= 0; i
< dbg_curr_process
->next_bp
; i
++)
593 if (bp
[i
].refcount
&& bp
[i
].enabled
&& !is_xpoint_break(i
) &&
594 get_watched_value(i
, &val
))
596 if (val
!= bp
[i
].w
.oldval
)
598 dbg_curr_process
->be_cpu
->clear_watchpoint(&dbg_context
, bp
[i
].info
);
599 bp
[i
].w
.oldval
= val
;
601 /* cannot break, because two watch points may have been triggered on
603 * only one will be reported to the user (FIXME ?)
611 /***********************************************************************
614 * Display break & watch points information.
616 void break_info(void)
619 int nbp
= 0, nwp
= 0;
620 struct dbg_delayed_bp
* dbp
= dbg_curr_process
->delayed_bp
;
621 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
623 for (i
= 1; i
< dbg_curr_process
->next_bp
; i
++)
627 if (is_xpoint_break(i
)) nbp
++; else nwp
++;
633 dbg_printf("Breakpoints:\n");
634 for (i
= 1; i
< dbg_curr_process
->next_bp
; i
++)
636 if (!bp
[i
].refcount
|| !is_xpoint_break(i
))
638 dbg_printf("%d: %c ", i
, bp
[i
].enabled
? 'y' : 'n');
639 print_address(&bp
[i
].addr
, TRUE
);
640 dbg_printf(" (%u)%s\n", bp
[i
].refcount
,
641 bp
[i
].xpoint_type
== be_xpoint_watch_exec
? " (hardware assisted)" : "");
642 if (bp
[i
].condition
!= NULL
)
644 dbg_printf("\t\tstop when ");
645 expr_print(bp
[i
].condition
);
650 else dbg_printf("No breakpoints\n");
653 dbg_printf("Watchpoints:\n");
654 for (i
= 1; i
< dbg_curr_process
->next_bp
; i
++)
656 if (!bp
[i
].refcount
|| is_xpoint_break(i
))
658 dbg_printf("%d: %c ", i
, bp
[i
].enabled
? 'y' : 'n');
659 print_address(&bp
[i
].addr
, TRUE
);
660 dbg_printf(" on %d byte%s (%c)\n",
661 bp
[i
].w
.len
+ 1, bp
[i
].w
.len
> 0 ? "s" : "",
662 bp
[i
].xpoint_type
== be_xpoint_watch_write
? 'W' : 'R');
663 if (bp
[i
].condition
!= NULL
)
665 dbg_printf("\t\tstop when ");
666 expr_print(bp
[i
].condition
);
671 else dbg_printf("No watchpoints\n");
672 if (dbg_curr_process
->num_delayed_bp
)
674 dbg_printf("Delayed breakpoints:\n");
675 for (i
= 0; i
< dbg_curr_process
->num_delayed_bp
; i
++)
677 if (dbp
[i
].is_symbol
)
679 dbg_printf("%d: %s", i
, dbp
[i
].u
.symbol
.name
);
680 if (dbp
[i
].u
.symbol
.lineno
!= -1)
681 dbg_printf(" at line %u", dbp
[i
].u
.symbol
.lineno
);
685 dbg_printf("%d: ", i
);
686 print_address(&dbp
[i
].u
.addr
, FALSE
);
693 /***********************************************************************
696 * Check whether or not the condition (bp / skipcount) of a break/watch
699 static BOOL
should_stop(int bpnum
)
701 struct dbg_breakpoint
* bp
= &dbg_curr_process
->bp
[bpnum
];
703 if (bp
->condition
!= NULL
)
705 struct dbg_lvalue lvalue
= expr_eval(bp
->condition
);
707 if (lvalue
.type
.id
== dbg_itype_none
)
710 * Something wrong - unable to evaluate this expression.
712 dbg_printf("Unable to evaluate expression ");
713 expr_print(bp
->condition
);
714 dbg_printf("\nTurning off condition\n");
715 break_add_condition(bpnum
, NULL
);
717 else if (!types_extract_as_integer(&lvalue
))
723 if (bp
->skipcount
> 0) bp
->skipcount
--;
724 return bp
->skipcount
== 0;
727 /***********************************************************************
728 * break_should_continue
730 * Determine if we should continue execution after a SIGTRAP signal when
731 * executing in the given mode.
733 BOOL
break_should_continue(ADDRESS64
* addr
, DWORD code
)
735 enum dbg_exec_mode mode
= dbg_curr_thread
->exec_mode
;
738 if (dbg_curr_thread
->stopped_xpoint
> 0)
740 if (!should_stop(dbg_curr_thread
->stopped_xpoint
)) return TRUE
;
742 switch (dbg_curr_process
->bp
[dbg_curr_thread
->stopped_xpoint
].xpoint_type
)
744 case be_xpoint_break
:
745 case be_xpoint_watch_exec
:
746 dbg_printf("Stopped on breakpoint %d at ", dbg_curr_thread
->stopped_xpoint
);
747 print_address(&dbg_curr_process
->bp
[dbg_curr_thread
->stopped_xpoint
].addr
, TRUE
);
750 case be_xpoint_watch_read
:
751 case be_xpoint_watch_write
:
752 dbg_printf("Stopped on watchpoint %d at ", dbg_curr_thread
->stopped_xpoint
);
753 print_address(addr
, TRUE
);
754 dbg_printf(" new value %I64x\n",
755 dbg_curr_process
->bp
[dbg_curr_thread
->stopped_xpoint
].w
.oldval
);
761 * If our mode indicates that we are stepping line numbers,
762 * get the current function, and figure out if we are exactly
763 * on a line number or not.
765 if (mode
== dbg_exec_step_over_line
|| mode
== dbg_exec_step_into_line
)
767 if (symbol_get_function_line_status(addr
) == dbg_on_a_line_number
)
768 dbg_curr_thread
->exec_count
--;
770 else if (mode
== dbg_exec_step_over_insn
|| mode
== dbg_exec_step_into_insn
)
771 dbg_curr_thread
->exec_count
--;
773 if (dbg_curr_thread
->exec_count
> 0 || mode
== dbg_exec_finish
)
776 * We still need to execute more instructions.
781 /* no breakpoint, continue if in continuous mode */
782 return mode
== dbg_exec_cont
|| mode
== dbg_exec_finish
;
785 /***********************************************************************
788 * Adjust PC to the address where the trap (if any) actually occurred
789 * Also sets dbg_curr_thread->stopped_xpoint
791 void break_adjust_pc(ADDRESS64
* addr
, DWORD code
, BOOL first_chance
, BOOL
* is_break
)
793 /* break / watch points are handled on first chance */
797 dbg_curr_thread
->stopped_xpoint
= -1;
802 /* If not single-stepping, back up to the break instruction */
803 if (code
== EXCEPTION_BREAKPOINT
)
804 addr
->Offset
+= dbg_curr_process
->be_cpu
->adjust_pc_for_break(&dbg_context
, TRUE
);
806 dbg_curr_thread
->stopped_xpoint
= find_xpoint(addr
, be_xpoint_break
);
807 dbg_curr_process
->bp
[0].enabled
= FALSE
; /* disable the step-over breakpoint */
809 if (dbg_curr_thread
->stopped_xpoint
> 0) return;
811 if (dbg_curr_thread
->stopped_xpoint
< 0)
813 dbg_curr_thread
->stopped_xpoint
= find_xpoint(addr
, be_xpoint_watch_exec
);
814 if (dbg_curr_thread
->stopped_xpoint
< 0)
815 dbg_curr_thread
->stopped_xpoint
= find_triggered_watch();
816 if (dbg_curr_thread
->stopped_xpoint
> 0)
818 /* If not single-stepping, do not back up over the break instruction */
819 if (code
== EXCEPTION_BREAKPOINT
)
820 addr
->Offset
+= dbg_curr_process
->be_cpu
->adjust_pc_for_break(&dbg_context
, FALSE
);
825 /* If there's no breakpoint and we are not single-stepping, then
826 * either we must have encountered a break insn in the Windows program
827 * or someone is trying to stop us
829 if (dbg_curr_thread
->stopped_xpoint
== -1 && code
== EXCEPTION_BREAKPOINT
)
832 addr
->Offset
+= dbg_curr_process
->be_cpu
->adjust_pc_for_break(&dbg_context
, FALSE
);
836 /***********************************************************************
837 * break_suspend_execution
839 * Remove all bp before entering the debug loop
841 void break_suspend_execution(void)
843 break_set_xpoints(FALSE
);
844 dbg_curr_process
->bp
[0] = dbg_curr_thread
->step_over_bp
;
847 /***********************************************************************
848 * break_restart_execution
850 * Set the bp to the correct state to restart execution
853 void break_restart_execution(int count
)
856 enum dbg_line_status status
;
857 enum dbg_exec_mode mode
, ret_mode
;
861 memory_get_current_pc(&addr
);
862 linear
= memory_to_linear_addr(&addr
);
865 * This is the mode we will be running in after we finish. We would like
866 * to be able to modify this in certain cases.
868 ret_mode
= mode
= dbg_curr_thread
->exec_mode
;
870 /* we've stopped on a xpoint (other than step over) */
871 if (dbg_curr_thread
->stopped_xpoint
> 0)
874 * If we have set a new value, then save it in the BP number.
876 if (count
!= 0 && mode
== dbg_exec_cont
)
878 dbg_curr_process
->bp
[dbg_curr_thread
->stopped_xpoint
].skipcount
= count
;
880 /* If we've stopped on a breakpoint, single step over it (, then run) */
881 if (is_xpoint_break(dbg_curr_thread
->stopped_xpoint
))
882 mode
= dbg_exec_step_into_insn
;
884 else if (mode
== dbg_exec_cont
&& count
> 1)
886 dbg_printf("Not stopped at any breakpoint; argument ignored.\n");
889 if (mode
== dbg_exec_finish
&& dbg_curr_process
->be_cpu
->is_function_return(linear
))
891 mode
= ret_mode
= dbg_exec_step_into_insn
;
895 * See if the function we are stepping into has debug info
896 * and line numbers. If not, then we step over it instead.
897 * FIXME - we need to check for things like thunks or trampolines,
898 * as the actual function may in fact have debug info.
900 if (dbg_curr_process
->be_cpu
->is_function_call(linear
, &callee
))
902 status
= symbol_get_function_line_status(&callee
);
904 /* FIXME: we need to get the thunk type */
906 * Anytime we have a trampoline, step over it.
908 if ((mode
== EXEC_STEP_OVER
|| mode
== EXEC_STEPI_OVER
)
909 && status
== dbg_in_a_thunk
)
911 WINE_WARN("Not stepping into trampoline at %p (no lines)\n",
912 memory_to_linear_addr(&callee
));
913 mode
= EXEC_STEP_OVER_TRAMPOLINE
;
916 if (mode
== dbg_exec_step_into_line
&& status
== dbg_no_line_info
)
918 WINE_WARN("Not stepping into function at %p (no lines)\n",
919 memory_to_linear_addr(&callee
));
920 mode
= dbg_exec_step_over_line
;
924 if (mode
== dbg_exec_step_into_line
&&
925 symbol_get_function_line_status(&addr
) == dbg_no_line_info
)
927 dbg_printf("Single stepping until exit from function,\n"
928 "which has no line number information.\n");
929 ret_mode
= mode
= dbg_exec_finish
;
934 case dbg_exec_cont
: /* Continuous execution */
935 dbg_curr_process
->be_cpu
->single_step(&dbg_context
, FALSE
);
936 break_set_xpoints(TRUE
);
940 case EXEC_STEP_OVER_TRAMPOLINE
:
942 * This is the means by which we step over our conversion stubs
943 * in callfrom*.s and callto*.s. We dig the appropriate address
944 * off the stack, and we set the breakpoint there instead of the
945 * address just after the call.
947 be_cpu
->get_addr(dbg_curr_thread
->handle
, &dbg_context
,
948 be_cpu_addr_stack
, &addr
);
949 /* FIXME: we assume stack grows as on an i386 */
950 addr
.Offset
+= 2 * sizeof(unsigned int);
951 dbg_read_memory(memory_to_linear_addr(&addr
),
952 &addr
.Offset
, sizeof(addr
.Offset
));
953 dbg_curr_process
->bp
[0].addr
= addr
;
954 dbg_curr_process
->bp
[0].enabled
= TRUE
;
955 dbg_curr_process
->bp
[0].refcount
= 1;
956 dbg_curr_process
->bp
[0].skipcount
= 0;
957 dbg_curr_process
->bp
[0].xpoint_type
= be_xpoint_break
;
958 dbg_curr_process
->bp
[0].condition
= NULL
;
959 be_cpu
->single_step(&dbg_context
, FALSE
);
960 break_set_xpoints(TRUE
);
964 case dbg_exec_finish
:
965 case dbg_exec_step_over_insn
: /* Stepping over a call */
966 case dbg_exec_step_over_line
: /* Stepping over a call */
967 if (dbg_curr_process
->be_cpu
->is_step_over_insn(linear
))
969 dbg_curr_process
->be_cpu
->disasm_one_insn(&addr
, FALSE
);
970 dbg_curr_process
->bp
[0].addr
= addr
;
971 dbg_curr_process
->bp
[0].enabled
= TRUE
;
972 dbg_curr_process
->bp
[0].refcount
= 1;
973 dbg_curr_process
->bp
[0].skipcount
= 0;
974 dbg_curr_process
->bp
[0].xpoint_type
= be_xpoint_break
;
975 dbg_curr_process
->bp
[0].condition
= NULL
;
976 dbg_curr_process
->be_cpu
->single_step(&dbg_context
, FALSE
);
977 break_set_xpoints(TRUE
);
980 /* else fall through to single-stepping */
982 case dbg_exec_step_into_line
: /* Single-stepping a line */
983 case dbg_exec_step_into_insn
: /* Single-stepping an instruction */
984 dbg_curr_process
->be_cpu
->single_step(&dbg_context
, TRUE
);
986 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
988 dbg_curr_thread
->step_over_bp
= dbg_curr_process
->bp
[0];
989 dbg_curr_thread
->exec_mode
= ret_mode
;
992 BOOL
break_add_condition(int num
, struct expr
* exp
)
994 if (num
<= 0 || num
>= dbg_curr_process
->next_bp
||
995 !dbg_curr_process
->bp
[num
].refcount
)
997 dbg_printf("Invalid breakpoint number %d\n", num
);
1001 if (dbg_curr_process
->bp
[num
].condition
!= NULL
)
1003 expr_free(dbg_curr_process
->bp
[num
].condition
);
1004 dbg_curr_process
->bp
[num
].condition
= NULL
;
1007 if (exp
!= NULL
) dbg_curr_process
->bp
[num
].condition
= expr_clone(exp
, NULL
);