* How to debug strange value changes of a variable?
@ 2014-12-31 1:03 Marcin Borkowski
2014-12-31 21:09 ` Michael Heerdegen
0 siblings, 1 reply; 4+ messages in thread
From: Marcin Borkowski @ 2014-12-31 1:03 UTC (permalink / raw)
To: Help Gnu Emacs mailing list
Hi there,
a few weeks ago I sent an email to the mu/mu4e mailing list, but got no
answer. (Not that I blame anyone, my problem might just be hard...)
I'd like to debug the issue myself, but have no clue how.
Here's (more or less) what happens: I define a buffer-local variable (by
make-variable-buffer-local), and define its default value (by
setq-default). Then, I have a function which updates its value. (Use
case: I have a few signatures, and I want to be able to cycle between
them. The variable is the number of the signature, which is incremented
with each cycle, and returns to zero when it reaches the length of the
list of signatures.)
Now somehow mu4e (I know it is to blame, since in stock message-mode,
with emacs -Q, and without mu4e, everything works as expected!) messes
around with the value of this variable /after the first increment/ (or
so it seems: it looks like that after some initialization - including
incf'ing that variable from its inital value of -1 - it somehow comes
back to its original (default) value). I'd like to check what function
and when changes its value. Is there any way to use Edebug (or anything
else) for this?
I know about edebug-set-global-break-condition, but this doesn't help a
lot: it can stop when the variable has some value, but does not tell me
/which/ piece of code changed it.
I also know about edebug-backtrace, but I'm not sure whether it will
help me. (I tried it, but it didn't seem to help.)
(A similar question is to find out what calls such-and-such function.
This one seems easier: I can just instrument the said function and then
press `d' in Edebug to see the backtrace. Am I right?)
TIA,
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How to debug strange value changes of a variable?
2014-12-31 1:03 How to debug strange value changes of a variable? Marcin Borkowski
@ 2014-12-31 21:09 ` Michael Heerdegen
2015-01-01 0:23 ` Marcin Borkowski
0 siblings, 1 reply; 4+ messages in thread
From: Michael Heerdegen @ 2014-12-31 21:09 UTC (permalink / raw)
To: help-gnu-emacs
Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:
> Now somehow mu4e (I know it is to blame, since in stock message-mode,
> with emacs -Q, and without mu4e, everything works as expected!) messes
> around with the value of this variable /after the first increment/ (or
> so it seems: it looks like that after some initialization - including
> incf'ing that variable from its inital value of -1 - it somehow comes
> back to its original (default) value). I'd like to check what function
> and when changes its value. Is there any way to use Edebug (or anything
> else) for this?
Are you sure you reference the variable's value with the same buffer
current? That's important of course.
Also note that changing a buffer's major mode removes all buffer local
bindings in the current buffer. That could maybe happen in your case.
> I know about edebug-set-global-break-condition, but this doesn't help a
> lot: it can stop when the variable has some value, but does not tell me
> /which/ piece of code changed it.
Indeed, that is not much helpful in this case, unless you instrument all
code that could be responsible, but that may slow down things
drastically.
Did you define the variable we speak about by yourself? If you did,
normally only your own code should change the variables binding.
> (A similar question is to find out what calls such-and-such function.
> This one seems easier: I can just instrument the said function and then
> press `d' in Edebug to see the backtrace. Am I right?)
Yes, you could. But for such questions, the ordinary debugger is IMHO
much simpler and more helpful (`debug-on-entry'). Load the elisp source
files before using it to avoid seeing byte code in the debugger output.
Michael.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How to debug strange value changes of a variable?
2014-12-31 21:09 ` Michael Heerdegen
@ 2015-01-01 0:23 ` Marcin Borkowski
2015-01-01 14:00 ` Alex Kost
0 siblings, 1 reply; 4+ messages in thread
From: Marcin Borkowski @ 2015-01-01 0:23 UTC (permalink / raw)
To: help-gnu-emacs
On 2014-12-31, at 22:09, Michael Heerdegen <michael_heerdegen@web.de> wrote:
> Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:
>
>> Now somehow mu4e (I know it is to blame, since in stock message-mode,
>> with emacs -Q, and without mu4e, everything works as expected!) messes
>> around with the value of this variable /after the first increment/ (or
>> so it seems: it looks like that after some initialization - including
>> incf'ing that variable from its inital value of -1 - it somehow comes
>> back to its original (default) value). I'd like to check what function
>> and when changes its value. Is there any way to use Edebug (or anything
>> else) for this?
>
> Are you sure you reference the variable's value with the same buffer
> current? That's important of course.
Yes, this I did check.
> Also note that changing a buffer's major mode removes all buffer local
> bindings in the current buffer. That could maybe happen in your case.
Thank you, thank you, thank you, thank you so much! I'd *never* think
of that (I didn't even know that). That was it! The first time my
function was called, the buffer was in fundamental mode; all subsequent
times, it was in mu4e-compose-mode. That should explain everything.
Now the question is: what to do. I could dive into mu4e sources (which
I'm just a bit too lazy to do now). I could just start
mu4e-compose-mode myself in my function and see what happens (I'll try
that). Other than that, I don't have many ideas.
>> I know about edebug-set-global-break-condition, but this doesn't help a
>> lot: it can stop when the variable has some value, but does not tell me
>> /which/ piece of code changed it.
>
> Indeed, that is not much helpful in this case, unless you instrument all
> code that could be responsible, but that may slow down things
> drastically.
What's more, some things might be done by functions written in C...
> Did you define the variable we speak about by yourself? If you did,
> normally only your own code should change the variables binding.
Yes.
>> (A similar question is to find out what calls such-and-such function.
>> This one seems easier: I can just instrument the said function and then
>> press `d' in Edebug to see the backtrace. Am I right?)
>
> Yes, you could. But for such questions, the ordinary debugger is IMHO
> much simpler and more helpful (`debug-on-entry'). Load the elisp source
> files before using it to avoid seeing byte code in the debugger output.
Thanks for the tip!
> Michael.
Thank you again and a happy new year!
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How to debug strange value changes of a variable?
2015-01-01 0:23 ` Marcin Borkowski
@ 2015-01-01 14:00 ` Alex Kost
0 siblings, 0 replies; 4+ messages in thread
From: Alex Kost @ 2015-01-01 14:00 UTC (permalink / raw)
To: Marcin Borkowski; +Cc: help-gnu-emacs
Marcin Borkowski (2015-01-01 03:23 +0300) wrote:
> On 2014-12-31, at 22:09, Michael Heerdegen <michael_heerdegen@web.de> wrote:
[...]
>> Also note that changing a buffer's major mode removes all buffer local
>> bindings in the current buffer. That could maybe happen in your case.
>
> Thank you, thank you, thank you, thank you so much! I'd *never* think
> of that (I didn't even know that). That was it! The first time my
> function was called, the buffer was in fundamental mode; all subsequent
> times, it was in mu4e-compose-mode. That should explain everything.
>
> Now the question is: what to do. I could dive into mu4e sources (which
> I'm just a bit too lazy to do now). I could just start
> mu4e-compose-mode myself in my function and see what happens (I'll try
> that). Other than that, I don't have many ideas.
[...]
I didn't follow the thread but IIUC you want your variable to survive a
changing of a major-mode. If so, you can do it using 'permanent-local'
property:
(put '<your-var> 'permanent-local t)
See (info "(elisp) Creating Buffer-Local").
--
Alex
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-01-01 14:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-31 1:03 How to debug strange value changes of a variable? Marcin Borkowski
2014-12-31 21:09 ` Michael Heerdegen
2015-01-01 0:23 ` Marcin Borkowski
2015-01-01 14:00 ` Alex Kost
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.