Revision eeacee4d

b/linux-user/main.c
1306 1306
    fprintf(stderr, fmt , ## __VA_ARGS__);                              \
1307 1307
    cpu_dump_state(env, stderr, fprintf, 0);                            \
1308 1308
    qemu_log(fmt, ## __VA_ARGS__);                                      \
1309
    if (logfile)                                                        \
1309
    if (qemu_log_enabled()) {                                           \
1310 1310
        log_cpu_state(env, 0);                                          \
1311
    }                                                                   \
1311 1312
} while (0)
1312 1313

  
1313 1314
static int do_store_exclusive(CPUPPCState *env)
b/linux-user/signal.c
4378 4378

  
4379 4379
sigsegv:
4380 4380
    unlock_user_struct(frame, frame_addr, 1);
4381
    if (logfile)
4382
        fprintf (logfile, "segfaulting from setup_frame\n");
4381
    qemu_log("segfaulting from setup_frame\n");
4383 4382
    force_sig(TARGET_SIGSEGV);
4384 4383
}
4385 4384

  
......
4447 4446

  
4448 4447
sigsegv:
4449 4448
    unlock_user_struct(rt_sf, rt_sf_addr, 1);
4450
    if (logfile)
4451
        fprintf (logfile, "segfaulting from setup_rt_frame\n");
4449
    qemu_log("segfaulting from setup_rt_frame\n");
4452 4450
    force_sig(TARGET_SIGSEGV);
4453 4451

  
4454 4452
}
......
4489 4487
sigsegv:
4490 4488
    unlock_user_struct(sr, sr_addr, 1);
4491 4489
    unlock_user_struct(sc, sc_addr, 1);
4492
    if (logfile)
4493
        fprintf (logfile, "segfaulting from do_sigreturn\n");
4490
    qemu_log("segfaulting from do_sigreturn\n");
4494 4491
    force_sig(TARGET_SIGSEGV);
4495 4492
    return 0;
4496 4493
}
......
4552 4549

  
4553 4550
sigsegv:
4554 4551
    unlock_user_struct(rt_sf, rt_sf_addr, 1);
4555
    if (logfile)
4556
        fprintf (logfile, "segfaulting from do_rt_sigreturn\n");
4552
    qemu_log("segfaulting from do_rt_sigreturn\n");
4557 4553
    force_sig(TARGET_SIGSEGV);
4558 4554
    return 0;
