--- hatari/src/debug/log.c 2019/04/09 08:48:37 1.1.1.1 +++ hatari/src/debug/log.c 2019/04/09 08:54:20 1.1.1.5 @@ -1,8 +1,8 @@ /* * Hatari - log.c * - * This file is distributed under the GNU Public License, version 2 or at - * your option any later version. Read the file gpl.txt for details. + * This file is distributed under the GNU General Public License, version 2 + * or at your option any later version. Read the file gpl.txt for details. * * Logger functions. * @@ -27,13 +27,36 @@ const char Log_fileid[] = "Hatari log.c #include "log.h" #include "screen.h" #include "file.h" +#include "vdi.h" +int ExceptionDebugMask; -static struct { - Uint32 Level; - const char *Name; -} -TraceOptions[] = { +typedef struct { + Uint64 flag; + const char *name; +} flagname_t; + +static flagname_t ExceptionFlags[] = { + { EXCEPT_NONE, "none" }, + + { EXCEPT_BUS, "bus" }, + { EXCEPT_ADDRESS, "address" }, + { EXCEPT_ILLEGAL, "illegal" }, + { EXCEPT_ZERODIV, "zerodiv" }, + { EXCEPT_CHK, "chk" }, + { EXCEPT_TRAPV, "trapv" }, + { EXCEPT_PRIVILEGE, "privilege" }, + { EXCEPT_NOHANDLER, "nohandler" }, + + { EXCEPT_DSP, "dsp" }, + + { EXCEPT_AUTOSTART, "autostart" }, + + { EXCEPT_ALL, "all" } +}; + +#if ENABLE_TRACING +static flagname_t TraceFlags[] = { { TRACE_NONE , "none" }, { TRACE_VIDEO_SYNC , "video_sync" } , @@ -66,6 +89,8 @@ TraceOptions[] = { { TRACE_FDC , "fdc" } , + { TRACE_ACIA , "acia" } , + { TRACE_IKBD_CMDS , "ikbd_cmds" } , { TRACE_IKBD_ACIA , "ikbd_acia" } , { TRACE_IKBD_EXEC , "ikbd_exec" } , @@ -77,6 +102,7 @@ TraceOptions[] = { { TRACE_OS_XBIOS , "xbios" }, { TRACE_OS_GEMDOS , "gemdos" }, { TRACE_OS_VDI , "vdi" }, + { TRACE_OS_AES , "aes" }, { TRACE_OS_ALL , "os_all" } , { TRACE_IOMEM_RD , "io_read" } , @@ -87,11 +113,33 @@ TraceOptions[] = { { TRACE_CROSSBAR , "crossbar" } , + { TRACE_VIDEL , "videl" } , + + { TRACE_DSP_HOST_INTERFACE, "dsp_host_interface" }, + { TRACE_DSP_HOST_COMMAND , "dsp_host_command" }, + { TRACE_DSP_HOST_SSI , "dsp_host_ssi" }, + { TRACE_DSP_INTERRUPT , "dsp_interrupt" }, + { TRACE_DSP_DISASM , "dsp_disasm" }, + { TRACE_DSP_DISASM_REG , "dsp_disasm_reg" }, + { TRACE_DSP_DISASM_MEM , "dsp_disasm_mem" }, + { TRACE_DSP_STATE , "dsp_state" }, + { TRACE_DSP_ALL , "dsp_all" }, + + { TRACE_DSP_SYMBOLS , "dsp_symbols" }, + { TRACE_CPU_SYMBOLS , "cpu_symbols" }, + + { TRACE_NVRAM , "nvram" } , + + { TRACE_SCSI_CMD , "scsi_cmd" } , + + { TRACE_NATFEATS , "natfeats" } , + { TRACE_ALL , "all" } }; +#endif /* ENABLE_TRACING */ -Uint32 LogTraceFlags = TRACE_NONE; +Uint64 LogTraceFlags = TRACE_NONE; FILE *TraceFile = NULL; static FILE *hLogFile = NULL; @@ -214,7 +262,7 @@ LOGTYPE Log_ParseOptions(const char *arg str = input; while (*str) { - *str++ = tolower(*arg++); + *str++ = tolower((unsigned char)*arg++); } for (level_str = levels; *level_str; level_str++, level++) { @@ -229,55 +277,49 @@ LOGTYPE Log_ParseOptions(const char *arg } -#if ENABLE_TRACING - /*-----------------------------------------------------------------------*/ /** * Parse a list of comma separated strings. * If the string is prefixed with an optional '+', - * corresponding trace flag is turned on. + * corresponding mask flag is turned on. * If the string is prefixed with a '-', - * corresponding trace flag is turned off. - * Result is stored in LogTraceFlags. + * corresponding mask flag is turned off. * Return error string (""=silent 'error') or NULL for success. */ -const char* Log_SetTraceOptions (const char *OptionsStr) +static const char* +Log_ParseOptionFlags (const char *FlagsStr, flagname_t *Flags, int MaxFlags, Uint64 *Mask) { - char *OptionsCopy; + char *FlagsCopy; char *cur, *sep; int i; int Mode; /* 0=add, 1=del */ - int MaxOptions; - - MaxOptions = ARRAYSIZE(TraceOptions); - /* special case for "help" : display the list of possible trace levels */ - if (strcmp (OptionsStr, "help") == 0) + /* special case for "help" : display the list of possible settings */ + if (strcmp (FlagsStr, "help") == 0) { - fprintf(stderr, "\nList of available trace levels :\n"); + fprintf(stderr, "\nList of available option flags :\n"); - for (i = 0; i < MaxOptions; i++) - fprintf(stderr, " %s\n", TraceOptions[i].Name); + for (i = 0; i < MaxFlags; i++) + fprintf(stderr, " %s\n", Flags[i].name); - fprintf(stderr, "Multiple trace levels can be separated by ','\n"); - fprintf(stderr, "Levels can be prefixed by '+' or '-' to be mixed.\n"); - fprintf(stderr, "Giving just trace level 'none' disables all traces.\n\n"); + fprintf(stderr, "Multiple flags can be separated by ','.\n"); + fprintf(stderr, "They can be prefixed by '+' or '-' to be mixed.\n"); + fprintf(stderr, "Giving just 'none' flag disables all of them.\n\n"); return ""; } - LogTraceFlags = TRACE_NONE; - if (strcmp (OptionsStr, "none") == 0) + if (strcmp (FlagsStr, "none") == 0) { return NULL; } - OptionsCopy = strdup(OptionsStr); - if (!OptionsCopy) + FlagsCopy = strdup(FlagsStr); + if (!FlagsCopy) { - return "strdup error in ParseTraceOptions"; + return "strdup error in Log_OptionFlags"; } - cur = OptionsCopy; + cur = FlagsCopy; while (cur) { sep = strchr(cur, ','); @@ -290,35 +332,73 @@ const char* Log_SetTraceOptions (const c else if (*cur == '-') { Mode = 1; cur++; } - for (i = 0; i < MaxOptions; i++) + for (i = 0; i < MaxFlags; i++) { - if (strcmp(cur, TraceOptions[i].Name) == 0) + if (strcmp(cur, Flags[i].name) == 0) break; } - if (i < MaxOptions) /* option found */ + if (i < MaxFlags) /* option found */ { if (Mode == 0) - LogTraceFlags |= TraceOptions[i].Level; + *Mask |= Flags[i].flag; else - LogTraceFlags &= (~TraceOptions[i].Level); + *Mask &= (~Flags[i].flag); } else { - fprintf(stderr, "Unknown trace type '%s'\n", cur); - free(OptionsCopy); - return "Unknown trace type."; + fprintf(stderr, "Unknown flag type '%s'\n", cur); + free(FlagsCopy); + return "Unknown flag type."; } cur = sep; } + + //fprintf(stderr, "flags parse <%x>\n", Mask); - //fprintf(stderr, "trace parse <%x>\n", LogTraceFlags); - - free (OptionsCopy); + free (FlagsCopy); return NULL; } +/** + * Parse exception flags and store results in ExceptionDebugMask. + * Return error string or NULL for success. + * + * See Log_ParseOptionFlags() for details. + */ +const char* Log_SetExceptionDebugMask (const char *FlagsStr) +{ + const char *errstr; + + Uint64 mask = EXCEPT_NONE; + errstr = Log_ParseOptionFlags(FlagsStr, ExceptionFlags, ARRAYSIZE(ExceptionFlags), &mask); + ConfigureParams.Log.nExceptionDebugMask = mask; + return errstr; +} + + +#if ENABLE_TRACING + +/** + * Parse trace flags and store results in LogTraceFlags. + * Return error string or NULL for success. + * + * See Log_ParseOptionFlags() for details. + */ +const char* Log_SetTraceOptions (const char *FlagsStr) +{ + const char *errstr; + + LogTraceFlags = TRACE_NONE; + errstr = Log_ParseOptionFlags(FlagsStr, TraceFlags, ARRAYSIZE(TraceFlags), &LogTraceFlags); + + /* Enable Hatari flags needed for tracing selected items */ + if (LogTraceFlags & (TRACE_OS_AES|TRACE_OS_VDI)) + bVdiAesIntercept = true; + + return errstr; +} /** * Readline match callback for trace type name completion. @@ -336,8 +416,8 @@ char *Log_MatchTrace(const char *text, i i = 0; } /* next match */ - while (i < ARRAYSIZE(TraceOptions)) { - name = TraceOptions[i++].Name; + while (i < ARRAYSIZE(TraceFlags)) { + name = TraceFlags[i++].name; if (strncasecmp(name, text, len) == 0) return (strdup(name)); } @@ -347,7 +427,7 @@ char *Log_MatchTrace(const char *text, i #else /* !ENABLE_TRACING */ /** dummy */ -const char* Log_SetTraceOptions (const char *OptionsStr) +const char* Log_SetTraceOptions (const char *FlagsStr) { return "Hatari has been compiled without ENABLE_TRACING!"; }