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
);
274 il
.SizeOfStruct
= sizeof(il
);
275 if (!SymGetLineFromAddr(dbg_curr_process
->handle
,
276 (DWORD
)memory_to_linear_addr(&addr
), &disp
, &il
))
278 dbg_printf("Unable to add breakpoint (unknown address)\n");
283 while (SymGetLinePrev(dbg_curr_process
->handle
, &iil
))
285 if (lineno
== iil
.LineNumber
&& !strcmp(il
.FileName
, iil
.FileName
))
287 addr
.Mode
= AddrModeFlat
;
288 addr
.Offset
= iil
.Address
;
294 if (!found
) while (SymGetLineNext(dbg_curr_process
->handle
, &iil
))
296 if (lineno
== iil
.LineNumber
&& !strcmp(il
.FileName
, iil
.FileName
))
298 addr
.Mode
= AddrModeFlat
;
299 addr
.Offset
= iil
.Address
;
306 dbg_printf("Unknown line number\n"
307 "(either out of file, or no code at given line number)\n");
312 break_add_break(&addr
, TRUE
);
315 /***********************************************************************
316 * break_check_delayed_bp
318 * Check is a registered delayed BP is now available.
320 void break_check_delayed_bp(void)
322 struct dbg_lvalue lvalue
;
324 struct dbg_delayed_bp
* dbp
= dbg_curr_process
->delayed_bp
;
326 for (i
= 0; i
< dbg_curr_process
->num_delayed_bp
; i
++)
328 if (dbp
[i
].is_symbol
)
330 if (symbol_get_lvalue(dbp
[i
].u
.symbol
.name
, dbp
[i
].u
.symbol
.lineno
,
331 &lvalue
, TRUE
) != sglv_found
)
333 if (lvalue
.cookie
!= DLV_TARGET
) continue;
336 lvalue
.addr
= dbp
[i
].u
.addr
;
337 WINE_TRACE("trying to add delayed %s-bp\n", dbp
[i
].is_symbol
? "S" : "A");
338 if (!dbp
[i
].is_symbol
)
339 WINE_TRACE("\t%04x:%08lx\n",
340 dbp
[i
].u
.addr
.Segment
, dbp
[i
].u
.addr
.Offset
);
342 WINE_TRACE("\t'%s' @ %d\n",
343 dbp
[i
].u
.symbol
.name
, dbp
[i
].u
.symbol
.lineno
);
345 if (break_add_break(&lvalue
.addr
, FALSE
))
346 memmove(&dbp
[i
], &dbp
[i
+1], (--dbg_curr_process
->num_delayed_bp
- i
) * sizeof(*dbp
));
350 /***********************************************************************
355 static void break_add_watch(const struct dbg_lvalue
* lvalue
, BOOL is_write
)
360 num
= init_xpoint((is_write
) ? be_xpoint_watch_write
: be_xpoint_watch_read
,
362 if (num
== -1) return;
364 if (lvalue
->type
.id
!= dbg_itype_none
)
366 if (types_get_info(&lvalue
->type
, TI_GET_LENGTH
, &l
))
370 case 4: case 2: case 1: break;
372 dbg_printf("Unsupported length (%lu) for watch-points, defaulting to 4\n", l
);
376 else dbg_printf("Cannot get watch size, defaulting to 4\n");
378 dbg_curr_process
->bp
[num
].w
.len
= l
- 1;
380 if (!get_watched_value(num
, &dbg_curr_process
->bp
[num
].w
.oldval
))
382 dbg_printf("Bad address. Watchpoint not set\n");
383 dbg_curr_process
->bp
[num
].refcount
= 0;
386 dbg_printf("Watchpoint %d at ", num
);
387 print_address(&dbg_curr_process
->bp
[num
].addr
, TRUE
);
391 /******************************************************************
392 * break_add_watch_from_lvalue
394 * Adds a watch point from an address (stored in a lvalue)
396 void break_add_watch_from_lvalue(const struct dbg_lvalue
* lvalue
)
398 struct dbg_lvalue lval
;
400 lval
.addr
.Mode
= AddrModeFlat
;
401 lval
.addr
.Offset
= types_extract_as_integer(lvalue
);
402 lval
.type
.id
= dbg_itype_none
;
404 break_add_watch(&lval
, TRUE
);
407 /***********************************************************************
408 * break_add_watch_from_id
410 * Add a watchpoint from a symbol name
412 void break_add_watch_from_id(const char *name
)
414 struct dbg_lvalue lvalue
;
416 switch (symbol_get_lvalue(name
, -1, &lvalue
, TRUE
))
419 break_add_watch(&lvalue
, 1);
422 dbg_printf("Unable to add watchpoint\n");
424 case sglv_aborted
: /* user aborted symbol lookup */
429 /***********************************************************************
430 * break_delete_xpoint
432 * Delete a breakpoint.
434 void break_delete_xpoint(int num
)
436 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
438 if ((num
<= 0) || (num
>= dbg_curr_process
->next_bp
) ||
439 bp
[num
].refcount
== 0)
441 dbg_printf("Invalid breakpoint number %d\n", num
);
445 if (--bp
[num
].refcount
> 0)
448 if (bp
[num
].condition
!= NULL
)
450 expr_free(bp
[num
].condition
);
451 bp
[num
].condition
= NULL
;
454 bp
[num
].enabled
= FALSE
;
455 bp
[num
].refcount
= 0;
456 bp
[num
].skipcount
= 0;
459 static inline BOOL
module_is_container(const IMAGEHLP_MODULE
* wmod_cntnr
,
460 const IMAGEHLP_MODULE
* wmod_child
)
462 return wmod_cntnr
->BaseOfImage
<= wmod_child
->BaseOfImage
&&
463 (DWORD
)wmod_cntnr
->BaseOfImage
+ wmod_cntnr
->ImageSize
>=
464 (DWORD
)wmod_child
->BaseOfImage
+ wmod_child
->ImageSize
;
467 /******************************************************************
468 * break_delete_xpoints_from_module
470 * Remove all Xpoints from module which base is 'base'
472 void break_delete_xpoints_from_module(unsigned long base
)
474 IMAGEHLP_MODULE im
, im_elf
;
477 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
479 /* FIXME: should do it also on the ELF sibbling if any */
480 im
.SizeOfStruct
= sizeof(im
);
481 im_elf
.SizeOfStruct
= sizeof(im_elf
);
482 if (!SymGetModuleInfo(dbg_curr_process
->handle
, base
, &im
)) return;
484 /* try to get in fact the underlying ELF module (if any) */
485 if (SymGetModuleInfo(dbg_curr_process
->handle
, im
.BaseOfImage
- 1, &im_elf
) &&
486 im_elf
.BaseOfImage
<= im
.BaseOfImage
&&
487 (DWORD
)im_elf
.BaseOfImage
+ im_elf
.ImageSize
>= (DWORD
)im
.BaseOfImage
+ im
.ImageSize
)
490 for (i
= 0; i
< dbg_curr_process
->next_bp
; i
++)
492 linear
= (DWORD
)memory_to_linear_addr(&bp
[i
].addr
);
493 if (bp
[i
].refcount
&& bp
[i
].enabled
&&
494 im
.BaseOfImage
<= linear
&& linear
< im
.BaseOfImage
+ im
.ImageSize
)
496 break_delete_xpoint(i
);
501 /***********************************************************************
502 * break_enable_xpoint
504 * Enable or disable a break point.
506 void break_enable_xpoint(int num
, BOOL enable
)
508 if ((num
<= 0) || (num
>= dbg_curr_process
->next_bp
) ||
509 dbg_curr_process
->bp
[num
].refcount
== 0)
511 dbg_printf("Invalid breakpoint number %d\n", num
);
514 dbg_curr_process
->bp
[num
].enabled
= (enable
) ? TRUE
: FALSE
;
515 dbg_curr_process
->bp
[num
].skipcount
= 0;
519 /***********************************************************************
520 * find_triggered_watch
522 * Lookup the watchpoints to see if one has been triggered
523 * Return >= (watch point index) if one is found and *oldval is set to
524 * the value watched before the TRAP
525 * Return -1 if none found (*oldval is undetermined)
527 * Unfortunately, Linux does *NOT* (A REAL PITA) report with ptrace
528 * the DR6 register value, so we have to look with our own need the
532 static int find_triggered_watch(LPDWORD oldval
)
536 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
538 /* Method 1 => get triggered watchpoint from context (doesn't work on Linux
539 * 2.2.x). This should be fixed in >= 2.2.16
541 for (i
= 0; i
< dbg_curr_process
->next_bp
; i
++)
545 if (bp
[i
].refcount
&& bp
[i
].enabled
&& bp
[i
].xpoint_type
!= be_xpoint_break
&&
546 (be_cpu
->is_watchpoint_set(&dbg_context
, bp
[i
].info
)))
548 be_cpu
->clear_watchpoint(&dbg_context
, bp
[i
].info
);
550 *oldval
= bp
[i
].w
.oldval
;
551 if (get_watched_value(i
, &val
))
553 bp
[i
].w
.oldval
= val
;
559 /* Method 1 failed, trying method 2 */
561 /* Method 2 => check if value has changed among registered watchpoints
562 * this really sucks, but this is how gdb 4.18 works on my linux box
565 for (i
= 0; i
< dbg_curr_process
->next_bp
; i
++)
569 if (bp
[i
].refcount
&& bp
[i
].enabled
&& bp
[i
].xpoint_type
!= be_xpoint_break
&&
570 get_watched_value(i
, &val
))
572 *oldval
= bp
[i
].w
.oldval
;
575 be_cpu
->clear_watchpoint(&dbg_context
, bp
[i
].info
);
576 bp
[i
].w
.oldval
= val
;
578 /* cannot break, because two watch points may have been triggered on
580 * only one will be reported to the user (FIXME ?)
588 /***********************************************************************
591 * Display break & watch points information.
593 void break_info(void)
596 int nbp
= 0, nwp
= 0;
597 struct dbg_delayed_bp
* dbp
= dbg_curr_process
->delayed_bp
;
598 struct dbg_breakpoint
* bp
= dbg_curr_process
->bp
;
600 for (i
= 1; i
< dbg_curr_process
->next_bp
; i
++)
604 if (bp
[i
].xpoint_type
== be_xpoint_break
) nbp
++; else nwp
++;
610 dbg_printf("Breakpoints:\n");
611 for (i
= 1; i
< dbg_curr_process
->next_bp
; i
++)
613 if (!bp
[i
].refcount
|| bp
[i
].xpoint_type
!= be_xpoint_break
)
615 dbg_printf("%d: %c ", i
, bp
[i
].enabled
? 'y' : 'n');
616 print_address(&bp
[i
].addr
, TRUE
);
617 dbg_printf(" (%u)\n", bp
[i
].refcount
);
618 if (bp
[i
].condition
!= NULL
)
620 dbg_printf("\t\tstop when ");
621 expr_print(bp
[i
].condition
);
626 else dbg_printf("No breakpoints\n");
629 dbg_printf("Watchpoints:\n");
630 for (i
= 1; i
< dbg_curr_process
->next_bp
; i
++)
632 if (!bp
[i
].refcount
|| bp
[i
].xpoint_type
== be_xpoint_break
)
634 dbg_printf("%d: %c ", i
, bp
[i
].enabled
? 'y' : 'n');
635 print_address(&bp
[i
].addr
, TRUE
);
636 dbg_printf(" on %d byte%s (%c)\n",
637 bp
[i
].w
.len
+ 1, bp
[i
].w
.len
> 0 ? "s" : "",
638 bp
[i
].xpoint_type
== be_xpoint_watch_write
? 'W' : 'R');
639 if (bp
[i
].condition
!= NULL
)
641 dbg_printf("\t\tstop when ");
642 expr_print(bp
[i
].condition
);
647 else dbg_printf("No watchpoints\n");
648 if (dbg_curr_process
->num_delayed_bp
)
650 dbg_printf("Delayed breakpoints:\n");
651 for (i
= 0; i
< dbg_curr_process
->num_delayed_bp
; i
++)
653 if (dbp
[i
].is_symbol
)
655 dbg_printf("%d: %s", i
, dbp
[i
].u
.symbol
.name
);
656 if (dbp
[i
].u
.symbol
.lineno
!= -1)
657 dbg_printf(" at line %u", dbp
[i
].u
.symbol
.lineno
);
661 dbg_printf("%d: ", i
);
662 print_address(&dbp
[i
].u
.addr
, FALSE
);
669 /***********************************************************************
672 * Check whether or not the condition (bp / skipcount) of a break/watch
675 static BOOL
should_stop(int bpnum
)
677 struct dbg_breakpoint
* bp
= &dbg_curr_process
->bp
[bpnum
];
679 if (bp
->condition
!= NULL
)
681 struct dbg_lvalue lvalue
= expr_eval(bp
->condition
);
683 if (lvalue
.type
.id
== dbg_itype_none
)
686 * Something wrong - unable to evaluate this expression.
688 dbg_printf("Unable to evaluate expression ");
689 expr_print(bp
->condition
);
690 dbg_printf("\nTurning off condition\n");
691 break_add_condition(bpnum
, NULL
);
693 else if (!types_extract_as_integer(&lvalue
))
699 if (bp
->skipcount
> 0) bp
->skipcount
--;
700 return bp
->skipcount
== 0;
703 /***********************************************************************
704 * break_should_continue
706 * Determine if we should continue execution after a SIGTRAP signal when
707 * executing in the given mode.
709 BOOL
break_should_continue(ADDRESS
* addr
, DWORD code
, int* count
, BOOL
* is_break
)
714 enum dbg_exec_mode mode
= dbg_curr_thread
->exec_mode
;
717 /* If not single-stepping, back up to the break instruction */
718 if (code
== EXCEPTION_BREAKPOINT
)
719 addr
->Offset
+= be_cpu
->adjust_pc_for_break(&dbg_context
, TRUE
);
721 bpnum
= find_xpoint(addr
, be_xpoint_break
);
722 dbg_curr_process
->bp
[0].enabled
= FALSE
; /* disable the step-over breakpoint */
726 if (!should_stop(bpnum
)) return TRUE
;
728 dbg_printf("Stopped on breakpoint %d at ", bpnum
);
729 print_address(&dbg_curr_process
->bp
[bpnum
].addr
, TRUE
);
734 wpnum
= find_triggered_watch(&oldval
);
737 /* If not single-stepping, do not back up over the break instruction */
738 if (code
== EXCEPTION_BREAKPOINT
)
739 addr
->Offset
+= be_cpu
->adjust_pc_for_break(&dbg_context
, FALSE
);
741 if (!should_stop(wpnum
)) return TRUE
;
743 dbg_printf("Stopped on watchpoint %d at ", wpnum
);
744 print_address(addr
, TRUE
);
745 dbg_printf(" values: old=%lu new=%lu\n",
746 oldval
, dbg_curr_process
->bp
[wpnum
].w
.oldval
);
751 * If our mode indicates that we are stepping line numbers,
752 * get the current function, and figure out if we are exactly
753 * on a line number or not.
755 if (mode
== dbg_exec_step_over_line
|| mode
== dbg_exec_step_into_line
)
757 if (symbol_get_function_line_status(addr
) == dbg_on_a_line_number
)
762 else if (mode
== dbg_exec_step_over_insn
|| mode
== dbg_exec_step_into_insn
)
767 if (*count
> 0 || mode
== dbg_exec_finish
)
770 * We still need to execute more instructions.
775 /* If there's no breakpoint and we are not single-stepping, then
776 * either we must have encountered a break insn in the Windows program
777 * or someone is trying to stop us
779 if (bpnum
== -1 && code
== EXCEPTION_BREAKPOINT
)
782 addr
->Offset
+= be_cpu
->adjust_pc_for_break(&dbg_context
, FALSE
);
786 /* no breakpoint, continue if in continuous mode */
787 return mode
== dbg_exec_cont
|| mode
== dbg_exec_finish
;
790 /***********************************************************************
791 * break_suspend_execution
793 * Remove all bp before entering the debug loop
795 void break_suspend_execution(void)
797 break_set_xpoints(FALSE
);
798 dbg_curr_process
->bp
[0] = dbg_curr_thread
->step_over_bp
;
801 /***********************************************************************
802 * break_restart_execution
804 * Set the bp to the correct state to restart execution
807 void break_restart_execution(int count
)
811 enum dbg_line_status status
;
812 enum dbg_exec_mode mode
, ret_mode
;
816 memory_get_current_pc(&addr
);
817 linear
= memory_to_linear_addr(&addr
);
820 * This is the mode we will be running in after we finish. We would like
821 * to be able to modify this in certain cases.
823 ret_mode
= mode
= dbg_curr_thread
->exec_mode
;
825 bp
= find_xpoint(&addr
, be_xpoint_break
);
826 if (bp
!= -1 && bp
!= 0)
829 * If we have set a new value, then save it in the BP number.
831 if (count
!= 0 && mode
== dbg_exec_cont
)
833 dbg_curr_process
->bp
[bp
].skipcount
= count
;
835 mode
= dbg_exec_step_into_insn
; /* If there's a breakpoint, skip it */
837 else if (mode
== dbg_exec_cont
&& count
> 1)
839 dbg_printf("Not stopped at any breakpoint; argument ignored.\n");
842 if (mode
== dbg_exec_finish
&& be_cpu
->is_function_return(linear
))
844 mode
= ret_mode
= dbg_exec_step_into_insn
;
848 * See if the function we are stepping into has debug info
849 * and line numbers. If not, then we step over it instead.
850 * FIXME - we need to check for things like thunks or trampolines,
851 * as the actual function may in fact have debug info.
853 if (be_cpu
->is_function_call(linear
, &callee
))
855 status
= symbol_get_function_line_status(&callee
);
857 /* FIXME: we need to get the thunk type */
859 * Anytime we have a trampoline, step over it.
861 if ((mode
== EXEC_STEP_OVER
|| mode
== EXEC_STEPI_OVER
)
862 && status
== dbg_in_a_thunk
)
864 WINE_WARN("Not stepping into trampoline at %p (no lines)\n",
865 memory_to_linear_addr(&callee
));
866 mode
= EXEC_STEP_OVER_TRAMPOLINE
;
869 if (mode
== dbg_exec_step_into_line
&& status
== dbg_no_line_info
)
871 WINE_WARN("Not stepping into function at %p (no lines)\n",
872 memory_to_linear_addr(&callee
));
873 mode
= dbg_exec_step_over_line
;
877 if (mode
== dbg_exec_step_into_line
&&
878 symbol_get_function_line_status(&addr
) == dbg_no_line_info
)
880 dbg_printf("Single stepping until exit from function, \n"
881 "which has no line number information.\n");
882 ret_mode
= mode
= dbg_exec_finish
;
887 case dbg_exec_cont
: /* Continuous execution */
888 be_cpu
->single_step(&dbg_context
, FALSE
);
889 break_set_xpoints(TRUE
);
893 case EXEC_STEP_OVER_TRAMPOLINE
:
895 * This is the means by which we step over our conversion stubs
896 * in callfrom*.s and callto*.s. We dig the appropriate address
897 * off the stack, and we set the breakpoint there instead of the
898 * address just after the call.
900 be_cpu
->get_addr(dbg_curr_thread
->handle
, &dbg_context
,
901 be_cpu_addr_stack
, &addr
);
902 /* FIXME: we assume stack grows as on a i386 */
903 addr
.Offset
+= 2 * sizeof(unsigned int);
904 dbg_read_memory(memory_to_linear_addr(&addr
),
905 &addr
.Offset
, sizeof(addr
.Offset
));
906 dbg_curr_process
->bp
[0].addr
= addr
;
907 dbg_curr_process
->bp
[0].enabled
= TRUE
;
908 dbg_curr_process
->bp
[0].refcount
= 1;
909 dbg_curr_process
->bp
[0].skipcount
= 0;
910 dbg_curr_process
->bp
[0].xpoint_type
= be_xpoint_break
;
911 dbg_curr_process
->bp
[0].condition
= NULL
;
912 be_cpu
->single_step(&dbg_context
, FALSE
);
913 break_set_xpoints(TRUE
);
917 case dbg_exec_finish
:
918 case dbg_exec_step_over_insn
: /* Stepping over a call */
919 case dbg_exec_step_over_line
: /* Stepping over a call */
920 if (be_cpu
->is_step_over_insn(linear
))
922 be_cpu
->disasm_one_insn(&addr
, FALSE
);
923 dbg_curr_process
->bp
[0].addr
= addr
;
924 dbg_curr_process
->bp
[0].enabled
= TRUE
;
925 dbg_curr_process
->bp
[0].refcount
= 1;
926 dbg_curr_process
->bp
[0].skipcount
= 0;
927 dbg_curr_process
->bp
[0].xpoint_type
= be_xpoint_break
;
928 dbg_curr_process
->bp
[0].condition
= NULL
;
929 be_cpu
->single_step(&dbg_context
, FALSE
);
930 break_set_xpoints(TRUE
);
933 /* else fall through to single-stepping */
935 case dbg_exec_step_into_line
: /* Single-stepping a line */
936 case dbg_exec_step_into_insn
: /* Single-stepping an instruction */
937 be_cpu
->single_step(&dbg_context
, TRUE
);
939 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
941 dbg_curr_thread
->step_over_bp
= dbg_curr_process
->bp
[0];
942 dbg_curr_thread
->exec_mode
= ret_mode
;
945 int break_add_condition(int num
, struct expr
* exp
)
947 if (num
<= 0 || num
>= dbg_curr_process
->next_bp
||
948 !dbg_curr_process
->bp
[num
].refcount
)
950 dbg_printf("Invalid breakpoint number %d\n", num
);
954 if (dbg_curr_process
->bp
[num
].condition
!= NULL
)
956 expr_free(dbg_curr_process
->bp
[num
].condition
);
957 dbg_curr_process
->bp
[num
].condition
= NULL
;
960 if (exp
!= NULL
) dbg_curr_process
->bp
[num
].condition
= expr_clone(exp
, NULL
);