4559 4555
}
b/qemu-log.c
25 25
#else
26 26
static const char *logfilename = "/tmp/qemu.log";
27 27
#endif
28
FILE *logfile;
29
int loglevel;
28
FILE *qemu_logfile;
29
int qemu_loglevel;
30 30
static int log_append = 0;
31 31

  
32
void qemu_log(const char *fmt, ...)
33
{
34
    va_list ap;
35

  
36
    va_start(ap, fmt);
37
    if (qemu_logfile) {
38
        vfprintf(qemu_logfile, fmt, ap);
39
    }
40
    va_end(ap);
41
}
42

  
43
void qemu_log_mask(int mask, const char *fmt, ...)
44
{
45
    va_list ap;
46

  
47
    va_start(ap, fmt);
48
    if ((qemu_loglevel & mask) && qemu_logfile) {
49
        vfprintf(qemu_logfile, fmt, ap);
50
    }
51
    va_end(ap);
52
}
53

  
32 54
/* enable or disable low levels log */
33 55
void cpu_set_log(int log_flags)
34 56
{
35
    loglevel = log_flags;
36
    if (loglevel && !logfile) {
37
        logfile = fopen(logfilename, log_append ? "a" : "w");
38
        if (!logfile) {
57
    qemu_loglevel = log_flags;
58
    if (qemu_loglevel && !qemu_logfile) {
59
        qemu_logfile = fopen(logfilename, log_append ? "a" : "w");
60
        if (!qemu_logfile) {
39 61
            perror(logfilename);
40 62
            _exit(1);
41 63
        }
......
43 65
        /* must avoid mmap() usage of glibc by setting a buffer "by hand" */
44 66
        {
45 67
            static char logfile_buf[4096];
46
            setvbuf(logfile, logfile_buf, _IOLBF, sizeof(logfile_buf));
68
            setvbuf(qemu_logfile, logfile_buf, _IOLBF, sizeof(logfile_buf));
47 69
        }
48 70
#elif defined(_WIN32)
49 71
        /* Win32 doesn't support line-buffering, so use unbuffered output. */
50
        setvbuf(logfile, NULL, _IONBF, 0);
72
        setvbuf(qemu_logfile, NULL, _IONBF, 0);
51 73
#else
52
        setvbuf(logfile, NULL, _IOLBF, 0);
74
        setvbuf(qemu_logfile, NULL, _IOLBF, 0);
53 75
#endif
54 76
        log_append = 1;
55 77
    }
56
    if (!loglevel && logfile) {
57
        fclose(logfile);
58
        logfile = NULL;
78
    if (!qemu_loglevel && qemu_logfile) {
79
        fclose(qemu_logfile);
80
        qemu_logfile = NULL;
59 81
    }
60 82
}
61 83

  
62 84
void cpu_set_log_filename(const char *filename)
63 85
{
64 86
    logfilename = strdup(filename);
65
    if (logfile) {
66
        fclose(logfile);
67
        logfile = NULL;
87
    if (qemu_logfile) {
88
        fclose(qemu_logfile);
89
        qemu_logfile = NULL;
68 90
    }
69
    cpu_set_log(loglevel);
91
    cpu_set_log(qemu_loglevel);
70 92
}
71 93

  
72 94
const CPULogItem cpu_log_items[] = {
b/qemu-log.h
1 1
#ifndef QEMU_LOG_H
2 2
#define QEMU_LOG_H
3 3

  
4
/* The deprecated global variables: */
5
extern FILE *logfile;
6
extern int loglevel;
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;
7 12

  
8 13
/* 
9 14
 * The new API:
......
14 19

  
15 20
/* Returns true if qemu_log() will really write somewhere
16 21
 */
17
#define qemu_log_enabled() (logfile != NULL)
22
static inline bool qemu_log_enabled(void)
23
{
24
    return qemu_logfile != NULL;
25
}
18 26

  
19 27
#define CPU_LOG_TB_OUT_ASM (1 << 0)
20 28
#define CPU_LOG_TB_IN_ASM  (1 << 1)
......
29 37

  
30 38
/* Returns true if a bit is set in the current loglevel mask
31 39
 */
32
#define qemu_loglevel_mask(b) ((loglevel & (b)) != 0)
40
static inline bool qemu_loglevel_mask(int mask)
41
{
42
    return (qemu_loglevel & mask) != 0;
43
}
33 44

  
34 45
/* Logging functions: */
35 46

  
36 47
/* main logging function
37 48
 */
38
#define qemu_log(...) do {                 \
39
        if (logfile)                       \
40
            fprintf(logfile, ## __VA_ARGS__); \
41
    } while (0)
49
void GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...);
42 50

  
43 51
/* vfprintf-like logging function
44 52
 */
45
#define qemu_log_vprintf(fmt, va) do {     \
46
        if (logfile)                       \
47
            vfprintf(logfile, fmt, va);    \
48
    } while (0)
53
static inline void qemu_log_vprintf(const char *fmt, va_list va)
54
{
55
    if (qemu_logfile) {
56
        vfprintf(qemu_logfile, fmt, va);
57
    }
58
}
49 59

  
50 60
/* log only if a bit is set on the current loglevel mask
51 61
 */
52
#define qemu_log_mask(b, ...) do {         \
53
        if (loglevel & (b))                \
54
            fprintf(logfile, ## __VA_ARGS__); \
55
    } while (0)
62
void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...);
56 63

  
57 64

  
58 65
/* Special cases: */
59 66

  
60 67
#ifdef NEED_CPU_H
61 68
/* cpu_dump_state() logging functions: */
62
#define log_cpu_state(env, f) cpu_dump_state((env), logfile, fprintf, (f));
63
#define log_cpu_state_mask(b, env, f) do {           \
64
      if (loglevel & (b)) log_cpu_state((env), (f)); \
65
  } while (0)
66

  
67
/* disas() and target_disas() to logfile: */
68
#define log_target_disas(start, len, flags) \
69
        target_disas(logfile, (start), (len), (flags))
70
#define log_disas(start, len) \
71
        disas(logfile, (start), (len))
72

  
69
static inline void log_cpu_state(CPUArchState *env1, int flags)
70
{
71
    cpu_dump_state(env1, qemu_logfile, fprintf, flags);
72
}
73

  
74
static inline void log_cpu_state_mask(int mask, CPUArchState *env1, int flags)
75
{
76
    if (qemu_loglevel & mask) {
77
        log_cpu_state(env1, flags);
78
    }
79
}
80

  
81
/* disas() and target_disas() to qemu_logfile: */
82
static inline void log_target_disas(target_ulong start, target_ulong len,
83
                                    int flags)
84
{
85
    target_disas(qemu_logfile, start, len, flags);
86
}
87

  
88
static inline void log_disas(void *code, unsigned long size)
89
{
90
    disas(qemu_logfile, code, size);
91
}
92

  
93
#if defined(CONFIG_USER_ONLY)
73 94
/* page_dump() output to the log file: */
74
#define log_page_dump() page_dump(logfile)
95
static inline void log_page_dump(void)
96
{
97
    page_dump(qemu_logfile);
98
}
99
#endif
75 100
#endif
76 101

  
77 102

  
78 103
/* Maintenance: */
79 104

  
80 105
/* fflush() the log file */
81
#define qemu_log_flush() fflush(logfile)
106
static inline void qemu_log_flush(void)
107
{
108
    fflush(qemu_logfile);
109
}
82 110

  
83 111
/* Close the log file */
84
#define qemu_log_close() do { \
85
        fclose(logfile);      \
86
        logfile = NULL;       \
87
    } while (0)
