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 #if !defined(hpux) && !defined(irix) && !defined(__i386__)
58 undo_fake_foreign_function_call(context);
60 arch_do_displaced_inst(context, orig_inst);
64 static lispobj find_code(os_context_t *context)
67 lispobj code = *os_context_register_addr(context, reg_CODE);
70 if (LowtagOf(code) != type_OtherPointer)
73 header = *(lispobj *)(code-type_OtherPointer);
75 if (TypeOf(header) == type_CodeHeader)
78 return code - HeaderValue(header)*sizeof(lispobj);
86 static lispobj find_code(os_context_t *context)
89 (lispobj)component_ptr_from_pc((lispobj *)(*os_context_pc_addr(context)));
94 return codeptr + type_OtherPointer;
99 static int compute_offset(os_context_t *context, lispobj code)
104 unsigned long code_start;
105 struct code *codeptr = (struct code *)native_pointer(code);
107 unsigned long pc = *os_context_pc_addr(context) & ~3;
109 unsigned long pc = *os_context_pc_addr(context);
112 code_start = (unsigned long)codeptr
113 + HeaderValue(codeptr->header)*sizeof(lispobj);
117 int offset = pc - code_start;
118 if (offset >= codeptr->code_size)
121 return make_fixnum(offset);
127 void handle_breakpoint(int signal, siginfo_t *info, os_context_t *context)
131 fake_foreign_function_call(context);
133 code = find_code(context);
135 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
136 compute_offset(context, code),
140 undo_fake_foreign_function_call(context);
143 void handle_breakpoint(int signal, siginfo_t* info, os_context_t *context)
145 lispobj code, context_sap = alloc_sap(context);
147 fake_foreign_function_call(context);
149 code = find_code(context);
151 /* Don't disallow recursive breakpoint traps. Otherwise, we can't
152 * use debugger breakpoints anywhere in here. */
153 sigprocmask(SIG_SETMASK, os_context_sigmask_addr(context), 0);
155 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
156 compute_offset(context, code),
160 undo_fake_foreign_function_call(context);
165 void *handle_function_end_breakpoint(int signal, siginfo_t *info,
166 os_context_t *context)
169 struct code *codeptr;
171 fake_foreign_function_call(context);
173 code = find_code(context);
174 codeptr = (struct code *)native_pointer(code);
176 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
177 compute_offset(context, code),
181 lra = codeptr->constants[REAL_LRA_SLOT];
183 if (codeptr->constants[KNOWN_RETURN_P_SLOT] == NIL) {
184 *os_context_register_addr(context, reg_CODE) = lra;
187 undo_fake_foreign_function_call(context);
188 return (void *)(lra-type_OtherPointer+sizeof(lispobj));
191 void *handle_function_end_breakpoint(int signal, siginfo_t *info,
192 os_context_t *context)
194 lispobj code, context_sap = alloc_sap(context);
195 struct code *codeptr;
197 fake_foreign_function_call(context);
199 code = find_code(context);
200 codeptr = (struct code *)native_pointer(code);
202 /* Don't disallow recursive breakpoint traps. Otherwise, we can't
203 * use debugger breakpoints anywhere in here. */
204 sigprocmask(SIG_SETMASK, os_context_sigmask_addr(context), 0);
206 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
207 compute_offset(context, code),
211 undo_fake_foreign_function_call(context);
213 return compute_pc(codeptr->constants[REAL_LRA_SLOT],
214 fixnum_value(codeptr->constants[REAL_LRA_SLOT+1]));