2 * Debugger break-points handling
4 * Copyright 1994 Martin von Loewis
5 * Copyright 1995 Alexandre Julliard
6 * Copyright 1999,2000 Eric Pouech
13 #define DR7_CONTROL_SHIFT 16
14 #define DR7_CONTROL_SIZE 4
16 #define DR7_RW_EXECUTE (0x0)
17 #define DR7_RW_WRITE (0x1)
18 #define DR7_RW_READ (0x3)
20 #define DR7_LEN_1 (0x0)
21 #define DR7_LEN_2 (0x4)
22 #define DR7_LEN_4 (0xC)
24 #define DR7_LOCAL_ENABLE_SHIFT 0
25 #define DR7_GLOBAL_ENABLE_SHIFT 1
26 #define DR7_ENABLE_SIZE 2
28 #define DR7_LOCAL_ENABLE_MASK (0x55)
29 #define DR7_GLOBAL_ENABLE_MASK (0xAA)
31 #define DR7_CONTROL_RESERVED (0xFC00)
32 #define DR7_LOCAL_SLOWDOWN (0x100)
33 #define DR7_GLOBAL_SLOWDOWN (0x200)
35 #define DR7_ENABLE_MASK(dr) (1<<(DR7_LOCAL_ENABLE_SHIFT+DR7_ENABLE_SIZE*(dr)))
36 #define IS_DR7_SET(ctrl,dr) ((ctrl)&DR7_ENABLE_MASK(dr))
37 #define INT3 0xcc /* int 3 opcode */
40 #define MAX_BREAKPOINTS 100
42 static DBG_BREAKPOINT breakpoints
[MAX_BREAKPOINTS
];
44 static int next_bp
= 1; /* breakpoint 0 is reserved for step-over */
46 /***********************************************************************
47 * DEBUG_IsStepOverInstr
49 * Determine if the instruction at CS:EIP is an instruction that
50 * we need to step over (like a call or a repetitive string move).
52 static BOOL
DEBUG_IsStepOverInstr(void)
59 addr
.seg
= DEBUG_context
.SegCs
;
60 addr
.off
= DEBUG_context
.Eip
;
61 /* FIXME: old code was using V86BASE(DEBUG_context)
62 * instead of passing thru DOSMEM_MemoryBase
64 instr
= (BYTE
*)DEBUG_ToLinear(&addr
);
68 if (!DEBUG_READ_MEM(instr
, &ch
, sizeof(ch
)))
73 /* Skip all prefixes */
81 case 0x66: /* opcode size prefix */
82 case 0x67: /* addr size prefix */
84 case 0xf2: /* repne */
89 /* Handle call instructions */
91 case 0xcd: /* int <intno> */
92 case 0xe8: /* call <offset> */
93 case 0x9a: /* lcall <seg>:<off> */
96 case 0xff: /* call <regmodrm> */
97 if (!DEBUG_READ_MEM(instr
+ 1, &ch
, sizeof(ch
)))
99 return (((ch
& 0x38) == 0x10) || ((ch
& 0x38) == 0x18));
101 /* Handle string instructions */
103 case 0x6c: /* insb */
104 case 0x6d: /* insw */
105 case 0x6e: /* outsb */
106 case 0x6f: /* outsw */
107 case 0xa4: /* movsb */
108 case 0xa5: /* movsw */
109 case 0xa6: /* cmpsb */
110 case 0xa7: /* cmpsw */
111 case 0xaa: /* stosb */
112 case 0xab: /* stosw */
113 case 0xac: /* lodsb */
114 case 0xad: /* lodsw */
115 case 0xae: /* scasb */
116 case 0xaf: /* scasw */
129 /***********************************************************************
132 * Determine if the instruction at CS:EIP is an instruction that
133 * is a function return.
135 BOOL
DEBUG_IsFctReturn(void)
142 addr
.seg
= DEBUG_context
.SegCs
;
143 addr
.off
= DEBUG_context
.Eip
;
144 /* FIXME: old code was using V86BASE(DEBUG_context)
145 * instead of passing thru DOSMEM_MemoryBase
147 instr
= (BYTE
*)DEBUG_ToLinear(&addr
);
149 if (!DEBUG_READ_MEM(instr
, &ch
, sizeof(ch
)))
152 return (ch
== 0xc2) || (ch
== 0xc3);
159 /***********************************************************************
160 * DEBUG_SetBreakpoints
162 * Set or remove all the breakpoints.
164 void DEBUG_SetBreakpoints( BOOL set
)
169 DEBUG_context
.Dr7
&= ~DR7_LOCAL_ENABLE_MASK
;
172 for (i
= 0; i
< next_bp
; i
++)
174 if (!(breakpoints
[i
].refcount
&& breakpoints
[i
].enabled
))
177 switch (breakpoints
[i
].type
) {
181 char ch
= set
? INT3
: breakpoints
[i
].u
.opcode
;
184 if (!DEBUG_WRITE_MEM( (void*)DEBUG_ToLinear(&breakpoints
[i
].addr
),
187 DEBUG_Printf(DBG_CHN_MESG
, "Invalid address for breakpoint %d, disabling it\n", i
);
188 breakpoints
[i
].enabled
= FALSE
;
197 int reg
= breakpoints
[i
].u
.w
.reg
;
202 case 0: lpdr
= &DEBUG_context
.Dr0
; break;
203 case 1: lpdr
= &DEBUG_context
.Dr1
; break;
204 case 2: lpdr
= &DEBUG_context
.Dr2
; break;
205 case 3: lpdr
= &DEBUG_context
.Dr3
; break;
206 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
209 *lpdr
= DEBUG_ToLinear(&breakpoints
[i
].addr
);
210 bits
= (breakpoints
[i
].u
.w
.rw
) ? DR7_RW_WRITE
: DR7_RW_READ
;
211 switch (breakpoints
[i
].u
.w
.len
+ 1)
213 case 4: bits
|= DR7_LEN_4
; break;
214 case 2: bits
|= DR7_LEN_2
; break;
215 case 1: bits
|= DR7_LEN_1
; break;
216 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
219 DEBUG_context
.Dr7
&= ~(0x0F << (DR7_CONTROL_SHIFT
+ DR7_CONTROL_SIZE
* reg
));
220 DEBUG_context
.Dr7
|= bits
<< (DR7_CONTROL_SHIFT
+ DR7_CONTROL_SIZE
* reg
);
221 DEBUG_context
.Dr7
|= DR7_ENABLE_MASK(reg
) | DR7_LOCAL_SLOWDOWN
;
229 /***********************************************************************
230 * DEBUG_FindBreakpoint
232 * Find the breakpoint for a given address. Return the breakpoint
233 * number or -1 if none.
234 * If type is DBG_BREAKPOINT, addr is a complete addr
235 * If type is DBG_WATCHPOINT, only addr.off is meaningful and contains
238 static int DEBUG_FindBreakpoint( const DBG_ADDR
*addr
, int type
)
242 for (i
= 0; i
< next_bp
; i
++)
244 if (breakpoints
[i
].refcount
&& breakpoints
[i
].enabled
&&
245 breakpoints
[i
].type
== type
)
247 if ((type
== DBG_BREAK
&&
248 breakpoints
[i
].addr
.seg
== addr
->seg
&&
249 breakpoints
[i
].addr
.off
== addr
->off
) ||
250 (type
== DBG_WATCH
&&
251 DEBUG_ToLinear(&breakpoints
[i
].addr
) == addr
->off
))
258 /***********************************************************************
261 * Find an empty slot in BP table to add a new break/watch point
263 static int DEBUG_InitXPoint(int type
, DBG_ADDR
* addr
)
267 for (num
= (next_bp
< MAX_BREAKPOINTS
) ? next_bp
++ : 1;
268 num
< MAX_BREAKPOINTS
; num
++)
270 if (breakpoints
[num
].refcount
== 0)
272 breakpoints
[num
].refcount
= 1;
273 breakpoints
[num
].enabled
= TRUE
;
274 breakpoints
[num
].type
= type
;
275 breakpoints
[num
].skipcount
= 0;
276 breakpoints
[num
].addr
= *addr
;
277 breakpoints
[num
].is32
= 1;
281 switch (DEBUG_GetSelectorType( addr
->seg
))
284 case 16: breakpoints
[num
].is32
= 0; break;
285 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
293 DEBUG_Printf( DBG_CHN_MESG
, "Too many breakpoints. Please delete some.\n" );
297 /***********************************************************************
298 * DEBUG_GetWatchedValue
300 * Returns the value watched by watch point 'num'.
302 static BOOL
DEBUG_GetWatchedValue( int num
, LPDWORD val
)
306 if (!DEBUG_READ_MEM((void*)DEBUG_ToLinear(&breakpoints
[num
].addr
),
307 buf
, breakpoints
[num
].u
.w
.len
+ 1))
310 switch (breakpoints
[num
].u
.w
.len
+ 1)
312 case 4: *val
= *(DWORD
*)buf
; break;
313 case 2: *val
= *(WORD
*)buf
; break;
314 case 1: *val
= *(BYTE
*)buf
; break;
315 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
320 /***********************************************************************
321 * DEBUG_AddBreakpoint
325 void DEBUG_AddBreakpoint( const DBG_VALUE
*_value
)
327 DBG_VALUE value
= *_value
;
332 assert(_value
->cookie
== DV_TARGET
|| _value
->cookie
== DV_HOST
);
334 DEBUG_FixAddress( &value
.addr
, DEBUG_context
.SegCs
);
336 if( value
.type
!= NULL
&& value
.type
== DEBUG_TypeIntConst
)
339 * We know that we have the actual offset stored somewhere
340 * else in 32-bit space. Grab it, and we
343 seg2
= value
.addr
.seg
;
345 value
.addr
.off
= DEBUG_GetExprValue(&value
, NULL
);
346 value
.addr
.seg
= seg2
;
349 if ((num
= DEBUG_FindBreakpoint(&value
.addr
, DBG_BREAK
)) >= 1)
351 breakpoints
[num
].refcount
++;
355 if (!DEBUG_READ_MEM_VERBOSE((void*)DEBUG_ToLinear( &value
.addr
), &ch
, sizeof(ch
)))
358 if ((num
= DEBUG_InitXPoint(DBG_BREAK
, &value
.addr
)) == -1)
361 breakpoints
[num
].u
.opcode
= ch
;
363 DEBUG_Printf( DBG_CHN_MESG
, "Breakpoint %d at ", num
);
364 DEBUG_PrintAddress( &breakpoints
[num
].addr
, breakpoints
[num
].is32
? 32 : 16,
366 DEBUG_Printf( DBG_CHN_MESG
, "\n" );
370 /***********************************************************************
371 * DEBUG_AddWatchpoint
375 void DEBUG_AddWatchpoint( const DBG_VALUE
*_value
, BOOL is_write
)
377 DBG_VALUE value
= *_value
;
382 assert(_value
->cookie
== DV_TARGET
|| _value
->cookie
== DV_HOST
);
385 DEBUG_FixAddress( &value
.addr
, DEBUG_context
.SegCs
);
388 if ( value
.type
!= NULL
&& value
.type
== DEBUG_TypeIntConst
)
391 * We know that we have the actual offset stored somewhere
392 * else in 32-bit space. Grab it, and we
395 seg2
= value
.addr
.seg
;
397 value
.addr
.off
= DEBUG_GetExprValue(&value
, NULL
);
398 value
.addr
.seg
= seg2
;
401 for (num
= 1; num
< next_bp
; num
++)
403 if (breakpoints
[num
].refcount
&& breakpoints
[num
].enabled
&&
404 breakpoints
[num
].type
== DBG_WATCH
) {
405 mask
|= (1 << breakpoints
[num
].u
.w
.reg
);
409 for (reg
= 0; reg
< 4 && (mask
& (1 << reg
)); reg
++);
412 DEBUG_Printf(DBG_CHN_MESG
, "All i386 hardware watchpoints have been set. Delete some\n");
417 if ((num
= DEBUG_InitXPoint(DBG_WATCH
, &value
.addr
)) == -1)
420 breakpoints
[num
].u
.w
.len
= 4 - 1;
421 if (_value
->type
&& DEBUG_GetObjectSize(_value
->type
) < 4)
422 breakpoints
[num
].u
.w
.len
= 2 - 1;
424 if (!DEBUG_GetWatchedValue( num
, &breakpoints
[num
].u
.w
.oldval
))
426 DEBUG_Printf(DBG_CHN_MESG
, "Bad address. Watchpoint not set\n");
427 breakpoints
[num
].refcount
= 0;
430 breakpoints
[num
].u
.w
.rw
= (is_write
) ? TRUE
: FALSE
;
431 breakpoints
[reg
].u
.w
.reg
= reg
;
433 DEBUG_Printf( DBG_CHN_MESG
, "Watchpoint %d at ", num
);
434 DEBUG_PrintAddress( &breakpoints
[num
].addr
, breakpoints
[num
].is32
? 32:16, TRUE
);
435 DEBUG_Printf( DBG_CHN_MESG
, "\n" );
438 /***********************************************************************
439 * DEBUG_DelBreakpoint
441 * Delete a breakpoint.
443 void DEBUG_DelBreakpoint( int num
)
445 if ((num
<= 0) || (num
>= next_bp
) || breakpoints
[num
].refcount
== 0)
447 DEBUG_Printf( DBG_CHN_MESG
, "Invalid breakpoint number %d\n", num
);
451 if (--breakpoints
[num
].refcount
> 0)
454 if( breakpoints
[num
].condition
!= NULL
)
456 DEBUG_FreeExpr(breakpoints
[num
].condition
);
457 breakpoints
[num
].condition
= NULL
;
460 breakpoints
[num
].enabled
= FALSE
;
461 breakpoints
[num
].refcount
= 0;
462 breakpoints
[num
].skipcount
= 0;
465 /***********************************************************************
466 * DEBUG_EnableBreakpoint
468 * Enable or disable a break point.
470 void DEBUG_EnableBreakpoint( int num
, BOOL enable
)
472 if ((num
<= 0) || (num
>= next_bp
) || breakpoints
[num
].refcount
== 0)
474 DEBUG_Printf( DBG_CHN_MESG
, "Invalid breakpoint number %d\n", num
);
477 breakpoints
[num
].enabled
= (enable
) ? TRUE
: FALSE
;
478 breakpoints
[num
].skipcount
= 0;
482 /***********************************************************************
483 * DEBUG_FindTriggeredWatchpoint
485 * Lookup the watchpoints to see if one has been triggered
486 * Return >= (watch point index) if one is found and *oldval is set to
487 * the value watched before the TRAP
488 * Return -1 if none found (*oldval is undetermined)
490 * Unfortunately, Linux does *NOT* (A REAL PITA) report with ptrace
491 * the DR6 register value, so we have to look with our own need the
495 static int DEBUG_FindTriggeredWatchpoint(LPDWORD oldval
)
501 /* Method 1 => get triggered watchpoint from context (doesn't work on Linux
504 for (i
= 0; i
< next_bp
; i
++)
507 if (breakpoints
[i
].refcount
&& breakpoints
[i
].enabled
&&
508 breakpoints
[i
].type
== DBG_WATCH
&&
509 (DEBUG_context
.Dr6
& (1 << breakpoints
[i
].u
.w
.reg
)))
511 DEBUG_context
.Dr6
&= ~(1 << breakpoints
[i
].u
.w
.reg
);
513 *oldval
= breakpoints
[i
].u
.w
.oldval
;
514 if (DEBUG_GetWatchedValue(i
, &val
)) {
515 breakpoints
[i
].u
.w
.oldval
= val
;
522 /* Method 1 failed, trying method2 */
524 /* Method 2 => check if value has changed among registered watchpoints
525 * this really sucks, but this is how gdb 4.18 works on my linux box
528 for (i
= 0; i
< next_bp
; i
++)
531 if (breakpoints
[i
].refcount
&& breakpoints
[i
].enabled
&&
532 breakpoints
[i
].type
== DBG_WATCH
&&
533 DEBUG_GetWatchedValue(i
, &val
))
535 *oldval
= breakpoints
[i
].u
.w
.oldval
;
538 DEBUG_context
.Dr6
&= ~(1 << breakpoints
[i
].u
.w
.reg
);
539 breakpoints
[i
].u
.w
.oldval
= val
;
541 /* cannot break, because two watch points may have been triggered on
543 * only one will be reported to the user (FIXME ?)
552 /***********************************************************************
553 * DEBUG_InfoBreakpoints
555 * Display break points information.
557 void DEBUG_InfoBreakpoints(void)
561 DEBUG_Printf( DBG_CHN_MESG
, "Breakpoints:\n" );
562 for (i
= 1; i
< next_bp
; i
++)
564 if (breakpoints
[i
].refcount
&& breakpoints
[i
].type
== DBG_BREAK
)
566 DEBUG_Printf( DBG_CHN_MESG
, "%d: %c ", i
, breakpoints
[i
].enabled
? 'y' : 'n');
567 DEBUG_PrintAddress( &breakpoints
[i
].addr
,
568 breakpoints
[i
].is32
? 32 : 16, TRUE
);
569 DEBUG_Printf( DBG_CHN_MESG
, " (%u)\n", breakpoints
[i
].refcount
);
570 if( breakpoints
[i
].condition
!= NULL
)
572 DEBUG_Printf(DBG_CHN_MESG
, "\t\tstop when ");
573 DEBUG_DisplayExpr(breakpoints
[i
].condition
);
574 DEBUG_Printf(DBG_CHN_MESG
, "\n");
578 DEBUG_Printf( DBG_CHN_MESG
, "Watchpoints:\n" );
579 for (i
= 1; i
< next_bp
; i
++)
581 if (breakpoints
[i
].refcount
&& breakpoints
[i
].type
== DBG_WATCH
)
583 DEBUG_Printf( DBG_CHN_MESG
, "%d: %c ", i
, breakpoints
[i
].enabled
? 'y' : 'n');
584 DEBUG_PrintAddress( &breakpoints
[i
].addr
,
585 breakpoints
[i
].is32
? 32 : 16, TRUE
);
586 DEBUG_Printf( DBG_CHN_MESG
, " on %d byte%s (%c)\n",
587 breakpoints
[i
].u
.w
.len
+ 1,
588 breakpoints
[i
].u
.w
.len
> 0 ? "s" : "",
589 breakpoints
[i
].u
.w
.rw
? 'W' : 'R');
590 if( breakpoints
[i
].condition
!= NULL
)
592 DEBUG_Printf(DBG_CHN_MESG
, "\t\tstop when ");
593 DEBUG_DisplayExpr(breakpoints
[i
].condition
);
594 DEBUG_Printf(DBG_CHN_MESG
, "\n");
600 /***********************************************************************
603 * Check whether or not the condition (bp / skipcount) of a break/watch
606 static BOOL
DEBUG_ShallBreak( int bpnum
)
608 if ( breakpoints
[bpnum
].condition
!= NULL
)
610 DBG_VALUE value
= DEBUG_EvalExpr(breakpoints
[bpnum
].condition
);
612 if ( value
.type
== NULL
)
615 * Something wrong - unable to evaluate this expression.
617 DEBUG_Printf(DBG_CHN_MESG
, "Unable to evaluate expression ");
618 DEBUG_DisplayExpr(breakpoints
[bpnum
].condition
);
619 DEBUG_Printf(DBG_CHN_MESG
, "\nTurning off condition\n");
620 DEBUG_AddBPCondition(bpnum
, NULL
);
622 else if( !DEBUG_GetExprValue( &value
, NULL
) )
628 if ( breakpoints
[bpnum
].skipcount
> 0 && --breakpoints
[bpnum
].skipcount
> 0 )
634 /***********************************************************************
635 * DEBUG_ShouldContinue
637 * Determine if we should continue execution after a SIGTRAP signal when
638 * executing in the given mode.
640 BOOL
DEBUG_ShouldContinue( DWORD code
, enum exec_mode mode
, int * count
)
646 struct symbol_info syminfo
;
649 /* If not single-stepping, back up over the int3 instruction */
650 if (code
== EXCEPTION_BREAKPOINT
)
654 DEBUG_GetCurrentAddress( &addr
);
655 bpnum
= DEBUG_FindBreakpoint( &addr
, DBG_BREAK
);
656 breakpoints
[0].enabled
= FALSE
; /* disable the step-over breakpoint */
658 if ((bpnum
!= 0) && (bpnum
!= -1))
660 if (!DEBUG_ShallBreak(bpnum
)) return TRUE
;
662 DEBUG_Printf( DBG_CHN_MESG
, "Stopped on breakpoint %d at ", bpnum
);
663 syminfo
= DEBUG_PrintAddress( &breakpoints
[bpnum
].addr
,
664 breakpoints
[bpnum
].is32
? 32 : 16, TRUE
);
665 DEBUG_Printf( DBG_CHN_MESG
, "\n" );
667 if( syminfo
.list
.sourcefile
!= NULL
)
668 DEBUG_List(&syminfo
.list
, NULL
, 0);
672 wpnum
= DEBUG_FindTriggeredWatchpoint(&oldval
);
673 if ((wpnum
!= 0) && (wpnum
!= -1))
675 /* If not single-stepping, do not back up over the int3 instruction */
676 if (code
== EXCEPTION_BREAKPOINT
)
683 if (!DEBUG_ShallBreak(wpnum
)) return TRUE
;
685 DEBUG_Printf(DBG_CHN_MESG
, "Stopped on watchpoint %d at ", wpnum
);
686 syminfo
= DEBUG_PrintAddress( &addr
, !addr
.seg
? 32 :
687 DEBUG_GetSelectorType( addr
.seg
), TRUE
);
689 DEBUG_Printf(DBG_CHN_MESG
, " values: old=%lu new=%lu\n",
690 oldval
, breakpoints
[wpnum
].u
.w
.oldval
);
691 if (syminfo
.list
.sourcefile
!= NULL
)
692 DEBUG_List(&syminfo
.list
, NULL
, 0);
697 * If our mode indicates that we are stepping line numbers,
698 * get the current function, and figure out if we are exactly
699 * on a line number or not.
701 if( mode
== EXEC_STEP_OVER
|| mode
== EXEC_STEP_INSTR
)
703 if( DEBUG_CheckLinenoStatus(&addr
) == AT_LINENUMBER
)
708 else if( mode
== EXEC_STEPI_OVER
|| mode
== EXEC_STEPI_INSTR
)
713 if( *count
> 0 || mode
== EXEC_FINISH
)
716 * We still need to execute more instructions.
722 * If we are about to stop, then print out the source line if we
725 if (mode
!= EXEC_CONT
&& mode
!= EXEC_PASS
&& mode
!= EXEC_FINISH
)
727 DEBUG_FindNearestSymbol( &addr
, TRUE
, NULL
, 0, &syminfo
.list
);
728 if( syminfo
.list
.sourcefile
!= NULL
)
730 DEBUG_List(&syminfo
.list
, NULL
, 0);
735 /* If there's no breakpoint and we are not single-stepping, then we */
736 /* must have encountered an int3 in the Windows program; let's skip it. */
737 if ((bpnum
== -1) && code
== EXCEPTION_BREAKPOINT
)
741 /* no breakpoint, continue if in continuous mode */
742 return (mode
== EXEC_CONT
|| mode
== EXEC_PASS
|| mode
== EXEC_FINISH
);
745 /***********************************************************************
746 * DEBUG_SuspendExecution
748 * Remove all breakpoints before entering the debug loop
750 void DEBUG_SuspendExecution( void )
752 DEBUG_SetBreakpoints( FALSE
);
753 breakpoints
[0] = DEBUG_CurrThread
->stepOverBP
;
756 /***********************************************************************
757 * DEBUG_RestartExecution
759 * Set the breakpoints to the correct state to restart execution
762 enum exec_mode
DEBUG_RestartExecution( enum exec_mode mode
, int count
)
769 enum exec_mode ret_mode
;
773 DEBUG_GetCurrentAddress( &addr
);
776 * This is the mode we will be running in after we finish. We would like
777 * to be able to modify this in certain cases.
781 bp
= DEBUG_FindBreakpoint( &addr
, DBG_BREAK
);
782 if ( bp
!= -1 && bp
!= 0)
785 * If we have set a new value, then save it in the BP number.
787 if( count
!= 0 && mode
== EXEC_CONT
)
789 breakpoints
[bp
].skipcount
= count
;
791 mode
= EXEC_STEPI_INSTR
; /* If there's a breakpoint, skip it */
795 if( mode
== EXEC_CONT
&& count
> 1 )
797 DEBUG_Printf(DBG_CHN_MESG
, "Not stopped at any breakpoint; argument ignored.\n");
801 if( mode
== EXEC_FINISH
&& DEBUG_IsFctReturn() )
803 mode
= ret_mode
= EXEC_STEPI_INSTR
;
806 instr
= DEBUG_ToLinear( &addr
);
807 DEBUG_READ_MEM((void*)instr
, &ch
, sizeof(ch
));
809 * See if the function we are stepping into has debug info
810 * and line numbers. If not, then we step over it instead.
811 * FIXME - we need to check for things like thunks or trampolines,
812 * as the actual function may in fact have debug info.
816 DEBUG_READ_MEM((void*)(instr
+ 1), &delta
, sizeof(delta
));
818 DEBUG_Disasm(&addr2
, FALSE
);
821 status
= DEBUG_CheckLinenoStatus(&addr2
);
823 * Anytime we have a trampoline, step over it.
825 if( ((mode
== EXEC_STEP_OVER
) || (mode
== EXEC_STEPI_OVER
))
826 && status
== FUNC_IS_TRAMPOLINE
)
829 DEBUG_Printf(DBG_CHN_MESG
, "Not stepping into trampoline at %x (no lines)\n",
832 mode
= EXEC_STEP_OVER_TRAMPOLINE
;
835 if( mode
== EXEC_STEP_INSTR
&& status
== FUNC_HAS_NO_LINES
)
838 DEBUG_Printf(DBG_CHN_MESG
, "Not stepping into function at %x (no lines)\n",
841 mode
= EXEC_STEP_OVER
;
846 if( mode
== EXEC_STEP_INSTR
)
848 if( DEBUG_CheckLinenoStatus(&addr
) == FUNC_HAS_NO_LINES
)
850 DEBUG_Printf(DBG_CHN_MESG
, "Single stepping until exit from function, \n");
851 DEBUG_Printf(DBG_CHN_MESG
, "which has no line number information.\n");
853 ret_mode
= mode
= EXEC_FINISH
;
859 case EXEC_CONT
: /* Continuous execution */
860 case EXEC_PASS
: /* Continue, passing exception */
862 DEBUG_context
.EFlags
&= ~STEP_FLAG
;
864 DEBUG_SetBreakpoints( TRUE
);
867 case EXEC_STEP_OVER_TRAMPOLINE
:
869 * This is the means by which we step over our conversion stubs
870 * in callfrom*.s and callto*.s. We dig the appropriate address
871 * off the stack, and we set the breakpoint there instead of the
872 * address just after the call.
875 DEBUG_READ_MEM((void*)(DEBUG_context
.Esp
+
876 2 * sizeof(unsigned int)),
877 &addr
.off
, sizeof(addr
.off
));
878 DEBUG_context
.EFlags
&= ~STEP_FLAG
;
880 breakpoints
[0].addr
= addr
;
881 breakpoints
[0].enabled
= TRUE
;
882 breakpoints
[0].refcount
= 1;
883 breakpoints
[0].skipcount
= 0;
884 DEBUG_READ_MEM((void*)DEBUG_ToLinear( &addr
), &breakpoints
[0].u
.opcode
,
886 DEBUG_SetBreakpoints( TRUE
);
890 case EXEC_STEPI_OVER
: /* Stepping over a call */
891 case EXEC_STEP_OVER
: /* Stepping over a call */
892 if (DEBUG_IsStepOverInstr())
895 DEBUG_context
.EFlags
&= ~STEP_FLAG
;
897 DEBUG_Disasm(&addr
, FALSE
);
898 breakpoints
[0].addr
= addr
;
899 breakpoints
[0].enabled
= TRUE
;
900 breakpoints
[0].refcount
= 1;
901 breakpoints
[0].skipcount
= 0;
902 DEBUG_READ_MEM((void*)DEBUG_ToLinear( &addr
), &breakpoints
[0].u
.opcode
,
904 DEBUG_SetBreakpoints( TRUE
);
907 /* else fall through to single-stepping */
909 case EXEC_STEP_INSTR
: /* Single-stepping an instruction */
910 case EXEC_STEPI_INSTR
: /* Single-stepping an instruction */
912 DEBUG_context
.EFlags
|= STEP_FLAG
;
918 RaiseException(DEBUG_STATUS_INTERNAL_ERROR
, 0, 0, NULL
);
920 DEBUG_CurrThread
->stepOverBP
= breakpoints
[0];
925 DEBUG_AddBPCondition(int num
, struct expr
* exp
)
927 if ((num
<= 0) || (num
>= next_bp
) || !breakpoints
[num
].refcount
)
929 DEBUG_Printf( DBG_CHN_MESG
, "Invalid breakpoint number %d\n", num
);
933 if( breakpoints
[num
].condition
!= NULL
)
935 DEBUG_FreeExpr(breakpoints
[num
].condition
);
936 breakpoints
[num
].condition
= NULL
;
941 breakpoints
[num
].condition
= DEBUG_CloneExpr(exp
);