112
static inline void qemu_log_close(void)
113
{
114
    fclose(qemu_logfile);
115
    qemu_logfile = NULL;
116
}
88 117

  
89 118
/* Set up a new log file */
90
#define qemu_log_set_file(f) do { \
91
        logfile = (f);            \
92
    } while (0)
119
static inline void qemu_log_set_file(FILE *f)
120
{
121
    qemu_logfile = f;
122
}
93 123

  
94 124
/* Set up a new log file, only if none is set */
95
#define qemu_log_try_set_file(f) do { \
96
        if (!logfile)                 \
97
            logfile = (f);            \
98
    } while (0)
125
static inline void qemu_log_try_set_file(FILE *f)
126
{
127
    if (!qemu_logfile) {
128
        qemu_logfile = f;
129
    }
130
}
99 131

  
100 132
/* define log items */
101 133
typedef struct CPULogItem {
b/qemu-tool.c
24 24

  
25 25
#include <sys/time.h>
26 26

  
27
FILE *logfile;
28

  
29 27
struct QEMUBH
30 28
{
31 29
    QEMUBHFunc *cb;
b/tcg/tcg.c
873 873
    [TCG_COND_GTU] = "gtu"
874 874
};
875 875

  
876
void tcg_dump_ops(TCGContext *s, FILE *outfile)
876
void tcg_dump_ops(TCGContext *s)
877 877
{
878 878
    const uint16_t *opc_ptr;
879 879
    const TCGArg *args;
......
896 896
#else
897 897
            pc = args[0];
898 898
#endif
899
            if (!first_insn) 
900
                fprintf(outfile, "\n");
901
            fprintf(outfile, " ---- 0x%" PRIx64, pc);
899
            if (!first_insn) {
900
                qemu_log("\n");
901
            }
902
            qemu_log(" ---- 0x%" PRIx64, pc);
902 903
            first_insn = 0;
903 904
            nb_oargs = def->nb_oargs;
904 905
            nb_iargs = def->nb_iargs;
......
912 913
            nb_iargs = arg & 0xffff;
913 914
            nb_cargs = def->nb_cargs;
914 915

  
915
            fprintf(outfile, " %s ", def->name);
916
            qemu_log(" %s ", def->name);
916 917

  
917 918
            /* function name */
918
            fprintf(outfile, "%s",
919
                    tcg_get_arg_str_idx(s, buf, sizeof(buf), args[nb_oargs + nb_iargs - 1]));
919
            qemu_log("%s",
920
                     tcg_get_arg_str_idx(s, buf, sizeof(buf),
921
                                         args[nb_oargs + nb_iargs - 1]));
920 922
            /* flags */
921
            fprintf(outfile, ",$0x%" TCG_PRIlx,
922
                    args[nb_oargs + nb_iargs]);
923
            qemu_log(",$0x%" TCG_PRIlx, args[nb_oargs + nb_iargs]);
923 924
            /* nb out args */
924
            fprintf(outfile, ",$%d", nb_oargs);
925
            qemu_log(",$%d", nb_oargs);
925 926
            for(i = 0; i < nb_oargs; i++) {
926
                fprintf(outfile, ",");
927
                fprintf(outfile, "%s",
928
                        tcg_get_arg_str_idx(s, buf, sizeof(buf), args[i]));
927
                qemu_log(",");
928
                qemu_log("%s", tcg_get_arg_str_idx(s, buf, sizeof(buf),
929
                                                   args[i]));
929 930
            }
930 931
            for(i = 0; i < (nb_iargs - 1); i++) {
931
                fprintf(outfile, ",");
932
                qemu_log(",");
932 933
                if (args[nb_oargs + i] == TCG_CALL_DUMMY_ARG) {
933
                    fprintf(outfile, "<dummy>");
934
                    qemu_log("<dummy>");
934 935
                } else {
935
                    fprintf(outfile, "%s",
936
                            tcg_get_arg_str_idx(s, buf, sizeof(buf), args[nb_oargs + i]));
936
                    qemu_log("%s", tcg_get_arg_str_idx(s, buf, sizeof(buf),
937
                                                       args[nb_oargs + i]));
937 938
                }
938 939
            }
939 940
        } else if (c == INDEX_op_movi_i32 
......
947 948
            nb_oargs = def->nb_oargs;
948 949
            nb_iargs = def->nb_iargs;
949 950
            nb_cargs = def->nb_cargs;
950
            fprintf(outfile, " %s %s,$", def->name, 
951
                    tcg_get_arg_str_idx(s, buf, sizeof(buf), args[0]));
951
            qemu_log(" %s %s,$", def->name,
952
                     tcg_get_arg_str_idx(s, buf, sizeof(buf), args[0]));
952 953
            val = args[1];
953 954
            th = tcg_find_helper(s, val);
954 955
            if (th) {
955
                fprintf(outfile, "%s", th->name);
956
                qemu_log("%s", th->name);
956 957
            } else {
957
                if (c == INDEX_op_movi_i32)
958
                    fprintf(outfile, "0x%x", (uint32_t)val);
959
                else
960
                    fprintf(outfile, "0x%" PRIx64 , (uint64_t)val);
958
                if (c == INDEX_op_movi_i32) {
959
                    qemu_log("0x%x", (uint32_t)val);
960
                } else {
961
                    qemu_log("0x%" PRIx64 , (uint64_t)val);
962
                }
961 963
            }
962 964
        } else {
963
            fprintf(outfile, " %s ", def->name);
965
            qemu_log(" %s ", def->name);
964 966
            if (c == INDEX_op_nopn) {
965 967
                /* variable number of arguments */
966 968
                nb_cargs = *args;
......
974 976
            
975 977
            k = 0;
976 978
            for(i = 0; i < nb_oargs; i++) {
977
                if (k != 0)
978
                    fprintf(outfile, ",");
979
                fprintf(outfile, "%s",
980
                        tcg_get_arg_str_idx(s, buf, sizeof(buf), args[k++]));
979
                if (k != 0) {
980
                    qemu_log(",");
981
                }
982
                qemu_log("%s", tcg_get_arg_str_idx(s, buf, sizeof(buf),
983
                                                   args[k++]));
981 984
            }
982 985
            for(i = 0; i < nb_iargs; i++) {
983
                if (k != 0)
984
                    fprintf(outfile, ",");
985
                fprintf(outfile, "%s",
986
                        tcg_get_arg_str_idx(s, buf, sizeof(buf), args[k++]));
986
                if (k != 0) {
987
                    qemu_log(",");
988
                }
989
                qemu_log("%s", tcg_get_arg_str_idx(s, buf, sizeof(buf),
990
                                                   args[k++]));
987 991
            }
988 992
            switch (c) {
989 993
            case INDEX_op_brcond_i32:
......
998 1002
#elif TCG_TARGET_REG_BITS == 64
999 1003
            case INDEX_op_setcond_i64:
1000 1004
#endif
1001
                if (args[k] < ARRAY_SIZE(cond_name) && cond_name[args[k]])
1002
                    fprintf(outfile, ",%s", cond_name[args[k++]]);
1003
                else
1004
                    fprintf(outfile, ",$0x%" TCG_PRIlx, args[k++]);
1005
                if (args[k] < ARRAY_SIZE(cond_name) && cond_name[args[k]]) {
1006
                    qemu_log(",%s", cond_name[args[k++]]);
1007
                } else {
1008
                    qemu_log(",$0x%" TCG_PRIlx, args[k++]);
1009
                }
1005 1010
                i = 1;
1006 1011
                break;
1007 1012
            default:
......
1009 1014
                break;
1010 1015
            }
1011 1016
            for(; i < nb_cargs; i++) {
1012
                if (k != 0)
1013
                    fprintf(outfile, ",");
1017
                if (k != 0) {
1018
                    qemu_log(",");
1019
                }
1014 1020
                arg = args[k++];
1015
                fprintf(outfile, "$0x%" TCG_PRIlx, arg);
1021
                qemu_log("$0x%" TCG_PRIlx, arg);
1016 1022
            }
1017 1023
        }
1018
        fprintf(outfile, "\n");
1024
        qemu_log("\n");
1019 1025
        args += nb_iargs + nb_oargs + nb_cargs;
1020 1026
    }
1021 1027
}
......
2048 2054
#ifdef DEBUG_DISAS
2049 2055
    if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP))) {
2050 2056
        qemu_log("OP:\n");
2051
        tcg_dump_ops(s, logfile);
2057
        tcg_dump_ops(s);
2052 2058
        qemu_log("\n");
2053 2059
    }
