import gdb-1999-07-07 post reformat
[external/binutils.git] / gdb / complaints.c
1 /* Support for complaint handling during symbol reading in GDB.
2    Copyright (C) 1990, 1991, 1992  Free Software Foundation, Inc.
3
4    This file is part of GDB.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place - Suite 330,
19    Boston, MA 02111-1307, USA.  */
20
21 #include "defs.h"
22 #include "complaints.h"
23 #include "gdbcmd.h"
24
25 extern void _initialize_complaints PARAMS ((void));
26
27 /* Structure to manage complaints about symbol file contents.  */
28
29 struct complaint complaint_root[1] =
30 {
31   {
32     (char *) NULL,              /* Complaint message */
33     0,                          /* Complaint counter */
34     complaint_root              /* Next complaint. */
35   }
36 };
37
38 /* How many complaints about a particular thing should be printed before
39    we stop whining about it?  Default is no whining at all, since so many
40    systems have ill-constructed symbol files.  */
41
42 static unsigned int stop_whining = 0;
43
44 /* Should each complaint be self explanatory, or should we assume that
45    a series of complaints is being produced? 
46    case 0:  self explanatory message.
47    case 1:  First message of a series that must start off with explanation.
48    case 2:  Subsequent message, when user already knows we are reading
49    symbols and we can just state our piece.  */
50
51 static int complaint_series = 0;
52
53 /* External variables and functions referenced. */
54
55 extern int info_verbose;
56 \f
57
58 /* Functions to handle complaints during symbol reading.  */
59
60 /* Print a complaint about the input symbols, and link the complaint block
61    into a chain for later handling.  */
62
63 /* VARARGS */
64 void
65 #ifdef ANSI_PROTOTYPES
66 complain (struct complaint *complaint,...)
67 #else
68 complain (va_alist)
69      va_dcl
70 #endif
71 {
72   va_list args;
73 #ifdef ANSI_PROTOTYPES
74   va_start (args, complaint);
75 #else
76   struct complaint *complaint;
77
78   va_start (args);
79   complaint = va_arg (args, struct complaint *);
80 #endif
81
82   complaint->counter++;
83   if (complaint->next == NULL)
84     {
85       complaint->next = complaint_root->next;
86       complaint_root->next = complaint;
87     }
88   if (complaint->counter > stop_whining)
89     {
90       return;
91     }
92   wrap_here ("");
93
94   switch (complaint_series + (info_verbose << 1))
95     {
96
97       /* Isolated messages, must be self-explanatory.  */
98     case 0:
99       begin_line ();
100       puts_filtered ("During symbol reading, ");
101       wrap_here ("");
102       vprintf_filtered (complaint->message, args);
103       puts_filtered (".\n");
104       break;
105
106       /* First of a series, without `set verbose'.  */
107     case 1:
108       begin_line ();
109       puts_filtered ("During symbol reading...");
110       vprintf_filtered (complaint->message, args);
111       puts_filtered ("...");
112       wrap_here ("");
113       complaint_series++;
114       break;
115
116       /* Subsequent messages of a series, or messages under `set verbose'.
117          (We'll already have produced a "Reading in symbols for XXX..."
118          message and will clean up at the end with a newline.)  */
119     default:
120       vprintf_filtered (complaint->message, args);
121       puts_filtered ("...");
122       wrap_here ("");
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_stdout);
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 (sym_reading, noisy)
141      int sym_reading;
142      int noisy;
143 {
144   struct complaint *p;
145
146   for (p = complaint_root->next; p != complaint_root; p = p->next)
147     {
148       p->counter = 0;
149     }
150
151   if (!sym_reading && !noisy && complaint_series > 1)
152     {
153       /* Terminate previous series, since caller won't.  */
154       puts_filtered ("\n");
155     }
156
157   complaint_series = sym_reading ? 1 + noisy : 0;
158 }
159
160 void
161 _initialize_complaints ()
162 {
163   add_show_from_set
164     (add_set_cmd ("complaints", class_support, var_zinteger,
165                   (char *) &stop_whining,
166                   "Set max number of complaints about incorrect symbols.",
167                   &setlist),
168      &showlist);
169
170 }