blob: 2a1e4e91ffc995a0c58cc52a0d75a2396a924823 [file] [log] [blame]
Alexandre Julliardded30381995-07-06 17:18:27 +00001/*
2 * Debugger break-points handling
3 *
4 * Copyright 1994 Martin von Loewis
5 * Copyright 1995 Alexandre Julliard
Eric Pouechd33bcb62000-03-15 19:57:20 +00006 * Copyright 1999,2000 Eric Pouech
Alexandre Julliardded30381995-07-06 17:18:27 +00007 */
Alexandre Julliard58199531994-04-21 01:20:00 +00008
Marcus Meissnerb0d52b01999-02-28 19:59:00 +00009#include "config.h"
Alexandre Julliardded30381995-07-06 17:18:27 +000010#include "debugger.h"
Alexandre Julliard58199531994-04-21 01:20:00 +000011
Eric Pouechd33bcb62000-03-15 19:57:20 +000012#ifdef __i386__
13#define DR7_CONTROL_SHIFT 16
14#define DR7_CONTROL_SIZE 4
15
16#define DR7_RW_EXECUTE (0x0)
17#define DR7_RW_WRITE (0x1)
18#define DR7_RW_READ (0x3)
19
20#define DR7_LEN_1 (0x0)
21#define DR7_LEN_2 (0x4)
22#define DR7_LEN_4 (0xC)
23
24#define DR7_LOCAL_ENABLE_SHIFT 0
25#define DR7_GLOBAL_ENABLE_SHIFT 1
26#define DR7_ENABLE_SIZE 2
27
28#define DR7_LOCAL_ENABLE_MASK (0x55)
29#define DR7_GLOBAL_ENABLE_MASK (0xAA)
30
31#define DR7_CONTROL_RESERVED (0xFC00)
32#define DR7_LOCAL_SLOWDOWN (0x100)
33#define DR7_GLOBAL_SLOWDOWN (0x200)
34
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))
Alexandre Julliardded30381995-07-06 17:18:27 +000037#define INT3 0xcc /* int 3 opcode */
Eric Pouechd33bcb62000-03-15 19:57:20 +000038#endif
Alexandre Julliard58199531994-04-21 01:20:00 +000039
Alexandre Julliardc6c09441997-01-12 18:32:19 +000040#define MAX_BREAKPOINTS 100
Alexandre Julliard234bc241994-12-10 13:02:28 +000041
Eric Pouech04c16b82000-04-30 12:21:15 +000042static DBG_BREAKPOINT breakpoints[MAX_BREAKPOINTS];
Alexandre Julliardded30381995-07-06 17:18:27 +000043
44static int next_bp = 1; /* breakpoint 0 is reserved for step-over */
45
Alexandre Julliardded30381995-07-06 17:18:27 +000046/***********************************************************************
Alexandre Julliardb7258be1995-09-01 15:57:28 +000047 * DEBUG_IsStepOverInstr
48 *
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).
51 */
Eric Pouech527eea92000-03-08 16:44:54 +000052static BOOL DEBUG_IsStepOverInstr(void)
Alexandre Julliardb7258be1995-09-01 15:57:28 +000053{
Ulrich Weigandb3ec4b91999-11-13 20:58:45 +000054#ifdef __i386__
Eric Pouech527eea92000-03-08 16:44:54 +000055 BYTE* instr;
56 BYTE ch;
57 DBG_ADDR addr;
58
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
63 */
64 instr = (BYTE*)DEBUG_ToLinear(&addr);
Alexandre Julliardb7258be1995-09-01 15:57:28 +000065
66 for (;;)
67 {
Eric Pouech527eea92000-03-08 16:44:54 +000068 if (!DEBUG_READ_MEM(instr, &ch, sizeof(ch)))
69 return FALSE;
70
71 switch (ch)
Alexandre Julliardb7258be1995-09-01 15:57:28 +000072 {
73 /* Skip all prefixes */
74
75 case 0x2e: /* cs: */
76 case 0x36: /* ss: */
77 case 0x3e: /* ds: */
78 case 0x26: /* es: */
79 case 0x64: /* fs: */
80 case 0x65: /* gs: */
81 case 0x66: /* opcode size prefix */
82 case 0x67: /* addr size prefix */
83 case 0xf0: /* lock */
84 case 0xf2: /* repne */
85 case 0xf3: /* repe */
86 instr++;
87 continue;
88
89 /* Handle call instructions */
90
Ove Kaaven69df3711998-10-11 12:27:04 +000091 case 0xcd: /* int <intno> */
Alexandre Julliardb7258be1995-09-01 15:57:28 +000092 case 0xe8: /* call <offset> */
93 case 0x9a: /* lcall <seg>:<off> */
94 return TRUE;
95
96 case 0xff: /* call <regmodrm> */
Eric Pouech527eea92000-03-08 16:44:54 +000097 if (!DEBUG_READ_MEM(instr + 1, &ch, sizeof(ch)))
98 return FALSE;
99 return (((ch & 0x38) == 0x10) || ((ch & 0x38) == 0x18));
Alexandre Julliardb7258be1995-09-01 15:57:28 +0000100
101 /* Handle string instructions */
102
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 */
117 return TRUE;
118
119 default:
120 return FALSE;
121 }
122 }
Ulrich Weigandb3ec4b91999-11-13 20:58:45 +0000123#else
124 return FALSE;
125#endif
Alexandre Julliardb7258be1995-09-01 15:57:28 +0000126}
127
128
129/***********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000130 * DEBUG_IsFctReturn
131 *
132 * Determine if the instruction at CS:EIP is an instruction that
133 * is a function return.
134 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000135BOOL DEBUG_IsFctReturn(void)
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000136{
Ulrich Weigandb3ec4b91999-11-13 20:58:45 +0000137#ifdef __i386__
Eric Pouech527eea92000-03-08 16:44:54 +0000138 BYTE* instr;
139 BYTE ch;
140 DBG_ADDR addr;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000141
Eric Pouech527eea92000-03-08 16:44:54 +0000142 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
146 */
147 instr = (BYTE*)DEBUG_ToLinear(&addr);
148
149 if (!DEBUG_READ_MEM(instr, &ch, sizeof(ch)))
Eric Pouechd33bcb62000-03-15 19:57:20 +0000150 return FALSE;
Eric Pouech527eea92000-03-08 16:44:54 +0000151
152 return (ch == 0xc2) || (ch == 0xc3);
Ulrich Weigandb3ec4b91999-11-13 20:58:45 +0000153#else
154 return FALSE;
155#endif
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000156}
157
158
159/***********************************************************************
Alexandre Julliardded30381995-07-06 17:18:27 +0000160 * DEBUG_SetBreakpoints
161 *
162 * Set or remove all the breakpoints.
163 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000164void DEBUG_SetBreakpoints( BOOL set )
Alexandre Julliardded30381995-07-06 17:18:27 +0000165{
Eric Pouechd33bcb62000-03-15 19:57:20 +0000166 int i;
167
168#ifdef __i386__
169 DEBUG_context.Dr7 &= ~DR7_LOCAL_ENABLE_MASK;
170#endif
171
172 for (i = 0; i < next_bp; i++)
173 {
174 if (!(breakpoints[i].refcount && breakpoints[i].enabled))
175 continue;
176
177 switch (breakpoints[i].type) {
178 case DBG_BREAK:
179 {
180#ifdef __i386__
Eric Pouechb9717452000-05-05 18:14:34 +0000181 char ch = set ? INT3 : breakpoints[i].u.b.opcode;
Eric Pouechd33bcb62000-03-15 19:57:20 +0000182
183 if (!DEBUG_WRITE_MEM( (void*)DEBUG_ToLinear(&breakpoints[i].addr),
184 &ch, sizeof(ch) ))
185 {
Eric Poueche5efa0c2000-04-13 19:31:58 +0000186 DEBUG_Printf(DBG_CHN_MESG, "Invalid address for breakpoint %d, disabling it\n", i);
Eric Pouechd33bcb62000-03-15 19:57:20 +0000187 breakpoints[i].enabled = FALSE;
188 }
Ulrich Weigand1cbf27a2000-06-04 01:33:21 +0000189#endif
Eric Pouechd33bcb62000-03-15 19:57:20 +0000190 }
191 break;
192 case DBG_WATCH:
193 if (set)
194 {
195#ifdef __i386__
196 DWORD bits;
197 int reg = breakpoints[i].u.w.reg;
198 LPDWORD lpdr = NULL;
Alexandre Julliardded30381995-07-06 17:18:27 +0000199
Eric Pouechd33bcb62000-03-15 19:57:20 +0000200 switch (reg)
201 {
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);
207 }
208
209 *lpdr = DEBUG_ToLinear(&breakpoints[i].addr);
Eric Pouechd33bcb62000-03-15 19:57:20 +0000210 bits = (breakpoints[i].u.w.rw) ? DR7_RW_WRITE : DR7_RW_READ;
211 switch (breakpoints[i].u.w.len + 1)
212 {
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);
217 }
218
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;
222#endif
223 }
224 break;
225 }
226 }
Alexandre Julliardded30381995-07-06 17:18:27 +0000227}
228
Alexandre Julliardded30381995-07-06 17:18:27 +0000229/***********************************************************************
230 * DEBUG_FindBreakpoint
231 *
232 * Find the breakpoint for a given address. Return the breakpoint
233 * number or -1 if none.
Eric Pouechd33bcb62000-03-15 19:57:20 +0000234 * If type is DBG_BREAKPOINT, addr is a complete addr
235 * If type is DBG_WATCHPOINT, only addr.off is meaningful and contains
236 * linear address
Alexandre Julliardded30381995-07-06 17:18:27 +0000237 */
Eric Pouechd33bcb62000-03-15 19:57:20 +0000238static int DEBUG_FindBreakpoint( const DBG_ADDR *addr, int type )
Alexandre Julliardded30381995-07-06 17:18:27 +0000239{
Eric Pouechd33bcb62000-03-15 19:57:20 +0000240 int i;
241
242 for (i = 0; i < next_bp; i++)
243 {
244 if (breakpoints[i].refcount && breakpoints[i].enabled &&
245 breakpoints[i].type == type )
246 {
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))
252 return i;
253 }
254 }
255 return -1;
Alexandre Julliardded30381995-07-06 17:18:27 +0000256}
257
Eric Pouechd33bcb62000-03-15 19:57:20 +0000258/***********************************************************************
259 * DEBUG_InitXPoint
260 *
261 * Find an empty slot in BP table to add a new break/watch point
262 */
263static int DEBUG_InitXPoint(int type, DBG_ADDR* addr)
264{
265 int num;
266
267 for (num = (next_bp < MAX_BREAKPOINTS) ? next_bp++ : 1;
268 num < MAX_BREAKPOINTS; num++)
269 {
270 if (breakpoints[num].refcount == 0)
271 {
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;
278#ifdef __i386__
279 if (addr->seg)
280 {
281 switch (DEBUG_GetSelectorType( addr->seg ))
282 {
283 case 32: break;
284 case 16: breakpoints[num].is32 = 0; break;
285 default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
286 }
287 }
288#endif
289 return num;
290 }
291 }
292
Eric Poueche5efa0c2000-04-13 19:31:58 +0000293 DEBUG_Printf( DBG_CHN_MESG, "Too many breakpoints. Please delete some.\n" );
Eric Pouechd33bcb62000-03-15 19:57:20 +0000294 return -1;
295}
296
297/***********************************************************************
298 * DEBUG_GetWatchedValue
299 *
300 * Returns the value watched by watch point 'num'.
301 */
302static BOOL DEBUG_GetWatchedValue( int num, LPDWORD val )
303{
304 BYTE buf[4];
305
306 if (!DEBUG_READ_MEM((void*)DEBUG_ToLinear(&breakpoints[num].addr),
307 buf, breakpoints[num].u.w.len + 1))
308 return FALSE;
309
310 switch (breakpoints[num].u.w.len + 1)
311 {
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);
316 }
317 return TRUE;
318}
Alexandre Julliardded30381995-07-06 17:18:27 +0000319
320/***********************************************************************
321 * DEBUG_AddBreakpoint
322 *
323 * Add a breakpoint.
324 */
Eric Pouechb9717452000-05-05 18:14:34 +0000325void DEBUG_AddBreakpoint( const DBG_VALUE *_value, BOOL (*func)(void) )
Alexandre Julliardded30381995-07-06 17:18:27 +0000326{
Eric Pouechd33bcb62000-03-15 19:57:20 +0000327 DBG_VALUE value = *_value;
Alexandre Julliardded30381995-07-06 17:18:27 +0000328 int num;
Alexandre Julliard349a9531997-02-02 19:01:52 +0000329 unsigned int seg2;
Eric Pouech527eea92000-03-08 16:44:54 +0000330 BYTE ch;
Alexandre Julliardded30381995-07-06 17:18:27 +0000331
Eric Pouechd33bcb62000-03-15 19:57:20 +0000332 assert(_value->cookie == DV_TARGET || _value->cookie == DV_HOST);
Alexandre Julliardded30381995-07-06 17:18:27 +0000333
Ulrich Weigand1cbf27a2000-06-04 01:33:21 +0000334#ifdef __i386__
Eric Pouechd33bcb62000-03-15 19:57:20 +0000335 DEBUG_FixAddress( &value.addr, DEBUG_context.SegCs );
Ulrich Weigand1cbf27a2000-06-04 01:33:21 +0000336#endif
Eric Pouech527eea92000-03-08 16:44:54 +0000337
Eric Pouechd33bcb62000-03-15 19:57:20 +0000338 if( value.type != NULL && value.type == DEBUG_TypeIntConst )
339 {
340 /*
341 * We know that we have the actual offset stored somewhere
342 * else in 32-bit space. Grab it, and we
343 * should be all set.
344 */
345 seg2 = value.addr.seg;
346 value.addr.seg = 0;
347 value.addr.off = DEBUG_GetExprValue(&value, NULL);
348 value.addr.seg = seg2;
349 }
350
351 if ((num = DEBUG_FindBreakpoint(&value.addr, DBG_BREAK)) >= 1)
Eric Pouech527eea92000-03-08 16:44:54 +0000352 {
353 breakpoints[num].refcount++;
354 return;
355 }
356
Eric Pouechd33bcb62000-03-15 19:57:20 +0000357 if (!DEBUG_READ_MEM_VERBOSE((void*)DEBUG_ToLinear( &value.addr ), &ch, sizeof(ch)))
Eric Pouech527eea92000-03-08 16:44:54 +0000358 return;
Alexandre Julliard349a9531997-02-02 19:01:52 +0000359
Eric Pouechd33bcb62000-03-15 19:57:20 +0000360 if ((num = DEBUG_InitXPoint(DBG_BREAK, &value.addr)) == -1)
361 return;
362
Eric Pouechb9717452000-05-05 18:14:34 +0000363 breakpoints[num].u.b.opcode = ch;
364 breakpoints[num].u.b.func = func;
Eric Pouechd33bcb62000-03-15 19:57:20 +0000365
Eric Poueche5efa0c2000-04-13 19:31:58 +0000366 DEBUG_Printf( DBG_CHN_MESG, "Breakpoint %d at ", num );
Eric Pouechd33bcb62000-03-15 19:57:20 +0000367 DEBUG_PrintAddress( &breakpoints[num].addr, breakpoints[num].is32 ? 32 : 16,
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000368 TRUE );
Eric Poueche5efa0c2000-04-13 19:31:58 +0000369 DEBUG_Printf( DBG_CHN_MESG, "\n" );
Alexandre Julliardded30381995-07-06 17:18:27 +0000370}
371
Eric Pouech911436b2000-06-18 19:30:24 +0000372/***********************************************************************
373 * DEBUG_AddBreakpointFromId
374 *
375 * Add a breakpoint from a function name (and eventually a line #)
376 */
377void DEBUG_AddBreakpointFromId(const char *name, int lineno)
378{
379 DBG_VALUE value;
380
381 if (DEBUG_GetSymbolValue(name, lineno, &value, TRUE))
382 DEBUG_AddBreakpoint(&value, NULL);
383 else
384 DEBUG_Printf(DBG_CHN_MESG, "Unable to add breakpoint\n");
385}
386
387/***********************************************************************
388 * DEBUG_AddBreakpointFromLineno
389 *
390 * Add a breakpoint from a line number in current file
391 */
392void DEBUG_AddBreakpointFromLineno(int lineno)
393{
394 DBG_VALUE value;
395
396 DEBUG_GetCurrentAddress(&value.addr);
397
398 if (lineno != -1) {
399 struct name_hash* nh;
400
401 DEBUG_FindNearestSymbol(&value.addr, TRUE, &nh, 0, NULL);
402 if (nh == NULL) {
403 DEBUG_Printf(DBG_CHN_MESG,"Unable to add breakpoint\n");
404 return;
405 }
406 DEBUG_GetLineNumberAddr(nh, lineno, &value.addr, TRUE);
407 }
408
409 value.type = NULL;
410 value.cookie = DV_TARGET;
411 DEBUG_AddBreakpoint( &value, NULL );
412}
Alexandre Julliardded30381995-07-06 17:18:27 +0000413
Eric Pouechd33bcb62000-03-15 19:57:20 +0000414 /***********************************************************************
415 * DEBUG_AddWatchpoint
416 *
417 * Add a watchpoint.
418 */
419void DEBUG_AddWatchpoint( const DBG_VALUE *_value, BOOL is_write )
420{
421 DBG_VALUE value = *_value;
Ulrich Weigand1cbf27a2000-06-04 01:33:21 +0000422 int num, reg = -1;
Eric Pouechd33bcb62000-03-15 19:57:20 +0000423 unsigned seg2;
424 DWORD mask = 0;
425
426 assert(_value->cookie == DV_TARGET || _value->cookie == DV_HOST);
427
Eric Poueche5efa0c2000-04-13 19:31:58 +0000428#ifdef __i386__
429 DEBUG_FixAddress( &value.addr, DEBUG_context.SegCs );
430#endif
Eric Pouechd33bcb62000-03-15 19:57:20 +0000431
432 if ( value.type != NULL && value.type == DEBUG_TypeIntConst )
433 {
434 /*
435 * We know that we have the actual offset stored somewhere
436 * else in 32-bit space. Grab it, and we
437 * should be all set.
438 */
439 seg2 = value.addr.seg;
440 value.addr.seg = 0;
441 value.addr.off = DEBUG_GetExprValue(&value, NULL);
442 value.addr.seg = seg2;
443 }
444
445 for (num = 1; num < next_bp; num++)
446 {
447 if (breakpoints[num].refcount && breakpoints[num].enabled &&
448 breakpoints[num].type == DBG_WATCH) {
449 mask |= (1 << breakpoints[num].u.w.reg);
450 }
451 }
452#ifdef __i386__
453 for (reg = 0; reg < 4 && (mask & (1 << reg)); reg++);
454 if (reg == 4)
455 {
Eric Poueche5efa0c2000-04-13 19:31:58 +0000456 DEBUG_Printf(DBG_CHN_MESG, "All i386 hardware watchpoints have been set. Delete some\n");
Eric Pouechd33bcb62000-03-15 19:57:20 +0000457 return;
458 }
459#endif
460
461 if ((num = DEBUG_InitXPoint(DBG_WATCH, &value.addr)) == -1)
462 return;
463
464 breakpoints[num].u.w.len = 4 - 1;
465 if (_value->type && DEBUG_GetObjectSize(_value->type) < 4)
466 breakpoints[num].u.w.len = 2 - 1;
467
468 if (!DEBUG_GetWatchedValue( num, &breakpoints[num].u.w.oldval))
469 {
Eric Poueche5efa0c2000-04-13 19:31:58 +0000470 DEBUG_Printf(DBG_CHN_MESG, "Bad address. Watchpoint not set\n");
Eric Pouechd33bcb62000-03-15 19:57:20 +0000471 breakpoints[num].refcount = 0;
472 }
473
474 breakpoints[num].u.w.rw = (is_write) ? TRUE : FALSE;
475 breakpoints[reg].u.w.reg = reg;
476
Eric Poueche5efa0c2000-04-13 19:31:58 +0000477 DEBUG_Printf( DBG_CHN_MESG, "Watchpoint %d at ", num );
Eric Pouechd33bcb62000-03-15 19:57:20 +0000478 DEBUG_PrintAddress( &breakpoints[num].addr, breakpoints[num].is32 ? 32:16, TRUE );
Eric Poueche5efa0c2000-04-13 19:31:58 +0000479 DEBUG_Printf( DBG_CHN_MESG, "\n" );
Eric Pouechd33bcb62000-03-15 19:57:20 +0000480}
481
Alexandre Julliardded30381995-07-06 17:18:27 +0000482/***********************************************************************
Eric Pouech911436b2000-06-18 19:30:24 +0000483 * DEBUG_AddWathpointFromId
484 *
485 * Add a watchpoint from a symbol name (and eventually a line #)
486 */
487void DEBUG_AddWatchpointFromId(const char *name, int lineno)
488{
489 DBG_VALUE value;
490
491 if( DEBUG_GetSymbolValue(name, lineno, &value, TRUE) )
492 DEBUG_AddWatchpoint( &value, 1 );
493 else
494 DEBUG_Printf(DBG_CHN_MESG, "Unable to add watchpoint\n");
495}
496
497/***********************************************************************
Alexandre Julliardded30381995-07-06 17:18:27 +0000498 * DEBUG_DelBreakpoint
499 *
500 * Delete a breakpoint.
501 */
502void DEBUG_DelBreakpoint( int num )
503{
Eric Pouechd33bcb62000-03-15 19:57:20 +0000504 if ((num <= 0) || (num >= next_bp) || breakpoints[num].refcount == 0)
Alexandre Julliardded30381995-07-06 17:18:27 +0000505 {
Eric Poueche5efa0c2000-04-13 19:31:58 +0000506 DEBUG_Printf( DBG_CHN_MESG, "Invalid breakpoint number %d\n", num );
Alexandre Julliardded30381995-07-06 17:18:27 +0000507 return;
508 }
Alexandre Julliard01d63461997-01-20 19:43:45 +0000509
Eric Pouech527eea92000-03-08 16:44:54 +0000510 if (--breakpoints[num].refcount > 0)
511 return;
512
Alexandre Julliard01d63461997-01-20 19:43:45 +0000513 if( breakpoints[num].condition != NULL )
Eric Pouechd33bcb62000-03-15 19:57:20 +0000514 {
515 DEBUG_FreeExpr(breakpoints[num].condition);
516 breakpoints[num].condition = NULL;
517 }
Alexandre Julliard01d63461997-01-20 19:43:45 +0000518
Alexandre Julliardded30381995-07-06 17:18:27 +0000519 breakpoints[num].enabled = FALSE;
Eric Pouech527eea92000-03-08 16:44:54 +0000520 breakpoints[num].refcount = 0;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000521 breakpoints[num].skipcount = 0;
Alexandre Julliardded30381995-07-06 17:18:27 +0000522}
523
Alexandre Julliardded30381995-07-06 17:18:27 +0000524/***********************************************************************
525 * DEBUG_EnableBreakpoint
526 *
527 * Enable or disable a break point.
528 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000529void DEBUG_EnableBreakpoint( int num, BOOL enable )
Alexandre Julliardded30381995-07-06 17:18:27 +0000530{
Eric Pouechd33bcb62000-03-15 19:57:20 +0000531 if ((num <= 0) || (num >= next_bp) || breakpoints[num].refcount == 0)
Alexandre Julliardded30381995-07-06 17:18:27 +0000532 {
Eric Poueche5efa0c2000-04-13 19:31:58 +0000533 DEBUG_Printf( DBG_CHN_MESG, "Invalid breakpoint number %d\n", num );
Alexandre Julliardded30381995-07-06 17:18:27 +0000534 return;
535 }
Eric Pouech527eea92000-03-08 16:44:54 +0000536 breakpoints[num].enabled = (enable) ? TRUE : FALSE;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000537 breakpoints[num].skipcount = 0;
Alexandre Julliardded30381995-07-06 17:18:27 +0000538}
539
540
541/***********************************************************************
Eric Pouechd33bcb62000-03-15 19:57:20 +0000542 * DEBUG_FindTriggeredWatchpoint
543 *
544 * Lookup the watchpoints to see if one has been triggered
545 * Return >= (watch point index) if one is found and *oldval is set to
546 * the value watched before the TRAP
547 * Return -1 if none found (*oldval is undetermined)
548 *
549 * Unfortunately, Linux does *NOT* (A REAL PITA) report with ptrace
550 * the DR6 register value, so we have to look with our own need the
551 * cause of the TRAP.
552 * -EP
553 */
554static int DEBUG_FindTriggeredWatchpoint(LPDWORD oldval)
555{
556 int i;
557 int found = -1;
Eric Pouechd33bcb62000-03-15 19:57:20 +0000558
559 /* Method 1 => get triggered watchpoint from context (doesn't work on Linux
560 * 2.2.x)
561 */
562 for (i = 0; i < next_bp; i++)
563 {
564#ifdef __i386__
Ulrich Weigand1cbf27a2000-06-04 01:33:21 +0000565 DWORD val = 0;
566
Eric Pouechd33bcb62000-03-15 19:57:20 +0000567 if (breakpoints[i].refcount && breakpoints[i].enabled &&
568 breakpoints[i].type == DBG_WATCH &&
569 (DEBUG_context.Dr6 & (1 << breakpoints[i].u.w.reg)))
570 {
571 DEBUG_context.Dr6 &= ~(1 << breakpoints[i].u.w.reg);
572
573 *oldval = breakpoints[i].u.w.oldval;
574 if (DEBUG_GetWatchedValue(i, &val)) {
575 breakpoints[i].u.w.oldval = val;
576 return i;
577 }
578 }
579#endif
580 }
581
582 /* Method 1 failed, trying method2 */
583
584 /* Method 2 => check if value has changed among registered watchpoints
585 * this really sucks, but this is how gdb 4.18 works on my linux box
586 * -EP
587 */
588 for (i = 0; i < next_bp; i++)
589 {
590#ifdef __i386__
Ulrich Weigand1cbf27a2000-06-04 01:33:21 +0000591 DWORD val = 0;
592
Eric Pouechd33bcb62000-03-15 19:57:20 +0000593 if (breakpoints[i].refcount && breakpoints[i].enabled &&
594 breakpoints[i].type == DBG_WATCH &&
595 DEBUG_GetWatchedValue(i, &val))
596 {
597 *oldval = breakpoints[i].u.w.oldval;
598 if (val != *oldval)
599 {
600 DEBUG_context.Dr6 &= ~(1 << breakpoints[i].u.w.reg);
601 breakpoints[i].u.w.oldval = val;
602 found = i;
603 /* cannot break, because two watch points may have been triggered on
604 * the same acces
605 * only one will be reported to the user (FIXME ?)
606 */
607 }
608 }
609#endif
610 }
611 return found;
612}
613
614/***********************************************************************
Alexandre Julliardded30381995-07-06 17:18:27 +0000615 * DEBUG_InfoBreakpoints
616 *
617 * Display break points information.
618 */
619void DEBUG_InfoBreakpoints(void)
620{
621 int i;
622
Eric Poueche5efa0c2000-04-13 19:31:58 +0000623 DEBUG_Printf( DBG_CHN_MESG, "Breakpoints:\n" );
Alexandre Julliardded30381995-07-06 17:18:27 +0000624 for (i = 1; i < next_bp; i++)
625 {
Eric Pouechd33bcb62000-03-15 19:57:20 +0000626 if (breakpoints[i].refcount && breakpoints[i].type == DBG_BREAK)
Alexandre Julliardded30381995-07-06 17:18:27 +0000627 {
Eric Poueche5efa0c2000-04-13 19:31:58 +0000628 DEBUG_Printf( DBG_CHN_MESG, "%d: %c ", i, breakpoints[i].enabled ? 'y' : 'n');
Eric Pouechd33bcb62000-03-15 19:57:20 +0000629 DEBUG_PrintAddress( &breakpoints[i].addr,
630 breakpoints[i].is32 ? 32 : 16, TRUE);
Eric Poueche5efa0c2000-04-13 19:31:58 +0000631 DEBUG_Printf( DBG_CHN_MESG, " (%u)\n", breakpoints[i].refcount );
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000632 if( breakpoints[i].condition != NULL )
Eric Pouech527eea92000-03-08 16:44:54 +0000633 {
Eric Poueche5efa0c2000-04-13 19:31:58 +0000634 DEBUG_Printf(DBG_CHN_MESG, "\t\tstop when ");
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000635 DEBUG_DisplayExpr(breakpoints[i].condition);
Eric Poueche5efa0c2000-04-13 19:31:58 +0000636 DEBUG_Printf(DBG_CHN_MESG, "\n");
Eric Pouech527eea92000-03-08 16:44:54 +0000637 }
Alexandre Julliardded30381995-07-06 17:18:27 +0000638 }
639 }
Eric Poueche5efa0c2000-04-13 19:31:58 +0000640 DEBUG_Printf( DBG_CHN_MESG, "Watchpoints:\n" );
Eric Pouechd33bcb62000-03-15 19:57:20 +0000641 for (i = 1; i < next_bp; i++)
642 {
643 if (breakpoints[i].refcount && breakpoints[i].type == DBG_WATCH)
644 {
Eric Poueche5efa0c2000-04-13 19:31:58 +0000645 DEBUG_Printf( DBG_CHN_MESG, "%d: %c ", i, breakpoints[i].enabled ? 'y' : 'n');
Eric Pouechd33bcb62000-03-15 19:57:20 +0000646 DEBUG_PrintAddress( &breakpoints[i].addr,
647 breakpoints[i].is32 ? 32 : 16, TRUE);
Eric Poueche5efa0c2000-04-13 19:31:58 +0000648 DEBUG_Printf( DBG_CHN_MESG, " on %d byte%s (%c)\n",
Eric Pouechd33bcb62000-03-15 19:57:20 +0000649 breakpoints[i].u.w.len + 1,
650 breakpoints[i].u.w.len > 0 ? "s" : "",
651 breakpoints[i].u.w.rw ? 'W' : 'R');
652 if( breakpoints[i].condition != NULL )
653 {
Eric Poueche5efa0c2000-04-13 19:31:58 +0000654 DEBUG_Printf(DBG_CHN_MESG, "\t\tstop when ");
Eric Pouechd33bcb62000-03-15 19:57:20 +0000655 DEBUG_DisplayExpr(breakpoints[i].condition);
Eric Poueche5efa0c2000-04-13 19:31:58 +0000656 DEBUG_Printf(DBG_CHN_MESG, "\n");
Eric Pouechd33bcb62000-03-15 19:57:20 +0000657 }
658 }
659 }
Alexandre Julliardded30381995-07-06 17:18:27 +0000660}
661
Alexandre Julliard491502b1997-11-01 19:08:16 +0000662/***********************************************************************
Eric Pouechd33bcb62000-03-15 19:57:20 +0000663 * DEBUG_ShallBreak
664 *
665 * Check whether or not the condition (bp / skipcount) of a break/watch
666 * point are met.
667 */
668static BOOL DEBUG_ShallBreak( int bpnum )
669{
670 if ( breakpoints[bpnum].condition != NULL )
671 {
672 DBG_VALUE value = DEBUG_EvalExpr(breakpoints[bpnum].condition);
673
674 if ( value.type == NULL )
675 {
676 /*
677 * Something wrong - unable to evaluate this expression.
678 */
Eric Poueche5efa0c2000-04-13 19:31:58 +0000679 DEBUG_Printf(DBG_CHN_MESG, "Unable to evaluate expression ");
Eric Pouechd33bcb62000-03-15 19:57:20 +0000680 DEBUG_DisplayExpr(breakpoints[bpnum].condition);
Eric Poueche5efa0c2000-04-13 19:31:58 +0000681 DEBUG_Printf(DBG_CHN_MESG, "\nTurning off condition\n");
Eric Pouechd33bcb62000-03-15 19:57:20 +0000682 DEBUG_AddBPCondition(bpnum, NULL);
683 }
684 else if( !DEBUG_GetExprValue( &value, NULL) )
685 {
686 return FALSE;
687 }
688 }
689
690 if ( breakpoints[bpnum].skipcount > 0 && --breakpoints[bpnum].skipcount > 0 )
691 return FALSE;
692
Eric Pouechb9717452000-05-05 18:14:34 +0000693 return (breakpoints[bpnum].u.b.func) ? (breakpoints[bpnum].u.b.func)() : TRUE;
Eric Pouechd33bcb62000-03-15 19:57:20 +0000694}
695
696/***********************************************************************
Alexandre Julliardded30381995-07-06 17:18:27 +0000697 * DEBUG_ShouldContinue
698 *
699 * Determine if we should continue execution after a SIGTRAP signal when
700 * executing in the given mode.
701 */
Eric Pouechebd01a92000-03-09 18:46:04 +0000702BOOL DEBUG_ShouldContinue( DWORD code, enum exec_mode mode, int * count )
Alexandre Julliardded30381995-07-06 17:18:27 +0000703{
Eric Pouechd33bcb62000-03-15 19:57:20 +0000704 DBG_ADDR addr;
705 int bpnum;
706 DWORD oldval;
707 int wpnum;
Ulrich Weigand1cbf27a2000-06-04 01:33:21 +0000708 int addrlen = 32;
Eric Pouechd33bcb62000-03-15 19:57:20 +0000709 struct symbol_info syminfo;
Alexandre Julliardded30381995-07-06 17:18:27 +0000710
Ulrich Weigandb3ec4b91999-11-13 20:58:45 +0000711#ifdef __i386__
Eric Pouech527eea92000-03-08 16:44:54 +0000712 /* If not single-stepping, back up over the int3 instruction */
Eric Pouechebd01a92000-03-09 18:46:04 +0000713 if (code == EXCEPTION_BREAKPOINT)
Eric Pouech527eea92000-03-08 16:44:54 +0000714 DEBUG_context.Eip--;
Ulrich Weigandb3ec4b91999-11-13 20:58:45 +0000715#endif
Alexandre Julliardded30381995-07-06 17:18:27 +0000716
Ulrich Weigandb3ec4b91999-11-13 20:58:45 +0000717 DEBUG_GetCurrentAddress( &addr );
Eric Pouechd33bcb62000-03-15 19:57:20 +0000718 bpnum = DEBUG_FindBreakpoint( &addr, DBG_BREAK );
Eric Pouech527eea92000-03-08 16:44:54 +0000719 breakpoints[0].enabled = FALSE; /* disable the step-over breakpoint */
Alexandre Julliardded30381995-07-06 17:18:27 +0000720
721 if ((bpnum != 0) && (bpnum != -1))
722 {
Eric Pouechd33bcb62000-03-15 19:57:20 +0000723 if (!DEBUG_ShallBreak(bpnum)) return TRUE;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000724
Eric Poueche5efa0c2000-04-13 19:31:58 +0000725 DEBUG_Printf( DBG_CHN_MESG, "Stopped on breakpoint %d at ", bpnum );
Eric Pouechd33bcb62000-03-15 19:57:20 +0000726 syminfo = DEBUG_PrintAddress( &breakpoints[bpnum].addr,
727 breakpoints[bpnum].is32 ? 32 : 16, TRUE );
Eric Poueche5efa0c2000-04-13 19:31:58 +0000728 DEBUG_Printf( DBG_CHN_MESG, "\n" );
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000729
Eric Pouechd33bcb62000-03-15 19:57:20 +0000730 if( syminfo.list.sourcefile != NULL )
731 DEBUG_List(&syminfo.list, NULL, 0);
Alexandre Julliardded30381995-07-06 17:18:27 +0000732 return FALSE;
733 }
Alexandre Julliardd90840e1996-06-11 16:02:08 +0000734
Eric Pouechd33bcb62000-03-15 19:57:20 +0000735 wpnum = DEBUG_FindTriggeredWatchpoint(&oldval);
736 if ((wpnum != 0) && (wpnum != -1))
737 {
738 /* If not single-stepping, do not back up over the int3 instruction */
739 if (code == EXCEPTION_BREAKPOINT)
740 {
Eric Poueche5efa0c2000-04-13 19:31:58 +0000741#ifdef __i386__
742 DEBUG_context.Eip++;
Eric Pouechd33bcb62000-03-15 19:57:20 +0000743 addr.off++;
Eric Poueche5efa0c2000-04-13 19:31:58 +0000744#endif
Eric Pouechd33bcb62000-03-15 19:57:20 +0000745 }
746 if (!DEBUG_ShallBreak(wpnum)) return TRUE;
747
Ulrich Weigand1cbf27a2000-06-04 01:33:21 +0000748#ifdef __i386__
749 addrlen = !addr.seg? 32 : DEBUG_GetSelectorType( addr.seg );
750#endif
Eric Poueche5efa0c2000-04-13 19:31:58 +0000751 DEBUG_Printf(DBG_CHN_MESG, "Stopped on watchpoint %d at ", wpnum);
Ulrich Weigand1cbf27a2000-06-04 01:33:21 +0000752 syminfo = DEBUG_PrintAddress( &addr, addrlen, TRUE );
Eric Pouechd33bcb62000-03-15 19:57:20 +0000753
Eric Poueche5efa0c2000-04-13 19:31:58 +0000754 DEBUG_Printf(DBG_CHN_MESG, " values: old=%lu new=%lu\n",
Eric Pouechd33bcb62000-03-15 19:57:20 +0000755 oldval, breakpoints[wpnum].u.w.oldval);
756 if (syminfo.list.sourcefile != NULL)
757 DEBUG_List(&syminfo.list, NULL, 0);
758 return FALSE;
759 }
760
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000761 /*
762 * If our mode indicates that we are stepping line numbers,
763 * get the current function, and figure out if we are exactly
764 * on a line number or not.
765 */
Eric Pouech527eea92000-03-08 16:44:54 +0000766 if( mode == EXEC_STEP_OVER || mode == EXEC_STEP_INSTR )
Eric Pouechd33bcb62000-03-15 19:57:20 +0000767 {
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000768 if( DEBUG_CheckLinenoStatus(&addr) == AT_LINENUMBER )
Eric Pouechd33bcb62000-03-15 19:57:20 +0000769 {
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000770 (*count)--;
Eric Pouechd33bcb62000-03-15 19:57:20 +0000771 }
772 }
773 else if( mode == EXEC_STEPI_OVER || mode == EXEC_STEPI_INSTR )
774 {
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000775 (*count)--;
Eric Pouechd33bcb62000-03-15 19:57:20 +0000776 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000777
778 if( *count > 0 || mode == EXEC_FINISH )
Eric Pouechd33bcb62000-03-15 19:57:20 +0000779 {
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000780 /*
781 * We still need to execute more instructions.
782 */
783 return TRUE;
Eric Pouechd33bcb62000-03-15 19:57:20 +0000784 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000785
786 /*
787 * If we are about to stop, then print out the source line if we
788 * have it.
789 */
Eric Pouechd33bcb62000-03-15 19:57:20 +0000790 if (mode != EXEC_CONT && mode != EXEC_PASS && mode != EXEC_FINISH)
791 {
792 DEBUG_FindNearestSymbol( &addr, TRUE, NULL, 0, &syminfo.list);
793 if( syminfo.list.sourcefile != NULL )
794 {
795 DEBUG_List(&syminfo.list, NULL, 0);
796 }
797 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000798
Ulrich Weigandb3ec4b91999-11-13 20:58:45 +0000799#ifdef __i386__
Alexandre Julliardd90840e1996-06-11 16:02:08 +0000800 /* If there's no breakpoint and we are not single-stepping, then we */
801 /* must have encountered an int3 in the Windows program; let's skip it. */
Eric Pouechebd01a92000-03-09 18:46:04 +0000802 if ((bpnum == -1) && code == EXCEPTION_BREAKPOINT)
Eric Pouech527eea92000-03-08 16:44:54 +0000803 DEBUG_context.Eip++;
Ulrich Weigandb3ec4b91999-11-13 20:58:45 +0000804#endif
Alexandre Julliardd90840e1996-06-11 16:02:08 +0000805
Eric Pouech527eea92000-03-08 16:44:54 +0000806 /* no breakpoint, continue if in continuous mode */
Alexandre Julliard410ae4f1999-06-18 18:23:11 +0000807 return (mode == EXEC_CONT || mode == EXEC_PASS || mode == EXEC_FINISH);
Alexandre Julliardded30381995-07-06 17:18:27 +0000808}
809
Eric Pouech527eea92000-03-08 16:44:54 +0000810/***********************************************************************
Eric Poueche5efa0c2000-04-13 19:31:58 +0000811 * DEBUG_SuspendExecution
Eric Pouech527eea92000-03-08 16:44:54 +0000812 *
813 * Remove all breakpoints before entering the debug loop
814 */
815void DEBUG_SuspendExecution( void )
816{
817 DEBUG_SetBreakpoints( FALSE );
818 breakpoints[0] = DEBUG_CurrThread->stepOverBP;
819}
Alexandre Julliardded30381995-07-06 17:18:27 +0000820
821/***********************************************************************
822 * DEBUG_RestartExecution
823 *
824 * Set the breakpoints to the correct state to restart execution
825 * in the given mode.
826 */
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000827enum exec_mode DEBUG_RestartExecution( enum exec_mode mode, int count )
Alexandre Julliardded30381995-07-06 17:18:27 +0000828{
Alexandre Julliard808cb041995-08-17 17:11:36 +0000829 DBG_ADDR addr;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000830 DBG_ADDR addr2;
831 int bp;
832 int delta;
833 int status;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000834 enum exec_mode ret_mode;
Eric Pouech527eea92000-03-08 16:44:54 +0000835 DWORD instr;
836 unsigned char ch;
Alexandre Julliardded30381995-07-06 17:18:27 +0000837
Ulrich Weigandb3ec4b91999-11-13 20:58:45 +0000838 DEBUG_GetCurrentAddress( &addr );
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000839
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000840 /*
841 * This is the mode we will be running in after we finish. We would like
842 * to be able to modify this in certain cases.
843 */
844 ret_mode = mode;
845
Eric Pouechd33bcb62000-03-15 19:57:20 +0000846 bp = DEBUG_FindBreakpoint( &addr, DBG_BREAK );
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000847 if ( bp != -1 && bp != 0)
848 {
849 /*
850 * If we have set a new value, then save it in the BP number.
851 */
852 if( count != 0 && mode == EXEC_CONT )
853 {
854 breakpoints[bp].skipcount = count;
855 }
856 mode = EXEC_STEPI_INSTR; /* If there's a breakpoint, skip it */
857 }
858 else
859 {
860 if( mode == EXEC_CONT && count > 1 )
861 {
Eric Poueche5efa0c2000-04-13 19:31:58 +0000862 DEBUG_Printf(DBG_CHN_MESG, "Not stopped at any breakpoint; argument ignored.\n");
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000863 }
864 }
865
866 if( mode == EXEC_FINISH && DEBUG_IsFctReturn() )
867 {
868 mode = ret_mode = EXEC_STEPI_INSTR;
869 }
870
Eric Pouech527eea92000-03-08 16:44:54 +0000871 instr = DEBUG_ToLinear( &addr );
872 DEBUG_READ_MEM((void*)instr, &ch, sizeof(ch));
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000873 /*
874 * See if the function we are stepping into has debug info
875 * and line numbers. If not, then we step over it instead.
876 * FIXME - we need to check for things like thunks or trampolines,
877 * as the actual function may in fact have debug info.
878 */
Eric Pouech527eea92000-03-08 16:44:54 +0000879 if( ch == 0xe8 )
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000880 {
Eric Pouech527eea92000-03-08 16:44:54 +0000881 DEBUG_READ_MEM((void*)(instr + 1), &delta, sizeof(delta));
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000882 addr2 = addr;
883 DEBUG_Disasm(&addr2, FALSE);
884 addr2.off += delta;
885
886 status = DEBUG_CheckLinenoStatus(&addr2);
887 /*
888 * Anytime we have a trampoline, step over it.
889 */
890 if( ((mode == EXEC_STEP_OVER) || (mode == EXEC_STEPI_OVER))
891 && status == FUNC_IS_TRAMPOLINE )
892 {
893#if 0
Eric Poueche5efa0c2000-04-13 19:31:58 +0000894 DEBUG_Printf(DBG_CHN_MESG, "Not stepping into trampoline at %x (no lines)\n",
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000895 addr2.off);
896#endif
897 mode = EXEC_STEP_OVER_TRAMPOLINE;
898 }
899
900 if( mode == EXEC_STEP_INSTR && status == FUNC_HAS_NO_LINES )
901 {
902#if 0
Eric Poueche5efa0c2000-04-13 19:31:58 +0000903 DEBUG_Printf(DBG_CHN_MESG, "Not stepping into function at %x (no lines)\n",
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000904 addr2.off);
905#endif
906 mode = EXEC_STEP_OVER;
907 }
908 }
909
910
911 if( mode == EXEC_STEP_INSTR )
912 {
913 if( DEBUG_CheckLinenoStatus(&addr) == FUNC_HAS_NO_LINES )
914 {
Eric Poueche5efa0c2000-04-13 19:31:58 +0000915 DEBUG_Printf(DBG_CHN_MESG, "Single stepping until exit from function, \n");
916 DEBUG_Printf(DBG_CHN_MESG, "which has no line number information.\n");
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000917
918 ret_mode = mode = EXEC_FINISH;
919 }
920 }
Alexandre Julliardded30381995-07-06 17:18:27 +0000921
922 switch(mode)
923 {
924 case EXEC_CONT: /* Continuous execution */
Alexandre Julliard410ae4f1999-06-18 18:23:11 +0000925 case EXEC_PASS: /* Continue, passing exception */
Ulrich Weigandb3ec4b91999-11-13 20:58:45 +0000926#ifdef __i386__
Eric Pouech527eea92000-03-08 16:44:54 +0000927 DEBUG_context.EFlags &= ~STEP_FLAG;
Ulrich Weigandb3ec4b91999-11-13 20:58:45 +0000928#endif
Alexandre Julliardded30381995-07-06 17:18:27 +0000929 DEBUG_SetBreakpoints( TRUE );
930 break;
931
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000932 case EXEC_STEP_OVER_TRAMPOLINE:
933 /*
934 * This is the means by which we step over our conversion stubs
935 * in callfrom*.s and callto*.s. We dig the appropriate address
936 * off the stack, and we set the breakpoint there instead of the
937 * address just after the call.
938 */
Ulrich Weigandb3ec4b91999-11-13 20:58:45 +0000939#ifdef __i386__
Eric Pouech527eea92000-03-08 16:44:54 +0000940 DEBUG_READ_MEM((void*)(DEBUG_context.Esp +
941 2 * sizeof(unsigned int)),
942 &addr.off, sizeof(addr.off));
943 DEBUG_context.EFlags &= ~STEP_FLAG;
Ulrich Weigandb3ec4b91999-11-13 20:58:45 +0000944#endif
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000945 breakpoints[0].addr = addr;
946 breakpoints[0].enabled = TRUE;
Eric Pouech527eea92000-03-08 16:44:54 +0000947 breakpoints[0].refcount = 1;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000948 breakpoints[0].skipcount = 0;
Eric Pouechb9717452000-05-05 18:14:34 +0000949 DEBUG_READ_MEM((void*)DEBUG_ToLinear( &addr ), &breakpoints[0].u.b.opcode,
Eric Pouechd33bcb62000-03-15 19:57:20 +0000950 sizeof(char));
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000951 DEBUG_SetBreakpoints( TRUE );
952 break;
953
954 case EXEC_FINISH:
955 case EXEC_STEPI_OVER: /* Stepping over a call */
Alexandre Julliardded30381995-07-06 17:18:27 +0000956 case EXEC_STEP_OVER: /* Stepping over a call */
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000957 if (DEBUG_IsStepOverInstr())
Alexandre Julliardb7258be1995-09-01 15:57:28 +0000958 {
Ulrich Weigandb3ec4b91999-11-13 20:58:45 +0000959#ifdef __i386__
Eric Pouech527eea92000-03-08 16:44:54 +0000960 DEBUG_context.EFlags &= ~STEP_FLAG;
Ulrich Weigandb3ec4b91999-11-13 20:58:45 +0000961#endif
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000962 DEBUG_Disasm(&addr, FALSE);
Alexandre Julliardb7258be1995-09-01 15:57:28 +0000963 breakpoints[0].addr = addr;
964 breakpoints[0].enabled = TRUE;
Eric Pouech527eea92000-03-08 16:44:54 +0000965 breakpoints[0].refcount = 1;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000966 breakpoints[0].skipcount = 0;
Eric Pouechb9717452000-05-05 18:14:34 +0000967 DEBUG_READ_MEM((void*)DEBUG_ToLinear( &addr ), &breakpoints[0].u.b.opcode,
Eric Pouechd33bcb62000-03-15 19:57:20 +0000968 sizeof(char));
Alexandre Julliardb7258be1995-09-01 15:57:28 +0000969 DEBUG_SetBreakpoints( TRUE );
970 break;
971 }
972 /* else fall through to single-stepping */
Alexandre Julliardded30381995-07-06 17:18:27 +0000973
974 case EXEC_STEP_INSTR: /* Single-stepping an instruction */
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000975 case EXEC_STEPI_INSTR: /* Single-stepping an instruction */
Ulrich Weigandb3ec4b91999-11-13 20:58:45 +0000976#ifdef __i386__
Eric Pouech527eea92000-03-08 16:44:54 +0000977 DEBUG_context.EFlags |= STEP_FLAG;
Ulrich Weigandb3ec4b91999-11-13 20:58:45 +0000978#endif
Alexandre Julliardded30381995-07-06 17:18:27 +0000979 break;
Eric Pouechd33bcb62000-03-15 19:57:20 +0000980 default:
981 RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
Alexandre Julliardded30381995-07-06 17:18:27 +0000982 }
Eric Pouech527eea92000-03-08 16:44:54 +0000983 DEBUG_CurrThread->stepOverBP = breakpoints[0];
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000984 return ret_mode;
985}
986
987int
988DEBUG_AddBPCondition(int num, struct expr * exp)
989{
Eric Pouech527eea92000-03-08 16:44:54 +0000990 if ((num <= 0) || (num >= next_bp) || !breakpoints[num].refcount)
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000991 {
Eric Poueche5efa0c2000-04-13 19:31:58 +0000992 DEBUG_Printf( DBG_CHN_MESG, "Invalid breakpoint number %d\n", num );
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000993 return FALSE;
994 }
995
996 if( breakpoints[num].condition != NULL )
997 {
998 DEBUG_FreeExpr(breakpoints[num].condition);
999 breakpoints[num].condition = NULL;
1000 }
1001
1002 if( exp != NULL )
1003 {
1004 breakpoints[num].condition = DEBUG_CloneExpr(exp);
1005 }
1006
1007 return TRUE;
Alexandre Julliard234bc241994-12-10 13:02:28 +00001008}