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
27 #define DR7_CONTROL_SHIFT 16
28 #define DR7_CONTROL_SIZE 4
30 #define DR7_RW_EXECUTE (0x0)
31 #define DR7_RW_WRITE (0x1)
32 #define DR7_RW_READ (0x3)
34 #define DR7_LEN_1 (0x0)
35 #define DR7_LEN_2 (0x4)
36 #define DR7_LEN_4 (0xC)
38 #define DR7_LOCAL_ENABLE_SHIFT 0
39 #define DR7_GLOBAL_ENABLE_SHIFT 1
40 #define DR7_ENABLE_SIZE 2
42 #define DR7_LOCAL_ENABLE_MASK (0x55)
43 #define DR7_GLOBAL_ENABLE_MASK (0xAA)
45 #define DR7_CONTROL_RESERVED (0xFC00)
46 #define DR7_LOCAL_SLOWDOWN (0x100)
47 #define DR7_GLOBAL_SLOWDOWN (0x200)
49 #define DR7_ENABLE_MASK(dr) (1<<(DR7_LOCAL_ENABLE_SHIFT+DR7_ENABLE_SIZE*(dr)))
50 #define IS_DR7_SET(ctrl,dr) ((ctrl)&DR7_ENABLE_MASK(dr))
51 #define INT3 0xcc /* int 3 opcode */
54 #define MAX_BREAKPOINTS 100
56 static DBG_BREAKPOINT breakpoints
[MAX_BREAKPOINTS
];
58 static int next_bp
= 1; /* breakpoint 0 is reserved for step-over */
60 /***********************************************************************
61 * DEBUG_IsStepOverInstr
63 * Determine if the instruction at CS:EIP is an instruction that
64 * we need to step over (like a call or a repetitive string move).
66 static BOOL
DEBUG_IsStepOverInstr(void)
73 addr
.seg
= DEBUG_context
.SegCs
;
74 addr
.off
= DEBUG_context
.Eip
;
75 /* FIXME: old code was using V86BASE(DEBUG_context)
76 * instead of passing through DOSMEM_MemoryBase
78 instr
= (BYTE
*)DEBUG_ToLinear(&addr
);
82 if (!DEBUG_READ_MEM(instr
, &ch
, sizeof(ch
)))
87 /* Skip all prefixes */
95 case 0x66: /* opcode size prefix */
96 case 0x67: /* addr size prefix */
98 case 0xf2: /* repne */
103 /* Handle call instructions */
105 case 0xcd: /* int <intno> */
106 case 0xe8: /* call <offset> */
107 case 0x9a: /* lcall <seg>:<off> */
110 case 0xff: /* call <regmodrm> */
111 if (!DEBUG_READ_MEM(instr
+ 1, &ch
, sizeof(ch
)))
113 return (((ch
& 0x38) == 0x10) || ((ch
& 0x38) == 0x18));
115 /* Handle string instructions */
117 case 0x6c: /* insb */
118 case 0x6d: /* insw */
119 case 0x6e: /* outsb */
120 case 0x6f: /* outsw */
121 case 0xa4: /* movsb */
122 case 0xa5: /* movsw */
123 case 0xa6: /* cmpsb */
124 case 0xa7: /* cmpsw */
125 case 0xaa: /* stosb */
126 case 0xab: /* stosw */
127 case 0xac: /* lodsb */
128 case 0xad: /* lodsw */
129 case 0xae: /* scasb */
130 case 0xaf: /* scasw */
143 /***********************************************************************
146 * Determine if the instruction at CS:EIP is an instruction that
147 * is a function return.
149 BOOL
DEBUG_IsFctReturn(void)
156 addr
.seg
= DEBUG_context
.SegCs
;
157 addr
.off
= DEBUG_context
.Eip
;
158 /* FIXME: old code was using V86BASE(DEBUG_context)
159 * instead of passing through DOSMEM_MemoryBase
161 instr
= (BYTE
*)DEBUG_ToLinear(&addr
);
163 if (!DEBUG_READ_MEM(instr
, &ch
, sizeof(ch
)))
166 return (ch
== 0xc2) || (ch
== 0xc3);
173 /***********************************************************************
174 * DEBUG_SetBreakpoints
176 * Set or remove all the breakpoints.
178 void DEBUG_SetBreakpoints( BOOL set
)
183 DEBUG_context
.Dr7
&= ~DR7_LOCAL_ENABLE_MASK
;
186 for (i
= 0; i
< next_bp
; i
++)
188 if (!(breakpoints
[i
].refcount
&& breakpoints
[i
].enabled
))
191 switch (breakpoints
[i
].type
) {
195 char ch
= set
? INT3
: breakpoints
[i
].u
.b
.opcode
;
197 if (!DEBUG_WRITE_MEM( (void*)DEBUG_ToLinear(&breakpoints
[i
].addr
),
200 DEBUG_Printf(DBG_CHN_MESG
, "Invalid address for breakpoint %d, disabling it\n", i
);
201 breakpoints
[i
].enabled
= FALSE
;
211 int reg
= breakpoints
[i
].u
.w
.reg
;
216 case 0: lpdr
= &DEBUG_context
.Dr0
; break;
217 case 1: lpdr
= &DEBUG_context
.Dr1
; break;
218 case 2: lpdr
= &DEBUG_context
.Dr2
; break;
219 case 3: lpdr
= &DEBUG_context
.Dr3
; break;
220 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
223 *lpdr
= DEBUG_ToLinear(&breakpoints
[i
].addr
);
224 bits
= (breakpoints
[i
].u
.w
.rw
) ? DR7_RW_WRITE
: DR7_RW_READ
;
225 switch (breakpoints
[i
].u
.w
.len
+ 1)
227 case 4: bits
|= DR7_LEN_4
; break;
228 case 2: bits
|= DR7_LEN_2
; break;
229 case 1: bits
|= DR7_LEN_1
; break;
230 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
233 DEBUG_context
.Dr7
&= ~(0x0F << (DR7_CONTROL_SHIFT
+ DR7_CONTROL_SIZE
* reg
));
234 DEBUG_context
.Dr7
|= bits
<< (DR7_CONTROL_SHIFT
+ DR7_CONTROL_SIZE
* reg
);
235 DEBUG_context
.Dr7
|= DR7_ENABLE_MASK(reg
) | DR7_LOCAL_SLOWDOWN
;
243 /***********************************************************************
244 * DEBUG_FindBreakpoint
246 * Find the breakpoint for a given address. Return the breakpoint
247 * number or -1 if none.
248 * If type is DBG_BREAKPOINT, addr is a complete addr
249 * If type is DBG_WATCHPOINT, only addr.off is meaningful and contains
252 static int DEBUG_FindBreakpoint( const DBG_ADDR
*addr
, int type
)
256 for (i
= 0; i
< next_bp
; i
++)
258 if (breakpoints
[i
].refcount
&& breakpoints
[i
].enabled
&&
259 breakpoints
[i
].type
== type
)
261 if ((type
== DBG_BREAK
&&
262 breakpoints
[i
].addr
.seg
== addr
->seg
&&
263 breakpoints
[i
].addr
.off
== addr
->off
) ||
264 (type
== DBG_WATCH
&&
265 DEBUG_ToLinear(&breakpoints
[i
].addr
) == addr
->off
))
272 /***********************************************************************
275 * Find an empty slot in BP table to add a new break/watch point
277 static int DEBUG_InitXPoint(int type
, DBG_ADDR
* addr
)
281 for (num
= (next_bp
< MAX_BREAKPOINTS
) ? next_bp
++ : 1;
282 num
< MAX_BREAKPOINTS
; num
++)
284 if (breakpoints
[num
].refcount
== 0)
286 breakpoints
[num
].refcount
= 1;
287 breakpoints
[num
].enabled
= TRUE
;
288 breakpoints
[num
].type
= type
;
289 breakpoints
[num
].skipcount
= 0;
290 breakpoints
[num
].addr
= *addr
;
291 switch (DEBUG_GetSelectorType( addr
->seg
))
294 breakpoints
[num
].is32
= 1;
298 breakpoints
[num
].is32
= 0;
301 RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
307 DEBUG_Printf( DBG_CHN_MESG
, "Too many breakpoints. Please delete some.\n" );
311 /***********************************************************************
312 * DEBUG_GetWatchedValue
314 * Returns the value watched by watch point 'num'.
316 static BOOL
DEBUG_GetWatchedValue( int num
, LPDWORD val
)
320 if (!DEBUG_READ_MEM((void*)DEBUG_ToLinear(&breakpoints
[num
].addr
),
321 buf
, breakpoints
[num
].u
.w
.len
+ 1))
324 switch (breakpoints
[num
].u
.w
.len
+ 1)
326 case 4: *val
= *(DWORD
*)buf
; break;
327 case 2: *val
= *(WORD
*)buf
; break;
328 case 1: *val
= *(BYTE
*)buf
; break;
329 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
334 /***********************************************************************
335 * DEBUG_AddBreakpoint
339 void DEBUG_AddBreakpoint( const DBG_VALUE
*_value
, BOOL (*func
)(void) )
341 DBG_VALUE value
= *_value
;
345 if( value
.type
!= NULL
&& value
.type
== DEBUG_GetBasicType(DT_BASIC_CONST_INT
) )
348 * We know that we have the actual offset stored somewhere
349 * else in 32-bit space. Grab it, and we
352 unsigned int seg2
= value
.addr
.seg
;
354 value
.addr
.off
= DEBUG_GetExprValue(&value
, NULL
);
355 value
.addr
.seg
= seg2
;
358 if ((num
= DEBUG_FindBreakpoint(&value
.addr
, DBG_BREAK
)) >= 1)
360 breakpoints
[num
].refcount
++;
364 if (!DEBUG_READ_MEM_VERBOSE((void*)DEBUG_ToLinear( &value
.addr
), &ch
, sizeof(ch
)))
366 DEBUG_Printf( DBG_CHN_MESG
, "Invalid address, can't set breakpoint\n");
370 if ((num
= DEBUG_InitXPoint(DBG_BREAK
, &value
.addr
)) == -1)
373 breakpoints
[num
].u
.b
.opcode
= ch
;
374 breakpoints
[num
].u
.b
.func
= func
;
376 DEBUG_Printf( DBG_CHN_MESG
, "Breakpoint %d at ", num
);
377 DEBUG_PrintAddress( &breakpoints
[num
].addr
, breakpoints
[num
].is32
? MODE_32
: MODE_16
,
379 DEBUG_Printf( DBG_CHN_MESG
, "\n" );
382 /***********************************************************************
383 * DEBUG_AddBreakpointFromId
385 * Add a breakpoint from a function name (and eventually a line #)
387 void DEBUG_AddBreakpointFromId(const char *name
, int lineno
)
392 if (DEBUG_GetSymbolValue(name
, lineno
, &value
, TRUE
)) {
393 DEBUG_AddBreakpoint(&value
, NULL
);
397 DEBUG_Printf(DBG_CHN_MESG
, "Unable to add breakpoint, will check again when a new DLL is loaded\n");
398 for (i
= 0; i
< DEBUG_CurrProcess
->num_delayed_bp
; i
++) {
399 if (!strcmp(name
, DEBUG_CurrProcess
->delayed_bp
[i
].name
) &&
400 lineno
== DEBUG_CurrProcess
->delayed_bp
[i
].lineno
) {
404 DEBUG_CurrProcess
->delayed_bp
= DBG_realloc(DEBUG_CurrProcess
->delayed_bp
,
405 sizeof(DBG_DELAYED_BP
) * ++DEBUG_CurrProcess
->num_delayed_bp
);
407 DEBUG_CurrProcess
->delayed_bp
[DEBUG_CurrProcess
->num_delayed_bp
- 1].name
= strcpy(DBG_alloc(strlen(name
) + 1), name
);
408 DEBUG_CurrProcess
->delayed_bp
[DEBUG_CurrProcess
->num_delayed_bp
- 1].lineno
= lineno
;
411 /***********************************************************************
412 * DEBUG_AddBreakpointFromLineno
414 * Add a breakpoint from a line number in current file
416 void DEBUG_AddBreakpointFromLineno(int lineno
)
420 DEBUG_GetCurrentAddress(&value
.addr
);
423 struct name_hash
* nh
;
425 DEBUG_FindNearestSymbol(&value
.addr
, TRUE
, &nh
, 0, NULL
);
427 DEBUG_Printf(DBG_CHN_MESG
, "Unable to add breakpoint\n");
430 DEBUG_GetLineNumberAddr(nh
, lineno
, &value
.addr
, TRUE
);
434 value
.cookie
= DV_TARGET
;
435 DEBUG_AddBreakpoint( &value
, NULL
);
438 /***********************************************************************
439 * DEBUG_CheckDelayedBP
441 * Check is a registered delayed BP is now available.
443 void DEBUG_CheckDelayedBP(void)
447 DBG_DELAYED_BP
* dbp
= DEBUG_CurrProcess
->delayed_bp
;
449 while (i
< DEBUG_CurrProcess
->num_delayed_bp
) {
450 if (DEBUG_GetSymbolValue(dbp
[i
].name
, dbp
[i
].lineno
, &value
, TRUE
)) {
451 DEBUG_AddBreakpoint(&value
, NULL
);
452 memmove(&dbp
[i
], &dbp
[i
+1], (--DEBUG_CurrProcess
->num_delayed_bp
- i
) * sizeof(*dbp
));
459 /***********************************************************************
460 * DEBUG_AddWatchpoint
464 void DEBUG_AddWatchpoint( const DBG_VALUE
*_value
, BOOL is_write
)
466 DBG_VALUE value
= *_value
;
471 assert(_value
->cookie
== DV_TARGET
|| _value
->cookie
== DV_HOST
);
474 DEBUG_FixAddress( &value
.addr
, DEBUG_context
.SegCs
);
477 if ( value
.type
!= NULL
&& value
.type
== DEBUG_GetBasicType(DT_BASIC_CONST_INT
) )
480 * We know that we have the actual offset stored somewhere
481 * else in 32-bit space. Grab it, and we
484 seg2
= value
.addr
.seg
;
486 value
.addr
.off
= DEBUG_GetExprValue(&value
, NULL
);
487 value
.addr
.seg
= seg2
;
490 for (num
= 1; num
< next_bp
; num
++)
492 if (breakpoints
[num
].refcount
&& breakpoints
[num
].enabled
&&
493 breakpoints
[num
].type
== DBG_WATCH
) {
494 mask
|= (1 << breakpoints
[num
].u
.w
.reg
);
498 for (reg
= 0; reg
< 4 && (mask
& (1 << reg
)); reg
++);
501 DEBUG_Printf(DBG_CHN_MESG
, "All i386 hardware watchpoints have been set. Delete some\n");
506 if ((num
= DEBUG_InitXPoint(DBG_WATCH
, &value
.addr
)) == -1)
509 breakpoints
[num
].u
.w
.len
= 4 - 1;
510 if (_value
->type
&& DEBUG_GetObjectSize(_value
->type
) < 4)
511 breakpoints
[num
].u
.w
.len
= 2 - 1;
513 if (!DEBUG_GetWatchedValue( num
, &breakpoints
[num
].u
.w
.oldval
))
515 DEBUG_Printf(DBG_CHN_MESG
, "Bad address. Watchpoint not set\n");
516 breakpoints
[num
].refcount
= 0;
520 breakpoints
[num
].u
.w
.rw
= (is_write
) ? TRUE
: FALSE
;
521 breakpoints
[reg
].u
.w
.reg
= reg
;
523 DEBUG_Printf( DBG_CHN_MESG
, "Watchpoint %d at ", num
);
524 DEBUG_PrintAddress( &breakpoints
[num
].addr
, breakpoints
[num
].is32
? MODE_32
: MODE_16
, TRUE
);
525 DEBUG_Printf( DBG_CHN_MESG
, "\n" );
529 /***********************************************************************
530 * DEBUG_AddWathpointFromId
532 * Add a watchpoint from a symbol name (and eventually a line #)
534 void DEBUG_AddWatchpointFromId(const char *name
)
538 if( DEBUG_GetSymbolValue(name
, -1, &value
, TRUE
) )
539 DEBUG_AddWatchpoint( &value
, 1 );
541 DEBUG_Printf(DBG_CHN_MESG
, "Unable to add watchpoint\n");
544 /***********************************************************************
545 * DEBUG_DelBreakpoint
547 * Delete a breakpoint.
549 void DEBUG_DelBreakpoint( int num
)
551 if ((num
<= 0) || (num
>= next_bp
) || breakpoints
[num
].refcount
== 0)
553 DEBUG_Printf( DBG_CHN_MESG
, "Invalid breakpoint number %d\n", num
);
557 if (--breakpoints
[num
].refcount
> 0)
560 if( breakpoints
[num
].condition
!= NULL
)
562 DEBUG_FreeExpr(breakpoints
[num
].condition
);
563 breakpoints
[num
].condition
= NULL
;
566 breakpoints
[num
].enabled
= FALSE
;
567 breakpoints
[num
].refcount
= 0;
568 breakpoints
[num
].skipcount
= 0;
571 /***********************************************************************
572 * DEBUG_EnableBreakpoint
574 * Enable or disable a break point.
576 void DEBUG_EnableBreakpoint( int num
, BOOL enable
)
578 if ((num
<= 0) || (num
>= next_bp
) || breakpoints
[num
].refcount
== 0)
580 DEBUG_Printf( DBG_CHN_MESG
, "Invalid breakpoint number %d\n", num
);
583 breakpoints
[num
].enabled
= (enable
) ? TRUE
: FALSE
;
584 breakpoints
[num
].skipcount
= 0;
588 /***********************************************************************
589 * DEBUG_FindTriggeredWatchpoint
591 * Lookup the watchpoints to see if one has been triggered
592 * Return >= (watch point index) if one is found and *oldval is set to
593 * the value watched before the TRAP
594 * Return -1 if none found (*oldval is undetermined)
596 * Unfortunately, Linux does *NOT* (A REAL PITA) report with ptrace
597 * the DR6 register value, so we have to look with our own need the
601 static int DEBUG_FindTriggeredWatchpoint(LPDWORD oldval
)
607 /* Method 1 => get triggered watchpoint from context (doesn't work on Linux
608 * 2.2.x). This should be fixed in >= 2.2.16
610 for (i
= 0; i
< next_bp
; i
++)
614 if (breakpoints
[i
].refcount
&& breakpoints
[i
].enabled
&&
615 breakpoints
[i
].type
== DBG_WATCH
&&
616 (DEBUG_context
.Dr6
& (1 << breakpoints
[i
].u
.w
.reg
)))
618 DEBUG_context
.Dr6
&= ~(1 << breakpoints
[i
].u
.w
.reg
);
620 *oldval
= breakpoints
[i
].u
.w
.oldval
;
621 if (DEBUG_GetWatchedValue(i
, &val
)) {
622 breakpoints
[i
].u
.w
.oldval
= val
;
628 /* Method 1 failed, trying method 2 */
630 /* Method 2 => check if value has changed among registered watchpoints
631 * this really sucks, but this is how gdb 4.18 works on my linux box
634 for (i
= 0; i
< next_bp
; i
++)
638 if (breakpoints
[i
].refcount
&& breakpoints
[i
].enabled
&&
639 breakpoints
[i
].type
== DBG_WATCH
&&
640 DEBUG_GetWatchedValue(i
, &val
))
642 *oldval
= breakpoints
[i
].u
.w
.oldval
;
645 DEBUG_context
.Dr6
&= ~(1 << breakpoints
[i
].u
.w
.reg
);
646 breakpoints
[i
].u
.w
.oldval
= val
;
648 /* cannot break, because two watch points may have been triggered on
650 * only one will be reported to the user (FIXME ?)
659 /***********************************************************************
660 * DEBUG_InfoBreakpoints
662 * Display break points information.
664 void DEBUG_InfoBreakpoints(void)
668 DEBUG_Printf( DBG_CHN_MESG
, "Breakpoints:\n" );
669 for (i
= 1; i
< next_bp
; i
++)
671 if (breakpoints
[i
].refcount
&& breakpoints
[i
].type
== DBG_BREAK
)
673 DEBUG_Printf( DBG_CHN_MESG
, "%d: %c ", i
, breakpoints
[i
].enabled
? 'y' : 'n');
674 DEBUG_PrintAddress( &breakpoints
[i
].addr
,
675 breakpoints
[i
].is32
? MODE_32
: MODE_16
, TRUE
);
676 DEBUG_Printf( DBG_CHN_MESG
, " (%u)\n", breakpoints
[i
].refcount
);
677 if( breakpoints
[i
].condition
!= NULL
)
679 DEBUG_Printf(DBG_CHN_MESG
, "\t\tstop when ");
680 DEBUG_DisplayExpr(breakpoints
[i
].condition
);
681 DEBUG_Printf(DBG_CHN_MESG
, "\n");
685 DEBUG_Printf( DBG_CHN_MESG
, "Watchpoints:\n" );
686 for (i
= 1; i
< next_bp
; i
++)
688 if (breakpoints
[i
].refcount
&& breakpoints
[i
].type
== DBG_WATCH
)
690 DEBUG_Printf( DBG_CHN_MESG
, "%d: %c ", i
, breakpoints
[i
].enabled
? 'y' : 'n');
691 DEBUG_PrintAddress( &breakpoints
[i
].addr
,
692 breakpoints
[i
].is32
? MODE_32
: MODE_16
, TRUE
);
693 DEBUG_Printf( DBG_CHN_MESG
, " on %d byte%s (%c)\n",
694 breakpoints
[i
].u
.w
.len
+ 1,
695 breakpoints
[i
].u
.w
.len
> 0 ? "s" : "",
696 breakpoints
[i
].u
.w
.rw
? 'W' : 'R');
697 if( breakpoints
[i
].condition
!= NULL
)
699 DEBUG_Printf(DBG_CHN_MESG
, "\t\tstop when ");
700 DEBUG_DisplayExpr(breakpoints
[i
].condition
);
701 DEBUG_Printf(DBG_CHN_MESG
, "\n");
707 /***********************************************************************
710 * Check whether or not the condition (bp / skipcount) of a break/watch
713 static BOOL
DEBUG_ShallBreak( int bpnum
)
715 if ( breakpoints
[bpnum
].condition
!= NULL
)
717 DBG_VALUE value
= DEBUG_EvalExpr(breakpoints
[bpnum
].condition
);
719 if ( value
.type
== NULL
)
722 * Something wrong - unable to evaluate this expression.
724 DEBUG_Printf(DBG_CHN_MESG
, "Unable to evaluate expression ");
725 DEBUG_DisplayExpr(breakpoints
[bpnum
].condition
);
726 DEBUG_Printf(DBG_CHN_MESG
, "\nTurning off condition\n");
727 DEBUG_AddBPCondition(bpnum
, NULL
);
729 else if( !DEBUG_GetExprValue( &value
, NULL
) )
735 if ( breakpoints
[bpnum
].skipcount
> 0 && --breakpoints
[bpnum
].skipcount
> 0 )
738 if ((breakpoints
[bpnum
].type
== DBG_BREAK
) && breakpoints
[bpnum
].u
.b
.func
)
739 return breakpoints
[bpnum
].u
.b
.func();
743 /***********************************************************************
744 * DEBUG_ShouldContinue
746 * Determine if we should continue execution after a SIGTRAP signal when
747 * executing in the given mode.
749 BOOL
DEBUG_ShouldContinue( DBG_ADDR
*addr
, DWORD code
, int * count
)
754 enum dbg_mode addr_mode
;
755 struct symbol_info syminfo
;
756 enum exec_mode mode
= DEBUG_CurrThread
->exec_mode
;
759 /* If not single-stepping, back up over the int3 instruction */
760 if (code
== EXCEPTION_BREAKPOINT
)
767 bpnum
= DEBUG_FindBreakpoint( addr
, DBG_BREAK
);
768 breakpoints
[0].enabled
= FALSE
; /* disable the step-over breakpoint */
770 if ((bpnum
!= 0) && (bpnum
!= -1))
772 if (!DEBUG_ShallBreak(bpnum
)) return TRUE
;
774 DEBUG_Printf( DBG_CHN_MESG
, "Stopped on breakpoint %d at ", bpnum
);
775 syminfo
= DEBUG_PrintAddress( &breakpoints
[bpnum
].addr
,
776 breakpoints
[bpnum
].is32
? MODE_32
: MODE_16
, TRUE
);
777 DEBUG_Printf( DBG_CHN_MESG
, "\n" );
779 if( syminfo
.list
.sourcefile
!= NULL
)
780 DEBUG_List(&syminfo
.list
, NULL
, 0);
784 wpnum
= DEBUG_FindTriggeredWatchpoint(&oldval
);
785 if ((wpnum
!= 0) && (wpnum
!= -1))
787 /* If not single-stepping, do not back up over the int3 instruction */
788 if (code
== EXCEPTION_BREAKPOINT
)
795 if (!DEBUG_ShallBreak(wpnum
)) return TRUE
;
797 addr_mode
= DEBUG_GetSelectorType( addr
->seg
);
798 DEBUG_Printf(DBG_CHN_MESG
, "Stopped on watchpoint %d at ", wpnum
);
799 syminfo
= DEBUG_PrintAddress( addr
, addr_mode
, TRUE
);
801 DEBUG_Printf(DBG_CHN_MESG
, " values: old=%lu new=%lu\n",
802 oldval
, breakpoints
[wpnum
].u
.w
.oldval
);
803 if (syminfo
.list
.sourcefile
!= NULL
)
804 DEBUG_List(&syminfo
.list
, NULL
, 0);
809 * If our mode indicates that we are stepping line numbers,
810 * get the current function, and figure out if we are exactly
811 * on a line number or not.
813 if( mode
== EXEC_STEP_OVER
|| mode
== EXEC_STEP_INSTR
)
815 if( DEBUG_CheckLinenoStatus(addr
) == AT_LINENUMBER
)
820 else if( mode
== EXEC_STEPI_OVER
|| mode
== EXEC_STEPI_INSTR
)
825 if( *count
> 0 || mode
== EXEC_FINISH
)
828 * We still need to execute more instructions.
834 * If we are about to stop, then print out the source line if we
837 if (mode
!= EXEC_CONT
&& mode
!= EXEC_FINISH
)
839 DEBUG_FindNearestSymbol( addr
, TRUE
, NULL
, 0, &syminfo
.list
);
840 if( syminfo
.list
.sourcefile
!= NULL
)
842 DEBUG_List(&syminfo
.list
, NULL
, 0);
847 /* If there's no breakpoint and we are not single-stepping, then we */
848 /* must have encountered an int3 in the Windows program; let's skip it. */
849 if ((bpnum
== -1) && code
== EXCEPTION_BREAKPOINT
)
856 /* no breakpoint, continue if in continuous mode */
857 return (mode
== EXEC_CONT
|| mode
== EXEC_FINISH
);
860 /***********************************************************************
861 * DEBUG_SuspendExecution
863 * Remove all breakpoints before entering the debug loop
865 void DEBUG_SuspendExecution( void )
867 DEBUG_SetBreakpoints( FALSE
);
868 breakpoints
[0] = DEBUG_CurrThread
->stepOverBP
;
871 /***********************************************************************
872 * DEBUG_RestartExecution
874 * Set the breakpoints to the correct state to restart execution
877 void DEBUG_RestartExecution( int count
)
884 enum exec_mode mode
, ret_mode
;
888 DEBUG_GetCurrentAddress( &addr
);
891 * This is the mode we will be running in after we finish. We would like
892 * to be able to modify this in certain cases.
894 ret_mode
= mode
= DEBUG_CurrThread
->exec_mode
;
896 bp
= DEBUG_FindBreakpoint( &addr
, DBG_BREAK
);
897 if ( bp
!= -1 && bp
!= 0)
900 * If we have set a new value, then save it in the BP number.
902 if( count
!= 0 && mode
== EXEC_CONT
)
904 breakpoints
[bp
].skipcount
= count
;
906 mode
= EXEC_STEPI_INSTR
; /* If there's a breakpoint, skip it */
910 if( mode
== EXEC_CONT
&& count
> 1 )
912 DEBUG_Printf(DBG_CHN_MESG
, "Not stopped at any breakpoint; argument ignored.\n");
916 if( mode
== EXEC_FINISH
&& DEBUG_IsFctReturn() )
918 mode
= ret_mode
= EXEC_STEPI_INSTR
;
921 instr
= DEBUG_ToLinear( &addr
);
922 DEBUG_READ_MEM((void*)instr
, &ch
, sizeof(ch
));
924 * See if the function we are stepping into has debug info
925 * and line numbers. If not, then we step over it instead.
926 * FIXME - we need to check for things like thunks or trampolines,
927 * as the actual function may in fact have debug info.
931 DEBUG_READ_MEM((void*)(instr
+ 1), &delta
, sizeof(delta
));
933 DEBUG_Disasm(&addr2
, FALSE
);
936 status
= DEBUG_CheckLinenoStatus(&addr2
);
938 * Anytime we have a trampoline, step over it.
940 if( ((mode
== EXEC_STEP_OVER
) || (mode
== EXEC_STEPI_OVER
))
941 && status
== FUNC_IS_TRAMPOLINE
)
944 DEBUG_Printf(DBG_CHN_MESG
, "Not stepping into trampoline at %x (no lines)\n",
947 mode
= EXEC_STEP_OVER_TRAMPOLINE
;
950 if( mode
== EXEC_STEP_INSTR
&& status
== FUNC_HAS_NO_LINES
)
953 DEBUG_Printf(DBG_CHN_MESG
, "Not stepping into function at %x (no lines)\n",
956 mode
= EXEC_STEP_OVER
;
961 if( mode
== EXEC_STEP_INSTR
)
963 if( DEBUG_CheckLinenoStatus(&addr
) == FUNC_HAS_NO_LINES
)
965 DEBUG_Printf(DBG_CHN_MESG
, "Single stepping until exit from function, \n");
966 DEBUG_Printf(DBG_CHN_MESG
, "which has no line number information.\n");
968 ret_mode
= mode
= EXEC_FINISH
;
974 case EXEC_CONT
: /* Continuous execution */
976 DEBUG_context
.EFlags
&= ~STEP_FLAG
;
978 DEBUG_SetBreakpoints( TRUE
);
981 case EXEC_STEP_OVER_TRAMPOLINE
:
983 * This is the means by which we step over our conversion stubs
984 * in callfrom*.s and callto*.s. We dig the appropriate address
985 * off the stack, and we set the breakpoint there instead of the
986 * address just after the call.
989 DEBUG_READ_MEM((void*)(DEBUG_context
.Esp
+
990 2 * sizeof(unsigned int)),
991 &addr
.off
, sizeof(addr
.off
));
992 DEBUG_context
.EFlags
&= ~STEP_FLAG
;
994 breakpoints
[0].addr
= addr
;
995 breakpoints
[0].enabled
= TRUE
;
996 breakpoints
[0].refcount
= 1;
997 breakpoints
[0].skipcount
= 0;
998 DEBUG_READ_MEM((void*)DEBUG_ToLinear( &addr
), &breakpoints
[0].u
.b
.opcode
,
1000 DEBUG_SetBreakpoints( TRUE
);
1004 case EXEC_STEPI_OVER
: /* Stepping over a call */
1005 case EXEC_STEP_OVER
: /* Stepping over a call */
1006 if (DEBUG_IsStepOverInstr())
1009 DEBUG_context
.EFlags
&= ~STEP_FLAG
;
1011 DEBUG_Disasm(&addr
, FALSE
);
1012 breakpoints
[0].addr
= addr
;
1013 breakpoints
[0].enabled
= TRUE
;
1014 breakpoints
[0].refcount
= 1;
1015 breakpoints
[0].skipcount
= 0;
1016 DEBUG_READ_MEM((void*)DEBUG_ToLinear( &addr
), &breakpoints
[0].u
.b
.opcode
,
1018 DEBUG_SetBreakpoints( TRUE
);
1021 /* else fall through to single-stepping */
1023 case EXEC_STEP_INSTR
: /* Single-stepping an instruction */
1024 case EXEC_STEPI_INSTR
: /* Single-stepping an instruction */
1026 DEBUG_context
.EFlags
|= STEP_FLAG
;
1030 RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
1032 DEBUG_CurrThread
->stepOverBP
= breakpoints
[0];
1033 DEBUG_CurrThread
->exec_mode
= ret_mode
;
1037 DEBUG_AddBPCondition(int num
, struct expr
* exp
)
1039 if ((num
<= 0) || (num
>= next_bp
) || !breakpoints
[num
].refcount
)
1041 DEBUG_Printf( DBG_CHN_MESG
, "Invalid breakpoint number %d\n", num
);
1045 if( breakpoints
[num
].condition
!= NULL
)
1047 DEBUG_FreeExpr(breakpoints
[num
].condition
);
1048 breakpoints
[num
].condition
= NULL
;
1053 breakpoints
[num
].condition
= DEBUG_CloneExpr(exp
);