--- hatari/src/debug/log.c 2019/04/09 08:54:20 1.1.1.5 +++ hatari/src/debug/log.c 2019/04/09 08:59:17 1.1.1.9 @@ -20,6 +20,7 @@ const char Log_fileid[] = "Hatari log.c #include #include #include +#include #include "main.h" #include "configuration.h" @@ -28,6 +29,7 @@ const char Log_fileid[] = "Hatari log.c #include "screen.h" #include "file.h" #include "vdi.h" +#include "options.h" int ExceptionDebugMask; @@ -46,6 +48,7 @@ static flagname_t ExceptionFlags[] = { { EXCEPT_CHK, "chk" }, { EXCEPT_TRAPV, "trapv" }, { EXCEPT_PRIVILEGE, "privilege" }, + { EXCEPT_TRACE, "trace" }, { EXCEPT_NOHANDLER, "nohandler" }, { EXCEPT_DSP, "dsp" }, @@ -83,6 +86,7 @@ static flagname_t TraceFlags[] = { { TRACE_CPU_PAIRING , "cpu_pairing" } , { TRACE_CPU_DISASM , "cpu_disasm" } , { TRACE_CPU_EXCEPTION , "cpu_exception" } , + { TRACE_CPU_REGS , "cpu_regs" } , { TRACE_CPU_ALL , "cpu_all" } , { TRACE_INT , "int" } , @@ -134,6 +138,18 @@ static flagname_t TraceFlags[] = { { TRACE_NATFEATS , "natfeats" } , + { TRACE_KEYMAP , "keymap" } , + + { TRACE_MIDI , "midi" } , + + { TRACE_IDE , "ide" } , + + { TRACE_OS_BASE , "os_base" } , + + { TRACE_SCSIDRV , "scsidrv" } , + + { TRACE_MEM , "mem" } , + { TRACE_ALL , "all" } }; #endif /* ENABLE_TRACING */ @@ -143,19 +159,40 @@ Uint64 LogTraceFlags = TRACE_NONE; FILE *TraceFile = NULL; static FILE *hLogFile = NULL; + +/* local settings, to be able change them temporarily */ static LOGTYPE TextLogLevel; static LOGTYPE AlertDlgLogLevel; /*-----------------------------------------------------------------------*/ /** + * Set default files to stderr (used at the very start, before parsing options) + */ +void Log_Default(void) +{ + hLogFile = stderr; + TraceFile = stderr; + TextLogLevel = LOG_INFO; +} + +/** + * Set local log levels from configuration values + */ +void Log_SetLevels(void) +{ + TextLogLevel = ConfigureParams.Log.nTextLogLevel; + AlertDlgLogLevel = ConfigureParams.Log.nAlertDlgLogLevel; +} + +/*-----------------------------------------------------------------------*/ +/** * Initialize the logging and tracing functionality (open the log files etc.). * * Return zero if that fails. */ int Log_Init(void) { - TextLogLevel = ConfigureParams.Log.nTextLogLevel; - AlertDlgLogLevel = ConfigureParams.Log.nAlertDlgLogLevel; + Log_SetLevels(); hLogFile = File_Open(ConfigureParams.Log.sLogFileName, "w"); TraceFile = File_Open(ConfigureParams.Log.sTraceFileName, "w"); @@ -189,6 +226,20 @@ void Log_UnInit(void) /*-----------------------------------------------------------------------*/ /** + * Print log prefix when needed + */ +static void Log_PrintPrefix(FILE *fp, LOGTYPE idx) +{ + static const char* prefix[] = LOG_NAMES; + + assert(idx >= 0 && idx < ARRAY_SIZE(prefix)); + if (prefix[idx]) + fprintf(fp, "%s: ", prefix[idx]); +} + + +/*-----------------------------------------------------------------------*/ +/** * Output string to log file */ void Log_Printf(LOGTYPE nType, const char *psFormat, ...) @@ -197,6 +248,7 @@ void Log_Printf(LOGTYPE nType, const cha if (hLogFile && nType <= TextLogLevel) { + Log_PrintPrefix(hLogFile, nType); va_start(argptr, psFormat); vfprintf(hLogFile, psFormat, argptr); va_end(argptr); @@ -218,6 +270,7 @@ void Log_AlertDlg(LOGTYPE nType, const c /* Output to log file: */ if (hLogFile && nType <= TextLogLevel) { + Log_PrintPrefix(hLogFile, nType); va_start(argptr, psFormat); vfprintf(hLogFile, psFormat, argptr); va_end(argptr); @@ -372,8 +425,8 @@ const char* Log_SetExceptionDebugMask (c const char *errstr; Uint64 mask = EXCEPT_NONE; - errstr = Log_ParseOptionFlags(FlagsStr, ExceptionFlags, ARRAYSIZE(ExceptionFlags), &mask); - ConfigureParams.Log.nExceptionDebugMask = mask; + errstr = Log_ParseOptionFlags(FlagsStr, ExceptionFlags, ARRAY_SIZE(ExceptionFlags), &mask); + ConfigureParams.Debugger.nExceptionDebugMask = mask; return errstr; } @@ -391,12 +444,15 @@ const char* Log_SetTraceOptions (const c const char *errstr; LogTraceFlags = TRACE_NONE; - errstr = Log_ParseOptionFlags(FlagsStr, TraceFlags, ARRAYSIZE(TraceFlags), &LogTraceFlags); + errstr = Log_ParseOptionFlags(FlagsStr, TraceFlags, ARRAY_SIZE(TraceFlags), &LogTraceFlags); /* Enable Hatari flags needed for tracing selected items */ if (LogTraceFlags & (TRACE_OS_AES|TRACE_OS_VDI)) bVdiAesIntercept = true; + if ((LogTraceFlags & TRACE_OS_BASE) && ConOutDevice == CONOUT_DEVICE_NONE) + ConOutDevice = 2; + return errstr; } @@ -416,7 +472,7 @@ char *Log_MatchTrace(const char *text, i i = 0; } /* next match */ - while (i < ARRAYSIZE(TraceFlags)) { + while (i < ARRAY_SIZE(TraceFlags)) { name = TraceFlags[i++].name; if (strncasecmp(name, text, len) == 0) return (strdup(name));