2 * This software is part of the SBCL system. See the README file for
5 * This software is derived from the CMU CL system, which was
6 * written at Carnegie Mellon University and released into the
7 * public domain. The software is in the public domain and is
8 * provided with absolutely no warranty. See the COPYING and CREDITS
9 * files for more information.
18 #include "interrupt.h"
23 #include "breakpoint.h"
25 #define REAL_LRA_SLOT 0
27 #define KNOWN_RETURN_P_SLOT 1
28 #define BOGUS_LRA_CONSTANTS 2
30 #define KNOWN_RETURN_P_SLOT 2
31 #define BOGUS_LRA_CONSTANTS 3
34 static void *compute_pc(lispobj code_obj, int pc_offset)
38 code = (struct code *)native_pointer(code_obj);
39 return (void *)((char *)code + HeaderValue(code->header)*sizeof(lispobj)
43 unsigned long breakpoint_install(lispobj code_obj, int pc_offset)
45 return arch_install_breakpoint(compute_pc(code_obj, pc_offset));
48 void breakpoint_remove(lispobj code_obj, int pc_offset,
49 unsigned long orig_inst)
51 arch_remove_breakpoint(compute_pc(code_obj, pc_offset), orig_inst);
54 void breakpoint_do_displaced_inst(os_context_t* context,
55 unsigned long orig_inst)
57 /* on platforms with sigreturn(), we go directly back from
58 * arch_do_displaced_inst() to lisp code, so we need to clean up
59 * our bindings now. (side note: I'd love to know in exactly what
60 * scenario the speed of breakpoint handling is critical enough to
61 * justify this maintenance mess)
65 #if !(defined(hpux) || defined(irix) || defined(__i386__) || defined(alpha))
66 undo_fake_foreign_function_call(context);
68 arch_do_displaced_inst(context, orig_inst);
72 static lispobj find_code(os_context_t *context)
75 lispobj code = *os_context_register_addr(context, reg_CODE);
78 if (lowtag_of(code) != OTHER_POINTER_LOWTAG)
81 header = *(lispobj *)(code-OTHER_POINTER_LOWTAG);
83 if (widetag_of(header) == CODE_HEADER_WIDETAG)
86 return code - HeaderValue(header)*sizeof(lispobj);
94 static lispobj find_code(os_context_t *context)
97 (lispobj)component_ptr_from_pc((lispobj *)(*os_context_pc_addr(context)));
102 return codeptr + OTHER_POINTER_LOWTAG;
107 static int compute_offset(os_context_t *context, lispobj code)
112 unsigned long code_start;
113 struct code *codeptr = (struct code *)native_pointer(code);
115 unsigned long pc = *os_context_pc_addr(context) & ~3;
117 unsigned long pc = *os_context_pc_addr(context);
120 code_start = (unsigned long)codeptr
121 + HeaderValue(codeptr->header)*sizeof(lispobj);
125 int offset = pc - code_start;
126 if (offset >= codeptr->code_size)
129 return make_fixnum(offset);
133 /* FIXME: I can see no really good reason these couldn't be merged, but haven't
134 * tried. The sigprocmask() call would work just as well on alpha as it
135 * presumably does on x86 -dan 2001.08.10
138 void handle_breakpoint(int signal, siginfo_t *info, os_context_t *context)
142 fake_foreign_function_call(context);
144 code = find_code(context);
146 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
147 compute_offset(context, code),
151 undo_fake_foreign_function_call(context);
154 void handle_breakpoint(int signal, siginfo_t* info, os_context_t *context)
156 lispobj code, context_sap = alloc_sap(context);
158 fake_foreign_function_call(context);
160 code = find_code(context);
162 /* Don't disallow recursive breakpoint traps. Otherwise, we can't
163 * use debugger breakpoints anywhere in here. */
164 sigprocmask(SIG_SETMASK, os_context_sigmask_addr(context), 0);
166 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
167 compute_offset(context, code),
171 undo_fake_foreign_function_call(context);
176 void *handle_fun_end_breakpoint(int signal, siginfo_t *info,
177 os_context_t *context)
180 struct code *codeptr;
182 fake_foreign_function_call(context);
184 code = find_code(context);
185 codeptr = (struct code *)native_pointer(code);
187 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
188 compute_offset(context, code),
192 lra = codeptr->constants[REAL_LRA_SLOT];
194 if (codeptr->constants[KNOWN_RETURN_P_SLOT] == NIL) {
195 *os_context_register_addr(context, reg_CODE) = lra;
198 undo_fake_foreign_function_call(context);
199 return (void *)(lra-OTHER_POINTER_LOWTAG+sizeof(lispobj));
202 void *handle_fun_end_breakpoint(int signal, siginfo_t *info,
203 os_context_t *context)
205 lispobj code, context_sap = alloc_sap(context);
206 struct code *codeptr;
208 fake_foreign_function_call(context);
210 code = find_code(context);
211 codeptr = (struct code *)native_pointer(code);
213 /* Don't disallow recursive breakpoint traps. Otherwise, we can't
214 * use debugger breakpoints anywhere in here. */
215 sigprocmask(SIG_SETMASK, os_context_sigmask_addr(context), 0);
217 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
218 compute_offset(context, code),
222 undo_fake_foreign_function_call(context);
224 return compute_pc(codeptr->constants[REAL_LRA_SLOT],
225 fixnum_value(codeptr->constants[REAL_LRA_SLOT+1]));