Raymond Toy pushed to branch issue-97-define-ud2-inst at cmucl / cmucl
Commits: 16043a5b by Raymond Toy at 2021-03-21T14:58:19-07:00 Add debugging prints
Add some prints to handle-breakpoints so we can see what lisp thinks is the breakpoint.
Add some prints to compute_offset and handle_breakpoint so we can see what C thinks is happening with breakpoints.
- - - - - 7a5a1513 by Raymond Toy at 2021-03-21T15:02:05-07:00 Add prints and fix issue with breakpoint offset off by one.
When handling the breakpoint in `sigill_handler`, we were decrementing the pc by one. I guess that was for the old INT3 where the pc would be at the next instruction. With UD2, the pc is at the beginning of the UD2 instruction.
With this change, setting breakpoints appear to work: ``` (break) bp :start :function #'kernel:%srqt 0 (kernel:%sqrt 2d0) *Breakpoint hit* [Condition of type SIMPLE-CONDITION]
Restarts: 0: [CONTINUE] Return from BREAK. 1: [ABORT ] Return to Top-Level.
Debug (type H for help)
(KERNEL:%SQRT 2.0d0) ```
Add some prints so we can see what's happening.
But removing breakpoints isn't working.
- - - - -
3 changed files:
- src/code/debug-int.lisp - src/lisp/breakpoint.c - src/lisp/x86-arch.c
Changes:
===================================== src/code/debug-int.lisp ===================================== @@ -4477,6 +4477,9 @@ The result is a symbol or nil if the routine cannot be found." ;;; (defun handle-breakpoint (offset component signal-context) (let ((data (breakpoint-data component offset nil))) + (format t "(handle-breakpoint ~A ~A ~A)~%" + offset component signal-context) + (format t " data = ~A~%" data) (unless data (error (intl:gettext "Unknown breakpoint in ~S at offset ~S.") (debug-function-name (debug-function-from-pc component offset))
===================================== src/lisp/breakpoint.c ===================================== @@ -192,6 +192,8 @@ compute_offset(os_context_t * scp, lispobj code, boolean function_end) static int compute_offset(os_context_t * scp, lispobj code, boolean function_end) { + fprintf(stderr, "compute_offset: code = 0x%lx\n", code); + if (code == NIL) return 0; else { @@ -206,11 +208,18 @@ compute_offset(os_context_t * scp, lispobj code, boolean function_end)
code_start = (unsigned long) codeptr + HeaderValue(codeptr->header) * sizeof(lispobj); + + fprintf(stderr, "compute_offset: pc = 0x%lx, code_start = 0x%lx\n", + pc, code_start); + if (pc < code_start) return 0; else { int offset = pc - code_start;
+ fprintf(stderr, "compute_offset: offset %d, size = %ld\n", + offset, codeptr->code_size); + if (offset >= codeptr->code_size) { return 0; } else { @@ -250,6 +259,11 @@ handle_breakpoint(int signal, int subcode, os_context_t * scp)
code = find_code(scp);
+#if 1 + fprintf(stderr, "handle_breakpoint\n"); + fprintf(stderr, " offset = %d\n", compute_offset(scp, code, 0)); +#endif + /* * Don't disallow recursive breakpoint traps. Otherwise, we can't * use debugger breakpoints anywhere in here.
===================================== src/lisp/x86-arch.c ===================================== @@ -209,6 +209,9 @@ arch_install_breakpoint(void *pc) char* ptr = (char *) pc; unsigned long result = *(unsigned long *) pc;
+ fprintf(stderr, "arch_install_breakpoint at %p, old code = 0x%lx\n", + pc, result); + #if 0 *(char *) pc = BREAKPOINT_INST; /* x86 INT3 */ *((char *) pc + 1) = trap_Breakpoint; /* Lisp trap code */ @@ -216,8 +219,6 @@ arch_install_breakpoint(void *pc) *ptr++ = 0x0f; /* UD2 */ *ptr++ = 0x0b; *ptr++ = trap_Breakpoint; /* Lisp trap code */ - *ptr++ = 1; /* Vector length */ - *ptr++ = 0; /* Junk data */ #endif
return result; @@ -300,7 +301,7 @@ sigill_handler(HANDLER_ARGS) { unsigned int trap; os_context_t* os_context = (os_context_t *) context; -#if 0 +#if 1 #if 0 fprintf(stderr, "x86sigtrap: %8x %x\n", SC_PC(os_os_context), *(unsigned char *) (SC_PC(os_context) - 1)); @@ -374,7 +375,7 @@ sigill_handler(HANDLER_ARGS) * arguments to follow. */
-#if 0 +#if 1 fprintf(stderr, "pc %x\n", *(unsigned short *)SC_PC(context)); #endif if (*(unsigned short *) SC_PC(context) == 0x0b0f) { @@ -383,7 +384,7 @@ sigill_handler(HANDLER_ARGS) abort(); }
-#if 0 +#if 1 fprintf(stderr, "code = %x\n", trap); #endif
@@ -415,19 +416,23 @@ sigill_handler(HANDLER_ARGS) break;
case trap_Breakpoint: -#if 0 +#if 1 fprintf(stderr, "*C break\n"); #endif +#if 0 SC_PC(os_context) -= 1; +#endif
handle_breakpoint(signal, CODE(code), os_context); -#if 0 +#if 1 fprintf(stderr, "*C break return\n"); #endif break;
case trap_FunctionEndBreakpoint: +#if 0 SC_PC(os_context) -= 1; +#endif SC_PC(os_context) = (int) handle_function_end_breakpoint(signal, CODE(code), os_context); break;
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/d9cbe149b97772150b8d035...