Revision 827b0813
b/qemu-error.c | ||
---|---|---|
41 | 41 |
va_end(ap); |
42 | 42 |
} |
43 | 43 |
|
44 |
static Location std_loc = { |
|
45 |
.kind = LOC_NONE |
|
46 |
}; |
|
47 |
static Location *cur_loc = &std_loc; |
|
48 |
|
|
49 |
/* |
|
50 |
* Push location saved in LOC onto the location stack, return it. |
|
51 |
* The top of that stack is the current location. |
|
52 |
* Needs a matching loc_pop(). |
|
53 |
*/ |
|
54 |
Location *loc_push_restore(Location *loc) |
|
55 |
{ |
|
56 |
assert(!loc->prev); |
|
57 |
loc->prev = cur_loc; |
|
58 |
cur_loc = loc; |
|
59 |
return loc; |
|
60 |
} |
|
61 |
|
|
62 |
/* |
|
63 |
* Initialize *LOC to "nowhere", push it onto the location stack. |
|
64 |
* The top of that stack is the current location. |
|
65 |
* Needs a matching loc_pop(). |
|
66 |
* Return LOC. |
|
67 |
*/ |
|
68 |
Location *loc_push_none(Location *loc) |
|
69 |
{ |
|
70 |
loc->kind = LOC_NONE; |
|
71 |
loc->prev = NULL; |
|
72 |
return loc_push_restore(loc); |
|
73 |
} |
|
74 |
|
|
75 |
/* |
|
76 |
* Pop the location stack. |
|
77 |
* LOC must be the current location, i.e. the top of the stack. |
|
78 |
*/ |
|
79 |
Location *loc_pop(Location *loc) |
|
80 |
{ |
|
81 |
assert(cur_loc == loc && loc->prev); |
|
82 |
cur_loc = loc->prev; |
|
83 |
loc->prev = NULL; |
|
84 |
return loc; |
|
85 |
} |
|
86 |
|
|
87 |
/* |
|
88 |
* Save the current location in LOC, return LOC. |
|
89 |
*/ |
|
90 |
Location *loc_save(Location *loc) |
|
91 |
{ |
|
92 |
*loc = *cur_loc; |
|
93 |
loc->prev = NULL; |
|
94 |
return loc; |
|
95 |
} |
|
96 |
|
|
97 |
/* |
|
98 |
* Change the current location to the one saved in LOC. |
|
99 |
*/ |
|
100 |
void loc_restore(Location *loc) |
|
101 |
{ |
|
102 |
Location *prev = cur_loc->prev; |
|
103 |
assert(!loc->prev); |
|
104 |
*cur_loc = *loc; |
|
105 |
cur_loc->prev = prev; |
|
106 |
} |
|
107 |
|
|
108 |
/* |
|
109 |
* Change the current location to "nowhere in particular". |
|
110 |
*/ |
|
111 |
void loc_set_none(void) |
|
112 |
{ |
|
113 |
cur_loc->kind = LOC_NONE; |
|
114 |
} |
|
115 |
|
|
116 |
/* |
|
117 |
* Print current location to current monitor if we have one, else to stderr. |
|
118 |
*/ |
|
119 |
void error_print_loc(void) |
|
120 |
{ |
|
121 |
switch (cur_loc->kind) { |
|
122 |
default: ; |
|
123 |
} |
|
124 |
} |
|
125 |
|
|
44 | 126 |
/* |
45 | 127 |
* Print an error message to current monitor if we have one, else to stderr. |
46 |
* Appends a newline to the message.
|
|
128 |
* Prepend the current location and append a newline.
|
|
47 | 129 |
* It's wrong to call this in a QMP monitor. Use qerror_report() there. |
48 | 130 |
*/ |
49 | 131 |
void error_report(const char *fmt, ...) |
50 | 132 |
{ |
51 | 133 |
va_list ap; |
52 | 134 |
|
135 |
error_print_loc(); |
|
53 | 136 |
va_start(ap, fmt); |
54 | 137 |
error_vprintf(fmt, ap); |
55 | 138 |
va_end(ap); |
b/qemu-error.h | ||
---|---|---|
13 | 13 |
#ifndef QEMU_ERROR_H |
14 | 14 |
#define QEMU_ERROR_H |
15 | 15 |
|
16 |
typedef struct Location { |
|
17 |
/* all members are private to qemu-error.c */ |
|
18 |
enum { LOC_NONE } 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 |
|
|
16 | 31 |
void error_vprintf(const char *fmt, va_list ap); |
17 | 32 |
void error_printf(const char *fmt, ...) __attribute__ ((format(printf, 1, 2))); |
33 |
void error_print_loc(void); |
|
18 | 34 |
void error_report(const char *fmt, ...) __attribute__ ((format(printf, 1, 2))); |
19 | 35 |
void qerror_report_internal(const char *file, int linenr, const char *func, |
20 | 36 |
const char *fmt, ...) |
b/qemu-option.c | ||
---|---|---|
27 | 27 |
#include <string.h> |
28 | 28 |
|
29 | 29 |
#include "qemu-common.h" |
30 |
#include "qemu-error.h" |
|
30 | 31 |
#include "qemu-option.h" |
31 | 32 |
|
32 | 33 |
/* |
... | ... | |
483 | 484 |
struct QemuOpts { |
484 | 485 |
char *id; |
485 | 486 |
QemuOptsList *list; |
487 |
Location loc; |
|
486 | 488 |
QTAILQ_HEAD(QemuOptHead, QemuOpt) head; |
487 | 489 |
QTAILQ_ENTRY(QemuOpts) next; |
488 | 490 |
}; |
... | ... | |
653 | 655 |
opts->id = qemu_strdup(id); |
654 | 656 |
} |
655 | 657 |
opts->list = list; |
658 |
loc_save(&opts->loc); |
|
656 | 659 |
QTAILQ_INIT(&opts->head); |
657 | 660 |
QTAILQ_INSERT_TAIL(&list->head, opts, next); |
658 | 661 |
return opts; |
... | ... | |
810 | 813 |
int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque, |
811 | 814 |
int abort_on_failure) |
812 | 815 |
{ |
816 |
Location loc; |
|
813 | 817 |
QemuOpts *opts; |
814 | 818 |
int rc = 0; |
815 | 819 |
|
820 |
loc_push_none(&loc); |
|
816 | 821 |
QTAILQ_FOREACH(opts, &list->head, next) { |
822 |
loc_restore(&opts->loc); |
|
817 | 823 |
rc |= func(opts, opaque); |
818 | 824 |
if (abort_on_failure && rc != 0) |
819 | 825 |
break; |
820 | 826 |
} |
827 |
loc_pop(&loc); |
|
821 | 828 |
return rc; |
822 | 829 |
} |
b/qemu-tool.c | ||
---|---|---|
104 | 104 |
return (tv.tv_sec * 1000000000LL + (tv.tv_usec * 1000)) / 1000000; |
105 | 105 |
} |
106 | 106 |
|
107 |
Location *loc_push_restore(Location *loc) |
|
108 |
{ |
|
109 |
return loc; |
|
110 |
} |
|
111 |
|
|
112 |
Location *loc_push_none(Location *loc) |
|
113 |
{ |
|
114 |
return loc; |
|
115 |
} |
|
116 |
|
|
117 |
Location *loc_pop(Location *loc) |
|
118 |
{ |
|
119 |
return loc; |
|
120 |
} |
|
121 |
|
|
122 |
Location *loc_save(Location *loc) |
|
123 |
{ |
|
124 |
return loc; |
|
125 |
} |
|
126 |
|
|
127 |
void loc_restore(Location *loc) |
|
128 |
{ |
|
129 |
} |
|
130 |
|
|
107 | 131 |
void error_report(const char *fmt, ...) |
108 | 132 |
{ |
109 | 133 |
va_list args; |
b/qerror.c | ||
---|---|---|
224 | 224 |
QError *qerr; |
225 | 225 |
|
226 | 226 |
qerr = qerror_new(); |
227 |
loc_save(&qerr->loc); |
|
227 | 228 |
qerr->linenr = linenr; |
228 | 229 |
qerr->file = file; |
229 | 230 |
qerr->func = func; |
... | ... | |
321 | 322 |
* it uses error_report() for this, so that the output is routed to the right |
322 | 323 |
* place (ie. stderr or Monitor's device). |
323 | 324 |
*/ |
324 |
void qerror_print(const QError *qerror)
|
|
325 |
void qerror_print(QError *qerror) |
|
325 | 326 |
{ |
326 | 327 |
QString *qstring = qerror_human(qerror); |
328 |
loc_push_restore(&qerror->loc); |
|
327 | 329 |
error_report("%s", qstring_get_str(qstring)); |
330 |
loc_pop(&qerror->loc); |
|
328 | 331 |
QDECREF(qstring); |
329 | 332 |
} |
330 | 333 |
|
b/qerror.h | ||
---|---|---|
14 | 14 |
|
15 | 15 |
#include "qdict.h" |
16 | 16 |
#include "qstring.h" |
17 |
#include "qemu-error.h" |
|
17 | 18 |
#include <stdarg.h> |
18 | 19 |
|
19 | 20 |
typedef struct QErrorStringTable { |
... | ... | |
24 | 25 |
typedef struct QError { |
25 | 26 |
QObject_HEAD; |
26 | 27 |
QDict *error; |
28 |
Location loc; |
|
27 | 29 |
int linenr; |
28 | 30 |
const char *file; |
29 | 31 |
const char *func; |
... | ... | |
34 | 36 |
QError *qerror_from_info(const char *file, int linenr, const char *func, |
35 | 37 |
const char *fmt, va_list *va); |
36 | 38 |
QString *qerror_human(const QError *qerror); |
37 |
void qerror_print(const QError *qerror);
|
|
39 |
void qerror_print(QError *qerror); |
|
38 | 40 |
QError *qobject_to_qerror(const QObject *obj); |
39 | 41 |
|
40 | 42 |
/* |
Also available in: Unified diff