[Kgdb-bugreport] emacs lisp for setting breakpoints
Status: Beta
Brought to you by:
jwessel
From: Ed L C. <ec...@ug...> - 2003-04-14 17:10:43
|
Hi. Emacs users may be interested in this code, since it can save a lot of time if you have several breakpoint locations that you keep having to set every time you start a new debugging session. Instructions are in the comments. Basically, emacs finds markers in the source buffers you have open and generates a list of gdb "break" instructions which it inserts into the current buffer. If a buffer is less recent than the associated file on disk, it stops and complains, so that you have a chance to update the buffer or save it somewhere first. Enjoy! ;;;; breakpoints.el - find marked breakpoints in buffers ;;; Ed L. Cashin releases this version of breakpoints.el into ;;; the public domain without any warranties. ;;; ;;; I noticed I was wasting a lot of time setting breakpoints ;;; at specific lines in files I had open in emacs. These ;;; simple lisp routines find those breakpoints, which it ;;; expects to be two lines below an "elc-break:" mark, and ;;; returns a string of gdb commands. ;;; ;;; do "M-x cmds-breakpoints RET" to insert the gdb commands ;;; into the buffer you're visiting. ;;; ;;; You will have to set bkpt-dbg-files to the right locations ;;; for your files. Also, unless you really want to use "elc-break:" ;;; to mark breakpoints in your kernel source, you'll need to set ;;; bkpt-marker-string too. ;;; (defvar bkpt-dbg-files '("/home/ecashin/kernel/linux-2.4.18-kgdb/mm/memory.c" "/home/ecashin/kernel/linux-2.4.18-kgdb/kernel/fork.c" "/home/ecashin/kernel/linux-2.4.18-kgdb/kernel/dclone.c") "the files I wuv to debug") (defvar bkpt-marker-string "elc-break:" "the string that appears two lines above the breakpoint") ;;; comment this out if not debugging: ;; (setq bkpt-dbg-buffer ;; (get-buffer-create "bkpt-dbg")) (defvar bkpt-dbg-buffer nil "the buffer where debugging info will go (no debugging if nil)") (defun dbgprt (s) (if bkpt-dbg-buffer (with-current-buffer bkpt-dbg-buffer (insert s)))) (defun get-breakpoints-buf (buf) "return list of all breakpoints in BUF as \"filename:lineno\" strings" (with-current-buffer buf (save-excursion (let ((pos) (fname (car (last (split-string buffer-file-name "/+")))) (bpts nil)) (if (not (verify-visited-file-modtime buf)) (error "buffer for %s is obsolete" fname)) (goto-char (point-min)) (while (setq pos (search-forward bkpt-marker-string nil t)) (dbgprt (format "get-breakpoints-buf: in %s found %d" fname pos)) (forward-line 3) (let ((entry (format "break %s:%d" fname (count-lines (point-min) (point))))) (setq bpts (cons entry bpts)))) bpts)))) (defun get-breakpoints () "find all breakpoints in the bkpt-dbg-files" (let ((acc) (count 0)) (mapc (lambda (buf) (let ((fname (with-current-buffer buf buffer-file-name))) (setq count (1+ count)) (if (and fname bkpt-dbg-buffer) (dbgprt (format "%3d: %s\n" count fname))) (if (member fname bkpt-dbg-files) (progn (dbgprt (format "%3d: %s MEMBER\n" count fname)) (setq acc (append (get-breakpoints-buf buf) acc)))))) (buffer-list)) acc)) (defun cmds-breakpoints () "list gdb commands for breakpoints found in open files from bkpt-dbg-files" (interactive) (insert (let ((bpts (get-breakpoints))) (with-temp-buffer (mapc (lambda (s) (insert (concat s "\n"))) bpts) (let ((s (buffer-string))) (if (> (length s) 0) (substring s 0 -1) "")))))) -- --Ed L Cashin | PGP public key: ec...@ug... | http://noserose.net/e/pgp/ |