From d6facc341a1bacd838ffed0e28e8b4e012c1bb02 Mon Sep 17 00:00:00 2001
From: wlott <wlott>
Date: Wed, 29 May 1991 12:14:30 +0000
Subject: [PATCH] Added function-end breapoint stuff.

---
 ldb/breakpoint.c  | 34 ++++++++++++++++++++++++++++------
 ldb/mips-assem.s  | 33 ++++++++++++++++++++++++++++++++-
 ldb/rt-arch.c     |  7 +++++++
 ldb/sparc-arch.c  | 15 +++++++++++++++
 ldb/sparc-assem.s | 30 ++++++++++++++++++++++++++++++
 5 files changed, 112 insertions(+), 7 deletions(-)

diff --git a/ldb/breakpoint.c b/ldb/breakpoint.c
index cd37cff5f..433a14528 100644
--- a/ldb/breakpoint.c
+++ b/ldb/breakpoint.c
@@ -87,19 +87,41 @@ int breakpoint_after_offset(scp)
 #endif
 }
 
-
-handle_breakpoint(signal, subcode, scp)
-     struct sigcontext *scp;
+static void internal_handle_breakpoint(scp, code)
+struct sigcontext *scp;
+lispobj code;
 {
-    struct code *code = (struct code *)PTR(scp->sc_regs[CODE]);
+    struct code *codeptr = (struct code *)PTR(code);
     lispobj *args;
 
     args = current_control_stack_pointer;
     current_control_stack_pointer += 3;
-    args[0] = fixnum(calc_offset(code, scp->sc_pc));
-    args[1] = scp->sc_regs[CODE];
+    args[0] = fixnum(calc_offset(codeptr, scp->sc_pc));
+    args[1] = code;
     args[2] = alloc_sap(scp);
     call_into_lisp(HANDLE_BREAKPOINT, SymbolFunction(HANDLE_BREAKPOINT),
 		   args, 3);
     scp->sc_mask = sigblock(0);
 }
+
+handle_breakpoint(signal, subcode, scp)
+     struct sigcontext *scp;
+{
+    internal_handle_breakpoint(scp, scp->sc_regs[CODE]);
+}
+
+handle_function_end_breakpoint(signal, subcode, scp)
+int signal, subcode;
+struct sigcontext *scp;
+{
+    extern char function_end_breakpoint_guts[], function_end_breakpoint_trap[];
+
+    lispobj code = scp->sc_pc - (unsigned long)function_end_breakpoint_trap
+	+ (unsigned long)function_end_breakpoint_guts -
+	((sizeof(struct code)+7)&~7) + type_OtherPointer;
+    struct code *codeptr = (struct code *)PTR(code);
+
+    internal_handle_breakpoint(scp, code);
+
+    scp->sc_pc = codeptr->constants[0]-type_OtherPointer+sizeof(lispobj);
+}
diff --git a/ldb/mips-assem.s b/ldb/mips-assem.s
index c3a589609..ce1eb4704 100644
--- a/ldb/mips-assem.s
+++ b/ldb/mips-assem.s
@@ -1,4 +1,4 @@
-/* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/ldb/Attic/mips-assem.s,v 1.11 1991/04/27 18:22:50 wlott Exp $ */
+/* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/ldb/Attic/mips-assem.s,v 1.12 1991/05/29 12:14:21 wlott Exp $ */
 #include <machine/regdef.h>
 
 #include "lisp.h"
@@ -322,3 +322,34 @@ closure_tramp:
 	.text
 	.globl	end_of_tramps
 end_of_tramps:
+
+
+/*
+ * Function-end breakpoint magic.
+ */
+
+	.text
+	.align	2
+	.set	noreorder
+	.globl	function_end_breakpoint_guts
+function_end_breakpoint_guts:
+	.word	type_ReturnPcHeader
+	beq	zero, zero, 1f
+	nop
+	li	NARGS, 4
+	move	A1, NULLREG
+	move	A2, NULLREG
+	move	A3, NULLREG
+	move	A4, NULLREG
+	move	A5, NULLREG
+1:
+
+	.globl	function_end_breakpoint_trap
+function_end_breakpoint_trap:
+	break	trap_FunctionEndBreakpoint
+	beq	zero, zero, 1b
+	nop
+
+	.globl	function_end_breakpoint_end
+function_end_breakpoint_end:
+	.set	reorder
diff --git a/ldb/rt-arch.c b/ldb/rt-arch.c
index 9967a4f8c..711b867d4 100644
--- a/ldb/rt-arch.c
+++ b/ldb/rt-arch.c
@@ -65,6 +65,13 @@ static sigtrap_handler(signal, code, context)
 	undo_fake_foreign_function_call(context);
 	break;
 
+      case trap_FunctionEndBreakpoint:
+	sigsetmask(context->sc_mask);
+	fake_foreign_function_call(context);
+	handle_function_end_breakpoint(signal, code, context);
+	undo_fake_foreign_function_call(context);
+	break;
+
       default:
 	interrupt_handle_now(signal, code, context);
 	break;
diff --git a/ldb/sparc-arch.c b/ldb/sparc-arch.c
index 666f8cd50..d93c4fb6c 100644
--- a/ldb/sparc-arch.c
+++ b/ldb/sparc-arch.c
@@ -89,6 +89,21 @@ struct sigcontext *context;
 	    interrupt_internal_error(signal, code, context, trap == trap_Cerror);
 	    break;
 
+	  case trap_Breakpoint:
+	    sigsetmask(context->sc_mask);
+	    fake_foreign_function_call(context);
+	    handle_breakpoint(signal, code, context);
+	    undo_fake_foreign_function_call(context);
+	    break;
+
+	  case trap_FunctionEndBreakpoint:
+	    sigsetmask(context->sc_mask);
+	    fake_foreign_function_call(context);
+	    handle_breakpoint(signal, code, context);
+	    undo_fake_foreign_function_call(context);
+	    scp->sc_npc = scp->sc_pc + 4;
+	    break;
+
 	  default:
 	    interrupt_handle_now(signal, code, context);
 	    break;
diff --git a/ldb/sparc-assem.s b/ldb/sparc-assem.s
index b99bfbb91..99b2c2f73 100644
--- a/ldb/sparc-assem.s
+++ b/ldb/sparc-assem.s
@@ -258,6 +258,36 @@ _closure_tramp:
 
 
 
+/*
+ * Function-end breakpoint magic.
+ */
+
+	.text
+	.align	8
+	.global	function_end_breakpoint_guts
+function_end_breakpoint_guts:
+	.word	type_ReturnPcHeader
+	b	1f
+	nop
+	mov	4, NARGS
+	mov	NULLREG, A1
+	mov	NULLREG, A2
+	mov	NULLREG, A3
+	mov	NULLREG, A4
+	mov	NULLREG, A5
+1:
+
+	.global	function_end_breakpoint_trap
+function_end_breakpoint_trap:
+	unimp	trap_FunctionEndBreakpoint
+	b	1b
+	nop
+
+	.global	function_end_breakpoint_end
+function_end_breakpoint_end:
+
+
+
 
 /****************************************************************\
 
-- 
GitLab