2054 2060
#endif
......
2069 2075
#ifdef DEBUG_DISAS
2070 2076
    if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP_OPT))) {
2071 2077
        qemu_log("OP after liveness analysis:\n");
2072
        tcg_dump_ops(s, logfile);
2078
        tcg_dump_ops(s);
2073 2079
        qemu_log("\n");
2074 2080
    }
2075 2081
#endif
b/tcg/tcg.h
571 571
/* only used for debugging purposes */
572 572
void tcg_register_helper(void *func, const char *name);
573 573
const char *tcg_helper_get_name(TCGContext *s, void *func);
574
void tcg_dump_ops(TCGContext *s, FILE *outfile);
574
void tcg_dump_ops(TCGContext *s);
575 575

  
576 576
void dump_ops(const uint16_t *opc_buf, const TCGArg *opparam_buf);
577 577
TCGv_i32 tcg_const_i32(int32_t val);
b/tcg/tci/tcg-target.c
878 878
#if defined(CONFIG_DEBUG_TCG_INTERPRETER)
879 879
    const char *envval = getenv("DEBUG_TCG");
880 880
    if (envval) {
881
        loglevel = strtol(envval, NULL, 0);
881
        cpu_set_log(strtol(envval, NULL, 0));
882 882
    }
883 883
#endif
884 884

  

Also available in: Unified diff