Raymond Toy pushed to branch issue-97-define-ud2-inst at cmucl / cmucl
Commits:
07da205f by Raymond Toy at 2021-03-28T08:02:04-07:00
Remove debugging prints
- - - - -
a99cd825 by Raymond Toy at 2021-03-28T08:02:24-07:00
Clean up and add comments on how things work.
- - - - -
4 changed files:
- src/code/debug-int.lisp
- src/lisp/breakpoint.c
- src/lisp/x86-arch.c
- src/lisp/x86-arch.h
Changes:
=====================================
src/code/debug-int.lisp
=====================================
@@ -4477,9 +4477,6 @@ 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,8 +192,6 @@ compute_offset(os_context_t * scp, lispobj code, boolean function_end)
static int
compute_offset(os_context_t * scp, lispobj code, boolean function_end)
{
- extern unsigned int debug_handlers;
-
DPRINTF(debug_handlers, (stderr, "compute_offset: code = 0x%lx\n", code));
if (code == NIL)
@@ -257,8 +255,6 @@ handle_breakpoint(int signal, int subcode, os_context_t * scp)
void
handle_breakpoint(int signal, int subcode, os_context_t * scp)
{
- extern unsigned int debug_handlers;
-
lispobj code, scp_sap = alloc_sap(scp);
fake_foreign_function_call(scp);
=====================================
src/lisp/x86-arch.c
=====================================
@@ -153,7 +153,8 @@ arch_skip_instruction(os_context_t * context)
/* Get and skip the lisp error code. */
char* pc = (char *) SC_PC(context);
- pc += 2; /* skip 0x0f and 0x0b */
+ /* Skip over the UD2 inst (0x0f, 0x0b) */
+ pc += 2;
code = *pc++;
SC_PC(context) = (unsigned long) pc;
@@ -173,6 +174,8 @@ arch_skip_instruction(os_context_t * context)
break;
case trap_Breakpoint:
+ lose("Unexpected breakpoint trap in arch_skip_instruction\n");
+ break;
case trap_FunctionEndBreakpoint:
break;
@@ -231,6 +234,11 @@ arch_remove_breakpoint(void *pc, unsigned long orig_inst)
(stderr, "arch_remove_breakpoint: %p orig %lx\n",
pc, orig_inst));
unsigned char *ptr = (unsigned char *) pc;
+ /*
+ * Just restore all the bytes from orig_inst. Should we just
+ * re-install just the one byte that was taken by the int3
+ * instruction?
+ */
ptr[0] = orig_inst & 0xff;
ptr[1] = (orig_inst >> 8) & 0xff;
ptr[2] = (orig_inst >> 16) & 0xff;
@@ -267,8 +275,12 @@ arch_do_displaced_inst(os_context_t * context, unsigned long orig_inst)
*((char *) pc) = orig_inst & 0xff;
+ /*
+ * If we have the SC_EFLAGS macro, we can enable single-stepping
+ * by setting the bit. Otherwise, we need a more complicated way
+ * of enabling single-stepping.
+ */
#ifdef SC_EFLAGS
- /* Enable single-stepping */
SC_EFLAGS(context) |= 0x100;
#else
@@ -305,6 +317,11 @@ arch_do_displaced_inst(os_context_t * context, unsigned long orig_inst)
}
+/*
+ * Handles the break instruction from lisp, which is now UD2 followed
+ * by the trap code. In particular, this does not handle the
+ * breakpoint traps.
+ */
void
sigill_handler(HANDLER_ARGS)
{
@@ -322,9 +339,6 @@ sigill_handler(HANDLER_ARGS)
*((unsigned char*)SC_PC(context) + 3),
*((unsigned char*)SC_PC(context) + 4)));
- if (single_stepping) {
- lose("sigill handler with single-stepping enabled?\n");
- }
/* This is just for info in case monitor wants to print an approx */
current_control_stack_pointer = (unsigned long *) SC_SP(os_context);
@@ -346,6 +360,14 @@ sigill_handler(HANDLER_ARGS)
DPRINTF(debug_handlers,
(stderr, "pc %x\n", *(unsigned short *)SC_PC(context)));
+ /*
+ * Make sure the trapping instruction is UD2. Abort if not.
+ *
+ * TODO: aborting is probably not the best idea. Could get here
+ * from other illegal instructions in, say, C code? Maybe we
+ * should call interrupt_handle_now, as we do below for an unknown
+ * trap code?
+ */
if (*(unsigned short *) SC_PC(context) == 0x0b0f) {
trap = *(((char *)SC_PC(context)) + 2);
} else {
@@ -413,6 +435,9 @@ sigill_handler(HANDLER_ARGS)
}
}
+/*
+ * Handles the breakpoint trap (int3) and also single-stepping
+ */
void
sigtrap_handler(HANDLER_ARGS)
{
@@ -464,6 +489,13 @@ sigtrap_handler(HANDLER_ARGS)
DPRINTF(debug_handlers, (stderr, "*C break\n"));
+ /*
+ * The int3 instruction causes a trap that leaves us just after
+ * the instruction. Backup one so we're at the beginning. This
+ * is really important so that when we handle the breakpoint, the
+ * offset of the instruction matches where Lisp thinks the
+ * breakpoint was placed.
+ */
SC_PC(os_context) -= 1;
handle_breakpoint(signal, CODE(code), os_context);
=====================================
src/lisp/x86-arch.h
=====================================
@@ -9,6 +9,13 @@
extern int arch_support_sse2(void);
extern boolean os_support_sse2(void);
+/*
+ * Set to non-zero to enable debug prints for debugging the sigill and
+ * sigtrap handlers and for debugging breakpoints.
+ */
+extern unsigned int debug_handlers;
+
+
/*
* Define macro to allocate a local array of the appropriate size
* where the fpu state can be stored.
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/d039eb90c6e86457c946c9…
--
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/d039eb90c6e86457c946c9…
You're receiving this email because of your account on gitlab.common-lisp.net.
Raymond Toy pushed to branch master at cmucl / cmucl
Commits:
1b27941a by Raymond Toy at 2021-03-22T20:00:49-07:00
Fix up headings for issue templates
The headings used to be `**foo**`, but it's better to use `## foo`.
The old headings would cause the following paragraph to be appended to
the heading. Thus
```
## foo
Text
```
became
```
foo Text
```
with "foo" in bold.
With the new markup, this doesn't happen.
- - - - -
5c92c14c by Raymond Toy at 2021-03-23T03:34:19+00:00
Merge branch 'fixup-template-headings' into 'master'
Fix up headings for issue templates
See merge request cmucl/cmucl!73
- - - - -
2 changed files:
- .gitlab/issue_templates/Bug.md
- .gitlab/issue_templates/Feature.md
Changes:
=====================================
.gitlab/issue_templates/Bug.md
=====================================
@@ -1,24 +1,24 @@
-**Describe the bug**
+## Describe the bug
A clear and concise description of what the bug is.
-**To Reproduce**
+## To Reproduce
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
-**Expected behavior**
+## Expected behavior
A clear and concise description of what you expected to happen.
-**Screenshots**
+## Screenshots
If applicable, add screenshots to help explain your problem.
-**Desktop (please complete the following information):**
+## Desktop (please complete the following information):
- OS: [e.g. Linux]
- Version [e.g. 21c]
-**Additional context**
+## Additional context
Add any other context about the problem here.
/label ~bug
=====================================
.gitlab/issue_templates/Feature.md
=====================================
@@ -1,10 +1,10 @@
-**Describe the feature**
+## Describe the feature
Briefly describe the feature you would like see.
-**Is there a prototype?**
+## Is there a prototype?
If you have a prototype, provide links to illustrate this addition. This is the best way to propose a new feature.
-**Describe the feature in more detail**
+## Describe the feature in more detail
Provide more information to describe the feature.
/label ~feature
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/9b1abca53598f03a5b39de…
--
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/9b1abca53598f03a5b39de…
You're receiving this email because of your account on gitlab.common-lisp.net.
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/d9cbe149b97772150b8d03…
--
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/d9cbe149b97772150b8d03…
You're receiving this email because of your account on gitlab.common-lisp.net.
Raymond Toy pushed to branch issue-97-define-ud2-inst at cmucl / cmucl
Commits:
73e864e8 by Raymond Toy at 2021-03-20T09:09:29-07:00
Fix disassembly of break inst
The code field for the break instruction had the wrong byte position.
It was (byte 8 8), but it should be (byte 8 16).
`(disassemble 'lisp::halt)` works now.
- - - - -
1 changed file:
- src/compiler/x86/insts.lisp
Changes:
=====================================
src/compiler/x86/insts.lisp
=====================================
@@ -2064,7 +2064,7 @@
(disassem:define-instruction-format (break 24 :default-printer '(:name :tab code))
(op :fields (list (byte 8 0) (byte 8 8)) :value '(#xb00001111 #b00001011))
- (code :field (byte 8 8)))
+ (code :field (byte 8 16)))
(define-emitter emit-break-inst 24
(byte 8 0) (byte 8 8) (byte 8 16))
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/73e864e8ddcef408af202f9…
--
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/73e864e8ddcef408af202f9…
You're receiving this email because of your account on gitlab.common-lisp.net.