1;; Verify that preprocessor symbols are defined in config.in. 2 3;; Copyright (C) 2020-2023 Free Software Foundation, Inc. 4;; 5;; This file is part of GDB. 6;; 7;; This program is free software; you can redistribute it and/or modify 8;; it under the terms of the GNU General Public License as published by 9;; the Free Software Foundation; either version 3 of the License, or 10;; (at your option) any later version. 11;; 12;; This program is distributed in the hope that it will be useful, 13;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15;; GNU General Public License for more details. 16;; 17;; You should have received a copy of the GNU General Public License 18;; along with this program. If not, see <http://www.gnu.org/licenses/>. 19 20;; To use: 21;; cd gdbsupport 22;; emacs --script check-defines.el 23 24(require 'cl-lib) 25 26(setq-default case-fold-search nil) 27 28;; The currently recognized macros. 29(defconst check-regexp "\\_<\\(\\(HAVE\\|PTRACE_TYPE\\|SIZEOF\\)_[a-zA-Z0-9_]+\\)\\_>") 30 31(defvar check-seen 0) 32 33;; Whitelist. These are things that have names like autoconf-created 34;; macros, but that are managed directly in the code. 35(put (intern "HAVE_USEFUL_SBRK") :check-ok t) 36(put (intern "HAVE_SOCKETS") :check-ok t) 37(put (intern "HAVE_F_GETFD") :check-ok t) 38(put (intern "HAVE_IS_TRIVIALLY_COPYABLE") :check-ok t) 39(put (intern "HAVE_IS_TRIVIALLY_CONSTRUCTIBLE") :check-ok t) 40(put (intern "HAVE_DOS_BASED_FILE_SYSTEM") :check-ok t) 41 42(defun check-read-config.in (file) 43 (save-excursion 44 (find-file-read-only file) 45 (goto-char (point-min)) 46 (while (re-search-forward "^#undef \\(.+\\)$" nil t) 47 (let ((name (match-string 1))) 48 (put (intern name) :check-ok t))))) 49 50(defun check-one-file (file) 51 (save-excursion 52 (find-file-read-only file) 53 (goto-char (point-min)) 54 (while (re-search-forward check-regexp nil t) 55 (let ((name (match-string 1))) 56 (unless (get (intern name) :check-ok) 57 (save-excursion 58 (goto-char (match-beginning 0)) 59 (cl-incf check-seen) 60 (message "%s:%d:%d: error: name %s not defined" 61 file 62 (line-number-at-pos) 63 (current-column) 64 name))))))) 65 66(defun check-directory (dir) 67 (dolist (file (directory-files dir t "\\.[ch]$")) 68 (check-one-file file))) 69 70(check-read-config.in "config.in") 71(check-read-config.in "../gnulib/config.in") 72(check-directory ".") 73(check-directory "../gdb/nat") 74(check-directory "../gdb/target") 75 76(when (> check-seen 0) 77 (message "%d errors seen" check-seen)) 78