--- hatari/src/debug/debugui.c 2019/04/09 08:51:09 1.1.1.4 +++ hatari/src/debug/debugui.c 2019/04/09 08:58:05 1.1.1.10 @@ -1,8 +1,8 @@ /* Hatari - debugui.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. debugui.c - this is the code for the mini-debugger. When the pause button is pressed, the emulator is (hopefully) halted and this little CLI can be used @@ -29,6 +29,7 @@ const char DebugUI_fileid[] = "Hatari de #include "m68000.h" #include "memorySnapShot.h" #include "options.h" +#include "reset.h" #include "screen.h" #include "statusbar.h" #include "str.h" @@ -37,15 +38,15 @@ const char DebugUI_fileid[] = "Hatari de #include "breakcond.h" #include "debugcpu.h" #include "debugdsp.h" +#include "68kDisass.h" #include "debugInfo.h" #include "debugui.h" #include "evaluate.h" #include "history.h" #include "symbols.h" +#include "vars.h" -int bExceptionDebugging = false; - -FILE *debugOutput = NULL; +FILE *debugOutput; static dbgcommand_t *debugCommand; static int debugCommands; @@ -53,8 +54,12 @@ static int debugCommands; /* stores last 'e' command result as hex, used for TAB-completion */ static char lastResult[10]; +/* parse debugger commands from here on init */ static const char *parseFileName; +/* to which directory to change after (potentially recursed) scripts parsing finishes */ +static char *finalDir; + /** * Save/Restore snapshot of debugging session variables @@ -82,7 +87,7 @@ void DebugUI_MemorySnapShot_Capture(cons if (File_Exists(filename)) { /* and parse back the saved breakpoints */ - DebugUI_ParseFile(filename); + DebugUI_ParseFile(filename, true); } } free(filename); @@ -111,17 +116,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; } @@ -167,8 +180,7 @@ static int DebugUI_Evaluate(int nArgc, c if (nArgc < 2) { - DebugUI_PrintCmdHelp(psArgs[0]); - return DEBUGGER_CMDDONE; + return DebugUI_PrintCmdHelp(psArgs[0]); } errstr = Eval_Expression(expression, &result, &offset, false); @@ -188,38 +200,47 @@ static int DebugUI_Evaluate(int nArgc, c */ static bool DebugUI_IsForDsp(const char *cmd) { - return ((cmd[0] == 'd' && cmd[1] && !cmd[2]) - || strncmp(cmd, "dsp", 3) == 0); + return ((cmd[0] == 'd' && isalpha((unsigned char)cmd[1]) + && !isalpha((unsigned char)cmd[2])) + || strncmp(cmd, "dsp", 3) == 0); } /** - * Evaluate everything include within "" and replace them with the result. - * Caller needs to free the returned string separately if its address - * doesn't match the given input string. + * Evaluate everything include within single or double quotes ("" or '') + * and replace them with the result. + * Caller needs to free the returned string separately. * - * Return string with expressions (potentially) expanded, or + * Return new string with expressions (potentially) expanded, or * NULL when there's an error in the expression. */ -static char *DebugUI_EvaluateExpressions(char *input) +static char *DebugUI_EvaluateExpressions(const char *initial) { int offset, count, diff, inputlen; - char *end, *start, *initial; + char *end, *start, *input; const char *errstr; char valuestr[12]; Uint32 value; bool fordsp; /* input is split later on, need to save len here */ + input = strdup(initial); + if (!input) + { + perror("ERROR: Input string alloc failed\n"); + return NULL; + } fordsp = DebugUI_IsForDsp(input); inputlen = strlen(input); - initial = start = input; - - while ((start = strchr(start, '"'))) + start = input; + + while ((count = strcspn(start, "\"'")) && *(start+count)) { - end = strchr(start+1, '"'); + start += count; + end = strchr(start+1, *start); if (!end) { - fprintf(stderr, "ERROR: matching '\"' missing from '%s'!\n", start); + fprintf(stderr, "ERROR: matching '%c' missing from '%s'!\n", *start, start); + free(input); return NULL; } @@ -233,15 +254,16 @@ static char *DebugUI_EvaluateExpressions *end = '\0'; errstr = Eval_Expression(start+1, &value, &offset, fordsp); if (errstr) { - *end = '"'; + *end = *start; /* restore expression mark */ fprintf(stderr, "Expression ERROR:\n'%s'\n%*c-%s\n", input, (int)(start-input)+offset+3, '^', errstr); + free(input); return NULL; } end++; - + count = sprintf(valuestr, "$%x", value); - fprintf(stderr, "- \"%s\" -> %s\n", start+1, valuestr); + fprintf(stderr, "- '%s' -> %s\n", start+1, valuestr); diff = end-start; if (count < diff) @@ -257,6 +279,7 @@ static char *DebugUI_EvaluateExpressions if (!tmp) { perror("ERROR: Input string alloc failed\n"); + free(input); return NULL; } @@ -266,8 +289,7 @@ static char *DebugUI_EvaluateExpressions start += count; memcpy(start, end, strlen(end) + 1); - if (input != initial) - free(input); + free(input); input = tmp; } } @@ -316,12 +338,11 @@ static int DebugUI_SetOptions(int argc, if (argc < 2) { - DebugUI_PrintCmdHelp(argv[0]); - return DEBUGGER_CMDDONE; + return DebugUI_PrintCmdHelp(argv[0]); } 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) { @@ -364,8 +385,7 @@ static int DebugUI_SetTracing(int argc, const char *errstr; if (argc != 2) { - DebugUI_PrintCmdHelp(argv[0]); - return DEBUGGER_CMDDONE; + return DebugUI_PrintCmdHelp(argv[0]); } errstr = Log_SetTraceOptions(argv[1]); if (errstr && errstr[0]) @@ -380,14 +400,58 @@ static int DebugUI_SetTracing(int argc, */ static int DebugUI_ChangeDir(int argc, char *argv[]) { + if (argc == 3 && strcmp("-f", argv[2]) == 0) + { + if (finalDir) + free(finalDir); + finalDir = strdup(argv[1]); + fprintf(stderr, "Will switch to '%s' dir after all scripts have finished.\n", argv[1]); + return DEBUGGER_CMDDONE; + } if (argc == 2) { if (chdir(argv[1]) == 0) return DEBUGGER_CMDDONE; perror("ERROR"); } - DebugUI_PrintCmdHelp(argv[0]); - return DEBUGGER_CMDDONE; + return DebugUI_PrintCmdHelp(argv[0]); +} + +/** + * Command: Rename file + */ +static int DebugUI_Rename(int argc, char *argv[]) +{ + if (argc == 3) + { + if (rename(argv[1], argv[2]) == 0) + return DEBUGGER_CMDDONE; + perror("ERROR"); + } + return DebugUI_PrintCmdHelp(argv[0]); +} + + +/** + * Command: Reset emulation + */ +static char *DebugUI_MatchReset(const char *text, int state) +{ + static const char* types[] = { "cold", "hard", "soft", "warm" }; + return DebugUI_MatchHelper(types, ARRAY_SIZE(types), text, state); +} +static int DebugUI_Reset(int argc, char *argv[]) +{ + if (argc != 2) + return DebugUI_PrintCmdHelp(argv[0]); + + if (strcmp(argv[1], "soft") == 0 || strcmp(argv[1], "warm") == 0) + Reset_Warm(); + else if (strcmp(argv[1], "cold") == 0 || strcmp(argv[1], "hard") == 0) + Reset_Cold(); + else + return DebugUI_PrintCmdHelp(argv[0]); + return DEBUGGER_END; } @@ -397,7 +461,7 @@ static int DebugUI_ChangeDir(int argc, c static int DebugUI_CommandsFromFile(int argc, char *argv[]) { if (argc == 2) - DebugUI_ParseFile(argv[1]); + DebugUI_ParseFile(argv[1], true); else DebugUI_PrintCmdHelp(argv[0]); return DEBUGGER_CMDDONE; @@ -409,8 +473,18 @@ static int DebugUI_CommandsFromFile(int */ static int DebugUI_QuitEmu(int nArgc, char *psArgv[]) { - bQuitProgram = true; - M68000_SetSpecial(SPCFLAG_BRK); /* Assure that CPU core shuts down */ + int exitval; + + if (nArgc > 2) + return DebugUI_PrintCmdHelp(psArgv[0]); + + if (nArgc == 2) + exitval = atoi(psArgv[1]); + else + exitval = 0; + + ConfigureParams.Log.bConfirmQuit = false; + Main_RequestQuit(exitval); return DEBUGGER_END; } @@ -418,7 +492,7 @@ static int DebugUI_QuitEmu(int nArgc, ch /** * Print help text for one command */ -void DebugUI_PrintCmdHelp(const char *psCmd) +int DebugUI_PrintCmdHelp(const char *psCmd) { dbgcommand_t *cmd; int i; @@ -449,11 +523,12 @@ void DebugUI_PrintCmdHelp(const char *ps fprintf(stderr, "Usage: %s %s\n", bShort ? cmd->sShortName : cmd->sLongName, cmd->sUsage); - return; + return DEBUGGER_CMDDONE; } } fprintf(stderr, "Unknown command '%s'\n", psCmd); + return DEBUGGER_CMDDONE; } @@ -466,8 +541,7 @@ static int DebugUI_Help(int nArgc, char if (nArgc > 1) { - DebugUI_PrintCmdHelp(psArgs[1]); - return DEBUGGER_CMDDONE; + return DebugUI_PrintCmdHelp(psArgs[1]); } for (i = 0; i < debugCommands; i++) @@ -551,23 +625,21 @@ 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 */ if (retval == DEBUGGER_CMDCONT) - strncpy(sLastCmd, psArgs[0], sizeof(sLastCmd)); + { + if (psArgs[0] != sLastCmd) + strlcpy(sLastCmd, psArgs[0], sizeof(sLastCmd)); + } else sLastCmd[0] = '\0'; free(input); @@ -578,6 +650,29 @@ static int DebugUI_ParseCommand(const ch /* See "info:readline" e.g. in Konqueror for readline usage. */ /** + * Generic readline match callback helper. + * STATE = 0 -> different text from previous one. + * Return next match or NULL if no matches. + */ +char *DebugUI_MatchHelper(const char **strings, int items, const char *text, int state) +{ + static int i, len; + + if (!state) + { + /* first match */ + len = strlen(text); + i = 0; + } + /* next match */ + while (i < items) { + if (strncasecmp(strings[i++], text, len) == 0) + return (strdup(strings[i-1])); + } + return NULL; +} + +/** * Readline match callback for long command name completion. * STATE = 0 -> different text from previous one. * Return next match or NULL if no matches. @@ -626,10 +721,10 @@ static char **DebugUI_Completion(const c size_t len; /* check where's the first word (ignore white space) */ - while (start < rl_point && isspace(rl_line_buffer[start])) + while (start < rl_point && isspace((unsigned char)rl_line_buffer[start])) start++; end = start; - while (end < rl_point && !isspace(rl_line_buffer[end])) + while (end < rl_point && !isspace((unsigned char)rl_line_buffer[end])) end++; if (end >= rl_point) @@ -686,14 +781,31 @@ static char **DebugUI_Completion(const c return rl_completion_matches(text, rl_filename_completion_function); } +/** + * Add non-repeated command to readline history + * and free the given string + */ +static void DebugUI_FreeCommand(char *input) +{ + if (input && *input) + { + HIST_ENTRY *hist = history_get(history_length); + /* don't store duplicate successive entries */ + if (!hist || !hist->line || strcmp(hist->line, input) != 0) + { + add_history(input); + } + free(input); + } +} /** * Read a command line from the keyboard and return a pointer to the string. * Only string returned by this function can be given for it as argument! * The string will be stored into command history buffer. - * @return Pointer to the string which should be deallocated after - * use or given back to this function for re-use/history. - * Returns NULL when error occured. + * @return Pointer to the string which should be given back to this + * function or DebugUI_FreeCommand() for re-use/history. + * Returns NULL when error occurred. */ static char *DebugUI_GetCommand(char *input) { @@ -702,27 +814,49 @@ static char *DebugUI_GetCommand(char *in /* Tell the completer that we want a crack first. */ rl_attempted_completion_function = DebugUI_Completion; - - if (input && *input) - { - HIST_ENTRY *hist = previous_history(); - /* don't store successive duplicate entries */ - if (!hist || !hist->line || strcmp(hist->line, input) != 0) - add_history(input); - free(input); - } - + DebugUI_FreeCommand(input); return Str_Trim(readline("> ")); } +/** + * Get readlines idea of the terminal size + */ +static void DebugUI_GetScreenSize(int *rows, int *cols) +{ + rl_get_screen_size(rows, cols); +} + #else /* !HAVE_LIBREADLINE */ /** + * Free Command input string + */ +static void DebugUI_FreeCommand(char *input) +{ + free(input); +} + +/** + * Get number of lines/columns for terminal output + */ +static void DebugUI_GetScreenSize(int *rows, int *cols) +{ + const char *p; + + *rows = 24; + *cols = 80; + if ((p = getenv("LINES")) != NULL) + *rows = (int)strtol(p, NULL, 0); + if ((p = getenv("COLUMS")) != NULL) + *cols = (int)strtol(p, NULL, 0); +} + +/** * Read a command line from the keyboard and return a pointer to the string. * Only string returned by this function can be given for it as argument! - * @return Pointer to the string which should be deallocated after - * use or given back to this function for re-use. - * Returns NULL when error occured. + * @return Pointer to the string which should be given back to this + * function or DebugUI_FreeCommand() for re-use/freeing. + * Returns NULL when error occurred. */ static char *DebugUI_GetCommand(char *input) { @@ -743,6 +877,29 @@ static char *DebugUI_GetCommand(char *in #endif /* !HAVE_LIBREADLINE */ +/** + * How many lines to "page" when user invokes calling command. + * + * If config value is >=0, use that. If it's negative, get number of lines + * from screensize. If even that's not defined, fall back to default value. + * + * @return Number of lines to output at the time. + */ +int DebugUI_GetPageLines(int config, int defvalue) +{ + int rows, cols; + + if (config >= 0) { + return config; + } + DebugUI_GetScreenSize(&rows, &cols); + /* leave 1 line for pager prompt */ + if (--rows > 0) { + return rows; + } + return defvalue; +} + static const dbgcommand_t uicommand[] = { @@ -751,17 +908,18 @@ static const dbgcommand_t uicommand[] = { DebugUI_ChangeDir, NULL, "cd", "", "change directory", - "\n" - "\tChange Hatari work directory.", + " [-f]\n" + "\tChange Hatari work directory. With '-f', directory is\n" + "\tchanged only after all script files have been parsed.", 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" @@ -777,13 +935,15 @@ static const dbgcommand_t uicommand[] = "[command]\n" "\tPrint help text for available commands.", false }, - { History_Parse, NULL, + { History_Parse, History_Match, "history", "hi", - "show last CPU & DSP PC values & executed instructions", - "on|off|\n" - "\t'on' and 'off' can be used to enabled & disable history,\n" - "\tcount will show (at max) given number of last saved PC values\n" - "\tand instructions at corresponding RAM addresses.", + "show last CPU/DSP PC values & executed instructions", + "cpu|dsp|on|off| [limit]|save \n" + "\t'cpu' and 'dsp' enable instruction history tracking for just given\n" + "\tprocessor, 'on' tracks them both, 'off' will disable history.\n" + "\tOptional 'limit' will set how many past instructions are tracked.\n" + "\tGiving just count will show (at max) given number of last saved PC\n" + "\tvalues and instructions currently at corresponding RAM addresses.", false }, { DebugInfo_Command, DebugInfo_MatchInfo, "info", "i", @@ -810,16 +970,29 @@ static const dbgcommand_t uicommand[] = "parse", "p", "get debugger commands from file", "[filename]\n" - "\tRead debugger commands from given file and do them.", + "\tRead debugger commands from given file and do them.\n" + "\tCurrent directory is script directory during this.\n" + "\tTo specify directory to be used also for breakpoint\n" + "\tscripts execution, use '-f' option for 'cd' command.", + false }, + { DebugUI_Rename, NULL, + "rename", "", + "rename given file", + "old new\n" + "\tRenames file with 'old' name to 'new'.", + false }, + { DebugUI_Reset, DebugUI_MatchReset, + "reset", "", + "reset emulation", + "\n", false }, { DebugUI_SetOptions, Opt_MatchOption, "setopt", "o", "set Hatari command line and debugger options", - "[|]\n" - "\tSet Hatari options. For example to enable exception catching,\n" - "\tuse following command line option: 'setopt --debug'. Special\n" - "\t'bin', 'dec' and 'hex' arguments change the default number base\n" - "\tused in debugger.", + "[bin|dec|hex|]\n" + "\tSpecial 'bin', 'dec' and 'hex' arguments change the default\n" + "\tnumber base used in debugger. lists available command\n" + "\tline options, 'setopt --help' their descriptions.", false }, { DebugUI_DoMemorySnap, NULL, "stateload", "", @@ -841,11 +1014,18 @@ 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", - "\n" - "\tLeave debugger and quit emulator.", + "[exit value]\n" + "\tLeave debugger and quit emulator with given exit value.", false } }; @@ -862,6 +1042,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. */ @@ -869,7 +1052,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); @@ -880,7 +1063,7 @@ void DebugUI_Init(void) debugCommands += dspcmds; if (parseFileName) - DebugUI_ParseFile(parseFileName); + DebugUI_ParseFile(parseFileName, true); } @@ -912,12 +1095,27 @@ void DebugUI(debug_reason_t reason) static const char *welcome = "\n----------------------------------------------------------------------" "\nYou have entered debug mode. Type c to continue emulation, h for help.\n"; + static bool recursing; + + if (recursing) + { + fprintf(stderr, "WARNING: recursive call to DebugUI (through profiler debug option?)!\n"); + recursing = false; + return; + } + recursing = true; History_Mark(reason); if (bInFullScreen) Screen_ReturnFromFullScreen(); + /* Make sure mouse isn't grabbed regardless of where + * this is invoked from. E.g. returning from fullscreen + * enables grab if that was enabled on windowed mode. + */ + SDL_WM_GrabInput(SDL_GRAB_OFF); + DebugUI_Init(); if (welcome) @@ -927,13 +1125,14 @@ void DebugUI(debug_reason_t reason) } DebugCpu_InitSession(); DebugDsp_InitSession(); + Symbols_LoadCurrentProgram(); DebugInfo_ShowSessionInfo(); /* override paused message so that user knows to look into console * on how to continue in case he invoked the debugger by accident. */ Statusbar_AddMessage("Console Debugger", 100); - Statusbar_Update(sdlscrn); + Statusbar_Update(sdlscrn, true); /* disable normal GUI alerts while on console */ alertLevel = Log_SetAlertLevel(LOG_FATAL); @@ -948,35 +1147,37 @@ void DebugUI(debug_reason_t reason) if (!psCmd) break; - /* returns new string if expressions needed expanding! */ + /* returns new expression expanded string */ if (!(expCmd = DebugUI_EvaluateExpressions(psCmd))) continue; /* Parse and execute the command string */ cmdret = DebugUI_ParseCommand(expCmd); - if (expCmd != psCmd) - free(expCmd); + free(expCmd); } while (cmdret != DEBUGGER_END); - /* free (and ignore) exit command */ - if (psCmd) - free(psCmd); + /* free exit command */ + DebugUI_FreeCommand(psCmd); Log_SetAlertLevel(alertLevel); - DebugUI_SetLogDefault(); DebugCpu_SetDebugging(); DebugDsp_SetDebugging(); + + recursing = false; } /** - * Read debugger commands from a file. - * return false for error, true for success. + * Read debugger commands from a file. If 'reinit' is set + * (as it normally should), reinitialize breakpoints etc. + * afterwards. return false for error, true for success. */ -bool DebugUI_ParseFile(const char *path) +bool DebugUI_ParseFile(const char *path, bool reinit) { + int recurse; + static int recursing; char *olddir, *dir, *cmd, *input, *expanded, *slash; FILE *fp; @@ -1003,15 +1204,18 @@ bool DebugUI_ParseFile(const char *path) if (chdir(dir) != 0) { perror("ERROR"); - if (olddir) - free(olddir); + free(olddir); free(dir); + fclose(fp); return false; } fprintf(stderr, "Changed to input file dir '%s'.\n", dir); } free(dir); + recurse = recursing; + recursing = true; + input = NULL; for (;;) { @@ -1036,11 +1240,13 @@ bool DebugUI_ParseFile(const char *path) cmd = Str_Trim(expanded); fprintf(stderr, "> %s\n", cmd); DebugUI_ParseCommand(cmd); - if (expanded != input) - free(expanded); + free(expanded); } + recursing = false; free(input); + fclose(fp); + if (olddir) { if (chdir(olddir) != 0) @@ -1050,26 +1256,80 @@ bool DebugUI_ParseFile(const char *path) free(olddir); } - DebugCpu_SetDebugging(); - DebugDsp_SetDebugging(); + if (!recurse) + { + /* current script (or something called by it) specified final dir */ + if (finalDir) + { + if (chdir(finalDir) != 0) + perror("ERROR"); + else + fprintf(stderr, "Delayed change to '%s' dir.\n", finalDir); + free(finalDir); + finalDir = NULL; + } + /* only top-level (non-recursed) call has valid re-init info, + * as that's the only one that can get directly called from + * breakpoints + */ + if (reinit) + { + DebugCpu_SetDebugging(); + DebugDsp_SetDebugging(); + } + } return true; } /** - * Remote/parallel debugger usage API. + * Remote/parallel debugger line usage API. * Return false for failed command, true for success. */ -bool DebugUI_RemoteParse(char *input) +bool DebugUI_ParseLine(const char *input) { - int ret; + char *expanded; + int ret = 0; DebugUI_Init(); - - ret = DebugUI_ParseCommand(input); - DebugCpu_SetDebugging(); - DebugDsp_SetDebugging(); + /* returns new string if input needed expanding! */ + expanded = DebugUI_EvaluateExpressions(input); + if (expanded) + { + fprintf(stderr, "> %s\n", expanded); + ret = DebugUI_ParseCommand(expanded); + free(expanded); + DebugCpu_SetDebugging(); + DebugDsp_SetDebugging(); + } return (ret == DEBUGGER_CMDDONE); } + +/** + * Debugger invocation based on exception + */ +void DebugUI_Exceptions(int nr, long pc) +{ + static struct { + int flag; + const char *name; + } ex[] = { + { EXCEPT_BUS, "Bus error" }, /* 2 */ + { EXCEPT_ADDRESS, "Address error" }, /* 3 */ + { EXCEPT_ILLEGAL, "Illegal instruction" }, /* 4 */ + { EXCEPT_ZERODIV, "Div by zero" }, /* 5 */ + { EXCEPT_CHK, "CHK" }, /* 6 */ + { EXCEPT_TRAPV, "TRAPV" }, /* 7 */ + { EXCEPT_PRIVILEGE, "Privilege violation" }, /* 8 */ + { EXCEPT_TRACE, "Trace" } /* 9 */ + }; + nr -= 2; + if (nr < 0 || nr >= ARRAY_SIZE(ex)) + return; + if (!(ExceptionDebugMask & ex[nr].flag)) + return; + fprintf(stderr,"%s exception at 0x%lx!\n", ex[nr].name, pc); + DebugUI(REASON_CPU_EXCEPTION); +}