root / qemu-log.c @ c3268cc1
History | View | Annotate | Download (4.8 kB)
1 | 5726c27f | Blue Swirl | /*
|
---|---|---|---|
2 | 5726c27f | Blue Swirl | * Logging support
|
3 | 5726c27f | Blue Swirl | *
|
4 | 5726c27f | Blue Swirl | * Copyright (c) 2003 Fabrice Bellard
|
5 | 5726c27f | Blue Swirl | *
|
6 | 5726c27f | Blue Swirl | * This library is free software; you can redistribute it and/or
|
7 | 5726c27f | Blue Swirl | * modify it under the terms of the GNU Lesser General Public
|
8 | 5726c27f | Blue Swirl | * License as published by the Free Software Foundation; either
|
9 | 5726c27f | Blue Swirl | * version 2 of the License, or (at your option) any later version.
|
10 | 5726c27f | Blue Swirl | *
|
11 | 5726c27f | Blue Swirl | * This library is distributed in the hope that it will be useful,
|
12 | 5726c27f | Blue Swirl | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 5726c27f | Blue Swirl | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 5726c27f | Blue Swirl | * Lesser General Public License for more details.
|
15 | 5726c27f | Blue Swirl | *
|
16 | 5726c27f | Blue Swirl | * You should have received a copy of the GNU Lesser General Public
|
17 | 5726c27f | Blue Swirl | * License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
18 | 5726c27f | Blue Swirl | */
|
19 | 5726c27f | Blue Swirl | |
20 | 5726c27f | Blue Swirl | #include "qemu-common.h" |
21 | 1de7afc9 | Paolo Bonzini | #include "qemu/log.h" |
22 | 5726c27f | Blue Swirl | |
23 | 40a50b0a | Markus Armbruster | static char *logfilename; |
24 | eeacee4d | Blue Swirl | FILE *qemu_logfile; |
25 | eeacee4d | Blue Swirl | int qemu_loglevel;
|
26 | 5726c27f | Blue Swirl | static int log_append = 0; |
27 | 5726c27f | Blue Swirl | |
28 | eeacee4d | Blue Swirl | void qemu_log(const char *fmt, ...) |
29 | eeacee4d | Blue Swirl | { |
30 | eeacee4d | Blue Swirl | va_list ap; |
31 | eeacee4d | Blue Swirl | |
32 | eeacee4d | Blue Swirl | va_start(ap, fmt); |
33 | eeacee4d | Blue Swirl | if (qemu_logfile) {
|
34 | eeacee4d | Blue Swirl | vfprintf(qemu_logfile, fmt, ap); |
35 | eeacee4d | Blue Swirl | } |
36 | eeacee4d | Blue Swirl | va_end(ap); |
37 | eeacee4d | Blue Swirl | } |
38 | eeacee4d | Blue Swirl | |
39 | eeacee4d | Blue Swirl | void qemu_log_mask(int mask, const char *fmt, ...) |
40 | eeacee4d | Blue Swirl | { |
41 | eeacee4d | Blue Swirl | va_list ap; |
42 | eeacee4d | Blue Swirl | |
43 | eeacee4d | Blue Swirl | va_start(ap, fmt); |
44 | eeacee4d | Blue Swirl | if ((qemu_loglevel & mask) && qemu_logfile) {
|
45 | eeacee4d | Blue Swirl | vfprintf(qemu_logfile, fmt, ap); |
46 | eeacee4d | Blue Swirl | } |
47 | eeacee4d | Blue Swirl | va_end(ap); |
48 | eeacee4d | Blue Swirl | } |
49 | eeacee4d | Blue Swirl | |
50 | 5726c27f | Blue Swirl | /* enable or disable low levels log */
|
51 | 24537a01 | Peter Maydell | void do_qemu_set_log(int log_flags, bool use_own_buffers) |
52 | 5726c27f | Blue Swirl | { |
53 | eeacee4d | Blue Swirl | qemu_loglevel = log_flags; |
54 | eeacee4d | Blue Swirl | if (qemu_loglevel && !qemu_logfile) {
|
55 | 989b697d | Peter Maydell | if (logfilename) {
|
56 | 989b697d | Peter Maydell | qemu_logfile = fopen(logfilename, log_append ? "a" : "w"); |
57 | 989b697d | Peter Maydell | if (!qemu_logfile) {
|
58 | 989b697d | Peter Maydell | perror(logfilename); |
59 | 989b697d | Peter Maydell | _exit(1);
|
60 | 989b697d | Peter Maydell | } |
61 | 989b697d | Peter Maydell | } else {
|
62 | 989b697d | Peter Maydell | /* Default to stderr if no log file specified */
|
63 | 989b697d | Peter Maydell | qemu_logfile = stderr; |
64 | 5726c27f | Blue Swirl | } |
65 | 5726c27f | Blue Swirl | /* must avoid mmap() usage of glibc by setting a buffer "by hand" */
|
66 | 3437e545 | Blue Swirl | if (use_own_buffers) {
|
67 | 5726c27f | Blue Swirl | static char logfile_buf[4096]; |
68 | 3437e545 | Blue Swirl | |
69 | eeacee4d | Blue Swirl | setvbuf(qemu_logfile, logfile_buf, _IOLBF, sizeof(logfile_buf));
|
70 | 3437e545 | Blue Swirl | } else {
|
71 | 3437e545 | Blue Swirl | #if defined(_WIN32)
|
72 | 3437e545 | Blue Swirl | /* Win32 doesn't support line-buffering, so use unbuffered output. */
|
73 | 3437e545 | Blue Swirl | setvbuf(qemu_logfile, NULL, _IONBF, 0); |
74 | 5726c27f | Blue Swirl | #else
|
75 | 3437e545 | Blue Swirl | setvbuf(qemu_logfile, NULL, _IOLBF, 0); |
76 | 5726c27f | Blue Swirl | #endif
|
77 | 3437e545 | Blue Swirl | log_append = 1;
|
78 | 3437e545 | Blue Swirl | } |
79 | 5726c27f | Blue Swirl | } |
80 | eeacee4d | Blue Swirl | if (!qemu_loglevel && qemu_logfile) {
|
81 | 989b697d | Peter Maydell | qemu_log_close(); |
82 | 5726c27f | Blue Swirl | } |
83 | 5726c27f | Blue Swirl | } |
84 | 5726c27f | Blue Swirl | |
85 | 9a7e5424 | Peter Maydell | void qemu_set_log_filename(const char *filename) |
86 | 5726c27f | Blue Swirl | { |
87 | 40a50b0a | Markus Armbruster | g_free(logfilename); |
88 | 636e0f27 | Markus Armbruster | logfilename = g_strdup(filename); |
89 | 989b697d | Peter Maydell | qemu_log_close(); |
90 | 24537a01 | Peter Maydell | qemu_set_log(qemu_loglevel); |
91 | 5726c27f | Blue Swirl | } |
92 | 5726c27f | Blue Swirl | |
93 | 38dad9e5 | Peter Maydell | const QEMULogItem qemu_log_items[] = {
|
94 | 5726c27f | Blue Swirl | { CPU_LOG_TB_OUT_ASM, "out_asm",
|
95 | 5726c27f | Blue Swirl | "show generated host assembly code for each compiled TB" },
|
96 | 5726c27f | Blue Swirl | { CPU_LOG_TB_IN_ASM, "in_asm",
|
97 | 5726c27f | Blue Swirl | "show target assembly code for each compiled TB" },
|
98 | 5726c27f | Blue Swirl | { CPU_LOG_TB_OP, "op",
|
99 | 5726c27f | Blue Swirl | "show micro ops for each compiled TB" },
|
100 | 5726c27f | Blue Swirl | { CPU_LOG_TB_OP_OPT, "op_opt",
|
101 | 3437e545 | Blue Swirl | "show micro ops (x86 only: before eflags optimization) and\n"
|
102 | 5726c27f | Blue Swirl | "after liveness analysis" },
|
103 | 5726c27f | Blue Swirl | { CPU_LOG_INT, "int",
|
104 | 5726c27f | Blue Swirl | "show interrupts/exceptions in short format" },
|
105 | 5726c27f | Blue Swirl | { CPU_LOG_EXEC, "exec",
|
106 | 5726c27f | Blue Swirl | "show trace before each executed TB (lots of logs)" },
|
107 | 5726c27f | Blue Swirl | { CPU_LOG_TB_CPU, "cpu",
|
108 | 5726c27f | Blue Swirl | "show CPU state before block translation" },
|
109 | 5726c27f | Blue Swirl | { CPU_LOG_PCALL, "pcall",
|
110 | 3437e545 | Blue Swirl | "x86 only: show protected mode far calls/returns/exceptions" },
|
111 | 5726c27f | Blue Swirl | { CPU_LOG_RESET, "cpu_reset",
|
112 | 3437e545 | Blue Swirl | "x86 only: show CPU state before CPU resets" },
|
113 | 5726c27f | Blue Swirl | { CPU_LOG_IOPORT, "ioport",
|
114 | 5726c27f | Blue Swirl | "show all i/o ports accesses" },
|
115 | dafdf1ab | Blue Swirl | { LOG_UNIMP, "unimp",
|
116 | dafdf1ab | Blue Swirl | "log unimplemented functionality" },
|
117 | e54eba19 | Peter Maydell | { LOG_GUEST_ERROR, "guest_errors",
|
118 | e54eba19 | Peter Maydell | "log when the guest OS does something invalid (eg accessing a\n"
|
119 | e54eba19 | Peter Maydell | "non-existent register)" },
|
120 | 5726c27f | Blue Swirl | { 0, NULL, NULL }, |
121 | 5726c27f | Blue Swirl | }; |
122 | 5726c27f | Blue Swirl | |
123 | 5726c27f | Blue Swirl | static int cmp1(const char *s1, int n, const char *s2) |
124 | 5726c27f | Blue Swirl | { |
125 | 5726c27f | Blue Swirl | if (strlen(s2) != n) {
|
126 | 5726c27f | Blue Swirl | return 0; |
127 | 5726c27f | Blue Swirl | } |
128 | 5726c27f | Blue Swirl | return memcmp(s1, s2, n) == 0; |
129 | 5726c27f | Blue Swirl | } |
130 | 5726c27f | Blue Swirl | |
131 | 5726c27f | Blue Swirl | /* takes a comma separated list of log masks. Return 0 if error. */
|
132 | 4fde1eba | Peter Maydell | int qemu_str_to_log_mask(const char *str) |
133 | 5726c27f | Blue Swirl | { |
134 | 38dad9e5 | Peter Maydell | const QEMULogItem *item;
|
135 | 5726c27f | Blue Swirl | int mask;
|
136 | 5726c27f | Blue Swirl | const char *p, *p1; |
137 | 5726c27f | Blue Swirl | |
138 | 5726c27f | Blue Swirl | p = str; |
139 | 5726c27f | Blue Swirl | mask = 0;
|
140 | 5726c27f | Blue Swirl | for (;;) {
|
141 | 5726c27f | Blue Swirl | p1 = strchr(p, ',');
|
142 | 5726c27f | Blue Swirl | if (!p1) {
|
143 | 5726c27f | Blue Swirl | p1 = p + strlen(p); |
144 | 5726c27f | Blue Swirl | } |
145 | 5726c27f | Blue Swirl | if (cmp1(p,p1-p,"all")) { |
146 | 38dad9e5 | Peter Maydell | for (item = qemu_log_items; item->mask != 0; item++) { |
147 | 5726c27f | Blue Swirl | mask |= item->mask; |
148 | 5726c27f | Blue Swirl | } |
149 | 5726c27f | Blue Swirl | } else {
|
150 | 38dad9e5 | Peter Maydell | for (item = qemu_log_items; item->mask != 0; item++) { |
151 | 5726c27f | Blue Swirl | if (cmp1(p, p1 - p, item->name)) {
|
152 | 5726c27f | Blue Swirl | goto found;
|
153 | 5726c27f | Blue Swirl | } |
154 | 5726c27f | Blue Swirl | } |
155 | 5726c27f | Blue Swirl | return 0; |
156 | 5726c27f | Blue Swirl | } |
157 | 5726c27f | Blue Swirl | found:
|
158 | 5726c27f | Blue Swirl | mask |= item->mask; |
159 | 5726c27f | Blue Swirl | if (*p1 != ',') { |
160 | 5726c27f | Blue Swirl | break;
|
161 | 5726c27f | Blue Swirl | } |
162 | 5726c27f | Blue Swirl | p = p1 + 1;
|
163 | 5726c27f | Blue Swirl | } |
164 | 5726c27f | Blue Swirl | return mask;
|
165 | 5726c27f | Blue Swirl | } |
166 | 59a6fa6e | Peter Maydell | |
167 | 59a6fa6e | Peter Maydell | void qemu_print_log_usage(FILE *f)
|
168 | 59a6fa6e | Peter Maydell | { |
169 | 38dad9e5 | Peter Maydell | const QEMULogItem *item;
|
170 | 59a6fa6e | Peter Maydell | fprintf(f, "Log items (comma separated):\n");
|
171 | 38dad9e5 | Peter Maydell | for (item = qemu_log_items; item->mask != 0; item++) { |
172 | 59a6fa6e | Peter Maydell | fprintf(f, "%-10s %s\n", item->name, item->help);
|
173 | 59a6fa6e | Peter Maydell | } |
174 | 59a6fa6e | Peter Maydell | } |