#include "defs.h"
#include "complaints.h"
#include "gdb_assert.h"
#include "command.h"
#include "gdbcmd.h"
extern void _initialize_complaints (void);
enum complaint_series {
ISOLATED_MESSAGE,
FIRST_MESSAGE,
SHORT_FIRST_MESSAGE,
SUBSEQUENT_MESSAGE
};
struct complain
{
const char *file;
int line;
const char *fmt;
int counter;
struct complain *next;
};
struct complaints
{
struct complain *root;
int series;
const char **explanation;
};
static struct complain complaint_sentinel;
static const char *symfile_explanations[] = {
"During symbol reading, %s.",
"During symbol reading...%s...",
"%s...",
"%s...",
NULL
};
static struct complaints symfile_complaint_book = {
&complaint_sentinel,
0,
symfile_explanations
};
struct complaints *symfile_complaints = &symfile_complaint_book;
static struct complaints *
get_complaints (struct complaints **c)
{
if ((*c) != NULL)
return (*c);
(*c) = XMALLOC (struct complaints);
(*c)->root = &complaint_sentinel;
(*c)->series = ISOLATED_MESSAGE;
(*c)->explanation = NULL;
return (*c);
}
static struct complain *
find_complaint (struct complaints *complaints, const char *file,
int line, const char *fmt)
{
struct complain *complaint;
for (complaint = complaints->root;
complaint != NULL;
complaint = complaint->next)
{
if (complaint->fmt == fmt
&& complaint->file == file
&& complaint->line == line)
return complaint;
}
complaint = XMALLOC (struct complain);
complaint->fmt = fmt;
complaint->file = file;
complaint->line = line;
complaint->counter = 0;
complaint->next = NULL;
complaint->next = complaints->root;
complaints->root = complaint;
return complaint;
}
static unsigned int stop_whining = 0;
static void
vcomplaint (struct complaints **c, const char *file, int line, const char *fmt,
va_list args)
{
struct complaints *complaints = get_complaints (c);
struct complain *complaint = find_complaint (complaints, file, line, fmt);
enum complaint_series series;
gdb_assert (complaints != NULL);
complaint->counter++;
if (complaint->counter > stop_whining)
return;
if (info_verbose)
series = SUBSEQUENT_MESSAGE;
else
series = complaints->series;
if (complaint->file != NULL)
internal_vwarning (complaint->file, complaint->line, complaint->fmt, args);
else if (warning_hook)
(*warning_hook) (complaint->fmt, args);
else
{
if (complaints->explanation == NULL)
vwarning (complaint->fmt, args);
else
{
char *msg;
struct cleanup *cleanups;
xvasprintf (&msg, complaint->fmt, args);
cleanups = make_cleanup (xfree, msg);
wrap_here ("");
if (series != SUBSEQUENT_MESSAGE)
begin_line ();
fprintf_filtered (gdb_stderr,
complaints->explanation[series],
msg);
if (series == ISOLATED_MESSAGE)
fputs_filtered ("\n", gdb_stderr);
else
wrap_here ("");
do_cleanups (cleanups);
}
}
switch (series)
{
case ISOLATED_MESSAGE:
break;
case FIRST_MESSAGE:
complaints->series = SUBSEQUENT_MESSAGE;
break;
case SUBSEQUENT_MESSAGE:
case SHORT_FIRST_MESSAGE:
complaints->series = SUBSEQUENT_MESSAGE;
break;
}
gdb_flush (gdb_stderr);
}
void
complaint (struct complaints **complaints, const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
vcomplaint (complaints, NULL, 0, fmt, args);
va_end (args);
}
void
internal_complaint (struct complaints **complaints, const char *file,
int line, const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
vcomplaint (complaints, file, line, fmt, args);
va_end (args);
}
void
clear_complaints (struct complaints **c, int less_verbose, int noisy)
{
struct complaints *complaints = get_complaints (c);
struct complain *p;
for (p = complaints->root; p != NULL; p = p->next)
{
p->counter = 0;
}
switch (complaints->series)
{
case FIRST_MESSAGE:
break;
case SHORT_FIRST_MESSAGE:
break;
case ISOLATED_MESSAGE:
break;
case SUBSEQUENT_MESSAGE:
fputs_unfiltered ("\n", gdb_stderr);
break;
default:
internal_error (__FILE__, __LINE__, "bad switch");
}
if (!less_verbose)
complaints->series = ISOLATED_MESSAGE;
else if (!noisy)
complaints->series = FIRST_MESSAGE;
else
complaints->series = SHORT_FIRST_MESSAGE;
}
void
_initialize_complaints (void)
{
add_setshow_cmd ("complaints", class_support, var_zinteger,
&stop_whining,
"Set max number of complaints about incorrect symbols.",
"Show max number of complaints about incorrect symbols.",
NULL, NULL,
&setlist, &showlist);
}