--- hatari/src/debug/log.c 2019/04/09 08:55:33 1.1.1.6 +++ 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" @@ -47,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" }, @@ -84,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" } , @@ -143,6 +146,10 @@ static flagname_t TraceFlags[] = { { TRACE_OS_BASE , "os_base" } , + { TRACE_SCSIDRV , "scsidrv" } , + + { TRACE_MEM , "mem" } , + { TRACE_ALL , "all" } }; #endif /* ENABLE_TRACING */ @@ -152,6 +159,8 @@ 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; @@ -163,6 +172,16 @@ 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; } /*-----------------------------------------------------------------------*/ @@ -173,8 +192,7 @@ void Log_Default(void) */ 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"); @@ -208,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, ...) @@ -216,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); @@ -237,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); @@ -391,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; } @@ -410,7 +444,7 @@ 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)) @@ -438,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));