/[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.1 - (hide annotations)
Tue Jun 23 11:24:49 1998 UTC (15 years, 10 months ago) by pw
Branch: RELENG_18
CVS Tags: RELEASE_18b
Changes since 1.6: +70 -3 lines
File MIME type: text/plain
This (huge) revision brings the RELENG_18 branch up to the current HEAD.
Note code/unix-glib2.lisp not yet included -- not sure it is ready to go.
1 ram 1.6 /*
2    
3 pw 1.6.2.1 $Header: /tiger/var/lib/cvsroots/cmucl/src/lisp/breakpoint.c,v 1.6.2.1 1998/06/23 11:24:49 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     sigsetmask(scp->sc_mask);
148    
149     funcall3(SymbolFunction(HANDLE_BREAKPOINT),
150     compute_offset(scp, code),
151     code,
152     scp_sap);
153    
154     undo_fake_foreign_function_call(scp);
155     }
156     #endif
157    
158     #ifndef i386
159 wlott 1.1 void *handle_function_end_breakpoint(int signal, int subcode,
160     struct sigcontext *scp)
161     {
162 wlott 1.2 lispobj code, lra;
163     struct code *codeptr;
164 wlott 1.1
165 wlott 1.2 fake_foreign_function_call(scp);
166 wlott 1.1
167 wlott 1.2 code = find_code(scp);
168     codeptr = (struct code *)PTR(code);
169    
170     funcall3(SymbolFunction(HANDLE_BREAKPOINT),
171     compute_offset(scp, code),
172     code,
173     alloc_sap(scp));
174    
175 wlott 1.1 lra = codeptr->constants[REAL_LRA_SLOT];
176 wlott 1.2 #ifdef reg_CODE
177 wlott 1.1 if (codeptr->constants[KNOWN_RETURN_P_SLOT] == NIL)
178 wlott 1.2 SC_REG(scp, reg_CODE) = lra;
179 wlott 1.1 #endif
180 pw 1.6.2.1 undo_fake_foreign_function_call(scp);
181     return (void *)(lra-type_OtherPointer+sizeof(lispobj));
182     }
183     #else
184     void *handle_function_end_breakpoint(int signal, int subcode,
185     struct sigcontext *scp)
186     {
187     lispobj code, scp_sap=alloc_sap(scp);
188     struct code *codeptr;
189    
190     fake_foreign_function_call(scp);
191    
192     code = find_code(scp);
193     codeptr = (struct code *)PTR(code);
194    
195     /* Don't disallow recursive breakpoint traps. Otherwise, we can't
196     * use debugger breakpoints anywhere in here. */
197     sigsetmask(scp->sc_mask);
198    
199     funcall3(SymbolFunction(HANDLE_BREAKPOINT),
200     compute_offset(scp, code),
201     code,
202     scp_sap);
203 wlott 1.2
204     undo_fake_foreign_function_call(scp);
205    
206 pw 1.6.2.1 return compute_pc(codeptr->constants[REAL_LRA_SLOT],
207     fixnum_value(codeptr->constants[REAL_LRA_SLOT+1]));
208 wlott 1.1 }
209 pw 1.6.2.1 #endif

  ViewVC Help
Powered by ViewVC 1.1.5