| 1 |
;;; systemtap-mode.el --- A mode for SystemTap |
| 2 |
|
| 3 |
;; Copyright (C) 2008, 2020 Tomoki Sekiyama <[email protected]> |
| 4 |
;; Copyright (C) 2012 RĂ¼diger Sonderfeld <[email protected]> |
| 5 |
|
| 6 |
;; Authors: 2008 Tomoki Sekiyama |
| 7 |
;; 2012 RĂ¼diger Sonderfeld |
| 8 |
;; Maintainer: [email protected] |
| 9 |
;; Keywords: tools languages |
| 10 |
;; Version: 0.02 |
| 11 |
;; URL: https://github.com/ruediger/systemtap-mode |
| 12 |
|
| 13 |
;; This file is NOT part of GNU Emacs. |
| 14 |
|
| 15 |
;; This program is free software; you can redistribute it and/or modify |
| 16 |
;; it under the terms of the GNU General Public License as published by |
| 17 |
;; the Free Software Foundation; either version 2 of the License, or |
| 18 |
;; (at your option) any later version. |
| 19 |
;; |
| 20 |
;; This program is distributed in the hope that it will be useful, |
| 21 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
;; GNU General Public License for more details. |
| 24 |
;; |
| 25 |
;; You should have received a copy of the GNU General Public License |
| 26 |
;; along with this program; see the file COPYING. If not, write to |
| 27 |
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 28 |
;; Boston, MA 02111-1307, USA. |
| 29 |
|
| 30 |
;;; Commentary: |
| 31 |
|
| 32 |
;; This code is based on the original systemtap-mode.el written by |
| 33 |
;; Tomoki Sekiyama. It can be found at |
| 34 |
;; http://coderepos.org/share/browser/lang/elisp/systemtap-mode/systemtap-mode.el?format=txt |
| 35 |
|
| 36 |
;; TODO: |
| 37 |
;; - indent embedded-C %{ ... %} correctly |
| 38 |
;; - add parameter for indentation |
| 39 |
;; - ... |
| 40 |
|
| 41 |
;;; Code: |
| 42 |
|
| 43 |
(defconst systemtap-mode-version "0.02" |
| 44 |
"SystemTap Mode version number.") |
| 45 |
|
| 46 |
(defgroup systemtap-mode nil |
| 47 |
"A mode for SystemTap." |
| 48 |
:prefix "systemtap-" |
| 49 |
:group 'tools |
| 50 |
:group 'languages) |
| 51 |
|
| 52 |
(require 'cc-mode) |
| 53 |
(require 'cc-awk) |
| 54 |
(eval-when-compile |
| 55 |
(require 'cc-langs) |
| 56 |
(require 'cc-fonts) |
| 57 |
(require 'cl-lib)) |
| 58 |
|
| 59 |
(eval-and-compile |
| 60 |
(c-add-language 'systemtap-mode 'awk-mode)) |
| 61 |
|
| 62 |
;; Syntax definitions for SystemTap |
| 63 |
(c-lang-defconst c-primitive-type-kwds |
| 64 |
systemtap '("string" "long" "global" "private")) |
| 65 |
|
| 66 |
(c-lang-defconst c-modifier-kwds |
| 67 |
systemtap (append '("probe" "function") (c-lang-const c-modifier-kwds))) |
| 68 |
|
| 69 |
(c-lang-defconst c-block-stmt-2-kwds |
| 70 |
systemtap '("else" "for" "foreach" "if" "while")) |
| 71 |
|
| 72 |
(c-lang-defconst c-simple-stmt-kwds |
| 73 |
systemtap '("break" "continue" "delete" "next" "return")) |
| 74 |
|
| 75 |
(c-lang-defconst c-identifier-syntax-modifications |
| 76 |
systemtap '((?. . "_") (?' . "."))) |
| 77 |
|
| 78 |
(defcustom systemtap-font-lock-extra-types nil |
| 79 |
"Font-lock extra types for SystemTap mode." |
| 80 |
:group 'systemtap-mode) |
| 81 |
|
| 82 |
(defconst systemtap-font-lock-keywords-1 (c-lang-const c-matchers-1 systemtap) |
| 83 |
"Minimal highlighting for SystemTap mode.") |
| 84 |
|
| 85 |
(defconst systemtap-font-lock-keywords-2 (c-lang-const c-matchers-2 systemtap) |
| 86 |
"Fast normal highlighting for SystemTap mode.") |
| 87 |
|
| 88 |
(defconst systemtap-font-lock-keywords-3 (c-lang-const c-matchers-3 systemtap) |
| 89 |
"Accurate normal highlighting for SystemTap mode.") |
| 90 |
|
| 91 |
(defvar systemtap-font-lock-keywords systemtap-font-lock-keywords-3 |
| 92 |
"Default expressions to highlight in SystemTap mode.") |
| 93 |
|
| 94 |
(defvar systemtap-mode-syntax-table nil |
| 95 |
"Syntax table used in systemtap-mode buffers.") |
| 96 |
(unless systemtap-mode-syntax-table |
| 97 |
(setq systemtap-mode-syntax-table |
| 98 |
(funcall (c-lang-const c-make-mode-syntax-table systemtap)))) |
| 99 |
|
| 100 |
(defvar systemtap-mode-abbrev-table nil |
| 101 |
"Abbreviation table used in systemtap-mode buffers.") |
| 102 |
|
| 103 |
(defvar systemtap-mode-map |
| 104 |
(let ((map (c-make-inherited-keymap))) |
| 105 |
(define-key map "\C-ce" 'systemtap-execute-script) |
| 106 |
(define-key map "\C-cc" 'systemtap-interrupt-script) |
| 107 |
map) |
| 108 |
"Keymap used in systemtap-mode buffers.") |
| 109 |
|
| 110 |
(easy-menu-define systemtap-menu systemtap-mode-map "SystemTap Mode Commands" |
| 111 |
(cons "SystemTap" |
| 112 |
(append |
| 113 |
'(["Execute This Script" systemtap-execute-script t] |
| 114 |
["Interrupt Execution of Script" systemtap-interrupt-script (get-process "systemtap-script")] |
| 115 |
"----") |
| 116 |
(c-lang-const c-mode-menu systemtap)))) |
| 117 |
|
| 118 |
;; Execution function of Current Script |
| 119 |
(defvar systemtap-buffer-name "*SystemTap*" |
| 120 |
"Name of the SystemTap execution buffer.") |
| 121 |
|
| 122 |
(defcustom systemtap-stap-program "stap" |
| 123 |
"SystemTap's stap program to execute scripts." |
| 124 |
:type 'file |
| 125 |
:group 'systemtap-mode) |
| 126 |
|
| 127 |
(defcustom systemtap-stap-options '("-v") |
| 128 |
"A list of options to give to stap." |
| 129 |
:type '(repeat string) |
| 130 |
:group 'systemtap-mode) |
| 131 |
|
| 132 |
(defun systemtap-execute-script () |
| 133 |
"Execute current SystemTap script." |
| 134 |
(interactive) |
| 135 |
(when (get-buffer systemtap-buffer-name) |
| 136 |
(kill-buffer systemtap-buffer-name)) |
| 137 |
(get-buffer-create systemtap-buffer-name) |
| 138 |
(display-buffer systemtap-buffer-name) |
| 139 |
(let* ((file-name (buffer-file-name)) |
| 140 |
(options (append systemtap-stap-options (list file-name)))) |
| 141 |
(apply #'start-process "systemtap-script" systemtap-buffer-name |
| 142 |
systemtap-stap-program options)) |
| 143 |
(message "Execution of SystemTap script started.")) |
| 144 |
|
| 145 |
(defun systemtap-interrupt-script () |
| 146 |
"Interrupt running SystemTap script." |
| 147 |
(interactive) |
| 148 |
(interrupt-process "systemtap-script") |
| 149 |
(message "SystemTap script is interrupted.")) |
| 150 |
|
| 151 |
(add-to-list 'auto-mode-alist '("\\.stp\\'" . systemtap-mode)) |
| 152 |
|
| 153 |
(add-to-list 'auto-mode-alist '("\\.stpm\\'" . systemtap-mode)) |
| 154 |
|
| 155 |
(require 'simple) |
| 156 |
|
| 157 |
(define-derived-mode systemtap-mode prog-mode "SystemTap" |
| 158 |
"Major mode for editing SystemTap scripts. |
| 159 |
|
| 160 |
Key bindings: |
| 161 |
\\{systemtap-mode-map}" |
| 162 |
:group 'systemtap |
| 163 |
:syntax-table systemtap-mode-syntax-table |
| 164 |
:abbrev-table systemtap-mode-abbrev-table |
| 165 |
(c-initialize-cc-mode t) |
| 166 |
(use-local-map systemtap-mode-map) |
| 167 |
(c-init-language-vars systemtap-mode) |
| 168 |
(c-common-init 'systemtap-mode) |
| 169 |
(easy-menu-add systemtap-menu) |
| 170 |
(c-run-mode-hooks 'c-mode-common-hook) |
| 171 |
(set (make-local-variable 'comment-start) "#") |
| 172 |
(c-update-modeline)) |
| 173 |
|
| 174 |
(provide 'systemtap-mode) |
| 175 |
|
| 176 |
;;; systemtap-mode.el ends here |