--- hatari/src/debug/debugui.c 2019/04/09 08:55:36 1.1.1.8 +++ hatari/src/debug/debugui.c 2019/04/09 08:56:50 1.1.1.9 @@ -44,6 +44,7 @@ const char DebugUI_fileid[] = "Hatari de #include "evaluate.h" #include "history.h" #include "symbols.h" +#include "vars.h" FILE *debugOutput; @@ -112,17 +113,25 @@ static void DebugUI_SetLogDefault(void) */ static int DebugUI_SetLogFile(int nArgc, char *psArgs[]) { - File_Close(debugOutput); - debugOutput = NULL; + if (debugOutput != stderr) + { + fprintf(stderr, "Debug log closed.\n"); + File_Close(debugOutput); + } + debugOutput = stderr; if (nArgc > 1) - debugOutput = File_Open(psArgs[1], "w"); - - if (debugOutput) - fprintf(stderr, "Debug log '%s' opened.\n", psArgs[1]); - else - debugOutput = stderr; - + { + if ((debugOutput = File_Open(psArgs[1], "w"))) + { + fprintf(stderr, "Debug log '%s' opened.\n", psArgs[1]); + } + else + { + fprintf(stderr, "Debug log '%s' opening FAILED.\n", psArgs[1]); + debugOutput = stderr; + } + } return DEBUGGER_CMDDONE; } @@ -330,7 +339,7 @@ static int DebugUI_SetOptions(int argc, } arg = argv[1]; - for (i = 0; i < ARRAYSIZE(bases); i++) + for (i = 0; i < ARRAY_SIZE(bases); i++) { if (strcasecmp(bases[i].name, arg) == 0) { @@ -418,7 +427,7 @@ static int DebugUI_Rename(int argc, char static char *DebugUI_MatchReset(const char *text, int state) { static const char* types[] = { "cold", "hard", "soft", "warm" }; - return DebugUI_MatchHelper(types, ARRAYSIZE(types), text, state); + return DebugUI_MatchHelper(types, ARRAY_SIZE(types), text, state); } static int DebugUI_Reset(int argc, char *argv[]) { @@ -605,18 +614,13 @@ static int DebugUI_ParseCommand(const ch delim = " \t"; /* Separate arguments and put the pointers into psArgs */ - for (nArgc = 1; nArgc < ARRAYSIZE(psArgs); nArgc++) + for (nArgc = 1; nArgc < ARRAY_SIZE(psArgs); nArgc++) { psArgs[nArgc] = strtok(NULL, delim); if (psArgs[nArgc] == NULL) break; } - if (!debugOutput) { - /* make sure also calls from control.c work */ - DebugUI_SetLogDefault(); - } - /* ... and execute the function */ retval = debugCommand[i].pFunction(nArgc, psArgs); /* Save commando string if it can be repeated */ @@ -810,8 +814,7 @@ static char *DebugUI_GetCommand(char *in */ static void DebugUI_FreeCommand(char *input) { - if (input) - free(input); + free(input); } /** @@ -851,14 +854,14 @@ static const dbgcommand_t uicommand[] = "\n" "\tChange Hatari work directory.", false }, - { DebugUI_Evaluate, Symbols_MatchCpuAddress, + { DebugUI_Evaluate, Vars_MatchCpuVariable, "evaluate", "e", "evaluate an expression", "\n" "\tEvaluate an expression and show the result. Expression can\n" - "\tinclude CPU register and symbol names, those are replaced\n" - "\tby their values. Supported operators in expressions are,\n" - "\tin the decending order of precedence:\n" + "\tinclude CPU register & symbol and Hatari variable names.\n" + "\tThose are replaced by their values. Supported operators in\n" + "\texpressions are, in the decending order of precedence:\n" "\t\t(), +, -, ~, *, /, +, -, >>, <<, ^, &, |\n" "\tParenthesis will fetch a _long_ value from the address\n" "\tto what the value inside it evaluates to. Prefixes can be\n" @@ -950,6 +953,13 @@ static const dbgcommand_t uicommand[] = "\tsettings. For example, to enable CPU disassembly and VBL\n" "\ttracing, use:\n\t\ttrace cpu_disasm,video_hbl", false }, + { Vars_List, NULL, + "variables", "v", + "List builtin symbols / variables", + "\n" + "\tList Hatari debugger builtin symbols / variables and their values.\n" + "\tThey're accepted by breakpoints and evaluate command.", + false }, { DebugUI_QuitEmu, NULL, "quit", "q", "quit emulator", @@ -971,6 +981,9 @@ void DebugUI_Init(void) if (debugCommands) return; + if (!debugOutput) + DebugUI_SetLogDefault(); + /* if you want disassembly or memdumping to start/continue from * specific address, you can set them in these functions. */ @@ -978,7 +991,7 @@ void DebugUI_Init(void) cpucmds = DebugCpu_Init(&cpucmd); /* on first time copy the command structures to a single table */ - debugCommands = ARRAYSIZE(uicommand); + debugCommands = ARRAY_SIZE(uicommand); debugCommand = malloc(sizeof(dbgcommand_t) * (dspcmds + cpucmds + debugCommands)); assert(debugCommand); @@ -1087,7 +1100,6 @@ void DebugUI(debug_reason_t reason) DebugUI_FreeCommand(psCmd); Log_SetAlertLevel(alertLevel); - DebugUI_SetLogDefault(); DebugCpu_SetDebugging(); DebugDsp_SetDebugging(); @@ -1129,8 +1141,7 @@ bool DebugUI_ParseFile(const char *path, if (chdir(dir) != 0) { perror("ERROR"); - if (olddir) - free(olddir); + free(olddir); free(dir); fclose(fp); return false; @@ -1227,10 +1238,11 @@ void DebugUI_Exceptions(int nr, long pc) { EXCEPT_ZERODIV, "Div by zero" }, /* 5 */ { EXCEPT_CHK, "CHK" }, /* 6 */ { EXCEPT_TRAPV, "TRAPV" }, /* 7 */ - { EXCEPT_PRIVILEGE, "Privilege violation" } /* 8 */ + { EXCEPT_PRIVILEGE, "Privilege violation" }, /* 8 */ + { EXCEPT_TRACE, "Trace" } /* 9 */ }; nr -= 2; - if (nr < 0 || nr >= ARRAYSIZE(ex)) + if (nr < 0 || nr >= ARRAY_SIZE(ex)) return; if (!(ExceptionDebugMask & ex[nr].flag)) return;