help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Executing Emacs commands when a gdb breakpoint is hit


From: Skip Montanaro
Subject: Re: Executing Emacs commands when a gdb breakpoint is hit
Date: Wed, 22 Jan 2020 07:48:17 -0600

>
> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]