Subject: bug#63084: 30.0.50; gud: set breakpoint while program is running

From: Eli Zaretskii <[email-masked]>
Date: Mon, 29 May 2023 14:45:22 +0300

> From: TatriX <[email-masked]>
> Date: Sun, 28 May 2023 23:10:21 +0200
> Cc: [email-masked], [email-masked]
> 
> One feature I'm really missing is a variable watcher.
> 
> There's a locals view which is useful sometimes, but gets messy when
> there are handfull of variables in scope.  Then there's a speedbar,
> but as far as I can tell it's impossible to make it into a regular
> window, which means it and cannot participate in my regular emacs
> window workflow, which is sub-optimal.

I'm not sure I understand: how does using Speedbar interfere with your
workflow?

> But the biggest issue with it is that it forgets what was added to
> it on every program restart, making it pretty much unusable for my
> needs.

I'm not sure how can this work otherwise: watchpoints are usually
context-dependent, and are automatically deleted when their component
variables go out of scope.  How would you know when to re-apply
watchpoint settings when you re-run the program?  You must be in the
correct call-stack frame to be able to do that, or else all you get as
an error from GDB.

The way to automate re-application of watchpoints is to create one or
more breakpoints, at suitable locations in the program, and have the
"commands" of those breakpoints insert watchpoints, then continue the
program.  This is usually done in a .gdbinit file (or some other
script file read by GDB), and I'm not sure I understand how you can do
that programmatically, since Emacs is not really aware of GDB
call-stack frames.

> I've played a bit with gdb-mi and managed to make something that
> somewhat works. Please check a screenshot in the attachment.
> 
> I can add variables to watch via the minibuffer. They get updated in
> the *gdb-watch* window through `-data-evaluate-expression` in the
> `gdb-stopped-functions` hook.
> 
> I've also started looking at "GDB/MI Variable Objects"(1) which looks
> like a proper way to add that functionality. But it requires a bit
> more work.

AFAIK, Variable Objects cannot be replacements for watchpoints, since
GDB must actively poll for updates of the values, as opposed to
watchpoints, whose changes cause the program to stop.

> How do you feel about having something similar in gdb-mi?

It would be a useful addition, but I'd expect it to be easily doable
by reusing what we currently have (I'm not sure I understand why we
currently insist on Speedbar for these displays).

Anyway, this should be discussed as a separate feature request, not as
part of this bug report.