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.
22 #include "interrupt.h"
27 #include "breakpoint.h"
29 #define REAL_LRA_SLOT 0
31 #define KNOWN_RETURN_P_SLOT 1
32 #define BOGUS_LRA_CONSTANTS 2
34 #define KNOWN_RETURN_P_SLOT 2
35 #define BOGUS_LRA_CONSTANTS 3
38 static void *compute_pc(lispobj code_obj, int pc_offset)
42 code = (struct code *)PTR(code_obj);
43 return (void *)((char *)code + HeaderValue(code->header)*sizeof(lispobj)
47 unsigned long breakpoint_install(lispobj code_obj, int pc_offset)
49 return arch_install_breakpoint(compute_pc(code_obj, pc_offset));
52 void breakpoint_remove(lispobj code_obj, int pc_offset,
53 unsigned long orig_inst)
55 arch_remove_breakpoint(compute_pc(code_obj, pc_offset), orig_inst);
58 void breakpoint_do_displaced_inst(os_context_t* context,
59 unsigned long orig_inst)
61 #if !defined(hpux) && !defined(irix) && !defined(__i386__)
62 undo_fake_foreign_function_call(context);
64 arch_do_displaced_inst(context, orig_inst);
68 static lispobj find_code(os_context_t *context)
71 lispobj code = *os_context_register_addr(context, reg_CODE);
74 if (LowtagOf(code) != type_OtherPointer)
77 header = *(lispobj *)(code-type_OtherPointer);
79 if (TypeOf(header) == type_CodeHeader)
82 return code - HeaderValue(header)*sizeof(lispobj);
90 static lispobj find_code(os_context_t *context)
92 lispobj codeptr = component_ptr_from_pc(*os_context_pc_addr(context));
97 return codeptr + type_OtherPointer;
102 static int compute_offset(os_context_t *context, lispobj code)
107 unsigned long code_start;
108 struct code *codeptr = (struct code *)PTR(code);
110 unsigned long pc = *os_context_pc_addr(context) & ~3;
112 unsigned long pc = *os_context_pc_addr(context);
115 code_start = (unsigned long)codeptr
116 + HeaderValue(codeptr->header)*sizeof(lispobj);
120 int offset = pc - code_start;
121 if (offset >= codeptr->code_size)
124 return make_fixnum(offset);
130 void handle_breakpoint(int signal, siginfo_t *info, os_context_t *context)
134 fake_foreign_function_call(context);
136 code = find_code(context);
138 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
139 compute_offset(context, code),
143 undo_fake_foreign_function_call(context);
146 void handle_breakpoint(int signal, siginfo_t* info, os_context_t *context)
148 lispobj code, context_sap = alloc_sap(context);
150 fake_foreign_function_call(context);
152 code = find_code(context);
154 /* Don't disallow recursive breakpoint traps. Otherwise, we can't
155 * use debugger breakpoints anywhere in here. */
156 sigprocmask(SIG_SETMASK, os_context_sigmask_addr(context), 0);
158 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
159 compute_offset(context, code),
163 undo_fake_foreign_function_call(context);
168 void *handle_function_end_breakpoint(int signal, siginfo_t *info,
169 os_context_t *context)
172 struct code *codeptr;
174 fake_foreign_function_call(context);
176 code = find_code(context);
177 codeptr = (struct code *)PTR(code);
179 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
180 compute_offset(context, code),
184 lra = codeptr->constants[REAL_LRA_SLOT];
186 if (codeptr->constants[KNOWN_RETURN_P_SLOT] == NIL) {
187 *os_context_register_addr(context, reg_CODE) = lra;
190 undo_fake_foreign_function_call(context);
191 return (void *)(lra-type_OtherPointer+sizeof(lispobj));
194 void *handle_function_end_breakpoint(int signal, siginfo_t *info,
195 os_context_t *context)
197 lispobj code, context_sap = alloc_sap(context);
198 struct code *codeptr;
200 fake_foreign_function_call(context);
202 code = find_code(context);
203 codeptr = (struct code *)PTR(code);
205 /* Don't disallow recursive breakpoint traps. Otherwise, we can't
206 * use debugger breakpoints anywhere in here. */
207 sigprocmask(SIG_SETMASK, os_context_sigmask_addr(context), 0);
209 funcall3(SymbolFunction(HANDLE_BREAKPOINT),
210 compute_offset(context, code),
214 undo_fake_foreign_function_call(context);
216 return compute_pc(codeptr->constants[REAL_LRA_SLOT],
217 fixnum_value(codeptr->constants[REAL_LRA_SLOT+1]));