blueswir1 | 79383c9 | 2008-08-30 09:51:20 +0000 | [diff] [blame] | 1 | #ifndef QEMU_LOG_H |
| 2 | #define QEMU_LOG_H |
| 3 | |
Blue Swirl | eeacee4 | 2012-06-03 16:35:32 +0000 | [diff] [blame] | 4 | #include <stdarg.h> |
| 5 | #ifdef NEED_CPU_H |
| 6 | #include "disas.h" |
| 7 | #endif |
| 8 | |
| 9 | /* Private global variables, don't use */ |
| 10 | extern FILE *qemu_logfile; |
| 11 | extern int qemu_loglevel; |
blueswir1 | 79383c9 | 2008-08-30 09:51:20 +0000 | [diff] [blame] | 12 | |
aliguori | 6d2c514 | 2009-01-15 21:52:11 +0000 | [diff] [blame] | 13 | /* |
| 14 | * The new API: |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | /* Log settings checking macros: */ |
| 19 | |
| 20 | /* Returns true if qemu_log() will really write somewhere |
| 21 | */ |
Blue Swirl | eeacee4 | 2012-06-03 16:35:32 +0000 | [diff] [blame] | 22 | static inline bool qemu_log_enabled(void) |
| 23 | { |
| 24 | return qemu_logfile != NULL; |
| 25 | } |
aliguori | 6d2c514 | 2009-01-15 21:52:11 +0000 | [diff] [blame] | 26 | |
Blue Swirl | 5726c27 | 2012-06-03 15:03:23 +0000 | [diff] [blame] | 27 | #define CPU_LOG_TB_OUT_ASM (1 << 0) |
| 28 | #define CPU_LOG_TB_IN_ASM (1 << 1) |
| 29 | #define CPU_LOG_TB_OP (1 << 2) |
| 30 | #define CPU_LOG_TB_OP_OPT (1 << 3) |
| 31 | #define CPU_LOG_INT (1 << 4) |
| 32 | #define CPU_LOG_EXEC (1 << 5) |
| 33 | #define CPU_LOG_PCALL (1 << 6) |
| 34 | #define CPU_LOG_IOPORT (1 << 7) |
| 35 | #define CPU_LOG_TB_CPU (1 << 8) |
| 36 | #define CPU_LOG_RESET (1 << 9) |
Blue Swirl | dafdf1a | 2012-06-03 17:04:28 +0000 | [diff] [blame] | 37 | #define LOG_UNIMP (1 << 10) |
Blue Swirl | 5726c27 | 2012-06-03 15:03:23 +0000 | [diff] [blame] | 38 | |
aliguori | 6d2c514 | 2009-01-15 21:52:11 +0000 | [diff] [blame] | 39 | /* Returns true if a bit is set in the current loglevel mask |
| 40 | */ |
Blue Swirl | eeacee4 | 2012-06-03 16:35:32 +0000 | [diff] [blame] | 41 | static inline bool qemu_loglevel_mask(int mask) |
| 42 | { |
| 43 | return (qemu_loglevel & mask) != 0; |
| 44 | } |
aliguori | 6d2c514 | 2009-01-15 21:52:11 +0000 | [diff] [blame] | 45 | |
aliguori | 6d2c514 | 2009-01-15 21:52:11 +0000 | [diff] [blame] | 46 | /* Logging functions: */ |
| 47 | |
| 48 | /* main logging function |
| 49 | */ |
Blue Swirl | eeacee4 | 2012-06-03 16:35:32 +0000 | [diff] [blame] | 50 | void GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...); |
aliguori | 6d2c514 | 2009-01-15 21:52:11 +0000 | [diff] [blame] | 51 | |
| 52 | /* vfprintf-like logging function |
| 53 | */ |
Stefan Weil | 726f8cb | 2012-06-23 20:41:10 +0200 | [diff] [blame] | 54 | static inline void GCC_FMT_ATTR(1, 0) |
| 55 | qemu_log_vprintf(const char *fmt, va_list va) |
Blue Swirl | eeacee4 | 2012-06-03 16:35:32 +0000 | [diff] [blame] | 56 | { |
| 57 | if (qemu_logfile) { |
| 58 | vfprintf(qemu_logfile, fmt, va); |
| 59 | } |
| 60 | } |
aliguori | 6d2c514 | 2009-01-15 21:52:11 +0000 | [diff] [blame] | 61 | |
| 62 | /* log only if a bit is set on the current loglevel mask |
| 63 | */ |
Blue Swirl | eeacee4 | 2012-06-03 16:35:32 +0000 | [diff] [blame] | 64 | void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...); |
aliguori | 6d2c514 | 2009-01-15 21:52:11 +0000 | [diff] [blame] | 65 | |
| 66 | |
aliguori | 6d2c514 | 2009-01-15 21:52:11 +0000 | [diff] [blame] | 67 | /* Special cases: */ |
| 68 | |
Andreas Färber | 3b82321 | 2012-06-09 03:54:30 +0200 | [diff] [blame] | 69 | #ifdef NEED_CPU_H |
aliguori | 6d2c514 | 2009-01-15 21:52:11 +0000 | [diff] [blame] | 70 | /* cpu_dump_state() logging functions: */ |
Blue Swirl | eeacee4 | 2012-06-03 16:35:32 +0000 | [diff] [blame] | 71 | static inline void log_cpu_state(CPUArchState *env1, int flags) |
| 72 | { |
Fabien Chouteau | c8f803e | 2012-05-14 23:39:09 +0000 | [diff] [blame] | 73 | if (qemu_log_enabled()) { |
| 74 | cpu_dump_state(env1, qemu_logfile, fprintf, flags); |
| 75 | } |
Blue Swirl | eeacee4 | 2012-06-03 16:35:32 +0000 | [diff] [blame] | 76 | } |
aliguori | 6d2c514 | 2009-01-15 21:52:11 +0000 | [diff] [blame] | 77 | |
Blue Swirl | eeacee4 | 2012-06-03 16:35:32 +0000 | [diff] [blame] | 78 | static inline void log_cpu_state_mask(int mask, CPUArchState *env1, int flags) |
| 79 | { |
| 80 | if (qemu_loglevel & mask) { |
| 81 | log_cpu_state(env1, flags); |
| 82 | } |
| 83 | } |
aliguori | 6d2c514 | 2009-01-15 21:52:11 +0000 | [diff] [blame] | 84 | |
Blue Swirl | eeacee4 | 2012-06-03 16:35:32 +0000 | [diff] [blame] | 85 | /* disas() and target_disas() to qemu_logfile: */ |
| 86 | static inline void log_target_disas(target_ulong start, target_ulong len, |
| 87 | int flags) |
| 88 | { |
| 89 | target_disas(qemu_logfile, start, len, flags); |
| 90 | } |
| 91 | |
| 92 | static inline void log_disas(void *code, unsigned long size) |
| 93 | { |
| 94 | disas(qemu_logfile, code, size); |
| 95 | } |
| 96 | |
| 97 | #if defined(CONFIG_USER_ONLY) |
aliguori | 6d2c514 | 2009-01-15 21:52:11 +0000 | [diff] [blame] | 98 | /* page_dump() output to the log file: */ |
Blue Swirl | eeacee4 | 2012-06-03 16:35:32 +0000 | [diff] [blame] | 99 | static inline void log_page_dump(void) |
| 100 | { |
| 101 | page_dump(qemu_logfile); |
| 102 | } |
| 103 | #endif |
Andreas Färber | 3b82321 | 2012-06-09 03:54:30 +0200 | [diff] [blame] | 104 | #endif |
aliguori | 6d2c514 | 2009-01-15 21:52:11 +0000 | [diff] [blame] | 105 | |
| 106 | |
aliguori | 6d2c514 | 2009-01-15 21:52:11 +0000 | [diff] [blame] | 107 | /* Maintenance: */ |
| 108 | |
| 109 | /* fflush() the log file */ |
Blue Swirl | eeacee4 | 2012-06-03 16:35:32 +0000 | [diff] [blame] | 110 | static inline void qemu_log_flush(void) |
| 111 | { |
| 112 | fflush(qemu_logfile); |
| 113 | } |
aliguori | 6d2c514 | 2009-01-15 21:52:11 +0000 | [diff] [blame] | 114 | |
| 115 | /* Close the log file */ |
Blue Swirl | eeacee4 | 2012-06-03 16:35:32 +0000 | [diff] [blame] | 116 | static inline void qemu_log_close(void) |
| 117 | { |
| 118 | fclose(qemu_logfile); |
| 119 | qemu_logfile = NULL; |
| 120 | } |
aliguori | 6d2c514 | 2009-01-15 21:52:11 +0000 | [diff] [blame] | 121 | |
| 122 | /* Set up a new log file */ |
Blue Swirl | eeacee4 | 2012-06-03 16:35:32 +0000 | [diff] [blame] | 123 | static inline void qemu_log_set_file(FILE *f) |
| 124 | { |
| 125 | qemu_logfile = f; |
| 126 | } |
aliguori | 6d2c514 | 2009-01-15 21:52:11 +0000 | [diff] [blame] | 127 | |
| 128 | /* Set up a new log file, only if none is set */ |
Blue Swirl | eeacee4 | 2012-06-03 16:35:32 +0000 | [diff] [blame] | 129 | static inline void qemu_log_try_set_file(FILE *f) |
| 130 | { |
| 131 | if (!qemu_logfile) { |
| 132 | qemu_logfile = f; |
| 133 | } |
| 134 | } |
aliguori | 6d2c514 | 2009-01-15 21:52:11 +0000 | [diff] [blame] | 135 | |
Blue Swirl | 5726c27 | 2012-06-03 15:03:23 +0000 | [diff] [blame] | 136 | /* define log items */ |
| 137 | typedef struct CPULogItem { |
| 138 | int mask; |
| 139 | const char *name; |
| 140 | const char *help; |
| 141 | } CPULogItem; |
| 142 | |
| 143 | extern const CPULogItem cpu_log_items[]; |
| 144 | |
Blue Swirl | 3437e54 | 2012-07-07 14:40:18 +0000 | [diff] [blame] | 145 | void qemu_set_log(int log_flags, bool use_own_buffers); |
| 146 | |
| 147 | static inline void cpu_set_log(int log_flags) |
| 148 | { |
| 149 | #ifdef CONFIG_USER_ONLY |
| 150 | qemu_set_log(log_flags, true); |
| 151 | #else |
| 152 | qemu_set_log(log_flags, false); |
| 153 | #endif |
| 154 | } |
| 155 | |
Blue Swirl | 5726c27 | 2012-06-03 15:03:23 +0000 | [diff] [blame] | 156 | void cpu_set_log_filename(const char *filename); |
| 157 | int cpu_str_to_log_mask(const char *str); |
aliguori | 6d2c514 | 2009-01-15 21:52:11 +0000 | [diff] [blame] | 158 | |
blueswir1 | 79383c9 | 2008-08-30 09:51:20 +0000 | [diff] [blame] | 159 | #endif |