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
,
57 dbg_curr_process
->process_io
,
58 &dbg_context
, bp
[i
].xpoint_type
, addr
,
61 ret
= be_cpu
->remove_Xpoint(dbg_curr_process
->handle
,
62 dbg_curr_process
->process_io
,
63 &dbg_context
, bp
[i
].xpoint_type
, addr
,
67 dbg_printf("Invalid address (");
68 print_address(&bp
[i
].addr
, FALSE
);
69 dbg_printf(") for breakpoint %d, disabling it\n", i
);
70 bp
[i
].enabled
= FALSE
;
75 /***********************************************************************
78 * Find the breakpoint for a given address. Return the breakpoint
79 * number or -1 if none.
81 static int find_xpoint(const ADDRESS
* addr
, enum be_xpoint_type type
)
84 void* lin
= memory_to_linear_addr(addr
);
85 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
87 for (i
= 0; i
< dbg_curr_process
->next_bp
; i
++)
89 if (bp
[i
].refcount
&& bp
[i
].enabled
&& bp
[i
].xpoint_type
== type
&&
90 memory_to_linear_addr(&bp
[i
].addr
) == lin
)
96 /***********************************************************************
99 * Find an empty slot in BP table to add a new break/watch point
101 static int init_xpoint(int type
, const ADDRESS
* addr
)
104 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
106 for (num
= (dbg_curr_process
->next_bp
< MAX_BREAKPOINTS
) ?
107 dbg_curr_process
->next_bp
++ : 1;
108 num
< MAX_BREAKPOINTS
; num
++)
110 if (bp
[num
].refcount
== 0)
112 bp
[num
].refcount
= 1;
113 bp
[num
].enabled
= TRUE
;
114 bp
[num
].xpoint_type
= type
;
115 bp
[num
].skipcount
= 0;
116 bp
[num
].addr
= *addr
;
121 dbg_printf("Too many bp. Please delete some.\n");
125 /***********************************************************************
128 * Returns the value watched by watch point 'num'.
130 static BOOL
get_watched_value(int num
, LPDWORD val
)
134 if (!dbg_read_memory(memory_to_linear_addr(&dbg_curr_process
->bp
[num
].addr
),
135 buf
, dbg_curr_process
->bp
[num
].w
.len
+ 1))
138 switch (dbg_curr_process
->bp
[num
].w
.len
+ 1)
140 case 4: *val
= *(DWORD
*)buf
; break;
141 case 2: *val
= *(WORD
*)buf
; break;
142 case 1: *val
= *(BYTE
*)buf
; break;
143 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
148 /***********************************************************************
153 BOOL
break_add_break(const ADDRESS
* addr
, BOOL verbose
)
157 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
159 if ((num
= find_xpoint(addr
, be_xpoint_break
)) >= 1)
162 dbg_printf("Breakpoint %d at ", num
);
163 print_address(&bp
[num
].addr
, TRUE
);
164 dbg_printf(" (refcount=%d)\n", bp
[num
].refcount
);
168 if (!dbg_read_memory(memory_to_linear_addr(addr
), &ch
, sizeof(ch
)))
172 dbg_printf("Invalid address ");
173 print_bare_address(addr
);
174 dbg_printf(", can't set breakpoint\n");
179 if ((num
= init_xpoint(be_xpoint_break
, addr
)) == -1)
182 dbg_printf("Breakpoint %d at ", num
);
183 print_address(&bp
[num
].addr
, TRUE
);
189 /***********************************************************************
190 * break_add_break_from_lvalue
194 BOOL
break_add_break_from_lvalue(const struct dbg_lvalue
* lvalue
)
198 addr
.Mode
= AddrModeFlat
;
199 addr
.Offset
= types_extract_as_integer(lvalue
);
201 if (!break_add_break(&addr
, TRUE
))
203 if (!DBG_IVAR(CanDeferOnBPByAddr
))
205 dbg_printf("Invalid address, can't set breakpoint\n"
206 "You can turn on deferring bp by address by setting $CanDeferOnBPByAddr to 1\n");
209 dbg_printf("Unable to add breakpoint, will check again any time a new DLL is loaded\n");
210 dbg_curr_process
->delayed_bp
=
211 dbg_heap_realloc(dbg_curr_process
->delayed_bp
,
212 sizeof(struct dbg_delayed_bp
) * ++dbg_curr_process
->num_delayed_bp
);
214 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].is_symbol
= FALSE
;
215 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].u
.addr
= addr
;
221 /***********************************************************************
222 * break_add_break_from_id
224 * Add a breakpoint from a function name (and eventually a line #)
226 void break_add_break_from_id(const char *name
, int lineno
)
228 struct dbg_lvalue lvalue
;
231 switch (symbol_get_lvalue(name
, lineno
, &lvalue
, TRUE
))
234 break_add_break(&lvalue
.addr
, TRUE
);
238 case sglv_aborted
: /* user aborted symbol lookup */
242 dbg_printf("Unable to add breakpoint, will check again when a new DLL is loaded\n");
243 for (i
= 0; i
< dbg_curr_process
->num_delayed_bp
; i
++)
245 if (dbg_curr_process
->delayed_bp
[i
].is_symbol
&&
246 !strcmp(name
, dbg_curr_process
->delayed_bp
[i
].u
.symbol
.name
) &&
247 lineno
== dbg_curr_process
->delayed_bp
[i
].u
.symbol
.lineno
)
250 dbg_curr_process
->delayed_bp
= dbg_heap_realloc(dbg_curr_process
->delayed_bp
,
251 sizeof(struct dbg_delayed_bp
) * ++dbg_curr_process
->num_delayed_bp
);
253 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].is_symbol
= TRUE
;
254 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].u
.symbol
.name
= strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(name
) + 1), name
);
255 dbg_curr_process
->delayed_bp
[dbg_curr_process
->num_delayed_bp
- 1].u
.symbol
.lineno
= lineno
;
258 /***********************************************************************
259 * break_add_break_from_lineno
261 * Add a breakpoint from a line number in current file
263 void break_add_break_from_lineno(int lineno
)
267 memory_get_current_pc(&addr
);
276 il
.SizeOfStruct
= sizeof(il
);
277 if (!SymGetLineFromAddr(dbg_curr_process
->handle
,
278 (DWORD
)memory_to_linear_addr(&addr
), &disp
, &il
))
280 dbg_printf("Unable to add breakpoint (unknown address)\n");
285 while (SymGetLinePrev(dbg_curr_process
->handle
, &iil
))
287 if (lineno
== iil
.LineNumber
&& !strcmp(il
.FileName
, iil
.FileName
))
289 addr
.Mode
= AddrModeFlat
;
290 addr
.Offset
= iil
.Address
;
296 if (!found
) while (SymGetLineNext(dbg_curr_process
->handle
, &iil
))
298 if (lineno
== iil
.LineNumber
&& !strcmp(il
.FileName
, iil
.FileName
))
300 addr
.Mode
= AddrModeFlat
;
301 addr
.Offset
= iil
.Address
;
308 dbg_printf("Unknown line number\n"
309 "(either out of file, or no code at given line number)\n");
314 break_add_break(&addr
, TRUE
);
317 /***********************************************************************
318 * break_check_delayed_bp
320 * Check is a registered delayed BP is now available.
322 void break_check_delayed_bp(void)
324 struct dbg_lvalue lvalue
;
326 struct dbg_delayed_bp
* dbp
= dbg_curr_process
->delayed_bp
;
328 for (i
= 0; i
< dbg_curr_process
->num_delayed_bp
; i
++)
330 if (dbp
[i
].is_symbol
)
332 if (symbol_get_lvalue(dbp
[i
].u
.symbol
.name
, dbp
[i
].u
.symbol
.lineno
,
333 &lvalue
, TRUE
) != sglv_found
)
335 if (lvalue
.cookie
!= DLV_TARGET
) continue;
338 lvalue
.addr
= dbp
[i
].u
.addr
;
339 WINE_TRACE("trying to add delayed %s-bp\n", dbp
[i
].is_symbol
? "S" : "A");
340 if (!dbp
[i
].is_symbol
)
341 WINE_TRACE("\t%04x:%08lx\n",
342 dbp
[i
].u
.addr
.Segment
, dbp
[i
].u
.addr
.Offset
);
344 WINE_TRACE("\t'%s' @ %d\n",
345 dbp
[i
].u
.symbol
.name
, dbp
[i
].u
.symbol
.lineno
);
347 if (break_add_break(&lvalue
.addr
, FALSE
))
348 memmove(&dbp
[i
], &dbp
[i
+1], (--dbg_curr_process
->num_delayed_bp
- i
) * sizeof(*dbp
));
352 /***********************************************************************
357 static void break_add_watch(const struct dbg_lvalue
* lvalue
, BOOL is_write
)
362 num
= init_xpoint((is_write
) ? be_xpoint_watch_write
: be_xpoint_watch_read
,
364 if (num
== -1) return;
366 if (lvalue
->type
.id
!= dbg_itype_none
)
368 if (types_get_info(&lvalue
->type
, TI_GET_LENGTH
, &l
))
372 case 4: case 2: case 1: break;
374 dbg_printf("Unsupported length (%lu) for watch-points, defaulting to 4\n", l
);
378 else dbg_printf("Cannot get watch size, defaulting to 4\n");
380 dbg_curr_process
->bp
[num
].w
.len
= l
- 1;
382 if (!get_watched_value(num
, &dbg_curr_process
->bp
[num
].w
.oldval
))
384 dbg_printf("Bad address. Watchpoint not set\n");
385 dbg_curr_process
->bp
[num
].refcount
= 0;
388 dbg_printf("Watchpoint %d at ", num
);
389 print_address(&dbg_curr_process
->bp
[num
].addr
, TRUE
);
393 /******************************************************************
394 * break_add_watch_from_lvalue
396 * Adds a watch point from an address (stored in a lvalue)
398 void break_add_watch_from_lvalue(const struct dbg_lvalue
* lvalue
)
400 struct dbg_lvalue lval
;
402 lval
.addr
.Mode
= AddrModeFlat
;
403 lval
.addr
.Offset
= types_extract_as_integer(lvalue
);
404 lval
.type
.id
= dbg_itype_none
;
406 break_add_watch(&lval
, TRUE
);
409 /***********************************************************************
410 * break_add_watch_from_id
412 * Add a watchpoint from a symbol name
414 void break_add_watch_from_id(const char *name
)
416 struct dbg_lvalue lvalue
;
418 switch (symbol_get_lvalue(name
, -1, &lvalue
, TRUE
))
421 break_add_watch(&lvalue
, 1);
424 dbg_printf("Unable to add watchpoint\n");
426 case sglv_aborted
: /* user aborted symbol lookup */
431 /***********************************************************************
432 * break_delete_xpoint
434 * Delete a breakpoint.
436 void break_delete_xpoint(int num
)
438 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
440 if ((num
<= 0) || (num
>= dbg_curr_process
->next_bp
) ||
441 bp
[num
].refcount
== 0)
443 dbg_printf("Invalid breakpoint number %d\n", num
);
447 if (--bp
[num
].refcount
> 0)
450 if (bp
[num
].condition
!= NULL
)
452 expr_free(bp
[num
].condition
);
453 bp
[num
].condition
= NULL
;
456 bp
[num
].enabled
= FALSE
;
457 bp
[num
].refcount
= 0;
458 bp
[num
].skipcount
= 0;
461 static inline BOOL
module_is_container(const IMAGEHLP_MODULE
* wmod_cntnr
,
462 const IMAGEHLP_MODULE
* wmod_child
)
464 return wmod_cntnr
->BaseOfImage
<= wmod_child
->BaseOfImage
&&
465 (DWORD
)wmod_cntnr
->BaseOfImage
+ wmod_cntnr
->ImageSize
>=
466 (DWORD
)wmod_child
->BaseOfImage
+ wmod_child
->ImageSize
;
469 /******************************************************************
470 * break_delete_xpoints_from_module
472 * Remove all Xpoints from module which base is 'base'
474 void break_delete_xpoints_from_module(unsigned long base
)
476 IMAGEHLP_MODULE im
, im_elf
;
479 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
481 /* FIXME: should do it also on the ELF sibbling if any */
482 im
.SizeOfStruct
= sizeof(im
);
483 im_elf
.SizeOfStruct
= sizeof(im_elf
);
484 if (!SymGetModuleInfo(dbg_curr_process
->handle
, base
, &im
)) return;
486 /* try to get in fact the underlying ELF module (if any) */
487 if (SymGetModuleInfo(dbg_curr_process
->handle
, im
.BaseOfImage
- 1, &im_elf
) &&
488 im_elf
.BaseOfImage
<= im
.BaseOfImage
&&
489 (DWORD
)im_elf
.BaseOfImage
+ im_elf
.ImageSize
>= (DWORD
)im
.BaseOfImage
+ im
.ImageSize
)
492 for (i
= 0; i
< dbg_curr_process
->next_bp
; i
++)
494 linear
= (DWORD
)memory_to_linear_addr(&bp
[i
].addr
);
495 if (bp
[i
].refcount
&& bp
[i
].enabled
&&
496 im
.BaseOfImage
<= linear
&& linear
< im
.BaseOfImage
+ im
.ImageSize
)
498 break_delete_xpoint(i
);
503 /***********************************************************************
504 * break_enable_xpoint
506 * Enable or disable a break point.
508 void break_enable_xpoint(int num
, BOOL enable
)
510 if ((num
<= 0) || (num
>= dbg_curr_process
->next_bp
) ||
511 dbg_curr_process
->bp
[num
].refcount
== 0)
513 dbg_printf("Invalid breakpoint number %d\n", num
);
516 dbg_curr_process
->bp
[num
].enabled
= (enable
) ? TRUE
: FALSE
;
517 dbg_curr_process
->bp
[num
].skipcount
= 0;
521 /***********************************************************************
522 * find_triggered_watch
524 * Lookup the watchpoints to see if one has been triggered
525 * Return >= (watch point index) if one is found and *oldval is set to
526 * the value watched before the TRAP
527 * Return -1 if none found (*oldval is undetermined)
529 * Unfortunately, Linux does *NOT* (A REAL PITA) report with ptrace
530 * the DR6 register value, so we have to look with our own need the
534 static int find_triggered_watch(LPDWORD oldval
)
538 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
540 /* Method 1 => get triggered watchpoint from context (doesn't work on Linux
541 * 2.2.x). This should be fixed in >= 2.2.16
543 for (i
= 0; i
< dbg_curr_process
->next_bp
; i
++)
547 if (bp
[i
].refcount
&& bp
[i
].enabled
&& bp
[i
].xpoint_type
!= be_xpoint_break
&&
548 (be_cpu
->is_watchpoint_set(&dbg_context
, bp
[i
].info
)))
550 be_cpu
->clear_watchpoint(&dbg_context
, bp
[i
].info
);
552 *oldval
= bp
[i
].w
.oldval
;
553 if (get_watched_value(i
, &val
))
555 bp
[i
].w
.oldval
= val
;
561 /* Method 1 failed, trying method 2 */
563 /* Method 2 => check if value has changed among registered watchpoints
564 * this really sucks, but this is how gdb 4.18 works on my linux box
567 for (i
= 0; i
< dbg_curr_process
->next_bp
; i
++)
571 if (bp
[i
].refcount
&& bp
[i
].enabled
&& bp
[i
].xpoint_type
!= be_xpoint_break
&&
572 get_watched_value(i
, &val
))
574 *oldval
= bp
[i
].w
.oldval
;
577 be_cpu
->clear_watchpoint(&dbg_context
, bp
[i
].info
);
578 bp
[i
].w
.oldval
= val
;
580 /* cannot break, because two watch points may have been triggered on
582 * only one will be reported to the user (FIXME ?)
590 /***********************************************************************
593 * Display break & watch points information.
595 void break_info(void)
598 int nbp
= 0, nwp
= 0;
599 struct dbg_delayed_bp
* dbp
= dbg_curr_process
->delayed_bp
;
600 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
602 for (i
= 1; i
< dbg_curr_process
->next_bp
; i
++)
606 if (bp
[i
].xpoint_type
== be_xpoint_break
) nbp
++; else nwp
++;
612 dbg_printf("Breakpoints:\n");
613 for (i
= 1; i
< dbg_curr_process
->next_bp
; i
++)
615 if (!bp
[i
].refcount
|| bp
[i
].xpoint_type
!= be_xpoint_break
)
617 dbg_printf("%d: %c ", i
, bp
[i
].enabled
? 'y' : 'n');
618 print_address(&bp
[i
].addr
, TRUE
);
619 dbg_printf(" (%u)\n", bp
[i
].refcount
);
620 if (bp
[i
].condition
!= NULL
)
622 dbg_printf("\t\tstop when ");
623 expr_print(bp
[i
].condition
);
628 else dbg_printf("No breakpoints\n");
631 dbg_printf("Watchpoints:\n");
632 for (i
= 1; i
< dbg_curr_process
->next_bp
; i
++)
634 if (!bp
[i
].refcount
|| bp
[i
].xpoint_type
== be_xpoint_break
)
636 dbg_printf("%d: %c ", i
, bp
[i
].enabled
? 'y' : 'n');
637 print_address(&bp
[i
].addr
, TRUE
);
638 dbg_printf(" on %d byte%s (%c)\n",
639 bp
[i
].w
.len
+ 1, bp
[i
].w
.len
> 0 ? "s" : "",
640 bp
[i
].xpoint_type
== be_xpoint_watch_write
? 'W' : 'R');
641 if (bp
[i
].condition
!= NULL
)
643 dbg_printf("\t\tstop when ");
644 expr_print(bp
[i
].condition
);
649 else dbg_printf("No watchpoints\n");
650 if (dbg_curr_process
->num_delayed_bp
)
652 dbg_printf("Delayed breakpoints:\n");
653 for (i
= 0; i
< dbg_curr_process
->num_delayed_bp
; i
++)
655 if (dbp
[i
].is_symbol
)
657 dbg_printf("%d: %s", i
, dbp
[i
].u
.symbol
.name
);
658 if (dbp
[i
].u
.symbol
.lineno
!= -1)
659 dbg_printf(" at line %u", dbp
[i
].u
.symbol
.lineno
);
663 dbg_printf("%d: ", i
);
664 print_address(&dbp
[i
].u
.addr
, FALSE
);
671 /***********************************************************************
674 * Check whether or not the condition (bp / skipcount) of a break/watch
677 static BOOL
should_stop(int bpnum
)
679 struct dbg_breakpoint
* bp
= &dbg_curr_process
->bp
[bpnum
];
681 if (bp
->condition
!= NULL
)
683 struct dbg_lvalue lvalue
= expr_eval(bp
->condition
);
685 if (lvalue
.type
.id
== dbg_itype_none
)
688 * Something wrong - unable to evaluate this expression.
690 dbg_printf("Unable to evaluate expression ");
691 expr_print(bp
->condition
);
692 dbg_printf("\nTurning off condition\n");
693 break_add_condition(bpnum
, NULL
);
695 else if (!types_extract_as_integer(&lvalue
))
701 if (bp
->skipcount
> 0) bp
->skipcount
--;
702 return bp
->skipcount
== 0;
705 /***********************************************************************
706 * break_should_continue
708 * Determine if we should continue execution after a SIGTRAP signal when
709 * executing in the given mode.
711 BOOL
break_should_continue(ADDRESS
* addr
, DWORD code
, int* count
, BOOL
* is_break
)
716 enum dbg_exec_mode mode
= dbg_curr_thread
->exec_mode
;
719 /* If not single-stepping, back up to the break instruction */
720 if (code
== EXCEPTION_BREAKPOINT
)
721 addr
->Offset
+= be_cpu
->adjust_pc_for_break(&dbg_context
, TRUE
);
723 bpnum
= find_xpoint(addr
, be_xpoint_break
);
724 dbg_curr_process
->bp
[0].enabled
= FALSE
; /* disable the step-over breakpoint */
728 if (!should_stop(bpnum
)) return TRUE
;
730 dbg_printf("Stopped on breakpoint %d at ", bpnum
);
731 print_address(&dbg_curr_process
->bp
[bpnum
].addr
, TRUE
);
736 wpnum
= find_triggered_watch(&oldval
);
739 /* If not single-stepping, do not back up over the break instruction */
740 if (code
== EXCEPTION_BREAKPOINT
)
741 addr
->Offset
+= be_cpu
->adjust_pc_for_break(&dbg_context
, FALSE
);
743 if (!should_stop(wpnum
)) return TRUE
;
745 dbg_printf("Stopped on watchpoint %d at ", wpnum
);
746 print_address(addr
, TRUE
);
747 dbg_printf(" values: old=%lu new=%lu\n",
748 oldval
, dbg_curr_process
->bp
[wpnum
].w
.oldval
);
753 * If our mode indicates that we are stepping line numbers,
754 * get the current function, and figure out if we are exactly
755 * on a line number or not.
757 if (mode
== dbg_exec_step_over_line
|| mode
== dbg_exec_step_into_line
)
759 if (symbol_get_function_line_status(addr
) == dbg_on_a_line_number
)
764 else if (mode
== dbg_exec_step_over_insn
|| mode
== dbg_exec_step_into_insn
)
769 if (*count
> 0 || mode
== dbg_exec_finish
)
772 * We still need to execute more instructions.
777 /* If there's no breakpoint and we are not single-stepping, then
778 * either we must have encountered a break insn in the Windows program
779 * or someone is trying to stop us
781 if (bpnum
== -1 && code
== EXCEPTION_BREAKPOINT
)
784 addr
->Offset
+= be_cpu
->adjust_pc_for_break(&dbg_context
, FALSE
);
788 /* no breakpoint, continue if in continuous mode */
789 return mode
== dbg_exec_cont
|| mode
== dbg_exec_finish
;
792 /***********************************************************************
793 * break_suspend_execution
795 * Remove all bp before entering the debug loop
797 void break_suspend_execution(void)
799 break_set_xpoints(FALSE
);
800 dbg_curr_process
->bp
[0] = dbg_curr_thread
->step_over_bp
;
803 /***********************************************************************
804 * break_restart_execution
806 * Set the bp to the correct state to restart execution
809 void break_restart_execution(int count
)
813 enum dbg_line_status status
;
814 enum dbg_exec_mode mode
, ret_mode
;
818 memory_get_current_pc(&addr
);
819 linear
= memory_to_linear_addr(&addr
);
822 * This is the mode we will be running in after we finish. We would like
823 * to be able to modify this in certain cases.
825 ret_mode
= mode
= dbg_curr_thread
->exec_mode
;
827 bp
= find_xpoint(&addr
, be_xpoint_break
);
828 if (bp
!= -1 && bp
!= 0)
831 * If we have set a new value, then save it in the BP number.
833 if (count
!= 0 && mode
== dbg_exec_cont
)
835 dbg_curr_process
->bp
[bp
].skipcount
= count
;
837 mode
= dbg_exec_step_into_insn
; /* If there's a breakpoint, skip it */
839 else if (mode
== dbg_exec_cont
&& count
> 1)
841 dbg_printf("Not stopped at any breakpoint; argument ignored.\n");
844 if (mode
== dbg_exec_finish
&& be_cpu
->is_function_return(linear
))
846 mode
= ret_mode
= dbg_exec_step_into_insn
;
850 * See if the function we are stepping into has debug info
851 * and line numbers. If not, then we step over it instead.
852 * FIXME - we need to check for things like thunks or trampolines,
853 * as the actual function may in fact have debug info.
855 if (be_cpu
->is_function_call(linear
, &callee
))
857 status
= symbol_get_function_line_status(&callee
);
859 /* FIXME: we need to get the thunk type */
861 * Anytime we have a trampoline, step over it.
863 if ((mode
== EXEC_STEP_OVER
|| mode
== EXEC_STEPI_OVER
)
864 && status
== dbg_in_a_thunk
)
866 WINE_WARN("Not stepping into trampoline at %p (no lines)\n",
867 memory_to_linear_addr(&callee
));
868 mode
= EXEC_STEP_OVER_TRAMPOLINE
;
871 if (mode
== dbg_exec_step_into_line
&& status
== dbg_no_line_info
)
873 WINE_WARN("Not stepping into function at %p (no lines)\n",
874 memory_to_linear_addr(&callee
));
875 mode
= dbg_exec_step_over_line
;
879 if (mode
== dbg_exec_step_into_line
&&
880 symbol_get_function_line_status(&addr
) == dbg_no_line_info
)
882 dbg_printf("Single stepping until exit from function, \n"
883 "which has no line number information.\n");
884 ret_mode
= mode
= dbg_exec_finish
;
889 case dbg_exec_cont
: /* Continuous execution */
890 be_cpu
->single_step(&dbg_context
, FALSE
);
891 break_set_xpoints(TRUE
);
895 case EXEC_STEP_OVER_TRAMPOLINE
:
897 * This is the means by which we step over our conversion stubs
898 * in callfrom*.s and callto*.s. We dig the appropriate address
899 * off the stack, and we set the breakpoint there instead of the
900 * address just after the call.
902 be_cpu
->get_addr(dbg_curr_thread
->handle
, &dbg_context
,
903 be_cpu_addr_stack
, &addr
);
904 /* FIXME: we assume stack grows as on an i386 */
905 addr
.Offset
+= 2 * sizeof(unsigned int);
906 dbg_read_memory(memory_to_linear_addr(&addr
),
907 &addr
.Offset
, sizeof(addr
.Offset
));
908 dbg_curr_process
->bp
[0].addr
= addr
;
909 dbg_curr_process
->bp
[0].enabled
= TRUE
;
910 dbg_curr_process
->bp
[0].refcount
= 1;
911 dbg_curr_process
->bp
[0].skipcount
= 0;
912 dbg_curr_process
->bp
[0].xpoint_type
= be_xpoint_break
;
913 dbg_curr_process
->bp
[0].condition
= NULL
;
914 be_cpu
->single_step(&dbg_context
, FALSE
);
915 break_set_xpoints(TRUE
);
919 case dbg_exec_finish
:
920 case dbg_exec_step_over_insn
: /* Stepping over a call */
921 case dbg_exec_step_over_line
: /* Stepping over a call */
922 if (be_cpu
->is_step_over_insn(linear
))
924 be_cpu
->disasm_one_insn(&addr
, FALSE
);
925 dbg_curr_process
->bp
[0].addr
= addr
;
926 dbg_curr_process
->bp
[0].enabled
= TRUE
;
927 dbg_curr_process
->bp
[0].refcount
= 1;
928 dbg_curr_process
->bp
[0].skipcount
= 0;
929 dbg_curr_process
->bp
[0].xpoint_type
= be_xpoint_break
;
930 dbg_curr_process
->bp
[0].condition
= NULL
;
931 be_cpu
->single_step(&dbg_context
, FALSE
);
932 break_set_xpoints(TRUE
);
935 /* else fall through to single-stepping */
937 case dbg_exec_step_into_line
: /* Single-stepping a line */
938 case dbg_exec_step_into_insn
: /* Single-stepping an instruction */
939 be_cpu
->single_step(&dbg_context
, TRUE
);
941 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
943 dbg_curr_thread
->step_over_bp
= dbg_curr_process
->bp
[0];
944 dbg_curr_thread
->exec_mode
= ret_mode
;
947 int break_add_condition(int num
, struct expr
* exp
)
949 if (num
<= 0 || num
>= dbg_curr_process
->next_bp
||
950 !dbg_curr_process
->bp
[num
].refcount
)
952 dbg_printf("Invalid breakpoint number %d\n", num
);
956 if (dbg_curr_process
->bp
[num
].condition
!= NULL
)
958 expr_free(dbg_curr_process
->bp
[num
].condition
);
959 dbg_curr_process
->bp
[num
].condition
= NULL
;
962 if (exp
!= NULL
) dbg_curr_process
->bp
[num
].condition
= expr_clone(exp
, NULL
);