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);
/* 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);
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 ());
/* 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<saved_warning_hook_ftype> m_saved_warning_hook;
-
/* The saved value of g_complaint_interceptor. */
scoped_restore_tmpl<complaint_interceptor *> m_saved_complaint_interceptor;
/* 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.
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 *);
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;
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
}
\f
+/* 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
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<target_terminal::scoped_restore_terminal_state> term_state;
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<warning_hook_handler> 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,