Preserve breakpoints when Edebug-reinstrumenting functions

* lisp/emacs-lisp/edebug.el (edebug--overlay-breakpoints): New
function (bug#23470).

* lisp/emacs-lisp/seq.el (seq-position): Autoload.
This commit is contained in:
Lars Ingebrigtsen 2019-10-20 13:10:59 +02:00
parent 0cbcd2869e
commit a4e7c15484
3 changed files with 33 additions and 6 deletions

View file

@ -1462,6 +1462,11 @@ the Elisp manual for documentation of the new mode and its commands.
** Edebug
---
*** Re-instrumenting a function with Edebug will now try to preserve
previously-set breakpoints. If the code has changed substantially,
this may not be possible.
+++
*** New command 'edebug-remove-instrumentation.
This command removes Edebug instrumentation from all functions that

View file

@ -1403,15 +1403,33 @@ contains a circular object."
(put edebug-def-name 'edebug
;; A struct or vector would be better here!!
(list edebug-form-begin-marker
nil ; clear breakpoints
(edebug--restore-breakpoints edebug-old-def-name)
edebug-offset-list
edebug-top-window-data
))
edebug-top-window-data))
(funcall edebug-new-definition-function edebug-def-name)
result
)))
(defun edebug--restore-breakpoints (name)
(let* ((data (get name 'edebug))
(offsets (nth 2 data))
(breakpoints (nth 1 data))
(start (nth 0 data))
index)
;; Breakpoints refer to offsets from the start of the function.
;; The start position is a marker, so it'll move around in a
;; similar fashion as the breakpoint markers. If we find a
;; breakpoint marker that refers to an offset (which is a place
;; where breakpoints can be made), then we restore it.
(cl-loop for breakpoint in breakpoints
for marker = (nth 3 breakpoint)
when (and (marker-position marker)
(setq index (seq-position
offsets
(- (marker-position marker) start))))
collect (cons index (cdr breakpoint)))))
(defun edebug-new-definition (def-name)
"Set up DEF-NAME to use Edebug's instrumentation functions."
(put def-name 'edebug-behavior 'edebug)
@ -3166,6 +3184,7 @@ the breakpoint."
(edebug-def-mark (car edebug-data))
(edebug-breakpoints (car (cdr edebug-data)))
(offset-vector (nth 2 edebug-data))
(position (+ edebug-def-mark (aref offset-vector index)))
present)
;; delete it either way
(setq present (assq index edebug-breakpoints))
@ -3176,8 +3195,10 @@ the breakpoint."
(setq edebug-breakpoints
(edebug-sort-alist
(cons
(list index condition temporary)
edebug-breakpoints) '<))
(list index condition temporary
(set-marker (make-marker) position))
edebug-breakpoints)
'<))
(if condition
(message "Breakpoint set in %s with condition: %s"
edebug-def-name condition)
@ -3187,7 +3208,7 @@ the breakpoint."
(message "No breakpoint here")))
(setcar (cdr edebug-data) edebug-breakpoints)
(goto-char (+ edebug-def-mark (aref offset-vector index)))
(goto-char position)
(edebug--overlay-breakpoints edebug-def-name)))))
(defun edebug--overlay-breakpoints (function)

View file

@ -380,6 +380,7 @@ Equality is defined by TESTFN if non-nil or by `equal' if nil."
(and (seq-every-p (lambda (item1) (seq-contains-p sequence2 item1 testfn)) sequence1)
(seq-every-p (lambda (item2) (seq-contains-p sequence1 item2 testfn)) sequence2)))
;;;###autoload
(cl-defgeneric seq-position (sequence elt &optional testfn)
"Return the index of the first element in SEQUENCE that is equal to ELT.
Equality is defined by TESTFN if non-nil or by `equal' if nil."