2012-06-03 19:03:23 +04:00
|
|
|
/*
|
|
|
|
* Logging support
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2020-10-23 15:44:24 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2012-06-03 19:03:23 +04:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-01-29 20:50:05 +03:00
|
|
|
#include "qemu/osdep.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/log.h"
|
2016-03-15 17:30:20 +03:00
|
|
|
#include "qemu/range.h"
|
|
|
|
#include "qemu/error-report.h"
|
2016-06-15 20:27:15 +03:00
|
|
|
#include "qapi/error.h"
|
2016-03-15 17:30:20 +03:00
|
|
|
#include "qemu/cutils.h"
|
2016-01-07 16:55:32 +03:00
|
|
|
#include "trace/control.h"
|
2019-11-19 00:15:25 +03:00
|
|
|
#include "qemu/thread.h"
|
2020-04-04 07:21:08 +03:00
|
|
|
#include "qemu/lockable.h"
|
2012-06-03 19:03:23 +04:00
|
|
|
|
2013-01-22 14:08:03 +04:00
|
|
|
static char *logfilename;
|
2019-11-19 00:15:25 +03:00
|
|
|
static QemuMutex qemu_logfile_mutex;
|
2019-11-19 00:15:27 +03:00
|
|
|
QemuLogFile *qemu_logfile;
|
2012-06-03 20:35:32 +04:00
|
|
|
int qemu_loglevel;
|
2012-06-03 19:03:23 +04:00
|
|
|
static int log_append = 0;
|
2016-03-15 17:30:20 +03:00
|
|
|
static GArray *debug_regions;
|
2012-06-03 19:03:23 +04:00
|
|
|
|
2016-06-24 05:15:55 +03:00
|
|
|
/* Return the number of characters emitted. */
|
|
|
|
int qemu_log(const char *fmt, ...)
|
2012-06-03 20:35:32 +04:00
|
|
|
{
|
2016-06-24 05:15:55 +03:00
|
|
|
int ret = 0;
|
2019-11-19 00:15:27 +03:00
|
|
|
QemuLogFile *logfile;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
2020-09-23 13:56:46 +03:00
|
|
|
logfile = qatomic_rcu_read(&qemu_logfile);
|
2019-11-19 00:15:27 +03:00
|
|
|
if (logfile) {
|
2016-06-24 05:15:55 +03:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
2019-11-19 00:15:27 +03:00
|
|
|
ret = vfprintf(logfile->fd, fmt, ap);
|
2016-06-24 05:15:55 +03:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
/* Don't pass back error results. */
|
|
|
|
if (ret < 0) {
|
|
|
|
ret = 0;
|
|
|
|
}
|
2012-06-03 20:35:32 +04:00
|
|
|
}
|
2019-11-19 00:15:27 +03:00
|
|
|
rcu_read_unlock();
|
2016-06-24 05:15:55 +03:00
|
|
|
return ret;
|
2012-06-03 20:35:32 +04:00
|
|
|
}
|
|
|
|
|
2019-11-19 00:15:25 +03:00
|
|
|
static void __attribute__((__constructor__)) qemu_logfile_init(void)
|
|
|
|
{
|
|
|
|
qemu_mutex_init(&qemu_logfile_mutex);
|
|
|
|
}
|
|
|
|
|
2019-11-19 00:15:27 +03:00
|
|
|
static void qemu_logfile_free(QemuLogFile *logfile)
|
|
|
|
{
|
|
|
|
g_assert(logfile);
|
|
|
|
|
|
|
|
if (logfile->fd != stderr) {
|
|
|
|
fclose(logfile->fd);
|
|
|
|
}
|
|
|
|
g_free(logfile);
|
|
|
|
}
|
|
|
|
|
2015-12-04 15:12:57 +03:00
|
|
|
static bool log_uses_own_buffers;
|
|
|
|
|
2012-06-03 19:03:23 +04:00
|
|
|
/* enable or disable low levels log */
|
2015-12-04 15:12:57 +03:00
|
|
|
void qemu_set_log(int log_flags)
|
2012-06-03 19:03:23 +04:00
|
|
|
{
|
2019-11-19 00:15:24 +03:00
|
|
|
bool need_to_open_file = false;
|
2019-11-19 00:15:27 +03:00
|
|
|
QemuLogFile *logfile;
|
|
|
|
|
2012-06-03 20:35:32 +04:00
|
|
|
qemu_loglevel = log_flags;
|
2016-01-07 16:55:30 +03:00
|
|
|
#ifdef CONFIG_TRACE_LOG
|
|
|
|
qemu_loglevel |= LOG_TRACE;
|
|
|
|
#endif
|
2019-11-19 00:15:24 +03:00
|
|
|
/*
|
|
|
|
* In all cases we only log if qemu_loglevel is set.
|
|
|
|
* Also:
|
|
|
|
* If not daemonized we will always log either to stderr
|
|
|
|
* or to a file (if there is a logfilename).
|
|
|
|
* If we are daemonized,
|
|
|
|
* we will only log if there is a logfilename.
|
|
|
|
*/
|
|
|
|
if (qemu_loglevel && (!is_daemonized() || logfilename)) {
|
|
|
|
need_to_open_file = true;
|
|
|
|
}
|
2020-04-04 07:21:08 +03:00
|
|
|
QEMU_LOCK_GUARD(&qemu_logfile_mutex);
|
2019-11-19 00:15:24 +03:00
|
|
|
if (qemu_logfile && !need_to_open_file) {
|
2019-11-19 00:15:27 +03:00
|
|
|
logfile = qemu_logfile;
|
2020-09-23 13:56:46 +03:00
|
|
|
qatomic_rcu_set(&qemu_logfile, NULL);
|
2019-11-19 00:15:27 +03:00
|
|
|
call_rcu(logfile, qemu_logfile_free, rcu);
|
2019-11-19 00:15:24 +03:00
|
|
|
} else if (!qemu_logfile && need_to_open_file) {
|
2019-11-19 00:15:27 +03:00
|
|
|
logfile = g_new0(QemuLogFile, 1);
|
2013-02-26 21:52:40 +04:00
|
|
|
if (logfilename) {
|
2019-11-19 00:15:27 +03:00
|
|
|
logfile->fd = fopen(logfilename, log_append ? "a" : "w");
|
|
|
|
if (!logfile->fd) {
|
|
|
|
g_free(logfile);
|
2013-02-26 21:52:40 +04:00
|
|
|
perror(logfilename);
|
|
|
|
_exit(1);
|
|
|
|
}
|
2016-02-18 14:38:38 +03:00
|
|
|
/* In case we are a daemon redirect stderr to logfile */
|
|
|
|
if (is_daemonized()) {
|
2019-11-19 00:15:27 +03:00
|
|
|
dup2(fileno(logfile->fd), STDERR_FILENO);
|
|
|
|
fclose(logfile->fd);
|
2016-02-18 14:38:38 +03:00
|
|
|
/* This will skip closing logfile in qemu_log_close() */
|
2019-11-19 00:15:27 +03:00
|
|
|
logfile->fd = stderr;
|
2016-02-18 14:38:38 +03:00
|
|
|
}
|
2013-02-26 21:52:40 +04:00
|
|
|
} else {
|
|
|
|
/* Default to stderr if no log file specified */
|
2016-02-29 14:18:40 +03:00
|
|
|
assert(!is_daemonized());
|
2019-11-19 00:15:27 +03:00
|
|
|
logfile->fd = stderr;
|
2012-06-03 19:03:23 +04:00
|
|
|
}
|
|
|
|
/* must avoid mmap() usage of glibc by setting a buffer "by hand" */
|
2015-12-04 15:12:57 +03:00
|
|
|
if (log_uses_own_buffers) {
|
2012-06-03 19:03:23 +04:00
|
|
|
static char logfile_buf[4096];
|
2012-07-07 18:40:18 +04:00
|
|
|
|
2019-11-19 00:15:27 +03:00
|
|
|
setvbuf(logfile->fd, logfile_buf, _IOLBF, sizeof(logfile_buf));
|
2012-07-07 18:40:18 +04:00
|
|
|
} else {
|
|
|
|
#if defined(_WIN32)
|
|
|
|
/* Win32 doesn't support line-buffering, so use unbuffered output. */
|
2019-11-19 00:15:27 +03:00
|
|
|
setvbuf(logfile->fd, NULL, _IONBF, 0);
|
2012-06-03 19:03:23 +04:00
|
|
|
#else
|
2019-11-19 00:15:27 +03:00
|
|
|
setvbuf(logfile->fd, NULL, _IOLBF, 0);
|
2012-06-03 19:03:23 +04:00
|
|
|
#endif
|
2012-07-07 18:40:18 +04:00
|
|
|
log_append = 1;
|
|
|
|
}
|
2020-09-23 13:56:46 +03:00
|
|
|
qatomic_rcu_set(&qemu_logfile, logfile);
|
2012-06-03 19:03:23 +04:00
|
|
|
}
|
|
|
|
}
|
2015-12-04 15:12:57 +03:00
|
|
|
|
|
|
|
void qemu_log_needs_buffers(void)
|
|
|
|
{
|
|
|
|
log_uses_own_buffers = true;
|
|
|
|
}
|
|
|
|
|
2016-03-15 17:30:23 +03:00
|
|
|
/*
|
|
|
|
* Allow the user to include %d in their logfile which will be
|
|
|
|
* substituted with the current PID. This is useful for debugging many
|
|
|
|
* nested linux-user tasks but will result in lots of logs.
|
2020-01-23 22:36:26 +03:00
|
|
|
*
|
|
|
|
* filename may be NULL. In that case, log output is sent to stderr
|
2016-03-15 17:30:23 +03:00
|
|
|
*/
|
2016-06-15 20:27:16 +03:00
|
|
|
void qemu_set_log_filename(const char *filename, Error **errp)
|
2012-06-03 19:03:23 +04:00
|
|
|
{
|
2013-01-22 14:08:03 +04:00
|
|
|
g_free(logfilename);
|
2019-11-19 00:15:23 +03:00
|
|
|
logfilename = NULL;
|
2016-03-15 17:30:23 +03:00
|
|
|
|
2020-01-23 22:36:26 +03:00
|
|
|
if (filename) {
|
|
|
|
char *pidstr = strstr(filename, "%");
|
|
|
|
if (pidstr) {
|
|
|
|
/* We only accept one %d, no other format strings */
|
|
|
|
if (pidstr[1] != 'd' || strchr(pidstr + 2, '%')) {
|
|
|
|
error_setg(errp, "Bad logfile format: %s", filename);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
logfilename = g_strdup_printf(filename, getpid());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logfilename = g_strdup(filename);
|
|
|
|
}
|
2016-03-15 17:30:23 +03:00
|
|
|
}
|
2020-01-23 22:36:26 +03:00
|
|
|
|
2013-02-26 21:52:40 +04:00
|
|
|
qemu_log_close();
|
2013-02-11 20:41:23 +04:00
|
|
|
qemu_set_log(qemu_loglevel);
|
2012-06-03 19:03:23 +04:00
|
|
|
}
|
|
|
|
|
2016-03-15 17:30:20 +03:00
|
|
|
/* 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) {
|
|
|
|
int i = 0;
|
|
|
|
for (i = 0; i < debug_regions->len; i++) {
|
log: Clean up misuse of Range for -dfilter
Range encodes an integer interval [a,b] as { begin = a, end = b + 1 },
where a \in [0,2^64-1] and b \in [1,2^64]. Thus, zero end is to be
interpreted as 2^64.
The implementation of -dfilter (commit 3514552) uses Range
differently: it encodes [a,b] as { begin = a, end = b }. The code
works, but it contradicts the specification of Range in range.h.
Switch to the specified representation. Since it can't represent
[0,UINT64_MAX], we have to reject that now. Add a test for it.
While we're rejecting anyway: observe that we reject -dfilter LOB..UPB
where LOB > UPB when UPB is zero, but happily create an empty Range
when it isn't. Reject it then, too, and add a test for it.
While there, add a positive test for the problematic upper bound
UINT64_MAX.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2016-07-01 14:47:46 +03:00
|
|
|
Range *range = &g_array_index(debug_regions, Range, i);
|
2016-07-01 14:47:47 +03:00
|
|
|
if (range_contains(range, addr)) {
|
2016-03-15 17:30:20 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-15 20:27:15 +03:00
|
|
|
void qemu_set_dfilter_ranges(const char *filter_spec, Error **errp)
|
2016-03-15 17:30:20 +03:00
|
|
|
{
|
|
|
|
gchar **ranges = g_strsplit(filter_spec, ",", 0);
|
2016-06-15 20:27:15 +03:00
|
|
|
int i;
|
2016-06-15 20:27:14 +03:00
|
|
|
|
|
|
|
if (debug_regions) {
|
|
|
|
g_array_unref(debug_regions);
|
|
|
|
debug_regions = NULL;
|
|
|
|
}
|
|
|
|
|
2016-06-15 20:27:15 +03:00
|
|
|
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;
|
log: Clean up misuse of Range for -dfilter
Range encodes an integer interval [a,b] as { begin = a, end = b + 1 },
where a \in [0,2^64-1] and b \in [1,2^64]. Thus, zero end is to be
interpreted as 2^64.
The implementation of -dfilter (commit 3514552) uses Range
differently: it encodes [a,b] as { begin = a, end = b }. The code
works, but it contradicts the specification of Range in range.h.
Switch to the specified representation. Since it can't represent
[0,UINT64_MAX], we have to reject that now. Add a test for it.
While we're rejecting anyway: observe that we reject -dfilter LOB..UPB
where LOB > UPB when UPB is zero, but happily create an empty Range
when it isn't. Reject it then, too, and add a test for it.
While there, add a positive test for the problematic upper bound
UINT64_MAX.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2016-07-01 14:47:46 +03:00
|
|
|
uint64_t r1val, r2val, lob, upb;
|
2016-06-15 20:27:15 +03:00
|
|
|
struct Range 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;
|
|
|
|
}
|
|
|
|
|
2017-02-21 23:13:50 +03:00
|
|
|
if (qemu_strtou64(r, &e, 0, &r1val)
|
2016-06-15 20:27:15 +03:00
|
|
|
|| e != range_op) {
|
|
|
|
error_setg(errp, "Invalid number to the left of %.*s",
|
|
|
|
(int)(r2 - range_op), range_op);
|
|
|
|
goto out;
|
|
|
|
}
|
2017-02-21 23:13:50 +03:00
|
|
|
if (qemu_strtou64(r2, NULL, 0, &r2val)) {
|
2016-06-15 20:27:15 +03:00
|
|
|
error_setg(errp, "Invalid number to the right of %.*s",
|
|
|
|
(int)(r2 - range_op), range_op);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (*range_op) {
|
|
|
|
case '+':
|
log: Clean up misuse of Range for -dfilter
Range encodes an integer interval [a,b] as { begin = a, end = b + 1 },
where a \in [0,2^64-1] and b \in [1,2^64]. Thus, zero end is to be
interpreted as 2^64.
The implementation of -dfilter (commit 3514552) uses Range
differently: it encodes [a,b] as { begin = a, end = b }. The code
works, but it contradicts the specification of Range in range.h.
Switch to the specified representation. Since it can't represent
[0,UINT64_MAX], we have to reject that now. Add a test for it.
While we're rejecting anyway: observe that we reject -dfilter LOB..UPB
where LOB > UPB when UPB is zero, but happily create an empty Range
when it isn't. Reject it then, too, and add a test for it.
While there, add a positive test for the problematic upper bound
UINT64_MAX.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2016-07-01 14:47:46 +03:00
|
|
|
lob = r1val;
|
|
|
|
upb = r1val + r2val - 1;
|
2016-06-15 20:27:15 +03:00
|
|
|
break;
|
|
|
|
case '-':
|
log: Clean up misuse of Range for -dfilter
Range encodes an integer interval [a,b] as { begin = a, end = b + 1 },
where a \in [0,2^64-1] and b \in [1,2^64]. Thus, zero end is to be
interpreted as 2^64.
The implementation of -dfilter (commit 3514552) uses Range
differently: it encodes [a,b] as { begin = a, end = b }. The code
works, but it contradicts the specification of Range in range.h.
Switch to the specified representation. Since it can't represent
[0,UINT64_MAX], we have to reject that now. Add a test for it.
While we're rejecting anyway: observe that we reject -dfilter LOB..UPB
where LOB > UPB when UPB is zero, but happily create an empty Range
when it isn't. Reject it then, too, and add a test for it.
While there, add a positive test for the problematic upper bound
UINT64_MAX.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2016-07-01 14:47:46 +03:00
|
|
|
upb = r1val;
|
|
|
|
lob = r1val - (r2val - 1);
|
2016-06-15 20:27:15 +03:00
|
|
|
break;
|
|
|
|
case '.':
|
log: Clean up misuse of Range for -dfilter
Range encodes an integer interval [a,b] as { begin = a, end = b + 1 },
where a \in [0,2^64-1] and b \in [1,2^64]. Thus, zero end is to be
interpreted as 2^64.
The implementation of -dfilter (commit 3514552) uses Range
differently: it encodes [a,b] as { begin = a, end = b }. The code
works, but it contradicts the specification of Range in range.h.
Switch to the specified representation. Since it can't represent
[0,UINT64_MAX], we have to reject that now. Add a test for it.
While we're rejecting anyway: observe that we reject -dfilter LOB..UPB
where LOB > UPB when UPB is zero, but happily create an empty Range
when it isn't. Reject it then, too, and add a test for it.
While there, add a positive test for the problematic upper bound
UINT64_MAX.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2016-07-01 14:47:46 +03:00
|
|
|
lob = r1val;
|
|
|
|
upb = r2val;
|
2016-06-15 20:27:15 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
2016-03-15 17:30:20 +03:00
|
|
|
}
|
2016-07-01 14:47:49 +03:00
|
|
|
if (lob > upb) {
|
log: Clean up misuse of Range for -dfilter
Range encodes an integer interval [a,b] as { begin = a, end = b + 1 },
where a \in [0,2^64-1] and b \in [1,2^64]. Thus, zero end is to be
interpreted as 2^64.
The implementation of -dfilter (commit 3514552) uses Range
differently: it encodes [a,b] as { begin = a, end = b }. The code
works, but it contradicts the specification of Range in range.h.
Switch to the specified representation. Since it can't represent
[0,UINT64_MAX], we have to reject that now. Add a test for it.
While we're rejecting anyway: observe that we reject -dfilter LOB..UPB
where LOB > UPB when UPB is zero, but happily create an empty Range
when it isn't. Reject it then, too, and add a test for it.
While there, add a positive test for the problematic upper bound
UINT64_MAX.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2016-07-01 14:47:46 +03:00
|
|
|
error_setg(errp, "Invalid range");
|
|
|
|
goto out;
|
|
|
|
}
|
2016-07-01 14:47:47 +03:00
|
|
|
range_set_bounds(&range, lob, upb);
|
2016-06-15 20:27:15 +03:00
|
|
|
g_array_append_val(debug_regions, range);
|
2016-03-15 17:30:20 +03:00
|
|
|
}
|
2016-06-15 20:27:15 +03:00
|
|
|
out:
|
|
|
|
g_strfreev(ranges);
|
2016-03-15 17:30:20 +03:00
|
|
|
}
|
|
|
|
|
2016-03-16 14:36:52 +03:00
|
|
|
/* fflush() the log file */
|
|
|
|
void qemu_log_flush(void)
|
|
|
|
{
|
2019-11-19 00:15:27 +03:00
|
|
|
QemuLogFile *logfile;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
2020-09-23 13:56:46 +03:00
|
|
|
logfile = qatomic_rcu_read(&qemu_logfile);
|
2019-11-19 00:15:27 +03:00
|
|
|
if (logfile) {
|
|
|
|
fflush(logfile->fd);
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
2016-03-16 14:36:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Close the log file */
|
|
|
|
void qemu_log_close(void)
|
|
|
|
{
|
2019-11-19 00:15:27 +03:00
|
|
|
QemuLogFile *logfile;
|
|
|
|
|
2019-11-19 00:15:25 +03:00
|
|
|
qemu_mutex_lock(&qemu_logfile_mutex);
|
2019-11-19 00:15:27 +03:00
|
|
|
logfile = qemu_logfile;
|
|
|
|
|
|
|
|
if (logfile) {
|
2020-09-23 13:56:46 +03:00
|
|
|
qatomic_rcu_set(&qemu_logfile, NULL);
|
2019-11-19 00:15:27 +03:00
|
|
|
call_rcu(logfile, qemu_logfile_free, rcu);
|
2016-03-16 14:36:52 +03:00
|
|
|
}
|
2019-11-19 00:15:25 +03:00
|
|
|
qemu_mutex_unlock(&qemu_logfile_mutex);
|
2016-03-16 14:36:52 +03:00
|
|
|
}
|
|
|
|
|
2013-02-11 20:41:25 +04:00
|
|
|
const QEMULogItem qemu_log_items[] = {
|
2012-06-03 19:03:23 +04:00
|
|
|
{ CPU_LOG_TB_OUT_ASM, "out_asm",
|
|
|
|
"show generated host assembly code for each compiled TB" },
|
|
|
|
{ CPU_LOG_TB_IN_ASM, "in_asm",
|
|
|
|
"show target assembly code for each compiled TB" },
|
|
|
|
{ CPU_LOG_TB_OP, "op",
|
|
|
|
"show micro ops for each compiled TB" },
|
|
|
|
{ CPU_LOG_TB_OP_OPT, "op_opt",
|
2016-06-24 06:34:33 +03:00
|
|
|
"show micro ops after optimization" },
|
|
|
|
{ CPU_LOG_TB_OP_IND, "op_ind",
|
|
|
|
"show micro ops before indirect lowering" },
|
2012-06-03 19:03:23 +04:00
|
|
|
{ CPU_LOG_INT, "int",
|
|
|
|
"show interrupts/exceptions in short format" },
|
|
|
|
{ CPU_LOG_EXEC, "exec",
|
|
|
|
"show trace before each executed TB (lots of logs)" },
|
|
|
|
{ CPU_LOG_TB_CPU, "cpu",
|
2016-03-15 17:30:17 +03:00
|
|
|
"show CPU registers before entering a TB (lots of logs)" },
|
2018-05-15 16:58:44 +03:00
|
|
|
{ CPU_LOG_TB_FPU, "fpu",
|
|
|
|
"include FPU registers in the 'cpu' logging" },
|
2014-12-13 19:48:18 +03:00
|
|
|
{ CPU_LOG_MMU, "mmu",
|
|
|
|
"log MMU-related activities" },
|
2012-06-03 19:03:23 +04:00
|
|
|
{ CPU_LOG_PCALL, "pcall",
|
2012-07-07 18:40:18 +04:00
|
|
|
"x86 only: show protected mode far calls/returns/exceptions" },
|
2012-06-03 19:03:23 +04:00
|
|
|
{ CPU_LOG_RESET, "cpu_reset",
|
2015-01-27 15:11:26 +03:00
|
|
|
"show CPU state before CPU resets" },
|
2012-06-03 21:04:28 +04:00
|
|
|
{ LOG_UNIMP, "unimp",
|
|
|
|
"log unimplemented functionality" },
|
2012-10-18 17:11:35 +04:00
|
|
|
{ LOG_GUEST_ERROR, "guest_errors",
|
|
|
|
"log when the guest OS does something invalid (eg accessing a\n"
|
|
|
|
"non-existent register)" },
|
2015-11-13 14:32:19 +03:00
|
|
|
{ CPU_LOG_PAGE, "page",
|
|
|
|
"dump pages at beginning of user mode emulation" },
|
2015-09-17 01:33:53 +03:00
|
|
|
{ CPU_LOG_TB_NOCHAIN, "nochain",
|
|
|
|
"do not chain compiled TBs so that \"exec\" and \"cpu\" show\n"
|
|
|
|
"complete traces" },
|
2019-10-11 18:34:05 +03:00
|
|
|
#ifdef CONFIG_PLUGIN
|
|
|
|
{ CPU_LOG_PLUGIN, "plugin", "output from TCG plugins\n"},
|
|
|
|
#endif
|
2020-02-04 05:54:14 +03:00
|
|
|
{ LOG_STRACE, "strace",
|
|
|
|
"log every user-mode syscall, its input, and its result" },
|
2012-06-03 19:03:23 +04:00
|
|
|
{ 0, NULL, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
/* takes a comma separated list of log masks. Return 0 if error. */
|
2013-02-11 20:41:22 +04:00
|
|
|
int qemu_str_to_log_mask(const char *str)
|
2012-06-03 19:03:23 +04:00
|
|
|
{
|
2013-02-11 20:41:25 +04:00
|
|
|
const QEMULogItem *item;
|
2016-09-06 21:25:43 +03:00
|
|
|
int mask = 0;
|
|
|
|
char **parts = g_strsplit(str, ",", 0);
|
|
|
|
char **tmp;
|
2012-06-03 19:03:23 +04:00
|
|
|
|
2016-09-06 21:25:43 +03:00
|
|
|
for (tmp = parts; tmp && *tmp; tmp++) {
|
|
|
|
if (g_str_equal(*tmp, "all")) {
|
2013-02-11 20:41:25 +04:00
|
|
|
for (item = qemu_log_items; item->mask != 0; item++) {
|
2012-06-03 19:03:23 +04:00
|
|
|
mask |= item->mask;
|
|
|
|
}
|
2016-01-07 16:55:32 +03:00
|
|
|
#ifdef CONFIG_TRACE_LOG
|
2016-09-06 21:25:43 +03:00
|
|
|
} else if (g_str_has_prefix(*tmp, "trace:") && (*tmp)[6] != '\0') {
|
|
|
|
trace_enable_events((*tmp) + 6);
|
2016-01-07 16:55:32 +03:00
|
|
|
mask |= LOG_TRACE;
|
|
|
|
#endif
|
2012-06-03 19:03:23 +04:00
|
|
|
} else {
|
2013-02-11 20:41:25 +04:00
|
|
|
for (item = qemu_log_items; item->mask != 0; item++) {
|
2016-09-06 21:25:43 +03:00
|
|
|
if (g_str_equal(*tmp, item->name)) {
|
2012-06-03 19:03:23 +04:00
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
}
|
2016-09-06 21:25:43 +03:00
|
|
|
goto error;
|
2016-01-07 16:55:32 +03:00
|
|
|
found:
|
|
|
|
mask |= item->mask;
|
2012-06-03 19:03:23 +04:00
|
|
|
}
|
|
|
|
}
|
2016-09-06 21:25:43 +03:00
|
|
|
|
|
|
|
g_strfreev(parts);
|
2012-06-03 19:03:23 +04:00
|
|
|
return mask;
|
2016-09-06 21:25:43 +03:00
|
|
|
|
|
|
|
error:
|
|
|
|
g_strfreev(parts);
|
|
|
|
return 0;
|
2012-06-03 19:03:23 +04:00
|
|
|
}
|
2013-02-11 20:41:21 +04:00
|
|
|
|
|
|
|
void qemu_print_log_usage(FILE *f)
|
|
|
|
{
|
2013-02-11 20:41:25 +04:00
|
|
|
const QEMULogItem *item;
|
2013-02-11 20:41:21 +04:00
|
|
|
fprintf(f, "Log items (comma separated):\n");
|
2013-02-11 20:41:25 +04:00
|
|
|
for (item = qemu_log_items; item->mask != 0; item++) {
|
2016-01-07 16:55:32 +03:00
|
|
|
fprintf(f, "%-15s %s\n", item->name, item->help);
|
2013-02-11 20:41:21 +04:00
|
|
|
}
|
2016-01-07 16:55:32 +03:00
|
|
|
#ifdef CONFIG_TRACE_LOG
|
|
|
|
fprintf(f, "trace:PATTERN enable trace events\n");
|
|
|
|
fprintf(f, "\nUse \"-d trace:help\" to get a list of trace events.\n\n");
|
|
|
|
#endif
|
2013-02-11 20:41:21 +04:00
|
|
|
}
|