xref: /qemu/include/qemu/error-report.h (revision 756a98dd)
1 /*
2  * Error reporting
3  *
4  * Copyright (C) 2010 Red Hat Inc.
5  *
6  * Authors:
7  *  Markus Armbruster <armbru@redhat.com>,
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2 or later.
10  * See the COPYING file in the top-level directory.
11  */
12 
13 #ifndef QEMU_ERROR_REPORT_H
14 #define QEMU_ERROR_REPORT_H
15 
16 typedef struct Location {
17     /* all members are private to qemu-error.c */
18     enum { LOC_NONE, LOC_CMDLINE, LOC_FILE } kind;
19     int num;
20     const void *ptr;
21     struct Location *prev;
22 } Location;
23 
24 Location *loc_push_restore(Location *loc);
25 Location *loc_push_none(Location *loc);
26 Location *loc_pop(Location *loc);
27 Location *loc_save(Location *loc);
28 void loc_restore(Location *loc);
29 void loc_set_none(void);
30 void loc_set_cmdline(char **argv, int idx, int cnt);
31 void loc_set_file(const char *fname, int lno);
32 
33 int error_vprintf(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0);
34 int error_printf(const char *fmt, ...) G_GNUC_PRINTF(1, 2);
35 
36 void error_vreport(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0);
37 void warn_vreport(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0);
38 void info_vreport(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0);
39 
40 void error_report(const char *fmt, ...) G_GNUC_PRINTF(1, 2);
41 void warn_report(const char *fmt, ...) G_GNUC_PRINTF(1, 2);
42 void info_report(const char *fmt, ...) G_GNUC_PRINTF(1, 2);
43 
44 bool error_report_once_cond(bool *printed, const char *fmt, ...)
45     G_GNUC_PRINTF(2, 3);
46 bool warn_report_once_cond(bool *printed, const char *fmt, ...)
47     G_GNUC_PRINTF(2, 3);
48 
49 void error_init(const char *argv0);
50 
51 /*
52  * Similar to error_report(), except it prints the message just once.
53  * Return true when it prints, false otherwise.
54  */
55 #define error_report_once(fmt, ...)                     \
56     ({                                                  \
57         static bool print_once_;                        \
58         error_report_once_cond(&print_once_,            \
59                                fmt, ##__VA_ARGS__);     \
60     })
61 
62 /*
63  * Similar to warn_report(), except it prints the message just once.
64  * Return true when it prints, false otherwise.
65  */
66 #define warn_report_once(fmt, ...)                      \
67     ({                                                  \
68         static bool print_once_;                        \
69         warn_report_once_cond(&print_once_,             \
70                               fmt, ##__VA_ARGS__);      \
71     })
72 
73 extern bool message_with_timestamp;
74 extern bool error_with_guestname;
75 extern const char *error_guest_name;
76 
77 #endif
78