... |
... |
@@ -25,6 +25,13 @@ |
25
|
25
|
|
26
|
26
|
unsigned long fast_random_state = 1;
|
27
|
27
|
|
|
28
|
+/*
|
|
29
|
+ * Set to positive value to enabled debug prints related to the sigill
|
|
30
|
+ * and sigtrap handlers. Also enables prints related to handling of
|
|
31
|
+ * breakpoints.
|
|
32
|
+ */
|
|
33
|
+unsigned int debug_handlers = 0;
|
|
34
|
+
|
28
|
35
|
#if defined(SOLARIS)
|
29
|
36
|
/*
|
30
|
37
|
* Use the /dev/cpu/self/cpuid interface on Solaris. We could use the
|
... |
... |
@@ -140,7 +147,8 @@ arch_skip_instruction(os_context_t * context) |
140
|
147
|
{
|
141
|
148
|
int vlen, code;
|
142
|
149
|
|
143
|
|
- DPRINTF(1, (stderr, "[arch_skip_inst at %lx>]\n", SC_PC(context)));
|
|
150
|
+ DPRINTF(debug_handlers,
|
|
151
|
+ (stderr, "[arch_skip_inst at %lx>]\n", SC_PC(context)));
|
144
|
152
|
|
145
|
153
|
/* Get and skip the lisp error code. */
|
146
|
154
|
char* pc = (char *) SC_PC(context);
|
... |
... |
@@ -178,7 +186,8 @@ arch_skip_instruction(os_context_t * context) |
178
|
186
|
break;
|
179
|
187
|
}
|
180
|
188
|
|
181
|
|
- DPRINTF(0, (stderr, "[arch_skip_inst resuming at %lx>]\n", SC_PC(context)));
|
|
189
|
+ DPRINTF(debug_handlers,
|
|
190
|
+ (stderr, "[arch_skip_inst resuming at %lx>]\n", SC_PC(context)));
|
182
|
191
|
}
|
183
|
192
|
|
184
|
193
|
unsigned char *
|
... |
... |
@@ -207,28 +216,20 @@ arch_install_breakpoint(void *pc) |
207
|
216
|
unsigned char* ptr = (unsigned char *) pc;
|
208
|
217
|
unsigned long result = ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
|
209
|
218
|
|
210
|
|
- fprintf(stderr, "arch_install_breakpoint at %p, old code = 0x%lx\n",
|
211
|
|
- pc, result);
|
212
|
|
-
|
213
|
|
-#if 1
|
214
|
|
- *(char *) pc = BREAKPOINT_INST; /* x86 INT3 */
|
215
|
|
-#if 0
|
216
|
|
- *((char *) pc + 1) = trap_Breakpoint; /* Lisp trap code */
|
217
|
|
-#endif
|
218
|
|
-#else
|
219
|
|
- *ptr++ = 0x0f; /* UD2 */
|
220
|
|
- *ptr++ = 0x0b;
|
221
|
|
- *ptr++ = trap_Breakpoint; /* Lisp trap code */
|
222
|
|
-#endif
|
|
219
|
+ DPRINTF(debug_handlers,
|
|
220
|
+ (stderr, "arch_install_breakpoint at %p, old code = 0x%lx\n",
|
|
221
|
+ pc, result));
|
223
|
222
|
|
|
223
|
+ *(char *) pc = BREAKPOINT_INST; /* x86 INT3 */
|
224
|
224
|
return result;
|
225
|
225
|
}
|
226
|
226
|
|
227
|
227
|
void
|
228
|
228
|
arch_remove_breakpoint(void *pc, unsigned long orig_inst)
|
229
|
229
|
{
|
230
|
|
- fprintf(stderr, "arch_remove_breakpoint: %p orig %lx\n",
|
231
|
|
- pc, orig_inst);
|
|
230
|
+ DPRINTF(debug_handlers,
|
|
231
|
+ (stderr, "arch_remove_breakpoint: %p orig %lx\n",
|
|
232
|
+ pc, orig_inst));
|
232
|
233
|
unsigned char *ptr = (unsigned char *) pc;
|
233
|
234
|
ptr[0] = orig_inst & 0xff;
|
234
|
235
|
ptr[1] = (orig_inst >> 8) & 0xff;
|
... |
... |
@@ -256,23 +257,15 @@ arch_do_displaced_inst(os_context_t * context, unsigned long orig_inst) |
256
|
257
|
{
|
257
|
258
|
unsigned char *pc = (unsigned char *) SC_PC(context);
|
258
|
259
|
|
259
|
|
- fprintf(stderr, "arch_do_displaced_inst: pc %p orig_inst %lx\n",
|
260
|
|
- pc, orig_inst);
|
|
260
|
+ DPRINTF(debug_handlers,
|
|
261
|
+ (stderr, "arch_do_displaced_inst: pc %p orig_inst %lx\n",
|
|
262
|
+ pc, orig_inst));
|
261
|
263
|
|
262
|
264
|
/*
|
263
|
265
|
* Put the original instruction back.
|
264
|
266
|
*/
|
265
|
267
|
|
266
|
|
-#if 1
|
267
|
268
|
*((char *) pc) = orig_inst & 0xff;
|
268
|
|
-#if 0
|
269
|
|
- *((char *) pc + 1) = (orig_inst & 0xff00) >> 8;
|
270
|
|
-#endif
|
271
|
|
-#else
|
272
|
|
- pc[0] = orig_inst & 0xff;
|
273
|
|
- pc[1] = (orig_inst >> 8) & 0xff;
|
274
|
|
- pc[2] = (orig_inst >> 16) & 0xff;
|
275
|
|
-#endif
|
276
|
269
|
|
277
|
270
|
#ifdef SC_EFLAGS
|
278
|
271
|
/* Enable single-stepping */
|
... |
... |
@@ -317,71 +310,25 @@ sigill_handler(HANDLER_ARGS) |
317
|
310
|
{
|
318
|
311
|
unsigned int trap;
|
319
|
312
|
os_context_t* os_context = (os_context_t *) context;
|
320
|
|
-#if 1
|
321
|
|
-#if 0
|
322
|
|
- fprintf(stderr, "x86sigtrap: %8x %x\n",
|
323
|
|
- SC_PC(os_os_context), *(unsigned char *) (SC_PC(os_context) - 1));
|
324
|
|
-#else
|
325
|
|
- fprintf(stderr,"x86sigill: fp=%lx sp=%lx pc=%lx { %x, %x, %x, %x, %x }\n",
|
326
|
|
- SC_REG(context, reg_FP),
|
327
|
|
- SC_REG(context, reg_SP),
|
328
|
|
- SC_PC(context),
|
329
|
|
- *(unsigned char*)(SC_PC(context) + 0), /* 0x0F */
|
330
|
|
- *(unsigned char*)(SC_PC(context) + 1), /* 0x0B */
|
331
|
|
- *(unsigned char*)(SC_PC(context) + 2),
|
332
|
|
- *(unsigned char*)(SC_PC(context) + 3),
|
333
|
|
- *(unsigned char*)(SC_PC(context) + 4));
|
334
|
|
-#endif
|
335
|
|
- fprintf(stderr, "sigtrap(%d %d %p)\n", signal, CODE(code), os_context);
|
336
|
|
-#endif
|
337
|
313
|
|
338
|
|
-#if 0
|
339
|
|
- if (single_stepping && (signal == SIGTRAP)) {
|
340
|
|
-#if 1
|
341
|
|
- fprintf(stderr, "* Single step trap %p\n", single_stepping);
|
342
|
|
-#endif
|
343
|
|
-
|
344
|
|
-#ifdef SC_EFLAGS
|
345
|
|
- /* Disable single-stepping */
|
346
|
|
- SC_EFLAGS(os_context) ^= 0x100;
|
347
|
|
-#else
|
348
|
|
- /* Un-install single step helper instructions. */
|
349
|
|
- *(single_stepping - 3) = single_step_save1;
|
350
|
|
- *(single_stepping - 2) = single_step_save2;
|
351
|
|
- *(single_stepping - 1) = single_step_save3;
|
352
|
|
- DPRINTF(0, (stderr, "Uninstalling helper instructions\n"));
|
353
|
|
-#endif
|
354
|
|
-
|
355
|
|
- /*
|
356
|
|
- * Re-install the breakpoint if possible.
|
357
|
|
- */
|
358
|
|
- fprintf(stderr, "* Maybe reinstall breakpoint for pc %p with single_stepping %p\n",
|
359
|
|
- (void*) SC_PC(os_context), single_stepping);
|
360
|
|
-
|
361
|
|
- if ((int) SC_PC(os_context) < (int) single_stepping + 3)
|
362
|
|
- fprintf(stderr, "* Breakpoint not re-install\n");
|
363
|
|
- else {
|
364
|
|
- char *ptr = (char *) single_stepping;
|
365
|
|
-
|
366
|
|
-#if 0
|
367
|
|
- ptr[0] = BREAKPOINT_INST; /* x86 INT3 */
|
368
|
|
- ptr[1] = trap_Breakpoint;
|
369
|
|
-#else
|
370
|
|
- ptr[0] = 0x0f;
|
371
|
|
- ptr[1] = 0x0b;
|
372
|
|
- ptr[2] = trap_Breakpoint;
|
373
|
|
-#endif
|
374
|
|
- }
|
375
|
|
-
|
376
|
|
- single_stepping = NULL;
|
377
|
|
- return;
|
|
314
|
+ DPRINTF(debug_handlers,
|
|
315
|
+ (stderr,"sigill: fp=%lx sp=%lx pc=%lx { %x, %x, %x, %x, %x }\n",
|
|
316
|
+ SC_REG(context, reg_FP),
|
|
317
|
+ SC_REG(context, reg_SP),
|
|
318
|
+ SC_PC(context),
|
|
319
|
+ *((unsigned char*)SC_PC(context) + 0), /* 0x0F */
|
|
320
|
+ *((unsigned char*)SC_PC(context) + 1), /* 0x0B */
|
|
321
|
+ *((unsigned char*)SC_PC(context) + 2),
|
|
322
|
+ *((unsigned char*)SC_PC(context) + 3),
|
|
323
|
+ *((unsigned char*)SC_PC(context) + 4)));
|
|
324
|
+
|
|
325
|
+ if (single_stepping) {
|
|
326
|
+ lose("sigill handler with single-stepping enabled?\n");
|
378
|
327
|
}
|
379
|
|
-#endif
|
380
|
328
|
|
381
|
329
|
/* This is just for info in case monitor wants to print an approx */
|
382
|
330
|
current_control_stack_pointer = (unsigned long *) SC_SP(os_context);
|
383
|
331
|
|
384
|
|
-
|
385
|
332
|
/*
|
386
|
333
|
* In many places in the switch below, we eventually throw instead
|
387
|
334
|
* of returning from the signal handler. So, just in case, set
|
... |
... |
@@ -396,22 +343,20 @@ sigill_handler(HANDLER_ARGS) |
396
|
343
|
* arguments to follow.
|
397
|
344
|
*/
|
398
|
345
|
|
399
|
|
-#if 1
|
400
|
|
- fprintf(stderr, "pc %x\n", *(unsigned short *)SC_PC(context));
|
401
|
|
-#endif
|
|
346
|
+ DPRINTF(debug_handlers,
|
|
347
|
+ (stderr, "pc %x\n", *(unsigned short *)SC_PC(context)));
|
|
348
|
+
|
402
|
349
|
if (*(unsigned short *) SC_PC(context) == 0x0b0f) {
|
403
|
350
|
trap = *(((char *)SC_PC(context)) + 2);
|
404
|
351
|
} else {
|
405
|
352
|
abort();
|
406
|
353
|
}
|
407
|
354
|
|
408
|
|
-#if 1
|
409
|
|
- fprintf(stderr, "code = %x\n", trap);
|
410
|
|
-#endif
|
|
355
|
+ DPRINTF(debug_handlers, (stderr, "code = %x\n", trap));
|
411
|
356
|
|
412
|
357
|
switch (trap) {
|
413
|
358
|
case trap_PendingInterrupt:
|
414
|
|
- DPRINTF(1, (stderr, "<trap Pending Interrupt.>\n"));
|
|
359
|
+ DPRINTF(debug_handlers, (stderr, "<trap Pending Interrupt.>\n"));
|
415
|
360
|
arch_skip_instruction(os_context);
|
416
|
361
|
interrupt_handle_pending(os_context);
|
417
|
362
|
break;
|
... |
... |
@@ -432,28 +377,15 @@ sigill_handler(HANDLER_ARGS) |
432
|
377
|
|
433
|
378
|
case trap_Error:
|
434
|
379
|
case trap_Cerror:
|
435
|
|
- DPRINTF(1, (stderr, "<trap Error %x>\n", CODE(code)));
|
|
380
|
+ DPRINTF(debug_handlers, (stderr, "<trap Error %x>\n", CODE(code)));
|
436
|
381
|
interrupt_internal_error(signal, code, os_context, CODE(code) == trap_Cerror);
|
437
|
382
|
break;
|
438
|
383
|
|
439
|
384
|
case trap_Breakpoint:
|
440
|
|
-#if 1
|
441
|
|
- fprintf(stderr, "*C break\n");
|
442
|
|
-#endif
|
443
|
|
-#if 0
|
444
|
|
- SC_PC(os_context) -= 1;
|
445
|
|
-#endif
|
446
|
|
-
|
447
|
|
- handle_breakpoint(signal, CODE(code), os_context);
|
448
|
|
-#if 1
|
449
|
|
- fprintf(stderr, "*C break return\n");
|
450
|
|
-#endif
|
|
385
|
+ lose("Unexpected breakpoint trap in sigill-hander.\n");
|
451
|
386
|
break;
|
452
|
387
|
|
453
|
388
|
case trap_FunctionEndBreakpoint:
|
454
|
|
-#if 0
|
455
|
|
- SC_PC(os_context) -= 1;
|
456
|
|
-#endif
|
457
|
389
|
SC_PC(os_context) =
|
458
|
390
|
(int) handle_function_end_breakpoint(signal, CODE(code), os_context);
|
459
|
391
|
break;
|
... |
... |
@@ -473,7 +405,7 @@ sigill_handler(HANDLER_ARGS) |
473
|
405
|
break;
|
474
|
406
|
#endif
|
475
|
407
|
default:
|
476
|
|
- DPRINTF(1,
|
|
408
|
+ DPRINTF(debug_handlers,
|
477
|
409
|
(stderr, "[C--trap default %d %d %p]\n", signal, CODE(code),
|
478
|
410
|
os_context));
|
479
|
411
|
interrupt_handle_now(signal, code, os_context);
|
... |
... |
@@ -486,21 +418,19 @@ sigtrap_handler(HANDLER_ARGS) |
486
|
418
|
{
|
487
|
419
|
os_context_t* os_context = (os_context_t *) context;
|
488
|
420
|
|
489
|
|
-#if 1
|
490
|
|
- fprintf(stderr,"sigtrap: fp=%lx sp=%lx pc=%lx { %x, %x, %x, %x, %x }\n",
|
491
|
|
- SC_REG(context, reg_FP),
|
492
|
|
- SC_REG(context, reg_SP),
|
493
|
|
- SC_PC(context),
|
494
|
|
- *(unsigned char*)(SC_PC(context) + 0), /* 0x0F */
|
495
|
|
- *(unsigned char*)(SC_PC(context) + 1), /* 0x0B */
|
496
|
|
- *(unsigned char*)(SC_PC(context) + 2),
|
497
|
|
- *(unsigned char*)(SC_PC(context) + 3),
|
498
|
|
- *(unsigned char*)(SC_PC(context) + 4));
|
499
|
|
-#endif
|
|
421
|
+ DPRINTF(debug_handlers,
|
|
422
|
+ (stderr,"sigtrap: fp=%lx sp=%lx pc=%lx { %x, %x, %x, %x, %x }\n",
|
|
423
|
+ SC_REG(context, reg_FP),
|
|
424
|
+ SC_REG(context, reg_SP),
|
|
425
|
+ SC_PC(context),
|
|
426
|
+ *((unsigned char*)SC_PC(context) + 0), /* 0x0F */
|
|
427
|
+ *((unsigned char*)SC_PC(context) + 1), /* 0x0B */
|
|
428
|
+ *((unsigned char*)SC_PC(context) + 2),
|
|
429
|
+ *((unsigned char*)SC_PC(context) + 3),
|
|
430
|
+ *(unsigned char*)(SC_PC(context) + 4)));
|
|
431
|
+
|
500
|
432
|
if (single_stepping && (signal == SIGTRAP)) {
|
501
|
|
-#if 1
|
502
|
|
- fprintf(stderr, "* Single step trap %p\n", single_stepping);
|
503
|
|
-#endif
|
|
433
|
+ DPRINTF(debug_handlers, (stderr, "* Single step trap %p\n", single_stepping));
|
504
|
434
|
|
505
|
435
|
#ifdef SC_EFLAGS
|
506
|
436
|
/* Disable single-stepping */
|
... |
... |
@@ -516,38 +446,29 @@ sigtrap_handler(HANDLER_ARGS) |
516
|
446
|
/*
|
517
|
447
|
* Re-install the breakpoint if possible.
|
518
|
448
|
*/
|
519
|
|
- fprintf(stderr, "* Maybe reinstall breakpoint for pc %p with single_stepping %p\n",
|
520
|
|
- (void*) SC_PC(os_context), single_stepping);
|
|
449
|
+ DPRINTF(debug_handlers,
|
|
450
|
+ (stderr, "* Maybe reinstall breakpoint for pc %p with single_stepping %p\n",
|
|
451
|
+ (void*) SC_PC(os_context), single_stepping));
|
521
|
452
|
|
522
|
453
|
if ((unsigned long) SC_PC(os_context) <= (unsigned long) single_stepping)
|
523
|
454
|
fprintf(stderr, "* Breakpoint not re-install\n");
|
524
|
455
|
else {
|
525
|
456
|
char *ptr = (char *) single_stepping;
|
526
|
457
|
|
527
|
|
-#if 0
|
528
|
458
|
ptr[0] = BREAKPOINT_INST; /* x86 INT3 */
|
529
|
|
- ptr[1] = trap_Breakpoint;
|
530
|
|
-#else
|
531
|
|
- ptr[0] = 0x0f;
|
532
|
|
- ptr[1] = 0x0b;
|
533
|
|
- ptr[2] = trap_Breakpoint;
|
534
|
|
-#endif
|
535
|
459
|
}
|
536
|
460
|
|
537
|
461
|
single_stepping = NULL;
|
538
|
462
|
return;
|
539
|
463
|
}
|
540
|
|
-#if 1
|
541
|
|
- fprintf(stderr, "*C break\n");
|
542
|
|
-#endif
|
543
|
|
-#if 1
|
544
|
|
- SC_PC(os_context) -= 1;
|
545
|
|
-#endif
|
546
|
464
|
|
547
|
|
- handle_breakpoint(signal, CODE(code), os_context);
|
548
|
|
-#if 1
|
549
|
|
- fprintf(stderr, "*C break return\n");
|
550
|
|
-#endif
|
|
465
|
+ DPRINTF(debug_handlers, (stderr, "*C break\n"));
|
|
466
|
+
|
|
467
|
+ SC_PC(os_context) -= 1;
|
|
468
|
+
|
|
469
|
+ handle_breakpoint(signal, CODE(code), os_context);
|
|
470
|
+
|
|
471
|
+ DPRINTF(debug_handlers, (stderr, "*C break return\n"));
|
551
|
472
|
}
|
552
|
473
|
|
553
|
474
|
|