unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Skip Montanaro <skip.montanaro@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Help GNU Emacs <help-gnu-emacs@gnu.org>
Subject: Re: Executing Emacs commands when a gdb breakpoint is hit
Date: Wed, 22 Jan 2020 07:48:17 -0600	[thread overview]
Message-ID: <CANc-5UziODCMhvwq8poxqmpFLNQ-gmKq3VemJg1WUP-jAzh1Qw@mail.gmail.com> (raw)
In-Reply-To: <83o8uwvekv.fsf@gnu.org>

>
> Upgrade to a newer Emacs.  This problem was fixed in Emacs 26.2.  A
> workaround is to use "commands" instead of its short form "comm".
>

Thanks. That's taken care of. Now, is it possible to trigger an Emacs Lisp
function of some sort when a GDB breakpoint is hit? I see the
gdb-stopped-functions variable. This simple function seems to execute when
my compiler_set_lineno breakpoint is hit:

(defun stopped (reason)
  (message "%s" reason))

(setq gdb-stopped-functions '(stopped))

I worked out a more complex stopped function which was supposed to get the
filename and current line number of the Python file being compiled. I was
able to execute the bits interactively to get the values I needed.
Unfortunately, the function is called before *gud-python* has a prompt
(it's not really ready for input). This is the key function which plucks
expression values from the *gud-python* session:

(defun get-gdb-value (expr)
  "evaluate EXPR in *gud-python* buffer and return as a string"
  (with-current-buffer "*gud-python*"
    (save-excursion
      (goto-char (point-max))
      (insert (concat "print " expr))
      (comint-send-input)
      (goto-char (point-max))
      (forward-line -1)
      (move-beginning-of-line nil)
      (search-forward " = '")
      (push-mark)
      (search-forward "'")
      (backward-char 1)
      (buffer-substring-no-properties (mark) (point))
      (pop-mark))))

It's called from my registered stop function like so:

    ...
     (let ((fname (get-gdb-value "c->c_filename"))
            (lineno (string-to-number (get-gdb-value "c->u->u_lineno")))
    ...

I tried sticking in a short sleep, but that didn't help. Is there a way to
force the *gud-python* to be ready for user input before calling
get-gdb-value?

Thanks,

Skip


  reply	other threads:[~2020-01-22 13:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-21 18:02 Executing Emacs commands when a gdb breakpoint is hit Skip Montanaro
2020-01-21 18:39 ` Eli Zaretskii
2020-01-22 13:48   ` Skip Montanaro [this message]
2020-01-22 17:04     ` Eli Zaretskii
2020-01-22 19:55       ` otadmor .
2020-01-22 21:07       ` Skip Montanaro
2020-01-23 14:45         ` Eli Zaretskii
2020-01-23 21:00           ` Skip Montanaro
2020-01-24  8:01             ` Eli Zaretskii
2020-04-07 20:21               ` otadmor .

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=CANc-5UziODCMhvwq8poxqmpFLNQ-gmKq3VemJg1WUP-jAzh1Qw@mail.gmail.com \
    --to=skip.montanaro@gmail.com \
    --cc=eliz@gnu.org \
    --cc=help-gnu-emacs@gnu.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).