aboutsummaryrefslogtreecommitdiff
path: root/emacs
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2024-04-05 09:08:12 +1100
committerYuchen Pei <id@ypei.org>2024-04-05 09:08:12 +1100
commit5e5406f6b1b47b84591ee9dea4233164e9a55fb0 (patch)
tree593e7eb9c4f3b0bc80c2e69718b97735cddad071 /emacs
parent1843b1e8d19acf8688bbb7981d9d75eae4f1378b (diff)
[emacs] improve org backtrace region
Diffstat (limited to 'emacs')
-rw-r--r--emacs/.emacs.d/lisp/my/my-mariadb.el93
-rw-r--r--emacs/.emacs.d/lisp/my/my-prog.el2
2 files changed, 94 insertions, 1 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-mariadb.el b/emacs/.emacs.d/lisp/my/my-mariadb.el
index 355b89e..984cc29 100644
--- a/emacs/.emacs.d/lisp/my/my-mariadb.el
+++ b/emacs/.emacs.d/lisp/my/my-mariadb.el
@@ -154,5 +154,98 @@
(kill-line 1)
)))
+(defvar my-mdev-32524-ids nil "List of ids used.")
+
+(defun my-mdev-32524-make-id ()
+ "Return an id on the current position."
+ (let* ((base
+ (replace-regexp-in-string
+ "::" "_"
+ (replace-regexp-in-string
+ "^\\(SPIDER_\\)?" "SPD_MID_"
+ (upcase (which-function)))))
+ (last-id (car my-mdev-32524-ids))
+ (counter (cdr last-id))
+ (result))
+ (if (equal (car last-id) base)
+ (progn
+ (setq result (format "%s_%d" base (1+ counter)))
+ (push (cons base (1+ counter)) my-mdev-32524-ids))
+ (setq result (format "%s_1" base))
+ (push (cons base 1) my-mdev-32524-ids))
+ result))
+
+(defun my-mdev-32524-replace-ids ()
+ "Replace magic id numbers with enum symbols."
+ (setq my-mdev-32524-ids nil)
+ (dolist (file (directory-files "./storage/spider" t ".\\(cc\\|h\\)$"))
+ ;; Don't do this with spd_malloc.{cc,h}
+ (unless (string-match "spd_malloc" file)
+ (with-current-buffer (find-file-noselect file)
+ (goto-char (point-min))
+ (while (re-search-forward
+ (concat
+ "\\(spider_alloc_calc_mem_init\\|init_calc_mem\\|spider_malloc\\|"
+ "spider_bulk_alloc_mem\\|spider_bulk_malloc\\)"
+ "\\(([^0-9)_]*\\)\\([0-9]+\\)")
+ nil t)
+ (let ((beg (match-beginning 3))
+ (end (match-end 3)))
+ (replace-region-contents beg end #'my-mdev-32524-make-id)))
+ (save-buffer)))))
+
+(defun my-mdev-32524-insert-enum-def ()
+ "Insert enum def at point according to `my-mdev-32524-ids'."
+ (with-current-buffer (find-file-noselect "./storage/spider/spd_include.h")
+ (goto-char (point-min))
+ (re-search-forward "#define.* SPIDER_CONN_META_BUF_LEN")
+ (beginning-of-line 2)
+ (let ((pre
+ "
+/*
+ IDs for spider mem alloc functions, including
+ - spider_alloc_calc_mem_init()
+ - spider_string::init_calc_mem()
+ - spider_malloc()
+ - spider_bulk_alloc_mem()
+ - spider_bulk_malloc()
+ In the format of
+ SPD_MID_<CALLSITE_FUNC_NAME_SANS_SPIDER_PREFIX>_<NO>
+*/
+enum spider_malloc_id {
+ ")
+ (middle (string-join
+ (sort
+ (mapcar
+ (lambda (pair)
+ (format "%s_%d" (car pair) (cdr pair)))
+ my-mdev-32524-ids)
+ #'string<)
+ ",
+ "))
+ (post "
+};
+"))
+ (insert (concat pre middle post))
+ (save-buffer))))
+
+(defun my-mdev-32524 ()
+ "Make changes for MDEV-32524. Assuming we are at the source root."
+ (interactive)
+ (my-mdev-32524-replace-ids)
+ (my-mdev-32524-insert-enum-def))
+
+(defun my-mdev-28861-ps ()
+ "Wrap the current line between --disable_ps_protocol and --enable_ps_protocol"
+ (interactive)
+ (save-excursion
+ (beginning-of-line)
+ (push-mark
+ (save-excursion
+ (beginning-of-line 2)
+ (point))
+ nil t)
+ (tempel-insert 'ps)))
+
(provide 'my-mariadb)
;;; my-mariadb.el ends here
diff --git a/emacs/.emacs.d/lisp/my/my-prog.el b/emacs/.emacs.d/lisp/my/my-prog.el
index bee132f..7e37611 100644
--- a/emacs/.emacs.d/lisp/my/my-prog.el
+++ b/emacs/.emacs.d/lisp/my/my-prog.el
@@ -255,7 +255,7 @@ Conversion is in a similar fashion to `my-org-backtrace-region'."
(with-current-buffer (gdb-stack-buffer-name)
(save-excursion
(goto-char (point-min))
- (while (re-search-forward "^[0-9]+\\ +in \\(.*\\) of \\(.*\\)$" nil t)
+ (while (re-search-forward "^\\ *[0-9]+\\ +in \\(.*\\) of \\(.*\\)$" nil t)
(setq func-name (match-string-no-properties 1)
file-location (match-string-no-properties 2))
(push (concat "[[" file-location "][" func-name "]]") results))))