forked from quil-lang/sbcl-librarian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvironment.lisp
30 lines (26 loc) · 1.25 KB
/
environment.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
;;;; This file exposes some environment related functions to the Lisp
;;;; runtime, so that we can manage things like Lisp threads, signals,
;;;; and entry into the Lisp debugger for interaction with foreign
;;;; code.
(in-package #:sbcl-librarian)
(defun enable-debugger ()
(setq sb-ext:*invoke-debugger-hook*
(lambda (condition old-hook)
(let ((sb-ext:*invoke-debugger-hook* nil))
;; This is a huge hack messing with the internals of the
;; session thread state in SBCL. SBCL doesn't know that
;; foreign callback threads could ever want to hijack the
;; main thread and become interactive themselves for
;; debugging. The session data-structure is also usually
;; protected by a lock, which we're not doing here because
;; this is a hack.
(push sb-thread::*current-thread*
(sb-thread::session-interactive-threads sb-thread::*session*))
(invoke-debugger condition))))
(sb-ext:enable-debugger))
(defun disable-debugger ()
(sb-ext:disable-debugger))
(define-api environment (:function-prefix "")
(:function
(("lisp_enable_debugger" enable-debugger) :void ())
(("lisp_disable_debugger" disable-debugger) :void ())))