--- hatari/src/debug/breakcond.c 2019/04/09 08:53:03 1.1.1.5 +++ hatari/src/debug/breakcond.c 2019/04/09 08:54:20 1.1.1.6 @@ -29,6 +29,7 @@ const char BreakCond_fileid[] = "Hatari #include "debug_priv.h" #include "breakcond.h" #include "debugcpu.h" +#include "debugdsp.h" #include "debugInfo.h" #include "debugui.h" #include "evaluate.h" @@ -43,9 +44,6 @@ const char BreakCond_fileid[] = "Hatari /* needs to go through long long to handle x=32 */ #define BITMASK(x) ((Uint32)(((unsigned long long)1<<(x))-1)) -#define BC_MAX_CONDITION_BREAKPOINTS 16 -#define BC_MAX_CONDITIONS_PER_BREAKPOINT 4 - #define BC_DEFAULT_DSP_SPACE 'P' typedef enum { @@ -103,15 +101,15 @@ typedef struct { typedef struct { char *expression; bc_options_t options; - bc_condition_t conditions[BC_MAX_CONDITIONS_PER_BREAKPOINT]; + bc_condition_t *conditions; int ccount; /* condition count */ int hits; /* how many times breakpoint hit */ } bc_breakpoint_t; -static bc_breakpoint_t BreakPointsCpu[BC_MAX_CONDITION_BREAKPOINTS]; -static bc_breakpoint_t BreakPointsDsp[BC_MAX_CONDITION_BREAKPOINTS]; -static int BreakPointCpuCount; -static int BreakPointDspCount; +static bc_breakpoint_t *BreakPointsCpu; +static bc_breakpoint_t *BreakPointsDsp; +static int BreakPointCpuCount, BreakPointCpuAllocated; +static int BreakPointDspCount, BreakPointDspAllocated; /* forward declarations */ @@ -295,9 +293,6 @@ static bool BreakCond_MatchConditions(bc break; case '!': hit = (lvalue != rvalue); - if (hit && condition->track) { - BreakCond_UpdateTracked(condition, lvalue); - } break; default: fprintf(stderr, "ERROR: Unknown breakpoint value comparison operator '%c'!\n", @@ -307,6 +302,9 @@ static bool BreakCond_MatchConditions(bc if (!hit) { return false; } + if (condition->track) { + BreakCond_UpdateTracked(condition, lvalue); + } } /* all conditions matched */ return true; @@ -540,7 +538,13 @@ static const var_addr_t hatari_vars[] = { "AesOpcode", (Uint32*)GetAesOpcode, VALUE_TYPE_FUNCTION32, 16, "by default FFFF" }, { "BiosOpcode", (Uint32*)GetBiosOpcode, VALUE_TYPE_FUNCTION32, 16, "by default FFFF" }, { "BSS", (Uint32*)DebugInfo_GetBSS, VALUE_TYPE_FUNCTION32, 0, "invalid before Desktop is up" }, + { "CpuInstr", (Uint32*)DebugCpu_InstrCount, VALUE_TYPE_FUNCTION32, 0, "CPU instructions count" }, + { "CpuOpcodeType", (Uint32*)DebugCpu_OpcodeType, VALUE_TYPE_FUNCTION32, 0, "CPU instruction type" }, { "DATA", (Uint32*)DebugInfo_GetDATA, VALUE_TYPE_FUNCTION32, 0, "invalid before Desktop is up" }, +#if ENABLE_DSP_EMU + { "DspInstr", (Uint32*)DebugDsp_InstrCount, VALUE_TYPE_FUNCTION32, 0, "DSP instructions count" }, + { "DspOpcodeType", (Uint32*)DebugDsp_OpcodeType, VALUE_TYPE_FUNCTION32, 0, "DSP instruction type" }, +#endif { "FrameCycles", (Uint32*)GetFrameCycles, VALUE_TYPE_FUNCTION32, 0, NULL }, { "GemdosOpcode", (Uint32*)GetGemdosOpcode, VALUE_TYPE_FUNCTION32, 16, "by default FFFF" }, { "HBL", (Uint32*)&nHBL, VALUE_TYPE_VAR32, sizeof(nHBL)*8, NULL }, @@ -720,7 +724,8 @@ static bool BreakCond_ParseRegister(cons &(bc_value->value.reg32), &(bc_value->mask)); if (regsize) { - if (bc_value->is_indirect && toupper(regname[0]) != 'R') { + if (bc_value->is_indirect + && toupper((unsigned char)regname[0]) != 'R') { fprintf(stderr, "ERROR: only R0-R7 DSP registers can be used for indirect addressing!\n"); EXITFUNC(("-> false (DSP)\n")); return false; @@ -829,7 +834,7 @@ static bool BreakCond_ParseAddressModifi case 'p': case 'x': case 'y': - mode = toupper(pstate->argv[pstate->arg][0]); + mode = toupper((unsigned char)pstate->argv[pstate->arg][0]); break; default: pstate->error = "invalid address space modifier"; @@ -933,7 +938,7 @@ static bool BreakCond_ParseValue(parser_ } str = pstate->argv[pstate->arg]; - if (isalpha(*str) || *str == '_') { + if (isalpha((unsigned char)*str) || *str == '_') { /* parse direct or indirect variable/register/symbol name */ if (bc_value->is_indirect) { /* a valid register or data symbol name? */ @@ -1113,16 +1118,11 @@ static bool BreakCond_CrossCheckValues(p * Return number of added conditions or zero for failure. */ static int BreakCond_ParseCondition(parser_state_t *pstate, bool bForDsp, - bc_condition_t *conditions, int ccount) + bc_breakpoint_t *bp, int ccount) { bc_condition_t condition; ENTERFUNC(("BreakCond_ParseCondition(...)\n")); - if (ccount >= BC_MAX_CONDITIONS_PER_BREAKPOINT) { - pstate->error = "max number of conditions exceeded"; - EXITFUNC(("-> 0 (no conditions free)\n")); - return 0; - } /* setup condition */ memset(&condition, 0, sizeof(bc_condition_t)); @@ -1151,12 +1151,19 @@ static int BreakCond_ParseCondition(pars EXITFUNC(("-> 0\n")); return 0; } - /* new condition */ - conditions[ccount++] = condition; + /* copy new condition */ + ccount += 1; + bp->conditions = realloc(bp->conditions, sizeof(bc_condition_t)*(ccount)); + if (!bp->conditions) { + pstate->error = "failed to allocate space for breakpoint condition"; + EXITFUNC(("-> 0\n")); + return 0; + } + bp->conditions[ccount-1] = condition; /* continue with next condition? */ if (pstate->arg == pstate->argc) { - EXITFUNC(("-> %d (conditions)\n", ccount-1)); + EXITFUNC(("-> %d conditions (all args parsed)\n", ccount)); return ccount; } if (strcmp(pstate->argv[pstate->arg], "&&") != 0) { @@ -1167,12 +1174,12 @@ static int BreakCond_ParseCondition(pars pstate->arg++; /* recurse conditions parsing */ - ccount = BreakCond_ParseCondition(pstate, bForDsp, conditions, ccount); + ccount = BreakCond_ParseCondition(pstate, bForDsp, bp, ccount); if (!ccount) { EXITFUNC(("-> 0\n")); return 0; } - EXITFUNC(("-> %d (conditions)\n", ccount-1)); + EXITFUNC(("-> %d conditions (recursed)\n", ccount)); return ccount; } @@ -1212,7 +1219,7 @@ static char *BreakCond_TokenizeExpressio has_comparison = false; for (src = expression; *src; src++) { /* discard white space in source */ - if (isspace(*src)) { + if (isspace((unsigned char)*src)) { continue; } /* separate tokens with single space in destination */ @@ -1240,7 +1247,7 @@ static char *BreakCond_TokenizeExpressio /* validate & copy other characters */ if (!sep) { /* variable/register/symbol or number prefix? */ - if (!(isalnum(*src) || *src == '_' || + if (!(isalnum((unsigned char)*src) || *src == '_' || *src == '$' || *src == '#' || *src == '%')) { pstate->error = "invalid character"; pstate->arg = src-expression; @@ -1297,22 +1304,41 @@ static char *BreakCond_TokenizeExpressio /** - * Helper to set corrent breakpoint list and type name to given variables. + * Set corrent breakpoint list and name for given CPU type. + * Make sure there's always space for at least one additional breakpoint. * Return pointer to breakpoint list count */ static int* BreakCond_GetListInfo(bc_breakpoint_t **bp, const char **name, bool bForDsp) { - int *bcount; + int *allocated, *bcount; if (bForDsp) { + allocated = &BreakPointDspAllocated; bcount = &BreakPointDspCount; *bp = BreakPointsDsp; *name = "DSP"; } else { + allocated = &BreakPointCpuAllocated; bcount = &BreakPointCpuCount; *bp = BreakPointsCpu; *name = "CPU"; } + /* allocate (more) space for breakpoints when needed */ + if (*bcount + 1 >= *allocated) { + if (!*allocated) { + /* initial count of available breakpoints */ + *allocated = 16; + } else { + *allocated *= 2; + } + *bp = realloc(*bp, *allocated * sizeof(bc_breakpoint_t)); + assert(*bp); + if (bForDsp) { + BreakPointsDsp = *bp; + } else { + BreakPointsCpu = *bp; + } + } return bcount; } @@ -1342,8 +1368,8 @@ static void BreakCond_CheckTracking(bc_b condition->rvalue.value.number = value; condition->rvalue.valuetype = VALUE_TYPE_NUMBER; condition->rvalue.is_indirect = false; - if (condition->comparison == '!') { - /* which changes will be traced */ + /* track those changes */ + if (condition->comparison != '=') { condition->track = true; track = true; } else { @@ -1372,18 +1398,23 @@ static bool BreakCond_Parse(const char * int ccount; bcount = BreakCond_GetListInfo(&bp, &name, bForDsp); - if (*bcount >= BC_MAX_CONDITION_BREAKPOINTS) { - fprintf(stderr, "ERROR: no free %s condition breakpoints left.\n", name); - return false; - } + bp += *bcount; memset(bp, 0, sizeof(bc_breakpoint_t)); normalized = BreakCond_TokenizeExpression(expression, &pstate); if (normalized) { bp->expression = normalized; - ccount = BreakCond_ParseCondition(&pstate, bForDsp, - bp->conditions, 0); + ccount = BreakCond_ParseCondition(&pstate, bForDsp, bp, 0); + /* fail? */ + if (!ccount) { + bp->expression = NULL; + if (bp->conditions) { + /* free what was allocated by ParseCondition */ + free(bp->conditions); + bp->conditions = NULL; + } + } bp->ccount = ccount; } else { ccount = 0; @@ -1442,7 +1473,6 @@ static bool BreakCond_Parse(const char * fprintf(stderr, "ERROR in tokenized string:\n'%s'\n%*c-%s\n", normalized, offset+2, '^', pstate.error); free(normalized); - bp->expression = NULL; } else { /* show original string and point out the character * where the error was encountered @@ -1530,10 +1560,13 @@ static bool BreakCond_Remove(int positio BreakCond_Print(&(bp[offset])); } free(bp[offset].expression); + free(bp[offset].conditions); + bp[offset].expression = NULL; + bp[offset].conditions = NULL; + if (bp[offset].options.filename) { free(bp[offset].options.filename); } - bp[offset].expression = NULL; if (position < *bcount) { memmove(bp+offset, bp+position, @@ -1696,7 +1729,7 @@ static bool BreakCond_Options(char *str, return false; } options->filename = filename; - } else if (isdigit(*option)) { + } else if (isdigit((unsigned char)*option)) { /* : */ skip = atoi(option); if (skip < 2) { @@ -1758,7 +1791,7 @@ bool BreakCond_Command(const char *args, /* index (for breakcond removal)? */ end = expression; - while (isdigit(*end)) { + while (isdigit((unsigned char)*end)) { end++; } if (end > expression && *end == '\0' &&