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 #include "genesis/code.h"
26 #include "genesis/fdefn.h"
28 #ifdef LISP_FEATURE_X86_64
29 #define REAL_LRA_SLOT 0
30 #define KNOWN_RETURN_P_SLOT 2
31 #define BOGUS_LRA_CONSTANTS 3
32 #elif defined(LISP_FEATURE_X86)
33 #define REAL_LRA_SLOT 1
34 #define KNOWN_RETURN_P_SLOT 3
35 #define BOGUS_LRA_CONSTANTS 4
37 #define REAL_LRA_SLOT 0
38 #define KNOWN_RETURN_P_SLOT 1
39 #define BOGUS_LRA_CONSTANTS 2
42 static void *compute_pc(lispobj code_obj
, int pc_offset
)
46 code
= (struct code
*)native_pointer(code_obj
);
47 return (void *)((char *)code
+ code_header_words(code
->header
)*sizeof(lispobj
)
51 unsigned int breakpoint_install(lispobj code_obj
, int pc_offset
)
53 return arch_install_breakpoint(compute_pc(code_obj
, pc_offset
));
56 void breakpoint_remove(lispobj code_obj
, int pc_offset
,
57 unsigned int orig_inst
)
59 arch_remove_breakpoint(compute_pc(code_obj
, pc_offset
), orig_inst
);
62 void breakpoint_do_displaced_inst(os_context_t
* context
,
63 unsigned int orig_inst
)
65 /* on platforms with sigreturn(), we go directly back from
66 * arch_do_displaced_inst() to lisp code, so we need to clean up
67 * our bindings now. (side note: I'd love to know in exactly what
68 * scenario the speed of breakpoint handling is critical enough to
69 * justify this maintenance mess)
73 #if (defined(LISP_FEATURE_SPARC) && defined (solaris))
74 undo_fake_foreign_function_call(context
);
76 arch_do_displaced_inst(context
, orig_inst
);
79 lispobj
find_code(os_context_t
*context
)
82 lispobj code
= *os_context_register_addr(context
, reg_CODE
);
85 if (lowtag_of(code
) != OTHER_POINTER_LOWTAG
)
88 header
= *(lispobj
*)(code
-OTHER_POINTER_LOWTAG
);
90 if (widetag_of(header
) == CODE_HEADER_WIDETAG
)
93 return code
- HeaderValue(header
)*sizeof(lispobj
);
96 (lispobj
)component_ptr_from_pc((lispobj
*)(*os_context_pc_addr(context
)));
101 return codeptr
+ OTHER_POINTER_LOWTAG
;
105 static long compute_offset(os_context_t
*context
, lispobj code
)
111 struct code
*codeptr
= (struct code
*)native_pointer(code
);
112 #ifdef LISP_FEATURE_HPPA
113 uword_t pc
= *os_context_pc_addr(context
) & ~3;
115 uword_t pc
= *os_context_pc_addr(context
);
118 code_start
= (uword_t
)codeptr
119 + code_header_words(codeptr
->header
)*sizeof(lispobj
);
123 uword_t offset
= pc
- code_start
;
124 if (offset
>= (uword_t
)fixnum_value(codeptr
->code_size
))
127 return make_fixnum(offset
);
132 void handle_breakpoint(os_context_t
*context
)
135 DX_ALLOC_SAP(context_sap
, context
);
137 fake_foreign_function_call(context
);
139 #ifndef LISP_FEATURE_SB_SAFEPOINT
140 unblock_gc_signals(0, 0);
142 code
= find_code(context
);
144 #ifndef LISP_FEATURE_WIN32
145 /* Don't disallow recursive breakpoint traps. Otherwise, we can't
146 * use debugger breakpoints anywhere in here. */
147 thread_sigmask(SIG_SETMASK
, os_context_sigmask_addr(context
), 0);
150 funcall3(StaticSymbolFunction(HANDLE_BREAKPOINT
),
151 compute_offset(context
, code
),
155 undo_fake_foreign_function_call(context
);
158 void *handle_fun_end_breakpoint(os_context_t
*context
)
161 struct code
*codeptr
;
162 DX_ALLOC_SAP(context_sap
, context
);
164 fake_foreign_function_call(context
);
166 #ifndef LISP_FEATURE_SB_SAFEPOINT
167 unblock_gc_signals(0, 0);
170 code
= find_code(context
);
171 codeptr
= (struct code
*)native_pointer(code
);
173 #ifndef LISP_FEATURE_WIN32
174 /* Don't disallow recursive breakpoint traps. Otherwise, we can't
175 * use debugger breakpoints anywhere in here. */
176 thread_sigmask(SIG_SETMASK
, os_context_sigmask_addr(context
), 0);
179 funcall3(StaticSymbolFunction(HANDLE_BREAKPOINT
),
180 compute_offset(context
, code
),
184 lra
= codeptr
->constants
[REAL_LRA_SLOT
];
186 #ifdef LISP_FEATURE_PPC
187 /* PPC now passes LRA objects in reg_LRA during return. Other
188 * platforms should as well, but haven't been fixed yet. */
189 *os_context_register_addr(context
, reg_LRA
) = lra
;
192 *os_context_register_addr(context
, reg_CODE
) = lra
;
196 undo_fake_foreign_function_call(context
);
199 return (void *)(lra
-OTHER_POINTER_LOWTAG
+sizeof(lispobj
));
201 return compute_pc(lra
, fixnum_value(codeptr
->constants
[REAL_LRA_SLOT
+1]));
206 handle_single_step_trap (os_context_t
*context
, int kind
, int register_offset
)
208 fake_foreign_function_call(context
);
210 #ifndef LISP_FEATURE_WIN32
211 thread_sigmask(SIG_SETMASK
, os_context_sigmask_addr(context
), 0);
214 funcall2(StaticSymbolFunction(HANDLE_SINGLE_STEP_TRAP
),
216 make_fixnum(register_offset
));
218 undo_fake_foreign_function_call(context
); /* blocks signals again */