2012-06-03 17:03:23 +02: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
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu-common.h"
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/log.h"
|
2012-06-03 17:03:23 +02:00
|
|
|
|
2013-01-22 11:08:03 +01:00
|
|
|
static char *logfilename;
|
2012-06-03 18:35:32 +02:00
|
|
|
FILE *qemu_logfile;
|
|
|
|
int qemu_loglevel;
|
2012-06-03 17:03:23 +02:00
|
|
|
static int log_append = 0;
|
|
|
|
|
2012-06-03 18:35:32 +02:00
|
|
|
void qemu_log(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
if (qemu_logfile) {
|
|
|
|
vfprintf(qemu_logfile, fmt, ap);
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void qemu_log_mask(int mask, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
if ((qemu_loglevel & mask) && qemu_logfile) {
|
|
|
|
vfprintf(qemu_logfile, fmt, ap);
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2012-06-03 17:03:23 +02:00
|
|
|
/* enable or disable low levels log */
|
2013-02-11 17:41:23 +01:00
|
|
|
void do_qemu_set_log(int log_flags, bool use_own_buffers)
|
2012-06-03 17:03:23 +02:00
|
|
|
{
|
2012-06-03 18:35:32 +02:00
|
|
|
qemu_loglevel = log_flags;
|
|
|
|
if (qemu_loglevel && !qemu_logfile) {
|
2013-02-26 18:52:40 +01:00
|
|
|
if (logfilename) {
|
|
|
|
qemu_logfile = fopen(logfilename, log_append ? "a" : "w");
|
|
|
|
if (!qemu_logfile) {
|
|
|
|
perror(logfilename);
|
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Default to stderr if no log file specified */
|
|
|
|
qemu_logfile = stderr;
|
2012-06-03 17:03:23 +02:00
|
|
|
}
|
|
|
|
/* must avoid mmap() usage of glibc by setting a buffer "by hand" */
|
2012-07-07 16:40:18 +02:00
|
|
|
if (use_own_buffers) {
|
2012-06-03 17:03:23 +02:00
|
|
|
static char logfile_buf[4096];
|
2012-07-07 16:40:18 +02:00
|
|
|
|
2012-06-03 18:35:32 +02:00
|
|
|
setvbuf(qemu_logfile, logfile_buf, _IOLBF, sizeof(logfile_buf));
|
2012-07-07 16:40:18 +02:00
|
|
|
} else {
|
|
|
|
#if defined(_WIN32)
|
|
|
|
/* Win32 doesn't support line-buffering, so use unbuffered output. */
|
|
|
|
setvbuf(qemu_logfile, NULL, _IONBF, 0);
|
2012-06-03 17:03:23 +02:00
|
|
|
#else
|
2012-07-07 16:40:18 +02:00
|
|
|
setvbuf(qemu_logfile, NULL, _IOLBF, 0);
|
2012-06-03 17:03:23 +02:00
|
|
|
#endif
|
2012-07-07 16:40:18 +02:00
|
|
|
log_append = 1;
|
|
|
|
}
|
2012-06-03 17:03:23 +02:00
|
|
|
}
|
2012-06-03 18:35:32 +02:00
|
|
|
if (!qemu_loglevel && qemu_logfile) {
|
2013-02-26 18:52:40 +01:00
|
|
|
qemu_log_close();
|
2012-06-03 17:03:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-11 17:41:20 +01:00
|
|
|
void qemu_set_log_filename(const char *filename)
|
2012-06-03 17:03:23 +02:00
|
|
|
{
|
2013-01-22 11:08:03 +01:00
|
|
|
g_free(logfilename);
|
2013-01-22 11:08:02 +01:00
|
|
|
logfilename = g_strdup(filename);
|
2013-02-26 18:52:40 +01:00
|
|
|
qemu_log_close();
|
2013-02-11 17:41:23 +01:00
|
|
|
qemu_set_log(qemu_loglevel);
|
2012-06-03 17:03:23 +02:00
|
|
|
}
|
|
|
|
|
2013-02-11 17:41:25 +01:00
|
|
|
const QEMULogItem qemu_log_items[] = {
|
2012-06-03 17:03:23 +02: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",
|
2012-07-07 16:40:18 +02:00
|
|
|
"show micro ops (x86 only: before eflags optimization) and\n"
|
2012-06-03 17:03:23 +02:00
|
|
|
"after liveness analysis" },
|
|
|
|
{ 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",
|
|
|
|
"show CPU state before block translation" },
|
|
|
|
{ CPU_LOG_PCALL, "pcall",
|
2012-07-07 16:40:18 +02:00
|
|
|
"x86 only: show protected mode far calls/returns/exceptions" },
|
2012-06-03 17:03:23 +02:00
|
|
|
{ CPU_LOG_RESET, "cpu_reset",
|
2012-07-07 16:40:18 +02:00
|
|
|
"x86 only: show CPU state before CPU resets" },
|
2012-06-03 17:03:23 +02:00
|
|
|
{ CPU_LOG_IOPORT, "ioport",
|
|
|
|
"show all i/o ports accesses" },
|
2012-06-03 19:04:28 +02:00
|
|
|
{ LOG_UNIMP, "unimp",
|
|
|
|
"log unimplemented functionality" },
|
2012-10-18 15:11:35 +02:00
|
|
|
{ LOG_GUEST_ERROR, "guest_errors",
|
|
|
|
"log when the guest OS does something invalid (eg accessing a\n"
|
|
|
|
"non-existent register)" },
|
2012-06-03 17:03:23 +02:00
|
|
|
{ 0, NULL, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static int cmp1(const char *s1, int n, const char *s2)
|
|
|
|
{
|
|
|
|
if (strlen(s2) != n) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return memcmp(s1, s2, n) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* takes a comma separated list of log masks. Return 0 if error. */
|
2013-02-11 17:41:22 +01:00
|
|
|
int qemu_str_to_log_mask(const char *str)
|
2012-06-03 17:03:23 +02:00
|
|
|
{
|
2013-02-11 17:41:25 +01:00
|
|
|
const QEMULogItem *item;
|
2012-06-03 17:03:23 +02:00
|
|
|
int mask;
|
|
|
|
const char *p, *p1;
|
|
|
|
|
|
|
|
p = str;
|
|
|
|
mask = 0;
|
|
|
|
for (;;) {
|
|
|
|
p1 = strchr(p, ',');
|
|
|
|
if (!p1) {
|
|
|
|
p1 = p + strlen(p);
|
|
|
|
}
|
|
|
|
if (cmp1(p,p1-p,"all")) {
|
2013-02-11 17:41:25 +01:00
|
|
|
for (item = qemu_log_items; item->mask != 0; item++) {
|
2012-06-03 17:03:23 +02:00
|
|
|
mask |= item->mask;
|
|
|
|
}
|
|
|
|
} else {
|
2013-02-11 17:41:25 +01:00
|
|
|
for (item = qemu_log_items; item->mask != 0; item++) {
|
2012-06-03 17:03:23 +02:00
|
|
|
if (cmp1(p, p1 - p, item->name)) {
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
found:
|
|
|
|
mask |= item->mask;
|
|
|
|
if (*p1 != ',') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p = p1 + 1;
|
|
|
|
}
|
|
|
|
return mask;
|
|
|
|
}
|
2013-02-11 17:41:21 +01:00
|
|
|
|
|
|
|
void qemu_print_log_usage(FILE *f)
|
|
|
|
{
|
2013-02-11 17:41:25 +01:00
|
|
|
const QEMULogItem *item;
|
2013-02-11 17:41:21 +01:00
|
|
|
fprintf(f, "Log items (comma separated):\n");
|
2013-02-11 17:41:25 +01:00
|
|
|
for (item = qemu_log_items; item->mask != 0; item++) {
|
2013-02-11 17:41:21 +01:00
|
|
|
fprintf(f, "%-10s %s\n", item->name, item->help);
|
|
|
|
}
|
|
|
|
}
|