xref: /qemu/util/log.c (revision c60f599b)
1d890d50dSDenis V. Lunev /*
2d890d50dSDenis V. Lunev  * Logging support
3d890d50dSDenis V. Lunev  *
4d890d50dSDenis V. Lunev  *  Copyright (c) 2003 Fabrice Bellard
5d890d50dSDenis V. Lunev  *
6d890d50dSDenis V. Lunev  * This library is free software; you can redistribute it and/or
7d890d50dSDenis V. Lunev  * modify it under the terms of the GNU Lesser General Public
8d890d50dSDenis V. Lunev  * License as published by the Free Software Foundation; either
961f3c91aSChetan Pant  * version 2.1 of the License, or (at your option) any later version.
10d890d50dSDenis V. Lunev  *
11d890d50dSDenis V. Lunev  * This library is distributed in the hope that it will be useful,
12d890d50dSDenis V. Lunev  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13d890d50dSDenis V. Lunev  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14d890d50dSDenis V. Lunev  * Lesser General Public License for more details.
15d890d50dSDenis V. Lunev  *
16d890d50dSDenis V. Lunev  * You should have received a copy of the GNU Lesser General Public
17d890d50dSDenis V. Lunev  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18d890d50dSDenis V. Lunev  */
19d890d50dSDenis V. Lunev 
20d38ea87aSPeter Maydell #include "qemu/osdep.h"
21d890d50dSDenis V. Lunev #include "qemu/log.h"
223514552eSAlex Bennée #include "qemu/range.h"
233514552eSAlex Bennée #include "qemu/error-report.h"
24bd6fee9fSMarkus Armbruster #include "qapi/error.h"
253514552eSAlex Bennée #include "qemu/cutils.h"
26c84ea00dSPaolo Bonzini #include "trace/control.h"
27b8121fe7SRobert Foley #include "qemu/thread.h"
286e8a355dSDaniel Brodsky #include "qemu/lockable.h"
29d890d50dSDenis V. Lunev 
30d890d50dSDenis V. Lunev static char *logfilename;
31b8121fe7SRobert Foley static QemuMutex qemu_logfile_mutex;
327606488cSRobert Foley QemuLogFile *qemu_logfile;
33d890d50dSDenis V. Lunev int qemu_loglevel;
34d890d50dSDenis V. Lunev static int log_append = 0;
353514552eSAlex Bennée static GArray *debug_regions;
36d890d50dSDenis V. Lunev 
37c59fe6e5SRichard Henderson /* Lock/unlock output. */
38c59fe6e5SRichard Henderson 
39*c60f599bSRichard Henderson FILE *qemu_log_trylock(void)
40c59fe6e5SRichard Henderson {
41c59fe6e5SRichard Henderson     QemuLogFile *logfile;
42*c60f599bSRichard Henderson 
43c59fe6e5SRichard Henderson     rcu_read_lock();
44c59fe6e5SRichard Henderson     logfile = qatomic_rcu_read(&qemu_logfile);
45c59fe6e5SRichard Henderson     if (logfile) {
46c59fe6e5SRichard Henderson         qemu_flockfile(logfile->fd);
47c59fe6e5SRichard Henderson         return logfile->fd;
48c59fe6e5SRichard Henderson     } else {
49*c60f599bSRichard Henderson         rcu_read_unlock();
50c59fe6e5SRichard Henderson         return NULL;
51c59fe6e5SRichard Henderson     }
52c59fe6e5SRichard Henderson }
53c59fe6e5SRichard Henderson 
54c59fe6e5SRichard Henderson void qemu_log_unlock(FILE *fd)
55c59fe6e5SRichard Henderson {
56c59fe6e5SRichard Henderson     if (fd) {
57c59fe6e5SRichard Henderson         qemu_funlockfile(fd);
58c59fe6e5SRichard Henderson         rcu_read_unlock();
59c59fe6e5SRichard Henderson     }
60*c60f599bSRichard Henderson }
61c59fe6e5SRichard Henderson 
62bdfb460eSRichard Henderson /* Return the number of characters emitted.  */
63bdfb460eSRichard Henderson int qemu_log(const char *fmt, ...)
64d890d50dSDenis V. Lunev {
65bdfb460eSRichard Henderson     int ret = 0;
667606488cSRobert Foley     QemuLogFile *logfile;
677606488cSRobert Foley 
687606488cSRobert Foley     rcu_read_lock();
69d73415a3SStefan Hajnoczi     logfile = qatomic_rcu_read(&qemu_logfile);
707606488cSRobert Foley     if (logfile) {
71bdfb460eSRichard Henderson         va_list ap;
72bdfb460eSRichard Henderson         va_start(ap, fmt);
737606488cSRobert Foley         ret = vfprintf(logfile->fd, fmt, ap);
74d890d50dSDenis V. Lunev         va_end(ap);
75bdfb460eSRichard Henderson 
76bdfb460eSRichard Henderson         /* Don't pass back error results.  */
77bdfb460eSRichard Henderson         if (ret < 0) {
78bdfb460eSRichard Henderson             ret = 0;
79bdfb460eSRichard Henderson         }
80bdfb460eSRichard Henderson     }
817606488cSRobert Foley     rcu_read_unlock();
82bdfb460eSRichard Henderson     return ret;
83d890d50dSDenis V. Lunev }
84d890d50dSDenis V. Lunev 
85b8121fe7SRobert Foley static void __attribute__((__constructor__)) qemu_logfile_init(void)
86b8121fe7SRobert Foley {
87b8121fe7SRobert Foley     qemu_mutex_init(&qemu_logfile_mutex);
88b8121fe7SRobert Foley }
89b8121fe7SRobert Foley 
907606488cSRobert Foley static void qemu_logfile_free(QemuLogFile *logfile)
917606488cSRobert Foley {
927606488cSRobert Foley     g_assert(logfile);
937606488cSRobert Foley 
947606488cSRobert Foley     if (logfile->fd != stderr) {
957606488cSRobert Foley         fclose(logfile->fd);
967606488cSRobert Foley     }
977606488cSRobert Foley     g_free(logfile);
987606488cSRobert Foley }
997606488cSRobert Foley 
100d890d50dSDenis V. Lunev /* enable or disable low levels log */
101c5955f4fSRichard Henderson bool qemu_set_log(int log_flags, Error **errp)
102d890d50dSDenis V. Lunev {
103045e8861SRobert Foley     bool need_to_open_file = false;
1047606488cSRobert Foley     QemuLogFile *logfile;
1057606488cSRobert Foley 
106d890d50dSDenis V. Lunev     qemu_loglevel = log_flags;
107ed7f5f1dSPaolo Bonzini #ifdef CONFIG_TRACE_LOG
108ed7f5f1dSPaolo Bonzini     qemu_loglevel |= LOG_TRACE;
109ed7f5f1dSPaolo Bonzini #endif
110045e8861SRobert Foley     /*
111045e8861SRobert Foley      * In all cases we only log if qemu_loglevel is set.
112045e8861SRobert Foley      * Also:
113045e8861SRobert Foley      *   If not daemonized we will always log either to stderr
114045e8861SRobert Foley      *     or to a file (if there is a logfilename).
115045e8861SRobert Foley      *   If we are daemonized,
116045e8861SRobert Foley      *     we will only log if there is a logfilename.
117045e8861SRobert Foley      */
118045e8861SRobert Foley     if (qemu_loglevel && (!is_daemonized() || logfilename)) {
119045e8861SRobert Foley         need_to_open_file = true;
120045e8861SRobert Foley     }
1216e8a355dSDaniel Brodsky     QEMU_LOCK_GUARD(&qemu_logfile_mutex);
122045e8861SRobert Foley     if (qemu_logfile && !need_to_open_file) {
1237606488cSRobert Foley         logfile = qemu_logfile;
124d73415a3SStefan Hajnoczi         qatomic_rcu_set(&qemu_logfile, NULL);
1257606488cSRobert Foley         call_rcu(logfile, qemu_logfile_free, rcu);
126045e8861SRobert Foley     } else if (!qemu_logfile && need_to_open_file) {
1277606488cSRobert Foley         logfile = g_new0(QemuLogFile, 1);
128d890d50dSDenis V. Lunev         if (logfilename) {
1297606488cSRobert Foley             logfile->fd = fopen(logfilename, log_append ? "a" : "w");
1307606488cSRobert Foley             if (!logfile->fd) {
131c5955f4fSRichard Henderson                 error_setg_errno(errp, errno, "Error opening logfile %s",
132c5955f4fSRichard Henderson                                  logfilename);
133c5955f4fSRichard Henderson                 return false;
134d890d50dSDenis V. Lunev             }
13596c33a45SDimitris Aragiorgis             /* In case we are a daemon redirect stderr to logfile */
13696c33a45SDimitris Aragiorgis             if (is_daemonized()) {
1377606488cSRobert Foley                 dup2(fileno(logfile->fd), STDERR_FILENO);
1387606488cSRobert Foley                 fclose(logfile->fd);
13996c33a45SDimitris Aragiorgis                 /* This will skip closing logfile in qemu_log_close() */
1407606488cSRobert Foley                 logfile->fd = stderr;
14196c33a45SDimitris Aragiorgis             }
142d890d50dSDenis V. Lunev         } else {
143d890d50dSDenis V. Lunev             /* Default to stderr if no log file specified */
144c586eac3SPaolo Bonzini             assert(!is_daemonized());
1457606488cSRobert Foley             logfile->fd = stderr;
146d890d50dSDenis V. Lunev         }
147d890d50dSDenis V. Lunev 
148d890d50dSDenis V. Lunev #if defined(_WIN32)
149d890d50dSDenis V. Lunev         /* Win32 doesn't support line-buffering, so use unbuffered output. */
1507606488cSRobert Foley         setvbuf(logfile->fd, NULL, _IONBF, 0);
151d890d50dSDenis V. Lunev #else
1527606488cSRobert Foley         setvbuf(logfile->fd, NULL, _IOLBF, 0);
153d890d50dSDenis V. Lunev #endif
154d890d50dSDenis V. Lunev         log_append = 1;
155d73415a3SStefan Hajnoczi         qatomic_rcu_set(&qemu_logfile, logfile);
156d890d50dSDenis V. Lunev     }
157c5955f4fSRichard Henderson     return true;
158d890d50dSDenis V. Lunev }
159f2937a33SPaolo Bonzini 
160f6880b7fSAlex Bennée /*
161f6880b7fSAlex Bennée  * Allow the user to include %d in their logfile which will be
162f6880b7fSAlex Bennée  * substituted with the current PID. This is useful for debugging many
163f6880b7fSAlex Bennée  * nested linux-user tasks but will result in lots of logs.
164e144a605SSalvador Fandino  *
165e144a605SSalvador Fandino  * filename may be NULL. In that case, log output is sent to stderr
166f6880b7fSAlex Bennée  */
167e2c7c6a4SRichard Henderson bool qemu_set_log_filename(const char *filename, Error **errp)
168d890d50dSDenis V. Lunev {
169d890d50dSDenis V. Lunev     g_free(logfilename);
1700f516ca4SRobert Foley     logfilename = NULL;
171f6880b7fSAlex Bennée 
172e144a605SSalvador Fandino     if (filename) {
173e144a605SSalvador Fandino             char *pidstr = strstr(filename, "%");
174f6880b7fSAlex Bennée             if (pidstr) {
175f6880b7fSAlex Bennée                 /* We only accept one %d, no other format strings */
176f6880b7fSAlex Bennée                 if (pidstr[1] != 'd' || strchr(pidstr + 2, '%')) {
177daa76aa4SMarkus Armbruster                     error_setg(errp, "Bad logfile format: %s", filename);
178e2c7c6a4SRichard Henderson                     return false;
179f6880b7fSAlex Bennée                 } else {
180f6880b7fSAlex Bennée                     logfilename = g_strdup_printf(filename, getpid());
181f6880b7fSAlex Bennée                 }
182f6880b7fSAlex Bennée             } else {
183d890d50dSDenis V. Lunev                 logfilename = g_strdup(filename);
184f6880b7fSAlex Bennée             }
185e144a605SSalvador Fandino     }
186e144a605SSalvador Fandino 
187d890d50dSDenis V. Lunev     qemu_log_close();
188c5955f4fSRichard Henderson     return qemu_set_log(qemu_loglevel, errp);
189d890d50dSDenis V. Lunev }
190d890d50dSDenis V. Lunev 
1913514552eSAlex Bennée /* Returns true if addr is in our debug filter or no filter defined
1923514552eSAlex Bennée  */
1933514552eSAlex Bennée bool qemu_log_in_addr_range(uint64_t addr)
1943514552eSAlex Bennée {
1953514552eSAlex Bennée     if (debug_regions) {
1963514552eSAlex Bennée         int i = 0;
1973514552eSAlex Bennée         for (i = 0; i < debug_regions->len; i++) {
19858e19e6eSMarkus Armbruster             Range *range = &g_array_index(debug_regions, Range, i);
199a0efbf16SMarkus Armbruster             if (range_contains(range, addr)) {
2003514552eSAlex Bennée                 return true;
2013514552eSAlex Bennée             }
2023514552eSAlex Bennée         }
2033514552eSAlex Bennée         return false;
2043514552eSAlex Bennée     } else {
2053514552eSAlex Bennée         return true;
2063514552eSAlex Bennée     }
2073514552eSAlex Bennée }
2083514552eSAlex Bennée 
2093514552eSAlex Bennée 
210bd6fee9fSMarkus Armbruster void qemu_set_dfilter_ranges(const char *filter_spec, Error **errp)
2113514552eSAlex Bennée {
2123514552eSAlex Bennée     gchar **ranges = g_strsplit(filter_spec, ",", 0);
213bd6fee9fSMarkus Armbruster     int i;
2142ec62faeSMarkus Armbruster 
2152ec62faeSMarkus Armbruster     if (debug_regions) {
2162ec62faeSMarkus Armbruster         g_array_unref(debug_regions);
2172ec62faeSMarkus Armbruster         debug_regions = NULL;
2182ec62faeSMarkus Armbruster     }
2192ec62faeSMarkus Armbruster 
2203514552eSAlex Bennée     debug_regions = g_array_sized_new(FALSE, FALSE,
2213514552eSAlex Bennée                                       sizeof(Range), g_strv_length(ranges));
222bd6fee9fSMarkus Armbruster     for (i = 0; ranges[i]; i++) {
223bd6fee9fSMarkus Armbruster         const char *r = ranges[i];
224bd6fee9fSMarkus Armbruster         const char *range_op, *r2, *e;
22558e19e6eSMarkus Armbruster         uint64_t r1val, r2val, lob, upb;
226bd6fee9fSMarkus Armbruster         struct Range range;
227bd6fee9fSMarkus Armbruster 
228bd6fee9fSMarkus Armbruster         range_op = strstr(r, "-");
229bd6fee9fSMarkus Armbruster         r2 = range_op ? range_op + 1 : NULL;
2303514552eSAlex Bennée         if (!range_op) {
2313514552eSAlex Bennée             range_op = strstr(r, "+");
2323514552eSAlex Bennée             r2 = range_op ? range_op + 1 : NULL;
2333514552eSAlex Bennée         }
2343514552eSAlex Bennée         if (!range_op) {
2353514552eSAlex Bennée             range_op = strstr(r, "..");
2363514552eSAlex Bennée             r2 = range_op ? range_op + 2 : NULL;
2373514552eSAlex Bennée         }
238bd6fee9fSMarkus Armbruster         if (!range_op) {
239bd6fee9fSMarkus Armbruster             error_setg(errp, "Bad range specifier");
240bd6fee9fSMarkus Armbruster             goto out;
241bd6fee9fSMarkus Armbruster         }
2423514552eSAlex Bennée 
243b30d1886SMarkus Armbruster         if (qemu_strtou64(r, &e, 0, &r1val)
244bd6fee9fSMarkus Armbruster             || e != range_op) {
245bd6fee9fSMarkus Armbruster             error_setg(errp, "Invalid number to the left of %.*s",
246bd6fee9fSMarkus Armbruster                        (int)(r2 - range_op), range_op);
247bd6fee9fSMarkus Armbruster             goto out;
248bd6fee9fSMarkus Armbruster         }
249b30d1886SMarkus Armbruster         if (qemu_strtou64(r2, NULL, 0, &r2val)) {
250bd6fee9fSMarkus Armbruster             error_setg(errp, "Invalid number to the right of %.*s",
251bd6fee9fSMarkus Armbruster                        (int)(r2 - range_op), range_op);
252bd6fee9fSMarkus Armbruster             goto out;
253bd6fee9fSMarkus Armbruster         }
2543514552eSAlex Bennée 
2553514552eSAlex Bennée         switch (*range_op) {
2563514552eSAlex Bennée         case '+':
25758e19e6eSMarkus Armbruster             lob = r1val;
25858e19e6eSMarkus Armbruster             upb = r1val + r2val - 1;
2593514552eSAlex Bennée             break;
2603514552eSAlex Bennée         case '-':
26158e19e6eSMarkus Armbruster             upb = r1val;
26258e19e6eSMarkus Armbruster             lob = r1val - (r2val - 1);
2633514552eSAlex Bennée             break;
2643514552eSAlex Bennée         case '.':
26558e19e6eSMarkus Armbruster             lob = r1val;
26658e19e6eSMarkus Armbruster             upb = r2val;
2673514552eSAlex Bennée             break;
2683514552eSAlex Bennée         default:
2693514552eSAlex Bennée             g_assert_not_reached();
2703514552eSAlex Bennée         }
27158eeb83cSMarkus Armbruster         if (lob > upb) {
27258e19e6eSMarkus Armbruster             error_setg(errp, "Invalid range");
27358e19e6eSMarkus Armbruster             goto out;
27458e19e6eSMarkus Armbruster         }
275a0efbf16SMarkus Armbruster         range_set_bounds(&range, lob, upb);
2763514552eSAlex Bennée         g_array_append_val(debug_regions, range);
2773514552eSAlex Bennée     }
278bd6fee9fSMarkus Armbruster out:
2793514552eSAlex Bennée     g_strfreev(ranges);
2803514552eSAlex Bennée }
2813514552eSAlex Bennée 
28299affd1dSDenis V. Lunev /* fflush() the log file */
28399affd1dSDenis V. Lunev void qemu_log_flush(void)
28499affd1dSDenis V. Lunev {
2857606488cSRobert Foley     QemuLogFile *logfile;
2867606488cSRobert Foley 
2877606488cSRobert Foley     rcu_read_lock();
288d73415a3SStefan Hajnoczi     logfile = qatomic_rcu_read(&qemu_logfile);
2897606488cSRobert Foley     if (logfile) {
2907606488cSRobert Foley         fflush(logfile->fd);
2917606488cSRobert Foley     }
2927606488cSRobert Foley     rcu_read_unlock();
29399affd1dSDenis V. Lunev }
29499affd1dSDenis V. Lunev 
29599affd1dSDenis V. Lunev /* Close the log file */
29699affd1dSDenis V. Lunev void qemu_log_close(void)
29799affd1dSDenis V. Lunev {
2987606488cSRobert Foley     QemuLogFile *logfile;
2997606488cSRobert Foley 
300b8121fe7SRobert Foley     qemu_mutex_lock(&qemu_logfile_mutex);
3017606488cSRobert Foley     logfile = qemu_logfile;
3027606488cSRobert Foley 
3037606488cSRobert Foley     if (logfile) {
304d73415a3SStefan Hajnoczi         qatomic_rcu_set(&qemu_logfile, NULL);
3057606488cSRobert Foley         call_rcu(logfile, qemu_logfile_free, rcu);
30699affd1dSDenis V. Lunev     }
307b8121fe7SRobert Foley     qemu_mutex_unlock(&qemu_logfile_mutex);
30899affd1dSDenis V. Lunev }
30999affd1dSDenis V. Lunev 
310d890d50dSDenis V. Lunev const QEMULogItem qemu_log_items[] = {
311d890d50dSDenis V. Lunev     { CPU_LOG_TB_OUT_ASM, "out_asm",
312d890d50dSDenis V. Lunev       "show generated host assembly code for each compiled TB" },
313d890d50dSDenis V. Lunev     { CPU_LOG_TB_IN_ASM, "in_asm",
314d890d50dSDenis V. Lunev       "show target assembly code for each compiled TB" },
315d890d50dSDenis V. Lunev     { CPU_LOG_TB_OP, "op",
316d890d50dSDenis V. Lunev       "show micro ops for each compiled TB" },
317d890d50dSDenis V. Lunev     { CPU_LOG_TB_OP_OPT, "op_opt",
3185a18407fSRichard Henderson       "show micro ops after optimization" },
3195a18407fSRichard Henderson     { CPU_LOG_TB_OP_IND, "op_ind",
3205a18407fSRichard Henderson       "show micro ops before indirect lowering" },
321d890d50dSDenis V. Lunev     { CPU_LOG_INT, "int",
322d890d50dSDenis V. Lunev       "show interrupts/exceptions in short format" },
323d890d50dSDenis V. Lunev     { CPU_LOG_EXEC, "exec",
324d890d50dSDenis V. Lunev       "show trace before each executed TB (lots of logs)" },
325d890d50dSDenis V. Lunev     { CPU_LOG_TB_CPU, "cpu",
32654195736SAlex Bennée       "show CPU registers before entering a TB (lots of logs)" },
327ae765180SPeter Maydell     { CPU_LOG_TB_FPU, "fpu",
328ae765180SPeter Maydell       "include FPU registers in the 'cpu' logging" },
329d890d50dSDenis V. Lunev     { CPU_LOG_MMU, "mmu",
330d890d50dSDenis V. Lunev       "log MMU-related activities" },
331d890d50dSDenis V. Lunev     { CPU_LOG_PCALL, "pcall",
332d890d50dSDenis V. Lunev       "x86 only: show protected mode far calls/returns/exceptions" },
333d890d50dSDenis V. Lunev     { CPU_LOG_RESET, "cpu_reset",
334d890d50dSDenis V. Lunev       "show CPU state before CPU resets" },
335d890d50dSDenis V. Lunev     { LOG_UNIMP, "unimp",
336d890d50dSDenis V. Lunev       "log unimplemented functionality" },
337d890d50dSDenis V. Lunev     { LOG_GUEST_ERROR, "guest_errors",
338d890d50dSDenis V. Lunev       "log when the guest OS does something invalid (eg accessing a\n"
339d890d50dSDenis V. Lunev       "non-existent register)" },
340d890d50dSDenis V. Lunev     { CPU_LOG_PAGE, "page",
341d890d50dSDenis V. Lunev       "dump pages at beginning of user mode emulation" },
342d890d50dSDenis V. Lunev     { CPU_LOG_TB_NOCHAIN, "nochain",
343d890d50dSDenis V. Lunev       "do not chain compiled TBs so that \"exec\" and \"cpu\" show\n"
344d890d50dSDenis V. Lunev       "complete traces" },
345ca76a669SAlex Bennée #ifdef CONFIG_PLUGIN
346ca76a669SAlex Bennée     { CPU_LOG_PLUGIN, "plugin", "output from TCG plugins\n"},
347ca76a669SAlex Bennée #endif
3484b25a506SJosh Kunz     { LOG_STRACE, "strace",
3494b25a506SJosh Kunz       "log every user-mode syscall, its input, and its result" },
350d890d50dSDenis V. Lunev     { 0, NULL, NULL },
351d890d50dSDenis V. Lunev };
352d890d50dSDenis V. Lunev 
353d890d50dSDenis V. Lunev /* takes a comma separated list of log masks. Return 0 if error. */
354d890d50dSDenis V. Lunev int qemu_str_to_log_mask(const char *str)
355d890d50dSDenis V. Lunev {
356d890d50dSDenis V. Lunev     const QEMULogItem *item;
35789d0a64fSDaniel P. Berrange     int mask = 0;
35889d0a64fSDaniel P. Berrange     char **parts = g_strsplit(str, ",", 0);
35989d0a64fSDaniel P. Berrange     char **tmp;
360d890d50dSDenis V. Lunev 
36189d0a64fSDaniel P. Berrange     for (tmp = parts; tmp && *tmp; tmp++) {
36289d0a64fSDaniel P. Berrange         if (g_str_equal(*tmp, "all")) {
363d890d50dSDenis V. Lunev             for (item = qemu_log_items; item->mask != 0; item++) {
364d890d50dSDenis V. Lunev                 mask |= item->mask;
365d890d50dSDenis V. Lunev             }
366c84ea00dSPaolo Bonzini #ifdef CONFIG_TRACE_LOG
36789d0a64fSDaniel P. Berrange         } else if (g_str_has_prefix(*tmp, "trace:") && (*tmp)[6] != '\0') {
36889d0a64fSDaniel P. Berrange             trace_enable_events((*tmp) + 6);
369c84ea00dSPaolo Bonzini             mask |= LOG_TRACE;
370c84ea00dSPaolo Bonzini #endif
371d890d50dSDenis V. Lunev         } else {
372d890d50dSDenis V. Lunev             for (item = qemu_log_items; item->mask != 0; item++) {
37389d0a64fSDaniel P. Berrange                 if (g_str_equal(*tmp, item->name)) {
374d890d50dSDenis V. Lunev                     goto found;
375d890d50dSDenis V. Lunev                 }
376d890d50dSDenis V. Lunev             }
37789d0a64fSDaniel P. Berrange             goto error;
378d890d50dSDenis V. Lunev         found:
379d890d50dSDenis V. Lunev             mask |= item->mask;
380c84ea00dSPaolo Bonzini         }
381d890d50dSDenis V. Lunev     }
38289d0a64fSDaniel P. Berrange 
38389d0a64fSDaniel P. Berrange     g_strfreev(parts);
384d890d50dSDenis V. Lunev     return mask;
38589d0a64fSDaniel P. Berrange 
38689d0a64fSDaniel P. Berrange  error:
38789d0a64fSDaniel P. Berrange     g_strfreev(parts);
38889d0a64fSDaniel P. Berrange     return 0;
389d890d50dSDenis V. Lunev }
390d890d50dSDenis V. Lunev 
391d890d50dSDenis V. Lunev void qemu_print_log_usage(FILE *f)
392d890d50dSDenis V. Lunev {
393d890d50dSDenis V. Lunev     const QEMULogItem *item;
394d890d50dSDenis V. Lunev     fprintf(f, "Log items (comma separated):\n");
395d890d50dSDenis V. Lunev     for (item = qemu_log_items; item->mask != 0; item++) {
396c84ea00dSPaolo Bonzini         fprintf(f, "%-15s %s\n", item->name, item->help);
397d890d50dSDenis V. Lunev     }
398c84ea00dSPaolo Bonzini #ifdef CONFIG_TRACE_LOG
399c84ea00dSPaolo Bonzini     fprintf(f, "trace:PATTERN   enable trace events\n");
400c84ea00dSPaolo Bonzini     fprintf(f, "\nUse \"-d trace:help\" to get a list of trace events.\n\n");
401c84ea00dSPaolo Bonzini #endif
402d890d50dSDenis V. Lunev }
403