diff options
| author | Noam Postavsky | 2016-12-02 20:39:10 -0500 |
|---|---|---|
| committer | Noam Postavsky | 2016-12-02 20:44:47 -0500 |
| commit | 88fefc3291060f18503738aaa4e81b98f1970a55 (patch) | |
| tree | f5d3a464be2d1472af9f0b754f8d22e915fc4cec /doc | |
| parent | 0fc4761ca88175c30da7209c9ab1cde788b66a76 (diff) | |
| parent | 56c817837bff3ffef587a9c80d619b9fe4886159 (diff) | |
| download | emacs-88fefc3291060f18503738aaa4e81b98f1970a55.tar.gz emacs-88fefc3291060f18503738aaa4e81b98f1970a55.zip | |
; Merge: Lisp watchpoints (Bug#24923)
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/debugging.texi | 31 | ||||
| -rw-r--r-- | doc/lispref/elisp.texi | 2 | ||||
| -rw-r--r-- | doc/lispref/variables.texi | 61 |
3 files changed, 94 insertions, 0 deletions
diff --git a/doc/lispref/debugging.texi b/doc/lispref/debugging.texi index 6c0908acccb..c80b0f95b37 100644 --- a/doc/lispref/debugging.texi +++ b/doc/lispref/debugging.texi | |||
| @@ -69,6 +69,7 @@ debugger recursively. @xref{Recursive Editing}. | |||
| 69 | * Error Debugging:: Entering the debugger when an error happens. | 69 | * Error Debugging:: Entering the debugger when an error happens. |
| 70 | * Infinite Loops:: Stopping and debugging a program that doesn't exit. | 70 | * Infinite Loops:: Stopping and debugging a program that doesn't exit. |
| 71 | * Function Debugging:: Entering it when a certain function is called. | 71 | * Function Debugging:: Entering it when a certain function is called. |
| 72 | * Variable Debugging:: Entering it when a variable is modified. | ||
| 72 | * Explicit Debug:: Entering it at a certain point in the program. | 73 | * Explicit Debug:: Entering it at a certain point in the program. |
| 73 | * Using Debugger:: What the debugger does; what you see while in it. | 74 | * Using Debugger:: What the debugger does; what you see while in it. |
| 74 | * Debugger Commands:: Commands used while in the debugger. | 75 | * Debugger Commands:: Commands used while in the debugger. |
| @@ -290,6 +291,36 @@ Calling @code{cancel-debug-on-entry} does nothing to a function which is | |||
| 290 | not currently set up to break on entry. | 291 | not currently set up to break on entry. |
| 291 | @end deffn | 292 | @end deffn |
| 292 | 293 | ||
| 294 | @node Variable Debugging | ||
| 295 | @subsection Entering the debugger when a variable is modified | ||
| 296 | @cindex variable write debugging | ||
| 297 | @cindex debugging changes to variables | ||
| 298 | |||
| 299 | Sometimes a problem with a function is due to a wrong setting of a | ||
| 300 | variable. Setting up the debugger to trigger whenever the variable is | ||
| 301 | changed is a quick way to find the origin of the setting. | ||
| 302 | |||
| 303 | @deffn Command debug-on-variable-change variable | ||
| 304 | This function arranges for the debugger to be called whenever | ||
| 305 | @var{variable} is modified. | ||
| 306 | |||
| 307 | It is implemented using the watchpoint mechanism, so it inherits the | ||
| 308 | same characteristics and limitations: all aliases of @var{variable} | ||
| 309 | will be watched together, only dynamic variables can be watched, and | ||
| 310 | changes to the objects referenced by variables are not detected. For | ||
| 311 | details, see @ref{Watching Variables}. | ||
| 312 | @end deffn | ||
| 313 | |||
| 314 | @deffn Command cancel-debug-on-variable-change &optional variable | ||
| 315 | This function undoes the effect of @code{debug-on-variable-change} on | ||
| 316 | @var{variable}. When called interactively, it prompts for | ||
| 317 | @var{variable} in the minibuffer. If @var{variable} is omitted or | ||
| 318 | @code{nil}, it cancels break-on-change for all variables. Calling | ||
| 319 | @code{cancel-debug-on-variable-change} does nothing to a variable | ||
| 320 | which is not currently set up to break on change. | ||
| 321 | @end deffn | ||
| 322 | |||
| 323 | |||
| 293 | @node Explicit Debug | 324 | @node Explicit Debug |
| 294 | @subsection Explicit Entry to the Debugger | 325 | @subsection Explicit Entry to the Debugger |
| 295 | @cindex debugger, explicit entry | 326 | @cindex debugger, explicit entry |
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi index 708bd9c3094..6983ab77c63 100644 --- a/doc/lispref/elisp.texi +++ b/doc/lispref/elisp.texi | |||
| @@ -498,6 +498,7 @@ Variables | |||
| 498 | * Accessing Variables:: Examining values of variables whose names | 498 | * Accessing Variables:: Examining values of variables whose names |
| 499 | are known only at run time. | 499 | are known only at run time. |
| 500 | * Setting Variables:: Storing new values in variables. | 500 | * Setting Variables:: Storing new values in variables. |
| 501 | * Watching Variables:: Running a function when a variable is changed. | ||
| 501 | * Variable Scoping:: How Lisp chooses among local and global values. | 502 | * Variable Scoping:: How Lisp chooses among local and global values. |
| 502 | * Buffer-Local Variables:: Variable values in effect only in one buffer. | 503 | * Buffer-Local Variables:: Variable values in effect only in one buffer. |
| 503 | * File Local Variables:: Handling local variable lists in files. | 504 | * File Local Variables:: Handling local variable lists in files. |
| @@ -642,6 +643,7 @@ The Lisp Debugger | |||
| 642 | * Error Debugging:: Entering the debugger when an error happens. | 643 | * Error Debugging:: Entering the debugger when an error happens. |
| 643 | * Infinite Loops:: Stopping and debugging a program that doesn't exit. | 644 | * Infinite Loops:: Stopping and debugging a program that doesn't exit. |
| 644 | * Function Debugging:: Entering it when a certain function is called. | 645 | * Function Debugging:: Entering it when a certain function is called. |
| 646 | * Variable Debugging:: Entering it when a variable is modified. | ||
| 645 | * Explicit Debug:: Entering it at a certain point in the program. | 647 | * Explicit Debug:: Entering it at a certain point in the program. |
| 646 | * Using Debugger:: What the debugger does; what you see while in it. | 648 | * Using Debugger:: What the debugger does; what you see while in it. |
| 647 | * Debugger Commands:: Commands used while in the debugger. | 649 | * Debugger Commands:: Commands used while in the debugger. |
diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi index 4f2274f81a0..d777e4da509 100644 --- a/doc/lispref/variables.texi +++ b/doc/lispref/variables.texi | |||
| @@ -34,6 +34,7 @@ representing the variable. | |||
| 34 | * Accessing Variables:: Examining values of variables whose names | 34 | * Accessing Variables:: Examining values of variables whose names |
| 35 | are known only at run time. | 35 | are known only at run time. |
| 36 | * Setting Variables:: Storing new values in variables. | 36 | * Setting Variables:: Storing new values in variables. |
| 37 | * Watching Variables:: Running a function when a variable is changed. | ||
| 37 | * Variable Scoping:: How Lisp chooses among local and global values. | 38 | * Variable Scoping:: How Lisp chooses among local and global values. |
| 38 | * Buffer-Local Variables:: Variable values in effect only in one buffer. | 39 | * Buffer-Local Variables:: Variable values in effect only in one buffer. |
| 39 | * File Local Variables:: Handling local variable lists in files. | 40 | * File Local Variables:: Handling local variable lists in files. |
| @@ -766,6 +767,66 @@ error is signaled. | |||
| 766 | @end example | 767 | @end example |
| 767 | @end defun | 768 | @end defun |
| 768 | 769 | ||
| 770 | @node Watching Variables | ||
| 771 | @section Running a function when a variable is changed. | ||
| 772 | @cindex variable watchpoints | ||
| 773 | @cindex watchpoints for Lisp variables | ||
| 774 | |||
| 775 | It is sometimes useful to take some action when a variable changes its | ||
| 776 | value. The watchpoint facility provides the means to do so. Some | ||
| 777 | possible uses for this feature include keeping display in sync with | ||
| 778 | variable settings, and invoking the debugger to track down unexpected | ||
| 779 | changes to variables (@pxref{Variable Debugging}). | ||
| 780 | |||
| 781 | The following functions may be used to manipulate and query the watch | ||
| 782 | functions for a variable. | ||
| 783 | |||
| 784 | @defun add-variable-watcher symbol watch-function | ||
| 785 | This function arranges for @var{watch-function} to be called whenever | ||
| 786 | @var{symbol} is modified. Modifications through aliases | ||
| 787 | (@pxref{Variable Aliases}) will have the same effect. | ||
| 788 | |||
| 789 | @var{watch-function} will be called with 4 arguments: (@var{symbol} | ||
| 790 | @var{newval} @var{operation} @var{where}). | ||
| 791 | |||
| 792 | @var{symbol} is the variable being changed. | ||
| 793 | @var{newval} is the value it will be changed to. | ||
| 794 | @var{operation} is a symbol representing the kind of change, one of: | ||
| 795 | `set', `let', `unlet', `makunbound', and `defvaralias'. | ||
| 796 | @var{where} is a buffer if the buffer-local value of the variable is | ||
| 797 | being changed, nil otherwise. | ||
| 798 | @end defun | ||
| 799 | |||
| 800 | @defun remove-variable-watch symbol watch-function | ||
| 801 | This function removes @var{watch-function} from @var{symbol}'s list of | ||
| 802 | watchers. | ||
| 803 | @end defun | ||
| 804 | |||
| 805 | @defun get-variable-watchers symbol | ||
| 806 | This function returns the list of @var{symbol}'s active watcher | ||
| 807 | functions. | ||
| 808 | @end defun | ||
| 809 | |||
| 810 | @subsection Limitations | ||
| 811 | |||
| 812 | There are a couple of ways in which a variable could be modifed (or at | ||
| 813 | least appear to be modified) without triggering a watchpoint. | ||
| 814 | |||
| 815 | Since watchpoints are attached to symbols, modification to the | ||
| 816 | objects contained within variables (e.g., by a list modification | ||
| 817 | function @pxref{Modifying Lists}) is not caught by this mechanism. | ||
| 818 | |||
| 819 | Additionally, C code can modify the value of variables directly, | ||
| 820 | bypassing the watchpoint mechanism. | ||
| 821 | |||
| 822 | A minor limitation of this feature, again because it targets symbols, | ||
| 823 | is that only variables of dynamic scope may be watched. This poses | ||
| 824 | little difficulty, since modifications to lexical variables can be | ||
| 825 | discovered easily by inspecting the code within the scope of the | ||
| 826 | variable (unlike dynamic variables, which can be modified by any code | ||
| 827 | at all, @pxref{Variable Scoping}). | ||
| 828 | |||
| 829 | |||
| 769 | @node Variable Scoping | 830 | @node Variable Scoping |
| 770 | @section Scoping Rules for Variable Bindings | 831 | @section Scoping Rules for Variable Bindings |
| 771 | @cindex scoping rule | 832 | @cindex scoping rule |