3

I'm trying to debug the infamous Unrecognized entry in undo list undo-tree-canary, and after having Emacs debugger triggered on error, I want to move back and forth between stack frames and to examine state of variables. Sort of what frame 3 command in gdb would do.

Unfortunately I haven't found this question asked before, and searching through Emacs documentation haven't been fruitful for me.

Hi-Angel
  • 525
  • 6
  • 18

1 Answers1

4

Simply move point in the *Backtrace* buffer to the corresponding line of the frame you're interested in.

examine state of variables

Then press v (debugger-toggle-locals) to show local variables in the frame, or e (debugger-eval-expression) to evaluate an expression in the frame's context. Note that you won't have access to lexical variables when the function is byte compiled.

npostavs
  • 9,033
  • 1
  • 21
  • 53
  • Doesn't seem to work. For example, the trace shows values of arguments that `primitive-undo` was called with, in particular "list" arg is set to "(undo-tree-canary)" text. But when I move point in \*Backtrace\* buffer over this line and evaluate `list` expecting to see its value, I get "void variable list". Same happens if I additionally press enter over the function, thus getting redirected to the source. The source of `simple.el` isn't byte-compiled for me. – Hi-Angel Jun 09 '19 at 16:32
  • I just figured I should use `e` to inspect variables in \*Backtrace\* buffer *(I've used `M-:` instead)*. Still, for every possible stack frame, when I evaluate with `e` the argument that the function in frame was called with, I get "void variable", even though I can see value of the argument inside the backtrace. – Hi-Angel Jun 09 '19 at 16:48
  • @Hi-Angel Are you stopping in `primitive-undo` using `debug-on-entry`? I noticed it seems to mess up the frames so the debugger gets a bit confused. – npostavs Jun 09 '19 at 18:15
  • I use `toggle-debug-on-error`, can it have a similar problem? Btw, thanks for the hint about `v`, when I press it over `primitive-undo`, I get only 2 local variables, and none of them are arguments of the function, [screenshot](https://i.imgur.com/f6t6K6d.png). I guess this is a bug in Emacs itself, right? – Hi-Angel Jun 09 '19 at 18:24
  • @Hi-Angel, hmm sort of works for me, I'm seeing the arguments to the function, but I can only evaluate them in the frame below that, [screenshot](https://i.imgur.com/oWYeRRq.png) – npostavs Jun 09 '19 at 18:55
  • @Hi-Angel "The source of simple.el isn't byte-compiled for me" - to be clear, you have to also load `simple.el`; by default you have `simple.elc` loaded which is byte compiled. – npostavs Jun 09 '19 at 18:57
  • Oh, so you was right all that time, about the file being byte-compiled! I was sure this is not the case, because I have `ido-mode` enabled, and when I do `C-x C-f` it seems the ido-mode just skips all files with `.elc` extensions, as if they weren't there. I.e. I was confused into thinking that none of files there has their `.elc` counterpart. Using `(load "simple.el")` made it work. – Hi-Angel Jun 09 '19 at 19:02
  • Thanks @npostavs - the debugger-toggle-locals is an eye-opener. Also works on let bindings etc... – Mark Apr 16 '20 at 09:18