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
);
30 #define DR7_CONTROL_SHIFT 16
31 #define DR7_CONTROL_SIZE 4
33 #define DR7_RW_EXECUTE (0x0)
34 #define DR7_RW_WRITE (0x1)
35 #define DR7_RW_READ (0x3)
37 #define DR7_LEN_1 (0x0)
38 #define DR7_LEN_2 (0x4)
39 #define DR7_LEN_4 (0xC)
41 #define DR7_LOCAL_ENABLE_SHIFT 0
42 #define DR7_GLOBAL_ENABLE_SHIFT 1
43 #define DR7_ENABLE_SIZE 2
45 #define DR7_LOCAL_ENABLE_MASK (0x55)
46 #define DR7_GLOBAL_ENABLE_MASK (0xAA)
48 #define DR7_CONTROL_RESERVED (0xFC00)
49 #define DR7_LOCAL_SLOWDOWN (0x100)
50 #define DR7_GLOBAL_SLOWDOWN (0x200)
52 #define DR7_ENABLE_MASK(dr) (1<<(DR7_LOCAL_ENABLE_SHIFT+DR7_ENABLE_SIZE*(dr)))
53 #define IS_DR7_SET(ctrl,dr) ((ctrl)&DR7_ENABLE_MASK(dr))
54 #define INT3 0xcc /* int 3 opcode */
57 #define MAX_BREAKPOINTS 100
59 static DBG_BREAKPOINT breakpoints
[MAX_BREAKPOINTS
];
61 static int next_bp
= 1; /* breakpoint 0 is reserved for step-over */
63 /***********************************************************************
64 * DEBUG_IsStepOverInstr
66 * Determine if the instruction at CS:EIP is an instruction that
67 * we need to step over (like a call or a repetitive string move).
69 static BOOL
DEBUG_IsStepOverInstr(void)
76 addr
.seg
= DEBUG_context
.SegCs
;
77 addr
.off
= DEBUG_context
.Eip
;
78 /* FIXME: old code was using V86BASE(DEBUG_context)
79 * instead of passing through DOSMEM_MemoryBase
81 instr
= (BYTE
*)DEBUG_ToLinear(&addr
);
85 if (!DEBUG_READ_MEM(instr
, &ch
, sizeof(ch
)))
90 /* Skip all prefixes */
98 case 0x66: /* opcode size prefix */
99 case 0x67: /* addr size prefix */
100 case 0xf0: /* lock */
101 case 0xf2: /* repne */
102 case 0xf3: /* repe */
106 /* Handle call instructions */
108 case 0xcd: /* int <intno> */
109 case 0xe8: /* call <offset> */
110 case 0x9a: /* lcall <seg>:<off> */
113 case 0xff: /* call <regmodrm> */
114 if (!DEBUG_READ_MEM(instr
+ 1, &ch
, sizeof(ch
)))
116 return (((ch
& 0x38) == 0x10) || ((ch
& 0x38) == 0x18));
118 /* Handle string instructions */
120 case 0x6c: /* insb */
121 case 0x6d: /* insw */
122 case 0x6e: /* outsb */
123 case 0x6f: /* outsw */
124 case 0xa4: /* movsb */
125 case 0xa5: /* movsw */
126 case 0xa6: /* cmpsb */
127 case 0xa7: /* cmpsw */
128 case 0xaa: /* stosb */
129 case 0xab: /* stosw */
130 case 0xac: /* lodsb */
131 case 0xad: /* lodsw */
132 case 0xae: /* scasb */
133 case 0xaf: /* scasw */
146 /***********************************************************************
149 * Determine if the instruction at CS:EIP is an instruction that
150 * is a function return.
152 BOOL
DEBUG_IsFctReturn(void)
159 addr
.seg
= DEBUG_context
.SegCs
;
160 addr
.off
= DEBUG_context
.Eip
;
161 /* FIXME: old code was using V86BASE(DEBUG_context)
162 * instead of passing through DOSMEM_MemoryBase
164 instr
= (BYTE
*)DEBUG_ToLinear(&addr
);
166 if (!DEBUG_READ_MEM(instr
, &ch
, sizeof(ch
)))
169 return (ch
== 0xc2) || (ch
== 0xc3);
176 /***********************************************************************
177 * DEBUG_SetBreakpoints
179 * Set or remove all the breakpoints.
181 void DEBUG_SetBreakpoints( BOOL set
)
186 DEBUG_context
.Dr7
&= ~DR7_LOCAL_ENABLE_MASK
;
189 for (i
= 0; i
< next_bp
; i
++)
191 if (!(breakpoints
[i
].refcount
&& breakpoints
[i
].enabled
))
194 switch (breakpoints
[i
].type
) {
198 char ch
= set
? INT3
: breakpoints
[i
].u
.b
.opcode
;
200 if (!DEBUG_WRITE_MEM( (void*)DEBUG_ToLinear(&breakpoints
[i
].addr
),
203 DEBUG_Printf("Invalid address for breakpoint %d, disabling it\n", i
);
204 breakpoints
[i
].enabled
= FALSE
;
214 int reg
= breakpoints
[i
].u
.w
.reg
;
219 case 0: lpdr
= &DEBUG_context
.Dr0
; break;
220 case 1: lpdr
= &DEBUG_context
.Dr1
; break;
221 case 2: lpdr
= &DEBUG_context
.Dr2
; break;
222 case 3: lpdr
= &DEBUG_context
.Dr3
; break;
223 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
226 *lpdr
= DEBUG_ToLinear(&breakpoints
[i
].addr
);
227 bits
= (breakpoints
[i
].u
.w
.rw
) ? DR7_RW_WRITE
: DR7_RW_READ
;
228 switch (breakpoints
[i
].u
.w
.len
+ 1)
230 case 4: bits
|= DR7_LEN_4
; break;
231 case 2: bits
|= DR7_LEN_2
; break;
232 case 1: bits
|= DR7_LEN_1
; break;
233 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
236 DEBUG_context
.Dr7
&= ~(0x0F << (DR7_CONTROL_SHIFT
+ DR7_CONTROL_SIZE
* reg
));
237 DEBUG_context
.Dr7
|= bits
<< (DR7_CONTROL_SHIFT
+ DR7_CONTROL_SIZE
* reg
);
238 DEBUG_context
.Dr7
|= DR7_ENABLE_MASK(reg
) | DR7_LOCAL_SLOWDOWN
;
246 /***********************************************************************
247 * DEBUG_FindBreakpoint
249 * Find the breakpoint for a given address. Return the breakpoint
250 * number or -1 if none.
251 * If type is DBG_BREAKPOINT, addr is a complete addr
252 * If type is DBG_WATCHPOINT, only addr.off is meaningful and contains
255 static int DEBUG_FindBreakpoint( const DBG_ADDR
*addr
, int type
)
259 for (i
= 0; i
< next_bp
; i
++)
261 if (breakpoints
[i
].refcount
&& breakpoints
[i
].enabled
&&
262 breakpoints
[i
].type
== type
)
264 if ((type
== DBG_BREAK
&&
265 breakpoints
[i
].addr
.seg
== addr
->seg
&&
266 breakpoints
[i
].addr
.off
== addr
->off
) ||
267 (type
== DBG_WATCH
&&
268 DEBUG_ToLinear(&breakpoints
[i
].addr
) == addr
->off
))
275 /***********************************************************************
278 * Find an empty slot in BP table to add a new break/watch point
280 static int DEBUG_InitXPoint(int type
, const DBG_ADDR
* addr
)
284 for (num
= (next_bp
< MAX_BREAKPOINTS
) ? next_bp
++ : 1;
285 num
< MAX_BREAKPOINTS
; num
++)
287 if (breakpoints
[num
].refcount
== 0)
289 breakpoints
[num
].refcount
= 1;
290 breakpoints
[num
].enabled
= TRUE
;
291 breakpoints
[num
].type
= type
;
292 breakpoints
[num
].skipcount
= 0;
293 breakpoints
[num
].addr
= *addr
;
294 switch (DEBUG_GetSelectorType( addr
->seg
))
297 breakpoints
[num
].is32
= 1;
301 breakpoints
[num
].is32
= 0;
304 RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
310 DEBUG_Printf("Too many breakpoints. Please delete some.\n");
314 /***********************************************************************
315 * DEBUG_GetWatchedValue
317 * Returns the value watched by watch point 'num'.
319 static BOOL
DEBUG_GetWatchedValue( int num
, LPDWORD val
)
323 if (!DEBUG_READ_MEM((void*)DEBUG_ToLinear(&breakpoints
[num
].addr
),
324 buf
, breakpoints
[num
].u
.w
.len
+ 1))
327 switch (breakpoints
[num
].u
.w
.len
+ 1)
329 case 4: *val
= *(DWORD
*)buf
; break;
330 case 2: *val
= *(WORD
*)buf
; break;
331 case 1: *val
= *(BYTE
*)buf
; break;
332 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
337 /***********************************************************************
338 * DEBUG_AddBreakpoint
342 BOOL
DEBUG_AddBreakpoint( const DBG_VALUE
*value
, BOOL (*func
)(void), BOOL verbose
)
347 if ((num
= DEBUG_FindBreakpoint(&value
->addr
, DBG_BREAK
)) >= 1)
349 breakpoints
[num
].refcount
++;
353 if (!DEBUG_READ_MEM((void*)DEBUG_ToLinear( &value
->addr
), &ch
, sizeof(ch
)))
356 DEBUG_Printf("Invalid address, can't set breakpoint\n");
360 if ((num
= DEBUG_InitXPoint(DBG_BREAK
, &value
->addr
)) == -1)
363 breakpoints
[num
].u
.b
.opcode
= ch
;
364 breakpoints
[num
].u
.b
.func
= func
;
366 DEBUG_Printf("Breakpoint %d at ", num
);
367 DEBUG_PrintAddress( &breakpoints
[num
].addr
, breakpoints
[num
].is32
? MODE_32
: MODE_16
,
374 /***********************************************************************
375 * DEBUG_AddBreakpointFromValue
379 BOOL
DEBUG_AddBreakpointFromValue( const DBG_VALUE
*_value
)
381 DBG_VALUE value
= *_value
;
383 if (value
.type
!= NULL
&& value
.type
== DEBUG_GetBasicType(DT_BASIC_CONST_INT
) && value
.cookie
== DV_HOST
)
386 * We know that we have the actual offset stored somewhere
387 * else in 32-bit space. Grab it, and we
390 unsigned int seg2
= value
.addr
.seg
;
392 value
.addr
.off
= DEBUG_GetExprValue(&value
, NULL
);
393 value
.addr
.seg
= seg2
;
394 value
.cookie
= DV_TARGET
;
397 if (!DEBUG_AddBreakpoint( &value
, NULL
, TRUE
))
399 if (!DBG_IVAR(CanDeferOnBPByAddr
))
401 DEBUG_Printf("Invalid address, can't set breakpoint\n"
402 "You can turn on deferring breakpoints by address by setting $CanDeferOnBPByAddr to 1\n");
405 DEBUG_Printf("Unable to add breakpoint, will check again any time a new DLL is loaded\n");
406 DEBUG_CurrProcess
->delayed_bp
= DBG_realloc(DEBUG_CurrProcess
->delayed_bp
,
407 sizeof(DBG_DELAYED_BP
) * ++DEBUG_CurrProcess
->num_delayed_bp
);
409 DEBUG_CurrProcess
->delayed_bp
[DEBUG_CurrProcess
->num_delayed_bp
- 1].is_symbol
= FALSE
;
410 DEBUG_CurrProcess
->delayed_bp
[DEBUG_CurrProcess
->num_delayed_bp
- 1].u
.value
= value
;
417 /***********************************************************************
418 * DEBUG_AddBreakpointFromId
420 * Add a breakpoint from a function name (and eventually a line #)
422 void DEBUG_AddBreakpointFromId(const char *name
, int lineno
)
427 switch (DEBUG_GetSymbolValue(name
, lineno
, &value
, TRUE
))
430 DEBUG_AddBreakpoint(&value
, NULL
, TRUE
);
434 case gsv_aborted
: /* user aborted symbol lookup */
438 DEBUG_Printf("Unable to add breakpoint, will check again when a new DLL is loaded\n");
439 for (i
= 0; i
< DEBUG_CurrProcess
->num_delayed_bp
; i
++)
441 if (DEBUG_CurrProcess
->delayed_bp
[i
].is_symbol
&&
442 !strcmp(name
, DEBUG_CurrProcess
->delayed_bp
[i
].u
.symbol
.name
) &&
443 lineno
== DEBUG_CurrProcess
->delayed_bp
[i
].u
.symbol
.lineno
)
446 DEBUG_CurrProcess
->delayed_bp
= DBG_realloc(DEBUG_CurrProcess
->delayed_bp
,
447 sizeof(DBG_DELAYED_BP
) * ++DEBUG_CurrProcess
->num_delayed_bp
);
449 DEBUG_CurrProcess
->delayed_bp
[DEBUG_CurrProcess
->num_delayed_bp
- 1].is_symbol
= TRUE
;
450 DEBUG_CurrProcess
->delayed_bp
[DEBUG_CurrProcess
->num_delayed_bp
- 1].u
.symbol
.name
= strcpy(DBG_alloc(strlen(name
) + 1), name
);
451 DEBUG_CurrProcess
->delayed_bp
[DEBUG_CurrProcess
->num_delayed_bp
- 1].u
.symbol
.lineno
= lineno
;
454 /***********************************************************************
455 * DEBUG_AddBreakpointFromLineno
457 * Add a breakpoint from a line number in current file
459 void DEBUG_AddBreakpointFromLineno(int lineno
)
463 DEBUG_GetCurrentAddress(&value
.addr
);
467 struct name_hash
* nh
;
469 DEBUG_FindNearestSymbol(&value
.addr
, TRUE
, &nh
, 0, NULL
);
472 DEBUG_Printf("Unable to add breakpoint\n");
475 if (!DEBUG_GetLineNumberAddr(nh
, lineno
, &value
.addr
, TRUE
))
477 DEBUG_Printf("Unknown line number\n"
478 "(either out of file, or no code at given line number)\n");
484 value
.cookie
= DV_TARGET
;
485 DEBUG_AddBreakpoint( &value
, NULL
, TRUE
);
488 /***********************************************************************
489 * DEBUG_CheckDelayedBP
491 * Check is a registered delayed BP is now available.
493 void DEBUG_CheckDelayedBP(void)
497 DBG_DELAYED_BP
* dbp
= DEBUG_CurrProcess
->delayed_bp
;
499 for (i
= 0; i
< DEBUG_CurrProcess
->num_delayed_bp
; i
++)
501 if (dbp
[i
].is_symbol
)
503 if (DEBUG_GetSymbolValue(dbp
[i
].u
.symbol
.name
, dbp
[i
].u
.symbol
.lineno
, &value
, TRUE
) != gsv_found
)
507 value
= dbp
[i
].u
.value
;
508 WINE_TRACE("trying to add delayed %s-bp\n", dbp
[i
].is_symbol
? "S" : "A");
509 if (!dbp
[i
].is_symbol
)
510 WINE_TRACE("\t%04x %04lx:%08lx\n",
511 dbp
[i
].u
.value
.cookie
,
512 dbp
[i
].u
.value
.addr
.seg
,
513 dbp
[i
].u
.value
.addr
.off
);
515 WINE_TRACE("\t'%s' @ %d\n",
516 dbp
[i
].u
.symbol
.name
, dbp
[i
].u
.symbol
.lineno
);
518 if (DEBUG_AddBreakpoint(&value
, NULL
, FALSE
))
519 memmove(&dbp
[i
], &dbp
[i
+1], (--DEBUG_CurrProcess
->num_delayed_bp
- i
) * sizeof(*dbp
));
523 /***********************************************************************
524 * DEBUG_AddWatchpoint
528 void DEBUG_AddWatchpoint( const DBG_VALUE
*_value
, BOOL is_write
)
530 DBG_VALUE value
= *_value
;
535 assert(_value
->cookie
== DV_TARGET
|| _value
->cookie
== DV_HOST
);
538 DEBUG_FixAddress( &value
.addr
, DEBUG_context
.SegCs
);
541 if ( value
.type
!= NULL
&& value
.type
== DEBUG_GetBasicType(DT_BASIC_CONST_INT
) )
544 * We know that we have the actual offset stored somewhere
545 * else in 32-bit space. Grab it, and we
548 seg2
= value
.addr
.seg
;
550 value
.addr
.off
= DEBUG_GetExprValue(&value
, NULL
);
551 value
.addr
.seg
= seg2
;
554 for (num
= 1; num
< next_bp
; num
++)
556 if (breakpoints
[num
].refcount
&& breakpoints
[num
].enabled
&&
557 breakpoints
[num
].type
== DBG_WATCH
) {
558 mask
|= (1 << breakpoints
[num
].u
.w
.reg
);
562 for (reg
= 0; reg
< 4 && (mask
& (1 << reg
)); reg
++);
565 DEBUG_Printf("All i386 hardware watchpoints have been set. Delete some\n");
570 if ((num
= DEBUG_InitXPoint(DBG_WATCH
, &value
.addr
)) == -1)
573 breakpoints
[num
].u
.w
.len
= 4 - 1;
574 if (_value
->type
&& DEBUG_GetObjectSize(_value
->type
) < 4)
575 breakpoints
[num
].u
.w
.len
= 2 - 1;
577 if (!DEBUG_GetWatchedValue( num
, &breakpoints
[num
].u
.w
.oldval
))
579 DEBUG_Printf("Bad address. Watchpoint not set\n");
580 breakpoints
[num
].refcount
= 0;
584 breakpoints
[num
].u
.w
.rw
= (is_write
) ? TRUE
: FALSE
;
585 breakpoints
[reg
].u
.w
.reg
= reg
;
587 DEBUG_Printf("Watchpoint %d at ", num
);
588 DEBUG_PrintAddress( &breakpoints
[num
].addr
, breakpoints
[num
].is32
? MODE_32
: MODE_16
, TRUE
);
593 /***********************************************************************
594 * DEBUG_AddWathpointFromId
596 * Add a watchpoint from a symbol name (and eventually a line #)
598 void DEBUG_AddWatchpointFromId(const char *name
)
602 switch (DEBUG_GetSymbolValue(name
, -1, &value
, TRUE
))
605 DEBUG_AddWatchpoint( &value
, 1 );
608 DEBUG_Printf("Unable to add watchpoint\n");
610 case gsv_aborted
: /* user aborted symbol lookup */
615 /***********************************************************************
616 * DEBUG_DelBreakpoint
618 * Delete a breakpoint.
620 void DEBUG_DelBreakpoint( int num
)
622 if ((num
<= 0) || (num
>= next_bp
) || breakpoints
[num
].refcount
== 0)
624 DEBUG_Printf("Invalid breakpoint number %d\n", num
);
628 if (--breakpoints
[num
].refcount
> 0)
631 if (breakpoints
[num
].condition
!= NULL
)
633 DEBUG_FreeExpr(breakpoints
[num
].condition
);
634 breakpoints
[num
].condition
= NULL
;
637 breakpoints
[num
].enabled
= FALSE
;
638 breakpoints
[num
].refcount
= 0;
639 breakpoints
[num
].skipcount
= 0;
642 /***********************************************************************
643 * DEBUG_EnableBreakpoint
645 * Enable or disable a break point.
647 void DEBUG_EnableBreakpoint( int num
, BOOL enable
)
649 if ((num
<= 0) || (num
>= next_bp
) || breakpoints
[num
].refcount
== 0)
651 DEBUG_Printf("Invalid breakpoint number %d\n", num
);
654 breakpoints
[num
].enabled
= (enable
) ? TRUE
: FALSE
;
655 breakpoints
[num
].skipcount
= 0;
659 /***********************************************************************
660 * DEBUG_FindTriggeredWatchpoint
662 * Lookup the watchpoints to see if one has been triggered
663 * Return >= (watch point index) if one is found and *oldval is set to
664 * the value watched before the TRAP
665 * Return -1 if none found (*oldval is undetermined)
667 * Unfortunately, Linux does *NOT* (A REAL PITA) report with ptrace
668 * the DR6 register value, so we have to look with our own need the
672 static int DEBUG_FindTriggeredWatchpoint(LPDWORD oldval
)
678 /* Method 1 => get triggered watchpoint from context (doesn't work on Linux
679 * 2.2.x). This should be fixed in >= 2.2.16
681 for (i
= 0; i
< next_bp
; i
++)
685 if (breakpoints
[i
].refcount
&& breakpoints
[i
].enabled
&&
686 breakpoints
[i
].type
== DBG_WATCH
&&
687 (DEBUG_context
.Dr6
& (1 << breakpoints
[i
].u
.w
.reg
)))
689 DEBUG_context
.Dr6
&= ~(1 << breakpoints
[i
].u
.w
.reg
);
691 *oldval
= breakpoints
[i
].u
.w
.oldval
;
692 if (DEBUG_GetWatchedValue(i
, &val
)) {
693 breakpoints
[i
].u
.w
.oldval
= val
;
699 /* Method 1 failed, trying method 2 */
701 /* Method 2 => check if value has changed among registered watchpoints
702 * this really sucks, but this is how gdb 4.18 works on my linux box
705 for (i
= 0; i
< next_bp
; i
++)
709 if (breakpoints
[i
].refcount
&& breakpoints
[i
].enabled
&&
710 breakpoints
[i
].type
== DBG_WATCH
&&
711 DEBUG_GetWatchedValue(i
, &val
))
713 *oldval
= breakpoints
[i
].u
.w
.oldval
;
716 DEBUG_context
.Dr6
&= ~(1 << breakpoints
[i
].u
.w
.reg
);
717 breakpoints
[i
].u
.w
.oldval
= val
;
719 /* cannot break, because two watch points may have been triggered on
721 * only one will be reported to the user (FIXME ?)
730 /***********************************************************************
731 * DEBUG_InfoBreakpoints
733 * Display break points information.
735 void DEBUG_InfoBreakpoints(void)
739 DEBUG_Printf("Breakpoints:\n");
740 for (i
= 1; i
< next_bp
; i
++)
742 if (breakpoints
[i
].refcount
&& breakpoints
[i
].type
== DBG_BREAK
)
744 DEBUG_Printf("%d: %c ", i
, breakpoints
[i
].enabled
? 'y' : 'n');
745 DEBUG_PrintAddress( &breakpoints
[i
].addr
,
746 breakpoints
[i
].is32
? MODE_32
: MODE_16
, TRUE
);
747 DEBUG_Printf(" (%u)\n", breakpoints
[i
].refcount
);
748 if( breakpoints
[i
].condition
!= NULL
)
750 DEBUG_Printf("\t\tstop when ");
751 DEBUG_DisplayExpr(breakpoints
[i
].condition
);
756 DEBUG_Printf("Watchpoints:\n");
757 for (i
= 1; i
< next_bp
; i
++)
759 if (breakpoints
[i
].refcount
&& breakpoints
[i
].type
== DBG_WATCH
)
761 DEBUG_Printf("%d: %c ", i
, breakpoints
[i
].enabled
? 'y' : 'n');
762 DEBUG_PrintAddress( &breakpoints
[i
].addr
,
763 breakpoints
[i
].is32
? MODE_32
: MODE_16
, TRUE
);
764 DEBUG_Printf(" on %d byte%s (%c)\n",
765 breakpoints
[i
].u
.w
.len
+ 1,
766 breakpoints
[i
].u
.w
.len
> 0 ? "s" : "",
767 breakpoints
[i
].u
.w
.rw
? 'W' : 'R');
768 if( breakpoints
[i
].condition
!= NULL
)
770 DEBUG_Printf("\t\tstop when ");
771 DEBUG_DisplayExpr(breakpoints
[i
].condition
);
778 /***********************************************************************
781 * Check whether or not the condition (bp / skipcount) of a break/watch
784 static BOOL
DEBUG_ShallBreak( int bpnum
)
786 if ( breakpoints
[bpnum
].condition
!= NULL
)
788 DBG_VALUE value
= DEBUG_EvalExpr(breakpoints
[bpnum
].condition
);
790 if ( value
.type
== NULL
)
793 * Something wrong - unable to evaluate this expression.
795 DEBUG_Printf("Unable to evaluate expression ");
796 DEBUG_DisplayExpr(breakpoints
[bpnum
].condition
);
797 DEBUG_Printf("\nTurning off condition\n");
798 DEBUG_AddBPCondition(bpnum
, NULL
);
800 else if( !DEBUG_GetExprValue( &value
, NULL
) )
806 if ( breakpoints
[bpnum
].skipcount
> 0 && --breakpoints
[bpnum
].skipcount
> 0 )
809 if ((breakpoints
[bpnum
].type
== DBG_BREAK
) && breakpoints
[bpnum
].u
.b
.func
)
810 return breakpoints
[bpnum
].u
.b
.func();
814 /***********************************************************************
815 * DEBUG_ShouldContinue
817 * Determine if we should continue execution after a SIGTRAP signal when
818 * executing in the given mode.
820 BOOL
DEBUG_ShouldContinue( DBG_ADDR
*addr
, DWORD code
, int * count
)
825 enum dbg_mode addr_mode
;
826 struct symbol_info syminfo
;
827 enum exec_mode mode
= DEBUG_CurrThread
->exec_mode
;
830 /* If not single-stepping, back up over the int3 instruction */
831 if (code
== EXCEPTION_BREAKPOINT
)
838 bpnum
= DEBUG_FindBreakpoint( addr
, DBG_BREAK
);
839 breakpoints
[0].enabled
= FALSE
; /* disable the step-over breakpoint */
841 if ((bpnum
!= 0) && (bpnum
!= -1))
843 if (!DEBUG_ShallBreak(bpnum
)) return TRUE
;
845 DEBUG_Printf("Stopped on breakpoint %d at ", bpnum
);
846 syminfo
= DEBUG_PrintAddress( &breakpoints
[bpnum
].addr
,
847 breakpoints
[bpnum
].is32
? MODE_32
: MODE_16
, TRUE
);
850 if( syminfo
.list
.sourcefile
!= NULL
)
851 DEBUG_List(&syminfo
.list
, NULL
, 0);
855 wpnum
= DEBUG_FindTriggeredWatchpoint(&oldval
);
856 if ((wpnum
!= 0) && (wpnum
!= -1))
858 /* If not single-stepping, do not back up over the int3 instruction */
859 if (code
== EXCEPTION_BREAKPOINT
)
866 if (!DEBUG_ShallBreak(wpnum
)) return TRUE
;
868 addr_mode
= DEBUG_GetSelectorType( addr
->seg
);
869 DEBUG_Printf("Stopped on watchpoint %d at ", wpnum
);
870 syminfo
= DEBUG_PrintAddress( addr
, addr_mode
, TRUE
);
872 DEBUG_Printf(" values: old=%lu new=%lu\n",
873 oldval
, breakpoints
[wpnum
].u
.w
.oldval
);
874 if (syminfo
.list
.sourcefile
!= NULL
)
875 DEBUG_List(&syminfo
.list
, NULL
, 0);
880 * If our mode indicates that we are stepping line numbers,
881 * get the current function, and figure out if we are exactly
882 * on a line number or not.
884 if( mode
== EXEC_STEP_OVER
|| mode
== EXEC_STEP_INSTR
)
886 if( DEBUG_CheckLinenoStatus(addr
) == AT_LINENUMBER
)
891 else if( mode
== EXEC_STEPI_OVER
|| mode
== EXEC_STEPI_INSTR
)
896 if( *count
> 0 || mode
== EXEC_FINISH
)
899 * We still need to execute more instructions.
905 * If we are about to stop, then print out the source line if we
908 if (mode
!= EXEC_CONT
&& mode
!= EXEC_FINISH
)
910 DEBUG_FindNearestSymbol(addr
, TRUE
, NULL
, 0, &syminfo
.list
);
911 if (syminfo
.list
.sourcefile
!= NULL
)
913 DEBUG_List(&syminfo
.list
, NULL
, 0);
918 /* If there's no breakpoint and we are not single-stepping, then
919 * either we must have encountered an int3 in the Windows program
920 * or someone is trying to stop us
921 * If the later, (no int3 opcode at current address) then stop,
922 * otherwise, let's skip it.
924 if ((bpnum
== -1) && code
== EXCEPTION_BREAKPOINT
)
928 if (!DEBUG_READ_MEM(&addr
, &c
, 1)) c
= 0xCC;
931 if (c
!= 0xCC) return FALSE
;
935 /* no breakpoint, continue if in continuous mode */
936 return (mode
== EXEC_CONT
|| mode
== EXEC_FINISH
);
939 /***********************************************************************
940 * DEBUG_SuspendExecution
942 * Remove all breakpoints before entering the debug loop
944 void DEBUG_SuspendExecution( void )
946 DEBUG_SetBreakpoints( FALSE
);
947 breakpoints
[0] = DEBUG_CurrThread
->stepOverBP
;
950 /***********************************************************************
951 * DEBUG_RestartExecution
953 * Set the breakpoints to the correct state to restart execution
956 void DEBUG_RestartExecution( int count
)
963 enum exec_mode mode
, ret_mode
;
967 DEBUG_GetCurrentAddress( &addr
);
970 * This is the mode we will be running in after we finish. We would like
971 * to be able to modify this in certain cases.
973 ret_mode
= mode
= DEBUG_CurrThread
->exec_mode
;
975 bp
= DEBUG_FindBreakpoint( &addr
, DBG_BREAK
);
976 if ( bp
!= -1 && bp
!= 0)
979 * If we have set a new value, then save it in the BP number.
981 if( count
!= 0 && mode
== EXEC_CONT
)
983 breakpoints
[bp
].skipcount
= count
;
985 mode
= EXEC_STEPI_INSTR
; /* If there's a breakpoint, skip it */
989 if( mode
== EXEC_CONT
&& count
> 1 )
991 DEBUG_Printf("Not stopped at any breakpoint; argument ignored.\n");
995 if( mode
== EXEC_FINISH
&& DEBUG_IsFctReturn() )
997 mode
= ret_mode
= EXEC_STEPI_INSTR
;
1000 instr
= DEBUG_ToLinear( &addr
);
1001 DEBUG_READ_MEM((void*)instr
, &ch
, sizeof(ch
));
1003 * See if the function we are stepping into has debug info
1004 * and line numbers. If not, then we step over it instead.
1005 * FIXME - we need to check for things like thunks or trampolines,
1006 * as the actual function may in fact have debug info.
1010 DEBUG_READ_MEM((void*)(instr
+ 1), &delta
, sizeof(delta
));
1012 DEBUG_Disasm(&addr2
, FALSE
);
1015 status
= DEBUG_CheckLinenoStatus(&addr2
);
1017 * Anytime we have a trampoline, step over it.
1019 if( ((mode
== EXEC_STEP_OVER
) || (mode
== EXEC_STEPI_OVER
))
1020 && status
== FUNC_IS_TRAMPOLINE
)
1022 WINE_TRACE("Not stepping into trampoline at %lx (no lines)\n",
1024 mode
= EXEC_STEP_OVER_TRAMPOLINE
;
1027 if( mode
== EXEC_STEP_INSTR
&& status
== FUNC_HAS_NO_LINES
)
1029 WINE_TRACE("Not stepping into function at %lx (no lines)\n",
1031 mode
= EXEC_STEP_OVER
;
1036 if( mode
== EXEC_STEP_INSTR
)
1038 if( DEBUG_CheckLinenoStatus(&addr
) == FUNC_HAS_NO_LINES
)
1040 DEBUG_Printf("Single stepping until exit from function, \n"
1041 "which has no line number information.\n");
1043 ret_mode
= mode
= EXEC_FINISH
;
1049 case EXEC_CONT
: /* Continuous execution */
1051 DEBUG_context
.EFlags
&= ~STEP_FLAG
;
1053 DEBUG_SetBreakpoints( TRUE
);
1056 case EXEC_STEP_OVER_TRAMPOLINE
:
1058 * This is the means by which we step over our conversion stubs
1059 * in callfrom*.s and callto*.s. We dig the appropriate address
1060 * off the stack, and we set the breakpoint there instead of the
1061 * address just after the call.
1064 DEBUG_READ_MEM((void*)(DEBUG_context
.Esp
+
1065 2 * sizeof(unsigned int)),
1066 &addr
.off
, sizeof(addr
.off
));
1067 DEBUG_context
.EFlags
&= ~STEP_FLAG
;
1069 breakpoints
[0].addr
= addr
;
1070 breakpoints
[0].enabled
= TRUE
;
1071 breakpoints
[0].refcount
= 1;
1072 breakpoints
[0].skipcount
= 0;
1073 DEBUG_READ_MEM((void*)DEBUG_ToLinear( &addr
), &breakpoints
[0].u
.b
.opcode
,
1075 DEBUG_SetBreakpoints( TRUE
);
1079 case EXEC_STEPI_OVER
: /* Stepping over a call */
1080 case EXEC_STEP_OVER
: /* Stepping over a call */
1081 if (DEBUG_IsStepOverInstr())
1084 DEBUG_context
.EFlags
&= ~STEP_FLAG
;
1086 DEBUG_Disasm(&addr
, FALSE
);
1087 breakpoints
[0].addr
= addr
;
1088 breakpoints
[0].enabled
= TRUE
;
1089 breakpoints
[0].refcount
= 1;
1090 breakpoints
[0].skipcount
= 0;
1091 DEBUG_READ_MEM((void*)DEBUG_ToLinear( &addr
), &breakpoints
[0].u
.b
.opcode
,
1093 DEBUG_SetBreakpoints( TRUE
);
1096 /* else fall through to single-stepping */
1098 case EXEC_STEP_INSTR
: /* Single-stepping an instruction */
1099 case EXEC_STEPI_INSTR
: /* Single-stepping an instruction */
1101 DEBUG_context
.EFlags
|= STEP_FLAG
;
1105 RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
1107 DEBUG_CurrThread
->stepOverBP
= breakpoints
[0];
1108 DEBUG_CurrThread
->exec_mode
= ret_mode
;
1112 DEBUG_AddBPCondition(int num
, struct expr
* exp
)
1114 if ((num
<= 0) || (num
>= next_bp
) || !breakpoints
[num
].refcount
)
1116 DEBUG_Printf("Invalid breakpoint number %d\n", num
);
1120 if( breakpoints
[num
].condition
!= NULL
)
1122 DEBUG_FreeExpr(breakpoints
[num
].condition
);
1123 breakpoints
[num
].condition
= NULL
;
1128 breakpoints
[num
].condition
= DEBUG_CloneExpr(exp
);