Fix RELOC_FOR_GLOBAL_SYMBOLS macro so that it can cope with user defined symbols...
[binutils-gdb.git] / gdb / complaints.h
blob995c35e0ab07f3d9d735502d7c266fbd0996aefc
1 /* Definitions for complaint handling during symbol reading in GDB.
3 Copyright (C) 1990-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
21 #if !defined (COMPLAINTS_H)
22 #define COMPLAINTS_H
24 #include <unordered_set>
26 /* Helper for complaint. */
27 extern void complaint_internal (const char *fmt, ...)
28 ATTRIBUTE_PRINTF (1, 2);
30 /* This controls whether complaints are emitted. */
32 extern int stop_whining;
34 /* Return true if complaints are enabled. This can be used to guard code
35 that is used only to decide whether to issue a complaint. */
37 static inline bool
38 have_complaint ()
40 return stop_whining > 0;
43 /* Register a complaint. This is a macro around complaint_internal to
44 avoid computing complaint's arguments when complaints are disabled.
45 Running FMT via gettext [i.e., _(FMT)] can be quite expensive, for
46 example. */
47 #define complaint(FMT, ...) \
48 do \
49 { \
50 if (have_complaint ()) \
51 complaint_internal (FMT, ##__VA_ARGS__); \
52 } \
53 while (0)
55 /* Clear out / initialize all complaint counters that have ever been
56 incremented. */
58 extern void clear_complaints ();
60 /* Type of collected complaints. */
62 typedef std::unordered_set<std::string> complaint_collection;
64 /* A class that can handle calls to complaint from multiple threads.
65 When this is instantiated, it hooks into the complaint mechanism,
66 so the 'complaint' macro can continue to be used. It collects all
67 the complaints (and warnings) emitted while it is installed, and
68 these can be retrieved before the object is destroyed. This is
69 intended for use from worker threads (though it will also work on
70 the main thread). Messages can be re-emitted on the main thread
71 using re_emit_complaints, see below. */
73 class complaint_interceptor final : public warning_hook_handler_type
75 public:
77 complaint_interceptor ();
78 ~complaint_interceptor () = default;
80 DISABLE_COPY_AND_ASSIGN (complaint_interceptor);
82 complaint_collection &&release ()
84 return std::move (m_complaints);
87 private:
89 /* The issued complaints. */
90 complaint_collection m_complaints;
92 /* The saved value of g_complaint_interceptor. */
93 scoped_restore_tmpl<complaint_interceptor *> m_saved_complaint_interceptor;
95 /* A helper function that is used by the 'complaint' implementation
96 to issue a complaint. */
97 void warn (const char *, va_list) override
98 ATTRIBUTE_PRINTF (2, 0);
100 /* This object. Used by the static callback function. */
101 static thread_local complaint_interceptor *g_complaint_interceptor;
103 /* Object to initialise the warning hook. */
104 scoped_restore_warning_hook m_saved_warning_hook;
107 /* Re-emit complaints that were collected by complaint_interceptor.
108 This can only be called on the main thread. */
110 extern void re_emit_complaints (const complaint_collection &);
112 #endif /* !defined (COMPLAINTS_H) */