qemu-log.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #ifndef QEMU_LOG_H
  2. #define QEMU_LOG_H
  3. #include <stdarg.h>
  4. #ifdef NEED_CPU_H
  5. #include "disas.h"
  6. #endif
  7. /* Private global variables, don't use */
  8. extern FILE *qemu_logfile;
  9. extern int qemu_loglevel;
  10. /*
  11. * The new API:
  12. *
  13. */
  14. /* Log settings checking macros: */
  15. /* Returns true if qemu_log() will really write somewhere
  16. */
  17. static inline bool qemu_log_enabled(void)
  18. {
  19. return qemu_logfile != NULL;
  20. }
  21. #define CPU_LOG_TB_OUT_ASM (1 << 0)
  22. #define CPU_LOG_TB_IN_ASM (1 << 1)
  23. #define CPU_LOG_TB_OP (1 << 2)
  24. #define CPU_LOG_TB_OP_OPT (1 << 3)
  25. #define CPU_LOG_INT (1 << 4)
  26. #define CPU_LOG_EXEC (1 << 5)
  27. #define CPU_LOG_PCALL (1 << 6)
  28. #define CPU_LOG_IOPORT (1 << 7)
  29. #define CPU_LOG_TB_CPU (1 << 8)
  30. #define CPU_LOG_RESET (1 << 9)
  31. #define LOG_UNIMP (1 << 10)
  32. /* Returns true if a bit is set in the current loglevel mask
  33. */
  34. static inline bool qemu_loglevel_mask(int mask)
  35. {
  36. return (qemu_loglevel & mask) != 0;
  37. }
  38. /* Logging functions: */
  39. /* main logging function
  40. */
  41. void GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...);
  42. /* vfprintf-like logging function
  43. */
  44. static inline void GCC_FMT_ATTR(1, 0)
  45. qemu_log_vprintf(const char *fmt, va_list va)
  46. {
  47. if (qemu_logfile) {
  48. vfprintf(qemu_logfile, fmt, va);
  49. }
  50. }
  51. /* log only if a bit is set on the current loglevel mask
  52. */
  53. void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...);
  54. /* Special cases: */
  55. #ifdef NEED_CPU_H
  56. /* cpu_dump_state() logging functions: */
  57. static inline void log_cpu_state(CPUArchState *env1, int flags)
  58. {
  59. if (qemu_log_enabled()) {
  60. cpu_dump_state(env1, qemu_logfile, fprintf, flags);
  61. }
  62. }
  63. static inline void log_cpu_state_mask(int mask, CPUArchState *env1, int flags)
  64. {
  65. if (qemu_loglevel & mask) {
  66. log_cpu_state(env1, flags);
  67. }
  68. }
  69. /* disas() and target_disas() to qemu_logfile: */
  70. static inline void log_target_disas(target_ulong start, target_ulong len,
  71. int flags)
  72. {
  73. target_disas(qemu_logfile, start, len, flags);
  74. }
  75. static inline void log_disas(void *code, unsigned long size)
  76. {
  77. disas(qemu_logfile, code, size);
  78. }
  79. #if defined(CONFIG_USER_ONLY)
  80. /* page_dump() output to the log file: */
  81. static inline void log_page_dump(void)
  82. {
  83. page_dump(qemu_logfile);
  84. }
  85. #endif
  86. #endif
  87. /* Maintenance: */
  88. /* fflush() the log file */
  89. static inline void qemu_log_flush(void)
  90. {
  91. fflush(qemu_logfile);
  92. }
  93. /* Close the log file */
  94. static inline void qemu_log_close(void)
  95. {
  96. fclose(qemu_logfile);
  97. qemu_logfile = NULL;
  98. }
  99. /* Set up a new log file */
  100. static inline void qemu_log_set_file(FILE *f)
  101. {
  102. qemu_logfile = f;
  103. }
  104. /* Set up a new log file, only if none is set */
  105. static inline void qemu_log_try_set_file(FILE *f)
  106. {
  107. if (!qemu_logfile) {
  108. qemu_logfile = f;
  109. }
  110. }
  111. /* define log items */
  112. typedef struct CPULogItem {
  113. int mask;
  114. const char *name;
  115. const char *help;
  116. } CPULogItem;
  117. extern const CPULogItem cpu_log_items[];
  118. void qemu_set_log(int log_flags, bool use_own_buffers);
  119. static inline void cpu_set_log(int log_flags)
  120. {
  121. #ifdef CONFIG_USER_ONLY
  122. qemu_set_log(log_flags, true);
  123. #else
  124. qemu_set_log(log_flags, false);
  125. #endif
  126. }
  127. void cpu_set_log_filename(const char *filename);
  128. int cpu_str_to_log_mask(const char *str);
  129. #endif