/[cmucl]/src/lisp/breakpoint.c
ViewVC logotype

Contents of /src/lisp/breakpoint.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Wed Aug 19 02:46:58 1992 UTC (21 years, 8 months ago) by wlott
Branch: MAIN
Changes since 1.1: +39 -24 lines
File MIME type: text/plain
Fixed to work.
1 #include <stdio.h>
2 #include <signal.h>
3
4 #include "lisp.h"
5 #include "os.h"
6 #include "internals.h"
7 #include "arch.h"
8 #include "lispregs.h"
9 #include "globals.h"
10 #include "alloc.h"
11 #include "breakpoint.h"
12
13 #define REAL_LRA_SLOT 0
14 #define KNOWN_RETURN_P_SLOT 1
15 #define BOGUS_LRA_CONSTANTS 2
16
17 static void *compute_pc(lispobj code_obj, int pc_offset)
18 {
19 struct code *code;
20
21 code = (struct code *)PTR(code_obj);
22 return (void *)((char *)code + HeaderValue(code->header)*sizeof(lispobj)
23 + pc_offset);
24 }
25
26 unsigned long breakpoint_install(lispobj code_obj, int pc_offset)
27 {
28 return arch_install_breakpoint(compute_pc(code_obj, pc_offset));
29 }
30
31 void breakpoint_remove(lispobj code_obj, int pc_offset,
32 unsigned long orig_inst)
33 {
34 arch_remove_breakpoint(compute_pc(code_obj, pc_offset), orig_inst);
35 }
36
37 void breakpoint_do_displaced_inst(struct sigcontext *scp,
38 unsigned long orig_inst)
39 {
40 undo_fake_foreign_function_call(scp);
41 arch_do_displaced_inst(scp, orig_inst);
42 }
43
44 static lispobj find_code(struct sigcontext *scp)
45 {
46 #ifdef reg_CODE
47 lispobj code = SC_REG(scp, reg_CODE), header;
48
49 if (LowtagOf(code) != type_OtherPointer)
50 return NIL;
51
52 header = *(lispobj *)(code-type_OtherPointer);
53
54 if (TypeOf(header) == type_CodeHeader)
55 return code;
56 else
57 return code - HeaderValue(header)*sizeof(lispobj);
58 #else
59 return NIL;
60 #endif
61 }
62
63 static int compute_offset(struct sigcontext *scp, lispobj code)
64 {
65 if (code == NIL)
66 return 0;
67 else {
68 unsigned long code_start;
69 struct code *codeptr = (struct code *)PTR(code);
70
71 code_start = (unsigned long)codeptr
72 + HeaderValue(codeptr->header)*sizeof(lispobj);
73 if (SC_PC(scp) < code_start)
74 return 0;
75 else {
76 int offset = SC_PC(scp) - code_start;
77 if (offset >= codeptr->code_size)
78 return 0;
79 else
80 return make_fixnum(offset);
81 }
82 }
83 }
84
85 void handle_breakpoint(int signal, int subcode, struct sigcontext *scp)
86 {
87 lispobj code;
88
89 fake_foreign_function_call(scp);
90
91 code = find_code(scp);
92 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
93 compute_offset(scp, code),
94 code,
95 alloc_sap(scp));
96
97 undo_fake_foreign_function_call(scp);
98 }
99
100 void *handle_function_end_breakpoint(int signal, int subcode,
101 struct sigcontext *scp)
102 {
103 lispobj code, lra;
104 struct code *codeptr;
105
106 fake_foreign_function_call(scp);
107
108 code = find_code(scp);
109 codeptr = (struct code *)PTR(code);
110
111 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
112 compute_offset(scp, code),
113 code,
114 alloc_sap(scp));
115
116 lra = codeptr->constants[REAL_LRA_SLOT];
117 #ifdef reg_CODE
118 if (codeptr->constants[KNOWN_RETURN_P_SLOT] == NIL)
119 SC_REG(scp, reg_CODE) = lra;
120 #endif
121
122 undo_fake_foreign_function_call(scp);
123
124 return (void *)(lra-type_OtherPointer+sizeof(lispobj));
125 }

  ViewVC Help
Powered by ViewVC 1.1.5