From 5fe70629ceafc157d896adec7799a8888d51dd6b Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 22 May 2025 11:54:16 -0600 Subject: 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. --- gdb/make-init-c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'gdb/make-init-c') 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 " 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 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" -- cgit v1.1