all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Lute Kamstra <Lute.Kamstra.lists@xs4all.nl>
Subject: Re: Lisp debugger problems.
Date: Mon, 28 Feb 2005 10:44:41 +0100	[thread overview]
Message-ID: <87hdjxhvcm.fsf@xs4all.nl> (raw)
In-Reply-To: <87u0nxcvn2.fsf@xs4all.nl> (Lute Kamstra's message of "Mon, 28 Feb 2005 02:37:21 +0100")

Lute Kamstra <Lute.Kamstra.lists@xs4all.nl> writes:

[...]

> I investigated this problem a bit more.  It seems that the bug only
> happens when the body of a function contains just one sexp.  For
> example, when I do:
>
>   (defun fun (a) "Docstring." (interactive) (1+ a))
>   (debug-on-entry 'fun)
>   (fun 1)
>
> to enter the debugger and then type j to invoke debugger-jump, then
> the return value is nil (wrong).  But when I do:
>
>   (defun fun (a) "Docstring." (interactive) a (1+ a))
>   (debug-on-entry 'fun)
>   (fun 1)
>
> to enter the debugger and then type j to invoke debugger-jump, then
> the return value is 2 (right).
>
> debug-on-entry inserts (debug 'debug) into the definition of fun:
>
>   (defun fun (a) "Docstring." (interactive) (1+ a))
>   (symbol-function 'fun)
>     => (lambda (a) "Docstring." (interactive) (1+ a))
>   (debug-on-entry 'fun)
>   (symbol-function 'fun)
>     => (lambda (a) "Docstring." (interactive) (debug (quote debug)) (1+ a))
>
> So when fun is called, it invokes the debugger.  Then the debugger
> calls debugger-jump, which changes the definition of fun by removing
> (debug 'debug).  So the definition of fun is changed in the middle
> of a call to fun.  My guess is that this somehow confuses the lisp
> interpreter (in case the body of fun consists of just one sexp) and
> causes it to produce the wrong return value.

What actually happens is that removing (debug 'debug) causes the sexp
immediately following it not to be evaluated.  The following patch
fixes this.  (As a bonus, checking for functions with an empty body is
not necessary anymore.)  Shall I commit it?

Lute.


*** lisp/emacs-lisp/debug.el	27 Feb 2005 09:57:51 -0000	1.67
--- lisp/emacs-lisp/debug.el	28 Feb 2005 09:29:13 -0000
***************
*** 25,31 ****
  
  ;;; Commentary:
  
! ;; This is a major mode documented in the Emacs manual.
  
  ;;; Code:
  
--- 25,31 ----
  
  ;;; Commentary:
  
! ;; This is a major mode documented in the Emacs Lisp manual.
  
  ;;; Code:
  
***************
*** 476,483 ****
  	(insert ? )))
    (beginning-of-line))
  
- 
- 
  (put 'debugger-env-macro 'lisp-indent-function 0)
  (defmacro debugger-env-macro (&rest body)
    "Run BODY in original environment."
--- 476,481 ----
***************
*** 698,719 ****
  	(debug-on-entry-1 function (cdr defn) flag)
        (or (eq (car defn) 'lambda)
  	  (error "%s not user-defined Lisp function" function))
!       (let ((tail (cddr defn)))
  	;; Skip the docstring.
! 	(if (stringp (car tail)) (setq tail (cdr tail)))
  	;; Skip the interactive form.
! 	(if (eq 'interactive (car-safe (car tail))) (setq tail (cdr tail)))
! 	(unless (eq flag (equal (car tail) '(debug 'debug)))
! 	  ;; If the function has no body, add nil as a body element.
! 	  (when (null tail)
! 	    (setq tail (list nil))
! 	    (nconc defn tail))
  	  ;; Add/remove debug statement as needed.
! 	  (if (not flag)
! 	      (progn (setcar tail (cadr tail))
! 		     (setcdr tail (cddr tail)))
! 	    (setcdr tail (cons (car tail) (cdr tail)))
! 	    (setcar tail '(debug 'debug))))
  	defn))))
  
  (defun debugger-list-functions ()
--- 696,711 ----
  	(debug-on-entry-1 function (cdr defn) flag)
        (or (eq (car defn) 'lambda)
  	  (error "%s not user-defined Lisp function" function))
!       (let ((tail (cdr defn)))
  	;; Skip the docstring.
! 	(when (stringp (cadr tail)) (setq tail (cdr tail)))
  	;; Skip the interactive form.
! 	(when (eq 'interactive (car-safe (cadr tail))) (setq tail (cdr tail)))
! 	(unless (eq flag (equal (cadr tail) '(debug 'debug)))
  	  ;; Add/remove debug statement as needed.
! 	  (if flag
! 	      (setcdr tail (cons '(debug 'debug) (cdr tail)))
! 	    (setcdr tail (cddr tail))))
  	defn))))
  
  (defun debugger-list-functions ()

  reply	other threads:[~2005-02-28  9:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-24  0:16 Lisp debugger problems Lute Kamstra
2005-02-28  1:37 ` Lute Kamstra
2005-02-28  9:44   ` Lute Kamstra [this message]
2005-02-28 11:26 ` Richard Stallman
2005-02-28 17:01   ` Lute Kamstra
2005-02-28 18:10     ` Stefan Monnier
2005-03-02 11:22       ` Richard Stallman
2005-03-02 16:15         ` Lute Kamstra
2005-03-03 20:57           ` Richard Stallman
2005-03-01 14:50   ` Lute Kamstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87hdjxhvcm.fsf@xs4all.nl \
    --to=lute.kamstra.lists@xs4all.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.