2001-11-06 Fred Fish <fnf@redhat.com>
[deliverable/binutils-gdb.git] / gdb / complaints.c
1 /* Support for complaint handling during symbol reading in GDB.
2 Copyright 1990, 1991, 1992, 1993, 1995, 1998, 1999, 2000
3 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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 2 of the License, or
10 (at your option) any later version.
11
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.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 #include "defs.h"
23 #include "complaints.h"
24 #include "gdbcmd.h"
25
26 extern void _initialize_complaints (void);
27
28 /* Structure to manage complaints about symbol file contents. */
29
30 struct complaint complaint_root[1] =
31 {
32 {
33 (char *) NULL, /* Complaint message */
34 0, /* Complaint counter */
35 complaint_root /* Next complaint. */
36 }
37 };
38
39 /* How many complaints about a particular thing should be printed before
40 we stop whining about it? Default is no whining at all, since so many
41 systems have ill-constructed symbol files. */
42
43 static unsigned int stop_whining = 0;
44
45 /* Should each complaint be self explanatory, or should we assume that
46 a series of complaints is being produced?
47 case 0: self explanatory message.
48 case 1: First message of a series that must start off with explanation.
49 case 2: Subsequent message, when user already knows we are reading
50 symbols and we can just state our piece. */
51
52 static int complaint_series = 0;
53
54 \f
55
56 /* Functions to handle complaints during symbol reading. */
57
58 /* Print a complaint about the input symbols, and link the complaint block
59 into a chain for later handling. */
60
61 void
62 complain (struct complaint *complaint,...)
63 {
64 va_list args;
65 va_start (args, complaint);
66
67 complaint->counter++;
68 if (complaint->next == NULL)
69 {
70 complaint->next = complaint_root->next;
71 complaint_root->next = complaint;
72 }
73 if (complaint->counter > stop_whining)
74 {
75 return;
76 }
77 wrap_here ("");
78
79 switch (complaint_series + (info_verbose << 1))
80 {
81
82 /* Isolated messages, must be self-explanatory. */
83 case 0:
84 if (warning_hook)
85 (*warning_hook) (complaint->message, args);
86 else
87 {
88 begin_line ();
89 fputs_filtered ("During symbol reading, ", gdb_stderr);
90 wrap_here ("");
91 vfprintf_filtered (gdb_stderr, complaint->message, args);
92 fputs_filtered (".\n", gdb_stderr);
93 }
94 break;
95
96 /* First of a series, without `set verbose'. */
97 case 1:
98 if (warning_hook)
99 (*warning_hook) (complaint->message, args);
100 else
101 {
102 begin_line ();
103 fputs_filtered ("During symbol reading...", gdb_stderr);
104 vfprintf_filtered (gdb_stderr, complaint->message, args);
105 fputs_filtered ("...", gdb_stderr);
106 wrap_here ("");
107 complaint_series++;
108 }
109 break;
110
111 /* Subsequent messages of a series, or messages under `set verbose'.
112 (We'll already have produced a "Reading in symbols for XXX..."
113 message and will clean up at the end with a newline.) */
114 default:
115 if (warning_hook)
116 (*warning_hook) (complaint->message, args);
117 else
118 {
119 vfprintf_filtered (gdb_stderr, complaint->message, args);
120 fputs_filtered ("...", gdb_stderr);
121 wrap_here ("");
122 }
123 }
124 /* If GDB dumps core, we'd like to see the complaints first. Presumably
125 GDB will not be sending so many complaints that this becomes a
126 performance hog. */
127 gdb_flush (gdb_stderr);
128 va_end (args);
129 }
130
131 /* Clear out all complaint counters that have ever been incremented.
132 If sym_reading is 1, be less verbose about successive complaints,
133 since the messages are appearing all together during a command that
134 reads symbols (rather than scattered around as psymtabs get fleshed
135 out into symtabs at random times). If noisy is 1, we are in a
136 noisy symbol reading command, and our caller will print enough
137 context for the user to figure it out. */
138
139 void
140 clear_complaints (int sym_reading, int noisy)
141 {
142 struct complaint *p;
143
144 for (p = complaint_root->next; p != complaint_root; p = p->next)
145 {
146 p->counter = 0;
147 }
148
149 if (!sym_reading && !noisy && complaint_series > 1 && !warning_hook)
150 {
151 /* Terminate previous series, since caller won't. */
152 puts_filtered ("\n");
153 }
154
155 complaint_series = sym_reading ? 1 + noisy : 0;
156 }
157
158 void
159 _initialize_complaints (void)
160 {
161 add_show_from_set
162 (add_set_cmd ("complaints", class_support, var_zinteger,
163 (char *) &stop_whining,
164 "Set max number of complaints about incorrect symbols.",
165 &setlist),
166 &showlist);
167
168 }
This page took 0.048599 seconds and 5 git commands to generate.