aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/log.c122
-rw-r--r--util/module.c6
2 files changed, 66 insertions, 62 deletions
diff --git a/util/log.c b/util/log.c
index 5ad72c197f..32e416051c 100644
--- a/util/log.c
+++ b/util/log.c
@@ -22,6 +22,7 @@
#include "qemu/log.h"
#include "qemu/range.h"
#include "qemu/error-report.h"
+#include "qapi/error.h"
#include "qemu/cutils.h"
#include "trace/control.h"
@@ -102,7 +103,7 @@ void qemu_log_needs_buffers(void)
* substituted with the current PID. This is useful for debugging many
* nested linux-user tasks but will result in lots of logs.
*/
-void qemu_set_log_filename(const char *filename)
+void qemu_set_log_filename(const char *filename, Error **errp)
{
char *pidstr;
g_free(logfilename);
@@ -111,8 +112,8 @@ void qemu_set_log_filename(const char *filename)
if (pidstr) {
/* We only accept one %d, no other format strings */
if (pidstr[1] != 'd' || strchr(pidstr + 2, '%')) {
- error_report("Bad logfile format: %s", filename);
- logfilename = NULL;
+ error_setg(errp, "Bad logfile format: %s", filename);
+ return;
} else {
logfilename = g_strdup_printf(filename, getpid());
}
@@ -142,68 +143,75 @@ bool qemu_log_in_addr_range(uint64_t addr)
}
-void qemu_set_dfilter_ranges(const char *filter_spec)
+void qemu_set_dfilter_ranges(const char *filter_spec, Error **errp)
{
gchar **ranges = g_strsplit(filter_spec, ",", 0);
- if (ranges) {
- gchar **next = ranges;
- gchar *r = *next++;
- debug_regions = g_array_sized_new(FALSE, FALSE,
- sizeof(Range), g_strv_length(ranges));
- while (r) {
- char *range_op = strstr(r, "-");
- char *r2 = range_op ? range_op + 1 : NULL;
- if (!range_op) {
- range_op = strstr(r, "+");
- r2 = range_op ? range_op + 1 : NULL;
- }
- if (!range_op) {
- range_op = strstr(r, "..");
- r2 = range_op ? range_op + 2 : NULL;
- }
- if (range_op) {
- const char *e = NULL;
- uint64_t r1val, r2val;
+ int i;
- if ((qemu_strtoull(r, &e, 0, &r1val) == 0) &&
- (qemu_strtoull(r2, NULL, 0, &r2val) == 0) &&
- r2val > 0) {
- struct Range range;
+ if (debug_regions) {
+ g_array_unref(debug_regions);
+ debug_regions = NULL;
+ }
- g_assert(e == range_op);
+ debug_regions = g_array_sized_new(FALSE, FALSE,
+ sizeof(Range), g_strv_length(ranges));
+ for (i = 0; ranges[i]; i++) {
+ const char *r = ranges[i];
+ const char *range_op, *r2, *e;
+ uint64_t r1val, r2val;
+ struct Range range;
- switch (*range_op) {
- case '+':
- {
- range.begin = r1val;
- range.end = r1val + (r2val - 1);
- break;
- }
- case '-':
- {
- range.end = r1val;
- range.begin = r1val - (r2val - 1);
- break;
- }
- case '.':
- range.begin = r1val;
- range.end = r2val;
- break;
- default:
- g_assert_not_reached();
- }
- g_array_append_val(debug_regions, range);
+ range_op = strstr(r, "-");
+ r2 = range_op ? range_op + 1 : NULL;
+ if (!range_op) {
+ range_op = strstr(r, "+");
+ r2 = range_op ? range_op + 1 : NULL;
+ }
+ if (!range_op) {
+ range_op = strstr(r, "..");
+ r2 = range_op ? range_op + 2 : NULL;
+ }
+ if (!range_op) {
+ error_setg(errp, "Bad range specifier");
+ goto out;
+ }
- } else {
- g_error("Failed to parse range in: %s", r);
- }
- } else {
- g_error("Bad range specifier in: %s", r);
- }
- r = *next++;
+ if (qemu_strtoull(r, &e, 0, &r1val)
+ || e != range_op) {
+ error_setg(errp, "Invalid number to the left of %.*s",
+ (int)(r2 - range_op), range_op);
+ goto out;
+ }
+ if (qemu_strtoull(r2, NULL, 0, &r2val)) {
+ error_setg(errp, "Invalid number to the right of %.*s",
+ (int)(r2 - range_op), range_op);
+ goto out;
+ }
+ if (r2val == 0) {
+ error_setg(errp, "Invalid range");
+ goto out;
+ }
+
+ switch (*range_op) {
+ case '+':
+ range.begin = r1val;
+ range.end = r1val + (r2val - 1);
+ break;
+ case '-':
+ range.end = r1val;
+ range.begin = r1val - (r2val - 1);
+ break;
+ case '.':
+ range.begin = r1val;
+ range.end = r2val;
+ break;
+ default:
+ g_assert_not_reached();
}
- g_strfreev(ranges);
+ g_array_append_val(debug_regions, range);
}
+out:
+ g_strfreev(ranges);
}
/* fflush() the log file */
diff --git a/util/module.c b/util/module.c
index ce058aef6f..86e3f7aba0 100644
--- a/util/module.c
+++ b/util/module.c
@@ -55,13 +55,9 @@ static void init_lists(void)
static ModuleTypeList *find_type(module_init_type type)
{
- ModuleTypeList *l;
-
init_lists();
- l = &init_type_list[type];
-
- return l;
+ return &init_type_list[type];
}
void register_module_init(void (*fn)(void), module_init_type type)