From: Aditya Vidyadhar Kamath Date: Fri, 26 Jan 2024 08:19:52 +0000 (-0600) Subject: Fix AIX build break. X-Git-Tag: gdb-15-branchpoint~1079 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=49346fa79442ba6f0be832c2c5af4360e52f070a;p=thirdparty%2Fbinutils-gdb.git Fix AIX build break. A recent commit broke AIX build. The thread_local type defined functions were being considered a weak symbol and hence while creating the binary these symbols were not visible. This patch is a fix for the same. --- diff --git a/gdb/complaints.c b/gdb/complaints.c index 0c46cd7c84f..496736fe95f 100644 --- a/gdb/complaints.c +++ b/gdb/complaints.c @@ -57,8 +57,9 @@ complaint_internal (const char *fmt, ...) va_start (args, fmt); - if (deprecated_warning_hook) - (*deprecated_warning_hook) (fmt, args); + warning_hook_handler handler = get_warning_hook_handler (); + if (handler != nullptr) + handler (fmt, args); else { gdb_puts (_("During symbol reading: "), gdb_stderr); @@ -84,15 +85,15 @@ thread_local complaint_interceptor *complaint_interceptor::g_complaint_intercept /* See complaints.h. */ complaint_interceptor::complaint_interceptor () - : m_saved_warning_hook (&deprecated_warning_hook, issue_complaint), - m_saved_complaint_interceptor (&g_complaint_interceptor, this) + : m_saved_complaint_interceptor (&g_complaint_interceptor, this), + m_saved_warning_hook (issue_complaint) { } /* A helper that wraps a warning hook. */ static void -wrap_warning_hook (void (*hook) (const char *, va_list), ...) +wrap_warning_hook (warning_hook_handler hook, ...) { va_list args; va_start (args, hook); @@ -109,8 +110,9 @@ re_emit_complaints (const complaint_collection &complaints) for (const std::string &str : complaints) { - if (deprecated_warning_hook) - wrap_warning_hook (deprecated_warning_hook, str.c_str ()); + warning_hook_handler handler = get_warning_hook_handler (); + if (handler != nullptr) + wrap_warning_hook (handler, str.c_str ()); else gdb_printf (gdb_stderr, _("During symbol reading: %s\n"), str.c_str ()); diff --git a/gdb/complaints.h b/gdb/complaints.h index baf10fd7dd7..8ac4c5034ee 100644 --- a/gdb/complaints.h +++ b/gdb/complaints.h @@ -89,11 +89,6 @@ private: /* The issued complaints. */ complaint_collection m_complaints; - typedef void (*saved_warning_hook_ftype) (const char *, va_list); - - /* The saved value of deprecated_warning_hook. */ - scoped_restore_tmpl m_saved_warning_hook; - /* The saved value of g_complaint_interceptor. */ scoped_restore_tmpl m_saved_complaint_interceptor; @@ -104,6 +99,9 @@ private: /* This object. Used by the static callback function. */ static thread_local complaint_interceptor *g_complaint_interceptor; + + /* Object to initialise the warning hook. */ + scoped_restore_warning_hook m_saved_warning_hook; }; /* Re-emit complaints that were collected by complaint_interceptor. diff --git a/gdb/defs.h b/gdb/defs.h index f4664000641..cf471bf5d66 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -562,8 +562,6 @@ extern void (*deprecated_print_frame_info_listing_hook) (struct symtab * s, int noerror); extern int (*deprecated_query_hook) (const char *, va_list) ATTRIBUTE_FPTR_PRINTF(1,0); -extern thread_local void (*deprecated_warning_hook) (const char *, va_list) - ATTRIBUTE_FPTR_PRINTF(1,0); extern void (*deprecated_readline_begin_hook) (const char *, ...) ATTRIBUTE_FPTR_PRINTF_1; extern char *(*deprecated_readline_hook) (const char *); diff --git a/gdb/interps.c b/gdb/interps.c index eddc7f3c871..391fea1da03 100644 --- a/gdb/interps.c +++ b/gdb/interps.c @@ -273,7 +273,6 @@ clear_interpreter_hooks (void) deprecated_print_frame_info_listing_hook = 0; /*print_frame_more_info_hook = 0; */ deprecated_query_hook = 0; - deprecated_warning_hook = 0; deprecated_readline_begin_hook = 0; deprecated_readline_hook = 0; deprecated_readline_end_hook = 0; diff --git a/gdb/top.c b/gdb/top.c index fb15c719564..5114713baa4 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -219,10 +219,6 @@ void (*deprecated_print_frame_info_listing_hook) (struct symtab * s, int (*deprecated_query_hook) (const char *, va_list); -/* Replaces most of warning. */ - -thread_local void (*deprecated_warning_hook) (const char *, va_list); - /* These three functions support getting lines of text from the user. They are used in sequence. First deprecated_readline_begin_hook is called with a text string that might be (for example) a message for diff --git a/gdb/utils.c b/gdb/utils.c index b326033e9ff..702c3f15826 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -128,7 +128,26 @@ show_pagination_enabled (struct ui_file *file, int from_tty, } +/* Warning hook pointer. This has to be 'static' to avoid link + problems with thread-locals on AIX. */ +static thread_local void (*warning_hook) (const char *, va_list); + +/* See utils.h. */ + +warning_hook_handler +get_warning_hook_handler () +{ + return warning_hook; +} + +/* See utils.h. */ + +scoped_restore_warning_hook::scoped_restore_warning_hook + (warning_hook_handler new_handler) + : m_save (make_scoped_restore (&warning_hook, new_handler)) +{ +} /* Print a warning message. The first argument STRING is the warning message, used as an fprintf format string, the second is the @@ -139,8 +158,8 @@ show_pagination_enabled (struct ui_file *file, int from_tty, void vwarning (const char *string, va_list args) { - if (deprecated_warning_hook) - (*deprecated_warning_hook) (string, args); + if (warning_hook != nullptr) + warning_hook (string, args); else { std::optional term_state; diff --git a/gdb/utils.h b/gdb/utils.h index a9d04746b21..7487590902a 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -373,6 +373,23 @@ assign_return_if_changed (T &lval, const T &val) return true; } +/* A function that can be used to intercept warnings. */ +typedef void (*warning_hook_handler) (const char *, va_list); + +/* Set the thread-local warning hook, and restore the old value when + finished. */ +class scoped_restore_warning_hook +{ +public: + explicit scoped_restore_warning_hook (warning_hook_handler new_handler); + +private: + scoped_restore_tmpl m_save; +}; + +/* Return the current warning handler. */ +extern warning_hook_handler get_warning_hook_handler (); + /* In some cases GDB needs to try several different solutions to a problem, if any of the solutions work then as far as the user is concerned the problem is solved, and GDB should continue without warnings. However,