[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 5/7] qemu-log: new option -dfilter to limit outpu
From: |
Alex Bennée |
Subject: |
[Qemu-devel] [PATCH v2 5/7] qemu-log: new option -dfilter to limit output |
Date: |
Fri, 28 Mar 2014 16:43:25 +0000 |
When debugging big programs or system emulation sometimes you want both
the verbosity of cpu,exec et all but don't want to generate lots of logs
for unneeded stuff. This patch adds a new option -dfilter which allows
you to specify interesting address ranges in the form:
-dfilter 0x8000-0x9000,0xffffffc000080000+0x200,...
Then logging code can use the new qemu_log_in_addr_range() function to
decide if it will output logging information for the given range.
Signed-off-by: Alex Bennée <address@hidden>
----
v2
- More clean-ups to the documentation
diff --git a/include/qemu/log.h b/include/qemu/log.h
index da22e13..8cfe57f 100644
--- a/include/qemu/log.h
+++ b/include/qemu/log.h
@@ -181,6 +181,8 @@ static inline void qemu_set_log(int log_flags)
}
void qemu_set_log_filename(const char *filename);
+void qemu_set_dfilter_ranges(const char *ranges);
+bool qemu_log_in_addr_range(uint64_t addr);
int qemu_str_to_log_mask(const char *str);
/* Print a usage message listing all the valid logging categories
diff --git a/qemu-log.c b/qemu-log.c
index 4dd530c..a54b332 100644
--- a/qemu-log.c
+++ b/qemu-log.c
@@ -19,11 +19,13 @@
#include "qemu-common.h"
#include "qemu/log.h"
+#include "qemu/range.h"
static char *logfilename;
FILE *qemu_logfile;
int qemu_loglevel;
static int log_append = 0;
+static GSList *debug_regions = NULL;
void qemu_log(const char *fmt, ...)
{
@@ -92,6 +94,60 @@ void qemu_set_log_filename(const char *filename)
qemu_set_log(qemu_loglevel);
}
+/* Returns true if addr is in our debug filter or no filter defined
+ */
+bool qemu_log_in_addr_range(uint64_t addr)
+{
+ if (debug_regions) {
+ GSList *region = debug_regions;
+ do {
+ struct Range *range = region->data;
+ if (addr >= range->begin && addr <= range->end) {
+ return true;
+ }
+ region = g_slist_next(region);
+ } while (region);
+ return false;
+ } else {
+ return true;
+ }
+}
+
+
+void qemu_set_dfilter_ranges(const char *filter_spec)
+{
+ gchar **ranges = g_strsplit(filter_spec, ",", 0);
+ if (ranges) {
+ gchar **next = ranges;
+ gchar *r = *next++;
+ while (r) {
+ gchar *delim = g_strrstr(r, "-");
+ if (!delim) {
+ delim = g_strrstr(r, "+");
+ }
+ if (delim) {
+ struct Range *range = g_malloc(sizeof(Range));
+ range->begin = strtoul(r, NULL, 0);
+ switch (*delim) {
+ case '+':
+ range->end = range->begin + strtoul(delim+1, NULL, 0);
+ break;
+ case '-':
+ range->end = strtoul(delim+1, NULL, 0);
+ break;
+ default:
+ g_assert_not_reached();
+ }
+ debug_regions = g_slist_append(debug_regions, range);
+ } else {
+ g_error("Bad range specifier in: %s", r);
+ }
+ r = *next++;
+ }
+ g_strfreev(ranges);
+ }
+}
+
const QEMULogItem qemu_log_items[] = {
{ CPU_LOG_TB_OUT_ASM, "out_asm",
"show generated host assembly code for each compiled TB" },
diff --git a/qemu-options.hx b/qemu-options.hx
index 2d33815..ae0b5c0 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2675,6 +2675,22 @@ STEXI
Output log in @var{logfile} instead of to stderr
ETEXI
+DEF("dfilter", HAS_ARG, QEMU_OPTION_DFILTER, \
+ "-dfilter range,.. filter debug output to range of addresses (useful for
-d cpu,exec,etc..)\n",
+ QEMU_ARCH_ALL)
+STEXI
address@hidden -dfilter @var{range1}[,...]
address@hidden -dfilter
+Filter debug output to that relevant to a range of target addresses. The filter
+spec can be either @address@hidden or @address@hidden where @var{start}
address@hidden and @var{size} are the addresses and sizes required. For example:
address@hidden
+ -dfilter 0x8000-0x9000,0xffffffc000080000+0x200
address@hidden example
+Will dump output for any code in the 0x1000 sized block starting at 0x8000 and
+the 0x200 sized block starting at 0xffffffc000080000.
+ETEXI
+
DEF("L", HAS_ARG, QEMU_OPTION_L, \
"-L path set the directory for the BIOS, VGA BIOS and keymaps\n",
QEMU_ARCH_ALL)
diff --git a/vl.c b/vl.c
index 9975e5a..c130c00 100644
--- a/vl.c
+++ b/vl.c
@@ -3334,6 +3334,9 @@ int main(int argc, char **argv, char **envp)
case QEMU_OPTION_D:
log_file = optarg;
break;
+ case QEMU_OPTION_DFILTER:
+ qemu_set_dfilter_ranges(optarg);
+ break;
case QEMU_OPTION_s:
add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT);
break;
--
1.9.1
- [Qemu-devel] [PATCH v2 0/7] qemu-log: various fixes and enhancements, Alex Bennée, 2014/03/28
- [Qemu-devel] [PATCH v2 1/7] qemu-log: correct help text for -d cpu, Alex Bennée, 2014/03/28
- [Qemu-devel] [PATCH v2 2/7] qemu-log: Avoid function call for disabled qemu_log_mask logging, Alex Bennée, 2014/03/28
- [Qemu-devel] [PATCH v2 4/7] qemu-log: support simple pid substitution in logfile, Alex Bennée, 2014/03/28
- [Qemu-devel] [PATCH v2 3/7] qemu-log: Improve the "exec" TB execution logging, Alex Bennée, 2014/03/28
- [Qemu-devel] [PATCH v2 5/7] qemu-log: new option -dfilter to limit output,
Alex Bennée <=
- [Qemu-devel] [PATCH v2 6/7] qemu-log: dfilter-ise exec, in_asm, out_asm, and op_opt, Alex Bennée, 2014/03/28
- [Qemu-devel] [PATCH v2 7/7] qemu-log: add nochain option to disable TB chaining, Alex Bennée, 2014/03/28