/
debug.lisp
43 lines (37 loc) · 1.49 KB
/
debug.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
31
32
33
34
35
36
37
38
39
40
41
42
43
;;;; Created on 2011-05-26 21:56:39
(in-package :mvc)
(defun kill-all-debugging-threads ()
"Used for destroy all debugging threads"
(bt:with-lock-held (*debugging-threads-lock*)
(dolist (thread *debugging-threads*)
(when (ignore-errors
(bt:destroy-thread thread)
t)
(setf *debugging-threads*
(remove thread *debugging-threads*))))))
(defun debug-mode-on ()
"Enable debug mode"
(setf *catch-errors-p* nil))
(defun debug-mode-off (&optional (kill-debugging-threads t))
"Turn off debug mode"
(setf *catch-errors-p* t)
(when kill-debugging-threads
(kill-all-debugging-threads)))
(defun maybe-invoke-debugger (condition)
(cond
((null *catch-errors-p*)
(when (< (length *debugging-threads*) *max-debugging-threads*)
(let ((thread (bt:current-thread)))
(bt:with-lock-held (*debugging-threads-lock*)
(push thread *debugging-threads*))
(unwind-protect
(invoke-debugger condition)
(bt:with-lock-held (*debugging-threads-lock*)
(setf *debugging-threads*
(remove thread *debugging-threads*)))))))
(t (hunchentoot:maybe-invoke-debugger condition))))
(defun after-close-swank-connection (connection)
"Turns off debug mode and destroy debugging threads after closing the connection with the swank-server"
(declare (ignore connection))
(debug-mode-off t))
#+swank (swank::add-hook swank::*connection-closed-hook* 'after-close-swank-connection)