Skip to content

Commit

Permalink
gdb: Add support for detecting deleted breakpoints
Browse files Browse the repository at this point in the history
Added a python event listener that prints a message whenever a
breakpoint is deleted.

The regexp for detecting deleted breakpoints is now applied repeatedly
as long as there are additional matches as the gdb listener writes
one message for each deleted breakpoint.

This should fix realgud#278, realgud#180 and realgud#61.
  • Loading branch information
lrittel committed Jul 12, 2022
1 parent 3c88611 commit 476ed27
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
17 changes: 11 additions & 6 deletions realgud/common/track.el
Original file line number Diff line number Diff line change
Expand Up @@ -658,22 +658,27 @@ of the breakpoints found in command buffer."
(let* ((loc-pat (realgud-cmdbuf-pat "brkpt-del")))
(when loc-pat
(let ((bp-num-group (realgud-loc-pat-num loc-pat))
(loc-regexp (realgud-loc-pat-regexp loc-pat)))
(when (and loc-regexp (string-match loc-regexp text))
(loc-regexp (realgud-loc-pat-regexp loc-pat))
(found-locs nil)
(current-pos 0))
(while (and loc-regexp current-pos (string-match loc-regexp text current-pos))
(let* ((bp-nums-str (match-string bp-num-group text))
(bp-num-strs (split-string bp-nums-str "[^0-9]+" t))
(bp-nums (mapcar #'string-to-number bp-num-strs))
(info realgud-cmdbuf-info)
(all-bps (realgud-cmdbuf-info-bp-list info))
(found-locs nil))
(all-bps (realgud-cmdbuf-info-bp-list info)))
(dolist (loc all-bps)
(when (memq (realgud-loc-num loc) bp-nums)
(push loc found-locs)
;; Remove loc from breakpoint list
(realgud-cmdbuf-info-bp-list=
(remove loc (realgud-cmdbuf-info-bp-list info)))))
;; return the locations
found-locs))))))))
(setq current-pos (match-end 0))))
;; Match-end returns 0 when the whole string was matched.
;; Setting current-pos to nil exits the loop
(if (= current-pos 0) (setq current-pos nil))
;; return the locations
found-locs))))))

(defun realgud-track-bp-enable-disable(text loc-pat enable? &optional cmdbuf)
"Do regular-expression matching see if a breakpoint has been enabled or disabled inside
Expand Down
3 changes: 3 additions & 0 deletions realgud/debugger/gdb/gdb.el
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ fringe and marginal icons.
;; if a relative path is supplied to gcc, gdb will display the relative path
;; tripping up realgud, causing it to ask if you want to blacklist the file.
(realgud-command "set filename-display absolute" nil nil nil)
;; gdb doesn't print a confirmation that a breakpoint was deleted successfully by default.
;; This event listener adds a status message for every deleted breakpoint.
(realgud-command "python gdb.events.breakpoint_deleted.connect(lambda b: print(f\"Deleted breakpoint {b.number}\"))" nil nil nil)
)))
)
))
Expand Down
5 changes: 4 additions & 1 deletion realgud/debugger/gdb/init.el
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ realgud-loc-pat struct")
;; response.
;; For example:
;; Deleted breakpoint 1
;; Deleted breakpoint 1 Deleted breakpoint 1
;; Deleted breakpoints 1 2 3 4
;; The event listener seems to trigger twice when a breakpoint is deleted using the
;; clear command. The regexp works around this by allowing one repetition of the match.
(setf (gethash "brkpt-del" realgud:gdb-pat-hash)
(make-realgud-loc-pat
:regexp "^Deleted breakpoints? \\(\\([0-9]+ *\\)+\\)\n"
:regexp "^\\(?:Deleted breakpoints? \\(\\([0-9]+ *\\)+\\) *\\)\\{1,2\\}\n"
:num 1))

(defconst realgud:gdb-frame-start-regexp
Expand Down

0 comments on commit 476ed27

Please sign in to comment.