2 * Debugger break-points handling
4 * Copyright 1994 Martin von Loewis
5 * Copyright 1995 Alexandre Julliard
6 * Copyright 1999,2000 Eric Pouech
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(winedbg
);
29 /***********************************************************************
32 * Set or remove all the breakpoints & watchpoints
34 void break_set_xpoints(BOOL set
)
36 static BOOL last
; /* = 0 = FALSE */
38 unsigned int i
, ret
, size
;
40 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
42 if (set
== last
) return;
45 for (i
= 0; i
< dbg_curr_process
->next_bp
; i
++)
47 if (!bp
[i
].refcount
|| !bp
[i
].enabled
) continue;
49 if (bp
[i
].xpoint_type
== be_xpoint_break
)
52 size
= bp
[i
].w
.len
+ 1;
53 addr
= (void*)memory_to_linear_addr(&bp
[i
].addr
);
56 ret
= be_cpu
->insert_Xpoint(dbg_curr_process
->handle
, &dbg_context
,
57 bp
[i
].xpoint_type
, addr
,
60 ret
= be_cpu
->remove_Xpoint(dbg_curr_process
->handle
, &dbg_context
,
61 bp
[i
].xpoint_type
, addr
,
65 dbg_printf("Invalid address (");
66 print_address(&bp
[i
].addr
, FALSE
);
67 dbg_printf(") for breakpoint %d, disabling it\n", i
);
68 bp
[i
].enabled
= FALSE
;
73 /***********************************************************************
76 * Find the breakpoint for a given address. Return the breakpoint
77 * number or -1 if none.
79 static int find_xpoint(const ADDRESS
* addr
, enum be_xpoint_type type
)
82 void* lin
= memory_to_linear_addr(addr
);
83 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
85 for (i
= 0; i
< dbg_curr_process
->next_bp
; i
++)
87 if (bp
[i
].refcount
&& bp
[i
].enabled
&& bp
[i
].xpoint_type
== type
&&
88 memory_to_linear_addr(&bp
[i
].addr
) == lin
)
94 /***********************************************************************
97 * Find an empty slot in BP table to add a new break/watch point
99 static int init_xpoint(int type
, const ADDRESS
* addr
)
102 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
104 for (num
= (dbg_curr_process
->next_bp
< MAX_BREAKPOINTS
) ?
105 dbg_curr_process
->next_bp
++ : 1;
106 num
< MAX_BREAKPOINTS
; num
++)
108 if (bp
[num
].refcount
== 0)
110 bp
[num
].refcount
= 1;
111 bp
[num
].enabled
= TRUE
;
112 bp
[num
].xpoint_type
= type
;
113 bp
[num
].skipcount
= 0;
114 bp
[num
].addr
= *addr
;
119 dbg_printf("Too many bp. Please delete some.\n");
123 /***********************************************************************
126 * Returns the value watched by watch point 'num'.
128 static BOOL
get_watched_value(int num
, LPDWORD val
)
132 if (!dbg_read_memory(memory_to_linear_addr(&dbg_curr_process
->bp
[num
].addr
),
133 buf
, dbg_curr_process
->bp
[num
].w
.len
+ 1))
136 switch (dbg_curr_process
->bp
[num
].w
.len
+ 1)
138 case 4: *val
= *(DWORD
*)buf
; break;
139 case 2: *val
= *(WORD
*)buf
; break;
140 case 1: *val
= *(BYTE
*)buf
; break;
141 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
146 /***********************************************************************
151 BOOL
break_add_break(const ADDRESS
* addr
, BOOL verbose
)
155 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
157 if ((num
= find_xpoint(addr
, be_xpoint_break
)) >= 1)
160 dbg_printf("Breakpoint %d at ", num
);
161 print_address(&bp
[num
].addr
, TRUE
);
162 dbg_printf(" (refcount=%d)\n", bp
[num
].refcount
);
166 if (!dbg_read_memory(memory_to_linear_addr(addr
), &ch
, sizeof(ch
)))
170 dbg_printf("Invalid address ");
171 print_bare_address(addr
);
172 dbg_printf(", can't set breakpoint\n");
177 if ((num
= init_xpoint(be_xpoint_break
, addr
)) == -1)
180 dbg_printf("Breakpoint %d at ", num
);
181 print_address(&bp
[num
].addr
, TRUE
);
187 /***********************************************************************
188 * break_add_break_from_lvalue
192 BOOL
break_add_break_from_lvalue(const struct dbg_lvalue
* lvalue
)
196 addr
.Mode
= AddrModeFlat
;
197 addr
.Offset
= types_extract_as_integer(lvalue
);
199 if (!break_add_break(&addr
, TRUE
))
201 if (!DBG_IVAR(CanDeferOnBPByAddr
))
203 dbg_printf("Invalid address, can't set breakpoint\n"
204 "You can turn on deferring bp by address by setting $CanDeferOnBPByAddr to 1\n");
207 dbg_printf("Unable to add breakpoint, will check again any time a new DLL is loaded\n");
208 dbg_curr_process
->delayed_bp
=
209 dbg_heap_realloc(dbg_curr_process
->delayed_bp
,
210 sizeof(struct dbg_delayed_bp
) * ++dbg_curr_process
->num_delayed_bp
);
212 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].is_symbol
= FALSE
;
213 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].u
.addr
= addr
;
219 /***********************************************************************
220 * break_add_break_from_id
222 * Add a breakpoint from a function name (and eventually a line #)
224 void break_add_break_from_id(const char *name
, int lineno
)
226 struct dbg_lvalue lvalue
;
229 switch (symbol_get_lvalue(name
, lineno
, &lvalue
, TRUE
))
232 break_add_break(&lvalue
.addr
, TRUE
);
236 case sglv_aborted
: /* user aborted symbol lookup */
240 dbg_printf("Unable to add breakpoint, will check again when a new DLL is loaded\n");
241 for (i
= 0; i
< dbg_curr_process
->num_delayed_bp
; i
++)
243 if (dbg_curr_process
->delayed_bp
[i
].is_symbol
&&
244 !strcmp(name
, dbg_curr_process
->delayed_bp
[i
].u
.symbol
.name
) &&
245 lineno
== dbg_curr_process
->delayed_bp
[i
].u
.symbol
.lineno
)
248 dbg_curr_process
->delayed_bp
= dbg_heap_realloc(dbg_curr_process
->delayed_bp
,
249 sizeof(struct dbg_delayed_bp
) * ++dbg_curr_process
->num_delayed_bp
);
251 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].is_symbol
= TRUE
;
252 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].u
.symbol
.name
= strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(name
) + 1), name
);
253 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].u
.symbol
.lineno
= lineno
;
256 /***********************************************************************
257 * break_add_break_from_lineno
259 * Add a breakpoint from a line number in current file
261 void break_add_break_from_lineno(int lineno
)
265 memory_get_current_pc(&addr
);
273 il
.SizeOfStruct
= sizeof(il
);
274 if (!SymGetLineFromAddr(dbg_curr_process
->handle
,
275 (DWORD
)memory_to_linear_addr(&addr
), NULL
, &il
))
277 dbg_printf("Unable to add breakpoint (unknown address)\n");
282 while (SymGetLinePrev(dbg_curr_process
->handle
, &iil
))
284 if (lineno
== iil
.LineNumber
&& !strcmp(il
.FileName
, iil
.FileName
))
286 addr
.Mode
= AddrModeFlat
;
287 addr
.Offset
= iil
.Address
;
293 if (!found
) while (SymGetLineNext(dbg_curr_process
->handle
, &iil
))
295 if (lineno
== iil
.LineNumber
&& !strcmp(il
.FileName
, iil
.FileName
))
297 addr
.Mode
= AddrModeFlat
;
298 addr
.Offset
= iil
.Address
;
305 dbg_printf("Unknown line number\n"
306 "(either out of file, or no code at given line number)\n");
311 break_add_break(&addr
, TRUE
);
314 /***********************************************************************
315 * break_check_delayed_bp
317 * Check is a registered delayed BP is now available.
319 void break_check_delayed_bp(void)
321 struct dbg_lvalue lvalue
;
323 struct dbg_delayed_bp
* dbp
= dbg_curr_process
->delayed_bp
;
325 for (i
= 0; i
< dbg_curr_process
->num_delayed_bp
; i
++)
327 if (dbp
[i
].is_symbol
)
329 if (symbol_get_lvalue(dbp
[i
].u
.symbol
.name
, dbp
[i
].u
.symbol
.lineno
,
330 &lvalue
, TRUE
) != sglv_found
)
332 if (lvalue
.cookie
!= DLV_TARGET
) continue;
335 lvalue
.addr
= dbp
[i
].u
.addr
;
336 WINE_TRACE("trying to add delayed %s-bp\n", dbp
[i
].is_symbol
? "S" : "A");
337 if (!dbp
[i
].is_symbol
)
338 WINE_TRACE("\t%04x:%08lx\n",
339 dbp
[i
].u
.addr
.Segment
, dbp
[i
].u
.addr
.Offset
);
341 WINE_TRACE("\t'%s' @ %d\n",
342 dbp
[i
].u
.symbol
.name
, dbp
[i
].u
.symbol
.lineno
);
344 if (break_add_break(&lvalue
.addr
, FALSE
))
345 memmove(&dbp
[i
], &dbp
[i
+1], (--dbg_curr_process
->num_delayed_bp
- i
) * sizeof(*dbp
));
349 /***********************************************************************
354 static void break_add_watch(const struct dbg_lvalue
* lvalue
, BOOL is_write
)
359 num
= init_xpoint((is_write
) ? be_xpoint_watch_write
: be_xpoint_watch_read
,
361 if (num
== -1) return;
363 if (lvalue
->type
.id
!= dbg_itype_none
)
365 if (types_get_info(&lvalue
->type
, TI_GET_LENGTH
, &l
))
369 case 4: case 2: case 1: break;
371 dbg_printf("Unsupported length (%lu) for watch-points, defaulting to 4\n", l
);
375 else dbg_printf("Cannot get watch size, defaulting to 4\n");
377 dbg_curr_process
->bp
[num
].w
.len
= l
- 1;
379 if (!get_watched_value(num
, &dbg_curr_process
->bp
[num
].w
.oldval
))
381 dbg_printf("Bad address. Watchpoint not set\n");
382 dbg_curr_process
->bp
[num
].refcount
= 0;
385 dbg_printf("Watchpoint %d at ", num
);
386 print_address(&dbg_curr_process
->bp
[num
].addr
, TRUE
);
390 /******************************************************************
391 * break_add_watch_from_lvalue
393 * Adds a watch point from an address (stored in a lvalue)
395 void break_add_watch_from_lvalue(const struct dbg_lvalue
* lvalue
)
397 struct dbg_lvalue lval
;
399 lval
.addr
.Mode
= AddrModeFlat
;
400 lval
.addr
.Offset
= types_extract_as_integer(lvalue
);
401 lval
.type
.id
= dbg_itype_none
;
403 break_add_watch(&lval
, TRUE
);
406 /***********************************************************************
407 * break_add_watch_from_id
409 * Add a watchpoint from a symbol name
411 void break_add_watch_from_id(const char *name
)
413 struct dbg_lvalue lvalue
;
415 switch (symbol_get_lvalue(name
, -1, &lvalue
, TRUE
))
418 break_add_watch(&lvalue
, 1);
421 dbg_printf("Unable to add watchpoint\n");
423 case sglv_aborted
: /* user aborted symbol lookup */
428 /***********************************************************************
429 * break_delete_xpoint
431 * Delete a breakpoint.
433 void break_delete_xpoint(int num
)
435 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
437 if ((num
<= 0) || (num
>= dbg_curr_process
->next_bp
) ||
438 bp
[num
].refcount
== 0)
440 dbg_printf("Invalid breakpoint number %d\n", num
);
444 if (--bp
[num
].refcount
> 0)
447 if (bp
[num
].condition
!= NULL
)
449 expr_free(bp
[num
].condition
);
450 bp
[num
].condition
= NULL
;
453 bp
[num
].enabled
= FALSE
;
454 bp
[num
].refcount
= 0;
455 bp
[num
].skipcount
= 0;
458 static inline BOOL
module_is_container(const IMAGEHLP_MODULE
* wmod_cntnr
,
459 const IMAGEHLP_MODULE
* wmod_child
)
461 return wmod_cntnr
->BaseOfImage
<= wmod_child
->BaseOfImage
&&
462 (DWORD
)wmod_cntnr
->BaseOfImage
+ wmod_cntnr
->ImageSize
>=
463 (DWORD
)wmod_child
->BaseOfImage
+ wmod_child
->ImageSize
;
466 /******************************************************************
467 * break_delete_xpoints_from_module
469 * Remove all Xpoints from module which base is 'base'
471 void break_delete_xpoints_from_module(unsigned long base
)
473 IMAGEHLP_MODULE im
, im_elf
;
476 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
478 /* FIXME: should do it also on the ELF sibbling if any */
479 im
.SizeOfStruct
= sizeof(im
);
480 im_elf
.SizeOfStruct
= sizeof(im_elf
);
481 if (!SymGetModuleInfo(dbg_curr_process
->handle
, base
, &im
)) return;
483 /* try to get in fact the underlying ELF module (if any) */
484 if (SymGetModuleInfo(dbg_curr_process
->handle
, im
.BaseOfImage
- 1, &im_elf
) &&
485 im_elf
.BaseOfImage
<= im
.BaseOfImage
&&
486 (DWORD
)im_elf
.BaseOfImage
+ im_elf
.ImageSize
>= (DWORD
)im
.BaseOfImage
+ im
.ImageSize
)
489 for (i
= 0; i
< dbg_curr_process
->next_bp
; i
++)
491 linear
= (DWORD
)memory_to_linear_addr(&bp
[i
].addr
);
492 if (bp
[i
].refcount
&& bp
[i
].enabled
&&
493 im
.BaseOfImage
<= linear
&& linear
< im
.BaseOfImage
+ im
.ImageSize
)
495 break_delete_xpoint(i
);
500 /***********************************************************************
501 * break_enable_xpoint
503 * Enable or disable a break point.
505 void break_enable_xpoint(int num
, BOOL enable
)
507 if ((num
<= 0) || (num
>= dbg_curr_process
->next_bp
) ||
508 dbg_curr_process
->bp
[num
].refcount
== 0)
510 dbg_printf("Invalid breakpoint number %d\n", num
);
513 dbg_curr_process
->bp
[num
].enabled
= (enable
) ? TRUE
: FALSE
;
514 dbg_curr_process
->bp
[num
].skipcount
= 0;
518 /***********************************************************************
519 * find_triggered_watch
521 * Lookup the watchpoints to see if one has been triggered
522 * Return >= (watch point index) if one is found and *oldval is set to
523 * the value watched before the TRAP
524 * Return -1 if none found (*oldval is undetermined)
526 * Unfortunately, Linux does *NOT* (A REAL PITA) report with ptrace
527 * the DR6 register value, so we have to look with our own need the
531 static int find_triggered_watch(LPDWORD oldval
)
535 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
537 /* Method 1 => get triggered watchpoint from context (doesn't work on Linux
538 * 2.2.x). This should be fixed in >= 2.2.16
540 for (i
= 0; i
< dbg_curr_process
->next_bp
; i
++)
544 if (bp
[i
].refcount
&& bp
[i
].enabled
&& bp
[i
].xpoint_type
!= be_xpoint_break
&&
545 (be_cpu
->is_watchpoint_set(&dbg_context
, bp
[i
].info
)))
547 be_cpu
->clear_watchpoint(&dbg_context
, bp
[i
].info
);
549 *oldval
= bp
[i
].w
.oldval
;
550 if (get_watched_value(i
, &val
))
552 bp
[i
].w
.oldval
= val
;
558 /* Method 1 failed, trying method 2 */
560 /* Method 2 => check if value has changed among registered watchpoints
561 * this really sucks, but this is how gdb 4.18 works on my linux box
564 for (i
= 0; i
< dbg_curr_process
->next_bp
; i
++)
568 if (bp
[i
].refcount
&& bp
[i
].enabled
&& bp
[i
].xpoint_type
!= be_xpoint_break
&&
569 get_watched_value(i
, &val
))
571 *oldval
= bp
[i
].w
.oldval
;
574 be_cpu
->clear_watchpoint(&dbg_context
, bp
[i
].info
);
575 bp
[i
].w
.oldval
= val
;
577 /* cannot break, because two watch points may have been triggered on
579 * only one will be reported to the user (FIXME ?)
587 /***********************************************************************
590 * Display break & watch points information.
592 void break_info(void)
595 int nbp
= 0, nwp
= 0;
596 struct dbg_delayed_bp
* dbp
= dbg_curr_process
->delayed_bp
;
597 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
599 for (i
= 1; i
< dbg_curr_process
->next_bp
; i
++)
603 if (bp
[i
].xpoint_type
== be_xpoint_break
) nbp
++; else nwp
++;
609 dbg_printf("Breakpoints:\n");
610 for (i
= 1; i
< dbg_curr_process
->next_bp
; i
++)
612 if (!bp
[i
].refcount
|| bp
[i
].xpoint_type
!= be_xpoint_break
)
614 dbg_printf("%d: %c ", i
, bp
[i
].enabled
? 'y' : 'n');
615 print_address(&bp
[i
].addr
, TRUE
);
616 dbg_printf(" (%u)\n", bp
[i
].refcount
);
617 if (bp
[i
].condition
!= NULL
)
619 dbg_printf("\t\tstop when ");
620 expr_print(bp
[i
].condition
);
625 else dbg_printf("No breakpoints\n");
628 dbg_printf("Watchpoints:\n");
629 for (i
= 1; i
< dbg_curr_process
->next_bp
; i
++)
631 if (!bp
[i
].refcount
|| bp
[i
].xpoint_type
== be_xpoint_break
)
633 dbg_printf("%d: %c ", i
, bp
[i
].enabled
? 'y' : 'n');
634 print_address(&bp
[i
].addr
, TRUE
);
635 dbg_printf(" on %d byte%s (%c)\n",
636 bp
[i
].w
.len
+ 1, bp
[i
].w
.len
> 0 ? "s" : "",
637 bp
[i
].xpoint_type
== be_xpoint_watch_write
? 'W' : 'R');
638 if (bp
[i
].condition
!= NULL
)
640 dbg_printf("\t\tstop when ");
641 expr_print(bp
[i
].condition
);
646 else dbg_printf("No watchpoints\n");
647 if (dbg_curr_process
->num_delayed_bp
)
649 dbg_printf("Delayed breakpoints:\n");
650 for (i
= 0; i
< dbg_curr_process
->num_delayed_bp
; i
++)
652 if (dbp
[i
].is_symbol
)
654 dbg_printf("%d: %s", i
, dbp
[i
].u
.symbol
.name
);
655 if (dbp
[i
].u
.symbol
.lineno
!= -1)
656 dbg_printf(" at line %u", dbp
[i
].u
.symbol
.lineno
);
660 dbg_printf("%d: ", i
);
661 print_address(&dbp
[i
].u
.addr
, FALSE
);
668 /***********************************************************************
671 * Check whether or not the condition (bp / skipcount) of a break/watch
674 static BOOL
should_stop(int bpnum
)
676 struct dbg_breakpoint
* bp
= &dbg_curr_process
->bp
[bpnum
];
678 if (bp
->condition
!= NULL
)
680 struct dbg_lvalue lvalue
= expr_eval(bp
->condition
);
682 if (lvalue
.type
.id
== dbg_itype_none
)
685 * Something wrong - unable to evaluate this expression.
687 dbg_printf("Unable to evaluate expression ");
688 expr_print(bp
->condition
);
689 dbg_printf("\nTurning off condition\n");
690 break_add_condition(bpnum
, NULL
);
692 else if (!types_extract_as_integer(&lvalue
))
698 if (bp
->skipcount
> 0) bp
->skipcount
--;
699 return bp
->skipcount
== 0;
702 /***********************************************************************
703 * break_should_continue
705 * Determine if we should continue execution after a SIGTRAP signal when
706 * executing in the given mode.
708 BOOL
break_should_continue(ADDRESS
* addr
, DWORD code
, int* count
, BOOL
* is_break
)
713 enum dbg_exec_mode mode
= dbg_curr_thread
->exec_mode
;
716 /* If not single-stepping, back up to the break instruction */
717 if (code
== EXCEPTION_BREAKPOINT
)
718 addr
->Offset
+= be_cpu
->adjust_pc_for_break(&dbg_context
, TRUE
);
720 bpnum
= find_xpoint(addr
, be_xpoint_break
);
721 dbg_curr_process
->bp
[0].enabled
= FALSE
; /* disable the step-over breakpoint */
725 if (!should_stop(bpnum
)) return TRUE
;
727 dbg_printf("Stopped on breakpoint %d at ", bpnum
);
728 print_address(&dbg_curr_process
->bp
[bpnum
].addr
, TRUE
);
733 wpnum
= find_triggered_watch(&oldval
);
736 /* If not single-stepping, do not back up over the break instruction */
737 if (code
== EXCEPTION_BREAKPOINT
)
738 addr
->Offset
+= be_cpu
->adjust_pc_for_break(&dbg_context
, FALSE
);
740 if (!should_stop(wpnum
)) return TRUE
;
742 dbg_printf("Stopped on watchpoint %d at ", wpnum
);
743 print_address(addr
, TRUE
);
744 dbg_printf(" values: old=%lu new=%lu\n",
745 oldval
, dbg_curr_process
->bp
[wpnum
].w
.oldval
);
750 * If our mode indicates that we are stepping line numbers,
751 * get the current function, and figure out if we are exactly
752 * on a line number or not.
754 if (mode
== dbg_exec_step_over_line
|| mode
== dbg_exec_step_into_line
)
756 if (symbol_get_function_line_status(addr
) == dbg_on_a_line_number
)
761 else if (mode
== dbg_exec_step_over_insn
|| mode
== dbg_exec_step_into_insn
)
766 if (*count
> 0 || mode
== dbg_exec_finish
)
769 * We still need to execute more instructions.
774 /* If there's no breakpoint and we are not single-stepping, then
775 * either we must have encountered a break insn in the Windows program
776 * or someone is trying to stop us
778 if (bpnum
== -1 && code
== EXCEPTION_BREAKPOINT
)
781 addr
->Offset
+= be_cpu
->adjust_pc_for_break(&dbg_context
, FALSE
);
785 /* no breakpoint, continue if in continuous mode */
786 return mode
== dbg_exec_cont
|| mode
== dbg_exec_finish
;
789 /***********************************************************************
790 * break_suspend_execution
792 * Remove all bp before entering the debug loop
794 void break_suspend_execution(void)
796 break_set_xpoints(FALSE
);
797 dbg_curr_process
->bp
[0] = dbg_curr_thread
->step_over_bp
;
800 /***********************************************************************
801 * break_restart_execution
803 * Set the bp to the correct state to restart execution
806 void break_restart_execution(int count
)
810 enum dbg_line_status status
;
811 enum dbg_exec_mode mode
, ret_mode
;
815 memory_get_current_pc(&addr
);
816 linear
= memory_to_linear_addr(&addr
);
819 * This is the mode we will be running in after we finish. We would like
820 * to be able to modify this in certain cases.
822 ret_mode
= mode
= dbg_curr_thread
->exec_mode
;
824 bp
= find_xpoint(&addr
, be_xpoint_break
);
825 if (bp
!= -1 && bp
!= 0)
828 * If we have set a new value, then save it in the BP number.
830 if (count
!= 0 && mode
== dbg_exec_cont
)
832 dbg_curr_process
->bp
[bp
].skipcount
= count
;
834 mode
= dbg_exec_step_into_insn
; /* If there's a breakpoint, skip it */
836 else if (mode
== dbg_exec_cont
&& count
> 1)
838 dbg_printf("Not stopped at any breakpoint; argument ignored.\n");
841 if (mode
== dbg_exec_finish
&& be_cpu
->is_function_return(linear
))
843 mode
= ret_mode
= dbg_exec_step_into_insn
;
847 * See if the function we are stepping into has debug info
848 * and line numbers. If not, then we step over it instead.
849 * FIXME - we need to check for things like thunks or trampolines,
850 * as the actual function may in fact have debug info.
852 if (be_cpu
->is_function_call(linear
, &callee
))
854 status
= symbol_get_function_line_status(&callee
);
856 /* FIXME: we need to get the thunk type */
858 * Anytime we have a trampoline, step over it.
860 if ((mode
== EXEC_STEP_OVER
|| mode
== EXEC_STEPI_OVER
)
861 && status
== dbg_in_a_thunk
)
863 WINE_WARN("Not stepping into trampoline at %p (no lines)\n",
864 memory_to_linear_addr(&callee
));
865 mode
= EXEC_STEP_OVER_TRAMPOLINE
;
868 if (mode
== dbg_exec_step_into_line
&& status
== dbg_no_line_info
)
870 WINE_WARN("Not stepping into function at %p (no lines)\n",
871 memory_to_linear_addr(&callee
));
872 mode
= dbg_exec_step_over_line
;
876 if (mode
== dbg_exec_step_into_line
&&
877 symbol_get_function_line_status(&addr
) == dbg_no_line_info
)
879 dbg_printf("Single stepping until exit from function, \n"
880 "which has no line number information.\n");
881 ret_mode
= mode
= dbg_exec_finish
;
886 case dbg_exec_cont
: /* Continuous execution */
887 be_cpu
->single_step(&dbg_context
, FALSE
);
888 break_set_xpoints(TRUE
);
892 case EXEC_STEP_OVER_TRAMPOLINE
:
894 * This is the means by which we step over our conversion stubs
895 * in callfrom*.s and callto*.s. We dig the appropriate address
896 * off the stack, and we set the breakpoint there instead of the
897 * address just after the call.
899 be_cpu
->get_addr(dbg_curr_thread
->handle
, &dbg_context
,
900 be_cpu_addr_stack
, &addr
);
901 /* FIXME: we assume stack grows as on a i386 */
902 addr
.Offset
+= 2 * sizeof(unsigned int);
903 dbg_read_memory(memory_to_linear_addr(&addr
),
904 &addr
.Offset
, sizeof(addr
.Offset
));
905 dbg_curr_process
->bp
[0].addr
= addr
;
906 dbg_curr_process
->bp
[0].enabled
= TRUE
;
907 dbg_curr_process
->bp
[0].refcount
= 1;
908 dbg_curr_process
->bp
[0].skipcount
= 0;
909 dbg_curr_process
->bp
[0].xpoint_type
= be_xpoint_break
;
910 dbg_curr_process
->bp
[0].condition
= NULL
;
911 be_cpu
->single_step(&dbg_context
, FALSE
);
912 break_set_xpoints(TRUE
);
916 case dbg_exec_finish
:
917 case dbg_exec_step_over_insn
: /* Stepping over a call */
918 case dbg_exec_step_over_line
: /* Stepping over a call */
919 if (be_cpu
->is_step_over_insn(linear
))
921 be_cpu
->disasm_one_insn(&addr
, FALSE
);
922 dbg_curr_process
->bp
[0].addr
= addr
;
923 dbg_curr_process
->bp
[0].enabled
= TRUE
;
924 dbg_curr_process
->bp
[0].refcount
= 1;
925 dbg_curr_process
->bp
[0].skipcount
= 0;
926 dbg_curr_process
->bp
[0].xpoint_type
= be_xpoint_break
;
927 dbg_curr_process
->bp
[0].condition
= NULL
;
928 be_cpu
->single_step(&dbg_context
, FALSE
);
929 break_set_xpoints(TRUE
);
932 /* else fall through to single-stepping */
934 case dbg_exec_step_into_line
: /* Single-stepping a line */
935 case dbg_exec_step_into_insn
: /* Single-stepping an instruction */
936 be_cpu
->single_step(&dbg_context
, TRUE
);
938 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
940 dbg_curr_thread
->step_over_bp
= dbg_curr_process
->bp
[0];
941 dbg_curr_thread
->exec_mode
= ret_mode
;
944 int break_add_condition(int num
, struct expr
* exp
)
946 if (num
<= 0 || num
>= dbg_curr_process
->next_bp
||
947 !dbg_curr_process
->bp
[num
].refcount
)
949 dbg_printf("Invalid breakpoint number %d\n", num
);
953 if (dbg_curr_process
->bp
[num
].condition
!= NULL
)
955 expr_free(dbg_curr_process
->bp
[num
].condition
);
956 dbg_curr_process
->bp
[num
].condition
= NULL
;
959 if (exp
!= NULL
) dbg_curr_process
->bp
[num
].condition
= expr_clone(exp
, NULL
);