aboutsummaryrefslogtreecommitdiff
path: root/gdb/make-init-c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2025-05-22 11:54:16 -0600
committerTom Tromey <tromey@adacore.com>2025-06-26 06:15:59 -0600
commit5fe70629ceafc157d896adec7799a8888d51dd6b (patch)
treed256c85b7b1dd9961bde24979bd9148a262c16f1 /gdb/make-init-c
parentcdf176bebcf2466b1e921d0e50e405b6e5994208 (diff)
downloadbinutils-5fe70629ceafc157d896adec7799a8888d51dd6b.zip
binutils-5fe70629ceafc157d896adec7799a8888d51dd6b.tar.gz
binutils-5fe70629ceafc157d896adec7799a8888d51dd6b.tar.bz2
Change file initialization to use INIT_GDB_FILE macro
This patch introduces a new macro, INIT_GDB_FILE. This is used to replace the current "_initialize_" idiom when introducing a per-file initialization function. That is, rather than write: void _initialize_something (); void _initialize_something () { ... } ... now you would write: INIT_GDB_FILE (something) { ... } The macro handles both the declaration and definition of the function. The point of this approach is that it makes it harder to accidentally cause an initializer to be omitted; see commit 2711e475 ("Ensure cooked_index_entry self-tests are run"). Specifically, the regexp now used by make-init-c seems harder to trick. New in v2: un-did some erroneous changes made by the script. The bulk of this patch was written by script. Regression tested on x86-64 Fedora 41.
Diffstat (limited to 'gdb/make-init-c')
-rwxr-xr-xgdb/make-init-c25
1 files changed, 14 insertions, 11 deletions
diff --git a/gdb/make-init-c b/gdb/make-init-c
index 5ea6df5..6834b43 100755
--- a/gdb/make-init-c
+++ b/gdb/make-init-c
@@ -25,12 +25,13 @@
#
# Where SOURCE-FILES is the list of source files to extract init functions from.
#
-# Formatting conventions: The name of the initialization routines must begin
-# with `_initialize_`, must start in column zero, and be followed with exactly
-# ` ()`. For example:
+
+# An initialization function is introduced using the "INIT_GDB_FILE"
+# macro. In ordinary code this expands to a function declaration (to
+# avoid a warning) and then the start of a definition. In the
+# generated init.c, though, it is expanded differently. For example:
#
-# void
-# _initialize_foo ()
+# INIT_GDB_FILE (foo)
# {
# ...
# }
@@ -43,19 +44,21 @@ echo "/* Do not modify this file. */"
echo "/* It is created automatically by the Makefile. */"
echo "#include <algorithm>"
echo ""
-sed -n -e 's/^\(void \|\)\(_initialize_[a-zA-Z0-9_]*\) ()$/\2/p' "$@" | while read -r name; do
- echo "extern initialize_file_ftype $name;"
-done
+echo "#undef INIT_GDB_FILE"
+echo "#define INIT_GDB_FILE(NAME) extern void _initialize_ ## NAME ();"
+grep -h '^[ ]*INIT_GDB_FILE\b' "$@"
echo ""
echo "void initialize_all_files ();"
echo "void"
echo "initialize_all_files ()"
echo "{"
+echo " typedef void initialize_file_ftype (void);"
+echo ""
echo " std::vector<initialize_file_ftype *> functions ="
echo " {"
-sed -n -e 's/^\(void \|\)\(_initialize_[a-zA-Z0-9_]*\) ()$/\2/p' "$@" | while read -r name; do
- echo " $name,"
-done
+echo "#undef INIT_GDB_FILE"
+echo "#define INIT_GDB_FILE(NAME) _initialize_ ## NAME,"
+grep -h '^[ ]*INIT_GDB_FILE\b' "$@"
echo " };"
echo ""
echo " /* If GDB_REVERSE_INIT_FUNCTIONS is set (any value), reverse the"