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

Contents of /src/lisp/breakpoint.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (show annotations)
Mon Jul 12 23:44:07 2004 UTC (9 years, 9 months ago) by pmai
Branch: MAIN
CVS Tags: snapshot-2004-10, snapshot-2004-08, snapshot-2004-09, snapshot-2004-12, snapshot-2004-11, snapshot-2005-03, snapshot-2005-01, ppc_gencgc_snap_2005-05-14, snapshot-2005-02
Branch point for: ppc_gencgc_branch
Changes since 1.13: +2 -2 lines
File MIME type: text/plain
Finish conversion from hardcoded sigcontext to os_context_t, as initiated
by the commit of the NetBSD support, and needed by the upcoming merge of
the OS X/Darwin port.
1 /*
2
3 $Header: /tiger/var/lib/cvsroots/cmucl/src/lisp/breakpoint.c,v 1.14 2004/07/12 23:44:07 pmai Exp $
4
5 This code was written as part of the CMU Common Lisp project at
6 Carnegie Mellon University, and has been placed in the public domain.
7
8 */
9
10 #include <stdio.h>
11 #include <signal.h>
12
13 #include "lisp.h"
14 #include "os.h"
15 #include "internals.h"
16 #include "interrupt.h"
17 #include "arch.h"
18 #include "lispregs.h"
19 #include "globals.h"
20 #include "alloc.h"
21 #include "breakpoint.h"
22 #if defined GENCGC
23 #include "gencgc.h"
24 #endif
25
26 #define REAL_LRA_SLOT 0
27 #ifndef i386
28 #define KNOWN_RETURN_P_SLOT 1
29 #define BOGUS_LRA_CONSTANTS 2
30 #else
31 #define KNOWN_RETURN_P_SLOT 2
32 #define BOGUS_LRA_CONSTANTS 3
33 #endif
34
35 static void *compute_pc(lispobj code_obj, int pc_offset)
36 {
37 struct code *code;
38
39 code = (struct code *)PTR(code_obj);
40 return (void *)((char *)code + HeaderValue(code->header) * sizeof(lispobj)
41 + pc_offset);
42 }
43
44 unsigned long breakpoint_install(lispobj code_obj, int pc_offset)
45 {
46 return arch_install_breakpoint(compute_pc(code_obj, pc_offset));
47 }
48
49 void breakpoint_remove(lispobj code_obj, int pc_offset,
50 unsigned long orig_inst)
51 {
52 arch_remove_breakpoint(compute_pc(code_obj, pc_offset), orig_inst);
53 }
54
55 void breakpoint_do_displaced_inst(os_context_t *scp,
56 unsigned long orig_inst)
57 {
58 #if !defined(hpux) && !defined(irix) && !defined(i386)
59 undo_fake_foreign_function_call(scp);
60 #endif
61 arch_do_displaced_inst(scp, orig_inst);
62 }
63
64 #ifndef i386
65 static lispobj find_code(os_context_t *scp)
66 {
67 #ifdef reg_CODE
68 lispobj code = SC_REG(scp, reg_CODE), header;
69
70 if (LowtagOf(code) != type_OtherPointer)
71 return NIL;
72
73 header = *(lispobj *)(code-type_OtherPointer);
74
75 if (TypeOf(header) == type_CodeHeader)
76 return code;
77 else
78 return code - HeaderValue(header)*sizeof(lispobj);
79 #else
80 return NIL;
81 #endif
82 }
83 #endif
84
85 #ifdef i386
86 static lispobj find_code(os_context_t *scp)
87 {
88 lispobj *codeptr = component_ptr_from_pc(SC_PC(scp));
89
90 if (codeptr == NULL)
91 return NIL;
92 else
93 return (lispobj) codeptr | type_OtherPointer;
94 }
95 #endif
96
97 static int compute_offset(os_context_t *scp, lispobj code)
98 {
99 if (code == NIL)
100 return 0;
101 else {
102 unsigned long code_start;
103 struct code *codeptr = (struct code *)PTR(code);
104 #ifdef parisc
105 unsigned long pc = SC_PC(scp) & ~3;
106 #else
107 unsigned long pc = SC_PC(scp);
108 #endif
109
110 code_start = (unsigned long)codeptr
111 + HeaderValue(codeptr->header)*sizeof(lispobj);
112 if (pc < code_start)
113 return 0;
114 else {
115 int offset = pc - code_start;
116 if (offset >= codeptr->code_size)
117 return 0;
118 else
119 return make_fixnum(offset);
120 }
121 }
122 }
123
124 #ifndef i386
125 void handle_breakpoint(int signal, int subcode, os_context_t *scp)
126 {
127 lispobj code;
128
129 fake_foreign_function_call(scp);
130
131 code = find_code(scp);
132
133 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
134 compute_offset(scp, code),
135 code,
136 alloc_sap(scp));
137
138 undo_fake_foreign_function_call(scp);
139 }
140 #else
141 void handle_breakpoint(int signal, int subcode, os_context_t *scp)
142 {
143 lispobj code, scp_sap=alloc_sap(scp);
144
145 fake_foreign_function_call(scp);
146
147 code = find_code(scp);
148
149 /*
150 * Don't disallow recursive breakpoint traps. Otherwise, we can't
151 * use debugger breakpoints anywhere in here.
152 */
153
154 #if defined POSIX_SIGS
155 sigprocmask(SIG_SETMASK,&scp->uc_sigmask,NULL);
156 #else
157 sigsetmask(scp->sc_mask);
158 #endif
159 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
160 compute_offset(scp, code),
161 code,
162 scp_sap);
163
164 undo_fake_foreign_function_call(scp);
165 }
166 #endif
167
168 #ifndef i386
169 void *handle_function_end_breakpoint(int signal, int subcode,
170 os_context_t *scp)
171 {
172 lispobj code, lra;
173 struct code *codeptr;
174
175 fake_foreign_function_call(scp);
176
177 code = find_code(scp);
178 codeptr = (struct code *)PTR(code);
179
180 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
181 compute_offset(scp, code),
182 code,
183 alloc_sap(scp));
184
185 lra = codeptr->constants[REAL_LRA_SLOT];
186 #ifdef reg_CODE
187 if (codeptr->constants[KNOWN_RETURN_P_SLOT] == NIL)
188 SC_REG(scp, reg_CODE) = lra;
189 #endif
190 undo_fake_foreign_function_call(scp);
191 return (void *)(lra-type_OtherPointer+sizeof(lispobj));
192 }
193 #else
194 void *handle_function_end_breakpoint(int signal, int subcode,
195 os_context_t *scp)
196 {
197 lispobj code, scp_sap=alloc_sap(scp);
198 struct code *codeptr;
199
200 fake_foreign_function_call(scp);
201
202 code = find_code(scp);
203 codeptr = (struct code *) PTR(code);
204
205 /*
206 * Don't disallow recursive breakpoint traps. Otherwise, we can't
207 * use debugger breakpoints anywhere in here.
208 */
209
210 #if defined POSIX_SIGS
211 sigprocmask(SIG_SETMASK,&scp->uc_sigmask,NULL);
212 #else
213 sigsetmask(scp->sc_mask);
214 #endif
215 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
216 compute_offset(scp, code),
217 code,
218 scp_sap);
219
220 undo_fake_foreign_function_call(scp);
221
222 return compute_pc(codeptr->constants[REAL_LRA_SLOT],
223 fixnum_value(codeptr->constants[REAL_LRA_SLOT + 1]));
224 }
225 #endif

  ViewVC Help
Powered by ViewVC 1.1.5