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

Contents of /src/lisp/breakpoint.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6.2.2 - (hide annotations)
Tue May 23 16:38:13 2000 UTC (13 years, 11 months ago) by pw
Branch: RELENG_18
CVS Tags: RELEASE_18c
Changes since 1.6.2.1: +9 -3 lines
File MIME type: text/plain
This set of revisions brings the RELENG_18 branch up to HEAD in preparation
for an 18c release.
1 ram 1.6 /*
2    
3 pw 1.6.2.2 $Header: /tiger/var/lib/cvsroots/cmucl/src/lisp/breakpoint.c,v 1.6.2.2 2000/05/23 16:38:13 pw 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    
23     #define REAL_LRA_SLOT 0
24 pw 1.6.2.1 #ifndef i386
25 wlott 1.1 #define KNOWN_RETURN_P_SLOT 1
26     #define BOGUS_LRA_CONSTANTS 2
27 pw 1.6.2.1 #else
28     #define KNOWN_RETURN_P_SLOT 2
29     #define BOGUS_LRA_CONSTANTS 3
30     #endif
31 wlott 1.1
32     static void *compute_pc(lispobj code_obj, int pc_offset)
33     {
34     struct code *code;
35    
36     code = (struct code *)PTR(code_obj);
37     return (void *)((char *)code + HeaderValue(code->header)*sizeof(lispobj)
38     + pc_offset);
39     }
40    
41     unsigned long breakpoint_install(lispobj code_obj, int pc_offset)
42     {
43     return arch_install_breakpoint(compute_pc(code_obj, pc_offset));
44     }
45    
46     void breakpoint_remove(lispobj code_obj, int pc_offset,
47     unsigned long orig_inst)
48     {
49     arch_remove_breakpoint(compute_pc(code_obj, pc_offset), orig_inst);
50     }
51    
52     void breakpoint_do_displaced_inst(struct sigcontext *scp,
53     unsigned long orig_inst)
54     {
55 pw 1.6.2.1 #if !defined(hpux) && !defined(irix) && !defined(i386)
56 wlott 1.2 undo_fake_foreign_function_call(scp);
57 wlott 1.3 #endif
58 wlott 1.1 arch_do_displaced_inst(scp, orig_inst);
59     }
60    
61 pw 1.6.2.1 #ifndef i386
62 wlott 1.1 static lispobj find_code(struct sigcontext *scp)
63     {
64 wlott 1.2 #ifdef reg_CODE
65     lispobj code = SC_REG(scp, reg_CODE), header;
66 wlott 1.1
67     if (LowtagOf(code) != type_OtherPointer)
68     return NIL;
69    
70 wlott 1.2 header = *(lispobj *)(code-type_OtherPointer);
71 wlott 1.1
72     if (TypeOf(header) == type_CodeHeader)
73     return code;
74     else
75 wlott 1.2 return code - HeaderValue(header)*sizeof(lispobj);
76 wlott 1.1 #else
77     return NIL;
78     #endif
79     }
80 pw 1.6.2.1 #endif
81    
82     #ifdef i386
83     static lispobj find_code(struct sigcontext *scp)
84     {
85     lispobj codeptr = component_ptr_from_pc(SC_PC(scp));
86    
87     if (codeptr==NULL)
88     return NIL;
89     return (codeptr+type_OtherPointer);
90     }
91     #endif
92 wlott 1.1
93 wlott 1.2 static int compute_offset(struct sigcontext *scp, lispobj code)
94 wlott 1.1 {
95     if (code == NIL)
96 wlott 1.2 return 0;
97 wlott 1.1 else {
98     unsigned long code_start;
99     struct code *codeptr = (struct code *)PTR(code);
100 wlott 1.3 #ifdef parisc
101     unsigned long pc = SC_PC(scp) & ~3;
102     #else
103     unsigned long pc = SC_PC(scp);
104     #endif
105 wlott 1.1
106     code_start = (unsigned long)codeptr
107     + HeaderValue(codeptr->header)*sizeof(lispobj);
108 wlott 1.3 if (pc < code_start)
109 wlott 1.2 return 0;
110 wlott 1.1 else {
111 wlott 1.3 int offset = pc - code_start;
112 wlott 1.1 if (offset >= codeptr->code_size)
113 wlott 1.2 return 0;
114     else
115     return make_fixnum(offset);
116 wlott 1.1 }
117     }
118 wlott 1.2 }
119 wlott 1.1
120 pw 1.6.2.1 #ifndef i386
121 wlott 1.2 void handle_breakpoint(int signal, int subcode, struct sigcontext *scp)
122     {
123     lispobj code;
124    
125     fake_foreign_function_call(scp);
126    
127     code = find_code(scp);
128 pw 1.6.2.1
129 wlott 1.1 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
130 wlott 1.2 compute_offset(scp, code),
131 wlott 1.1 code,
132     alloc_sap(scp));
133    
134 wlott 1.2 undo_fake_foreign_function_call(scp);
135 wlott 1.1 }
136 pw 1.6.2.1 #else
137     void handle_breakpoint(int signal, int subcode, struct sigcontext *scp)
138     {
139     lispobj code, scp_sap=alloc_sap(scp);
140    
141     fake_foreign_function_call(scp);
142    
143     code = find_code(scp);
144 wlott 1.1
145 pw 1.6.2.1 /* Don't disallow recursive breakpoint traps. Otherwise, we can't */
146     /* use debugger breakpoints anywhere in here. */
147 pw 1.6.2.2 #if defined POSIX_SIGS
148     sigprocmask(SIG_SETMASK,&scp->sc_mask,NULL);
149     #else
150 pw 1.6.2.1 sigsetmask(scp->sc_mask);
151 pw 1.6.2.2 #endif
152 pw 1.6.2.1 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
153     compute_offset(scp, code),
154     code,
155     scp_sap);
156    
157     undo_fake_foreign_function_call(scp);
158     }
159     #endif
160    
161     #ifndef i386
162 wlott 1.1 void *handle_function_end_breakpoint(int signal, int subcode,
163     struct sigcontext *scp)
164     {
165 wlott 1.2 lispobj code, lra;
166     struct code *codeptr;
167 wlott 1.1
168 wlott 1.2 fake_foreign_function_call(scp);
169 wlott 1.1
170 wlott 1.2 code = find_code(scp);
171     codeptr = (struct code *)PTR(code);
172    
173     funcall3(SymbolFunction(HANDLE_BREAKPOINT),
174     compute_offset(scp, code),
175     code,
176     alloc_sap(scp));
177    
178 wlott 1.1 lra = codeptr->constants[REAL_LRA_SLOT];
179 wlott 1.2 #ifdef reg_CODE
180 wlott 1.1 if (codeptr->constants[KNOWN_RETURN_P_SLOT] == NIL)
181 wlott 1.2 SC_REG(scp, reg_CODE) = lra;
182 wlott 1.1 #endif
183 pw 1.6.2.1 undo_fake_foreign_function_call(scp);
184     return (void *)(lra-type_OtherPointer+sizeof(lispobj));
185     }
186     #else
187     void *handle_function_end_breakpoint(int signal, int subcode,
188     struct sigcontext *scp)
189     {
190     lispobj code, scp_sap=alloc_sap(scp);
191     struct code *codeptr;
192    
193     fake_foreign_function_call(scp);
194    
195     code = find_code(scp);
196     codeptr = (struct code *)PTR(code);
197    
198     /* Don't disallow recursive breakpoint traps. Otherwise, we can't
199     * use debugger breakpoints anywhere in here. */
200 pw 1.6.2.2 #if defined POSIX_SIGS
201     sigprocmask(SIG_SETMASK,&scp->sc_mask,NULL);
202     #else
203 pw 1.6.2.1 sigsetmask(scp->sc_mask);
204 pw 1.6.2.2 #endif
205 pw 1.6.2.1 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
206     compute_offset(scp, code),
207     code,
208     scp_sap);
209 wlott 1.2
210     undo_fake_foreign_function_call(scp);
211    
212 pw 1.6.2.1 return compute_pc(codeptr->constants[REAL_LRA_SLOT],
213     fixnum_value(codeptr->constants[REAL_LRA_SLOT+1]));
214 wlott 1.1 }
215 pw 1.6.2.1 #endif

  ViewVC Help
Powered by ViewVC 1.1.5