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

Contents of /src/lisp/breakpoint.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (hide annotations)
Wed Jul 7 15:03:11 2004 UTC (9 years, 9 months ago) by rtoy
Branch: MAIN
CVS Tags: prm-before-macosx-merge-tag
Changes since 1.12: +10 -10 lines
File MIME type: text/plain
Changes from Robert Swindells to support NetBSD.
1 ram 1.6 /*
2    
3 rtoy 1.13 $Header: /tiger/var/lib/cvsroots/cmucl/src/lisp/breakpoint.c,v 1.13 2004/07/07 15:03:11 rtoy Exp $
4 ram 1.6
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 wlott 1.1 #include <stdio.h>
11     #include <signal.h>
12    
13     #include "lisp.h"
14     #include "os.h"
15     #include "internals.h"
16 ram 1.5 #include "interrupt.h"
17 wlott 1.1 #include "arch.h"
18     #include "lispregs.h"
19     #include "globals.h"
20     #include "alloc.h"
21     #include "breakpoint.h"
22 dtc 1.12 #if defined GENCGC
23     #include "gencgc.h"
24     #endif
25 wlott 1.1
26     #define REAL_LRA_SLOT 0
27 dtc 1.8 #ifndef i386
28 wlott 1.1 #define KNOWN_RETURN_P_SLOT 1
29     #define BOGUS_LRA_CONSTANTS 2
30 dtc 1.8 #else
31     #define KNOWN_RETURN_P_SLOT 2
32     #define BOGUS_LRA_CONSTANTS 3
33     #endif
34 wlott 1.1
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 dtc 1.11 return (void *)((char *)code + HeaderValue(code->header) * sizeof(lispobj)
41 wlott 1.1 + 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 rtoy 1.13 void breakpoint_do_displaced_inst(os_context_t *scp,
56 wlott 1.1 unsigned long orig_inst)
57     {
58 dtc 1.7 #if !defined(hpux) && !defined(irix) && !defined(i386)
59 wlott 1.2 undo_fake_foreign_function_call(scp);
60 wlott 1.3 #endif
61 wlott 1.1 arch_do_displaced_inst(scp, orig_inst);
62     }
63    
64 dtc 1.7 #ifndef i386
65 wlott 1.1 static lispobj find_code(struct sigcontext *scp)
66     {
67 wlott 1.2 #ifdef reg_CODE
68     lispobj code = SC_REG(scp, reg_CODE), header;
69 wlott 1.1
70     if (LowtagOf(code) != type_OtherPointer)
71     return NIL;
72    
73 wlott 1.2 header = *(lispobj *)(code-type_OtherPointer);
74 wlott 1.1
75     if (TypeOf(header) == type_CodeHeader)
76     return code;
77     else
78 wlott 1.2 return code - HeaderValue(header)*sizeof(lispobj);
79 wlott 1.1 #else
80     return NIL;
81     #endif
82     }
83 dtc 1.7 #endif
84    
85     #ifdef i386
86 rtoy 1.13 static lispobj find_code(os_context_t *scp)
87 dtc 1.7 {
88 dtc 1.12 lispobj *codeptr = component_ptr_from_pc(SC_PC(scp));
89 dtc 1.7
90 dtc 1.11 if (codeptr == NULL)
91 dtc 1.7 return NIL;
92 dtc 1.11 else
93 dtc 1.12 return (lispobj) codeptr | type_OtherPointer;
94 dtc 1.7 }
95     #endif
96 wlott 1.1
97 rtoy 1.13 static int compute_offset(os_context_t *scp, lispobj code)
98 wlott 1.1 {
99     if (code == NIL)
100 wlott 1.2 return 0;
101 wlott 1.1 else {
102     unsigned long code_start;
103     struct code *codeptr = (struct code *)PTR(code);
104 wlott 1.3 #ifdef parisc
105     unsigned long pc = SC_PC(scp) & ~3;
106     #else
107     unsigned long pc = SC_PC(scp);
108     #endif
109 wlott 1.1
110     code_start = (unsigned long)codeptr
111     + HeaderValue(codeptr->header)*sizeof(lispobj);
112 wlott 1.3 if (pc < code_start)
113 wlott 1.2 return 0;
114 wlott 1.1 else {
115 wlott 1.3 int offset = pc - code_start;
116 wlott 1.1 if (offset >= codeptr->code_size)
117 wlott 1.2 return 0;
118     else
119     return make_fixnum(offset);
120 wlott 1.1 }
121     }
122 wlott 1.2 }
123 wlott 1.1
124 dtc 1.9 #ifndef i386
125 rtoy 1.13 void handle_breakpoint(int signal, int subcode, os_context_t *scp)
126 dtc 1.9 {
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 rtoy 1.13 void handle_breakpoint(int signal, int subcode, os_context_t *scp)
142 wlott 1.2 {
143 dtc 1.7 lispobj code, scp_sap=alloc_sap(scp);
144 wlott 1.2
145     fake_foreign_function_call(scp);
146    
147     code = find_code(scp);
148 dtc 1.7
149 dtc 1.11 /*
150     * Don't disallow recursive breakpoint traps. Otherwise, we can't
151     * use debugger breakpoints anywhere in here.
152     */
153    
154 pw 1.10 #if defined POSIX_SIGS
155 rtoy 1.13 sigprocmask(SIG_SETMASK,&scp->uc_sigmask,NULL);
156 pw 1.10 #else
157 dtc 1.7 sigsetmask(scp->sc_mask);
158 pw 1.10 #endif
159 wlott 1.1 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
160 wlott 1.2 compute_offset(scp, code),
161 wlott 1.1 code,
162 dtc 1.7 scp_sap);
163 wlott 1.1
164 wlott 1.2 undo_fake_foreign_function_call(scp);
165 wlott 1.1 }
166 dtc 1.9 #endif
167 wlott 1.1
168 dtc 1.8 #ifndef i386
169 wlott 1.1 void *handle_function_end_breakpoint(int signal, int subcode,
170 rtoy 1.13 os_context_t *scp)
171 wlott 1.1 {
172 dtc 1.9 lispobj code, lra;
173 wlott 1.2 struct code *codeptr;
174 wlott 1.1
175 wlott 1.2 fake_foreign_function_call(scp);
176 wlott 1.1
177 wlott 1.2 code = find_code(scp);
178     codeptr = (struct code *)PTR(code);
179    
180     funcall3(SymbolFunction(HANDLE_BREAKPOINT),
181     compute_offset(scp, code),
182     code,
183 dtc 1.9 alloc_sap(scp));
184 wlott 1.2
185 wlott 1.1 lra = codeptr->constants[REAL_LRA_SLOT];
186 wlott 1.2 #ifdef reg_CODE
187 wlott 1.1 if (codeptr->constants[KNOWN_RETURN_P_SLOT] == NIL)
188 wlott 1.2 SC_REG(scp, reg_CODE) = lra;
189 wlott 1.1 #endif
190 dtc 1.8 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 rtoy 1.13 os_context_t *scp)
196 dtc 1.8 {
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 dtc 1.11 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 dtc 1.8
210 pw 1.10 #if defined POSIX_SIGS
211 rtoy 1.13 sigprocmask(SIG_SETMASK,&scp->uc_sigmask,NULL);
212 pw 1.10 #else
213 dtc 1.8 sigsetmask(scp->sc_mask);
214 pw 1.10 #endif
215 dtc 1.8 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
216     compute_offset(scp, code),
217     code,
218     scp_sap);
219 wlott 1.2
220     undo_fake_foreign_function_call(scp);
221    
222 dtc 1.8 return compute_pc(codeptr->constants[REAL_LRA_SLOT],
223 dtc 1.11 fixnum_value(codeptr->constants[REAL_LRA_SLOT + 1]));
224 dtc 1.8 }
225 dtc 1.7 #endif

  ViewVC Help
Powered by ViewVC 1.1.5