--- hatari/src/debug/breakcond.c 2019/04/09 08:55:33 1.1.1.7 +++ hatari/src/debug/breakcond.c 2019/04/09 08:56:46 1.1.1.8 @@ -1,7 +1,7 @@ /* Hatari - breakcond.c - Copyright (c) 2009-2012 by Eero Tamminen + Copyright (c) 2009-2016 by Eero Tamminen 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. @@ -23,8 +23,7 @@ const char BreakCond_fileid[] = "Hatari #include "dsp.h" #include "stMemory.h" #include "str.h" -#include "screen.h" /* for defines needed by video.h */ -#include "video.h" /* for Hatari video variable addresses */ +#include "vars.h" #include "debug_priv.h" #include "breakcond.h" @@ -46,21 +45,6 @@ const char BreakCond_fileid[] = "Hatari #define BC_DEFAULT_DSP_SPACE 'P' -typedef enum { - /* plain number */ - VALUE_TYPE_NUMBER = 0, - - /* functions to call to get value */ - VALUE_TYPE_FUNCTION32 = 2, - - /* internal Hatari value variables */ - VALUE_TYPE_VAR32 = 4, - - /* size must match register size used in BreakCond_ParseRegister() */ - VALUE_TYPE_REG16 = 16, - VALUE_TYPE_REG32 = 32 -} value_t; - static inline bool is_register_type(value_t vtype) { /* type used for CPU/DSP registers */ return (vtype == VALUE_TYPE_REG16 || vtype == VALUE_TYPE_REG32); @@ -128,7 +112,7 @@ static bc_breakpoints_t DspBreakPoints = /* forward declarations */ -static int BreakCond_DoDelayedActions(bc_breakpoints_t *bps, int triggered); +static void BreakCond_DoDelayedActions(bc_breakpoints_t *bps); static bool BreakCond_Remove(bc_breakpoints_t *bps, int position); static void BreakCond_Print(bc_breakpoint_t *bp); @@ -323,15 +307,16 @@ static bool BreakCond_MatchConditions(bc /** - * Show all breakpoints which conditions matched and return which matched - * @return index to last matching (non-tracing) breakpoint, - * or zero if none matched + * Check and show which breakpoints' conditions matched + * @return true if (non-tracing) breakpoint was hit, + * or false if none matched */ -static int BreakCond_MatchBreakPoints(bc_breakpoints_t *bps) +static bool BreakCond_MatchBreakPoints(bc_breakpoints_t *bps) { bc_breakpoint_t *bp; bool changes = false; - int i, ret = 0; + bool hit = false; + int i; /* array should not be changed while it's being traversed */ assert(likely(!bps->delayed_change)); @@ -377,32 +362,32 @@ static int BreakCond_MatchBreakPoints(bc } if (!bp->options.trace) { /* index for current hit, they start from 1 */ - ret = i + 1; + hit = true; } /* continue checking breakpoints to make sure all relevant actions get performed */ } } bps->delayed_change = false; if (unlikely(changes)) { - ret = BreakCond_DoDelayedActions(bps, ret); + BreakCond_DoDelayedActions(bps); } - return ret; + return hit; } /* ------------- breakpoint condition checking, public API ------------- */ /** - * Return matched CPU breakpoint index or zero for no hits. + * Return true if there were CPU breakpoint hits, false otherwise. */ -int BreakCond_MatchCpu(void) +bool BreakCond_MatchCpu(void) { return BreakCond_MatchBreakPoints(&CpuBreakPoints); } /** - * Return matched DSP breakpoint index or zero for no hits. + * Return true if there were DSP breakpoint hits, false otherwise. */ -int BreakCond_MatchDsp(void) +bool BreakCond_MatchDsp(void) { return BreakCond_MatchBreakPoints(&DspBreakPoints); } @@ -435,189 +420,6 @@ typedef struct { } parser_state_t; -/* Hatari variable name & address array items */ -typedef struct { - const char *name; - Uint32 *addr; - value_t vtype; - size_t bits; - const char *constraints; -} var_addr_t; - -/* Accessor functions for calculated Hatari values */ -static Uint32 GetLineCycles(void) -{ - int dummy1, dummy2, lcycles; - Video_GetPosition(&dummy1, &dummy2 , &lcycles); - return lcycles; -} -static Uint32 GetFrameCycles(void) -{ - int dummy1, dummy2, fcycles; - Video_GetPosition(&fcycles, &dummy1, &dummy2); - return fcycles; -} - -/* helpers for TOS OS call opcode accessor functions */ -#define INVALID_OPCODE 0xFFFFu - -static inline Uint16 getLineOpcode(Uint8 line) -{ - Uint32 pc; - Uint16 instr; - pc = M68000_GetPC(); - instr = STMemory_ReadWord(pc); - /* for opcode X, Line-A = 0xA00X, Line-F = 0xF00X */ - if ((instr >> 12) == line) { - return instr & 0xFF; - } - return INVALID_OPCODE; -} -static inline bool isTrap(Uint8 trap) -{ - Uint32 pc; - Uint16 instr; - pc = M68000_GetPC(); - instr = STMemory_ReadWord(pc); - return (instr == (Uint16)0x4e40u + trap); -} -static inline Uint16 getControlOpcode(void) -{ - /* Control[] address from D1, opcode in Control[0] */ - return STMemory_ReadWord(STMemory_ReadLong(Regs[REG_D1])); -} -static inline Uint16 getStackOpcode(void) -{ - return STMemory_ReadWord(Regs[REG_A7]); -} - -/* Actual TOS OS call opcode accessor functions */ -static Uint32 GetLineAOpcode(void) -{ - return getLineOpcode(0xA); -} -static Uint32 GetLineFOpcode(void) -{ - return getLineOpcode(0xF); -} -static Uint32 GetGemdosOpcode(void) -{ - if (isTrap(1)) { - return getStackOpcode(); - } - return INVALID_OPCODE; -} -static Uint32 GetBiosOpcode(void) -{ - if (isTrap(13)) { - return getStackOpcode(); - } - return INVALID_OPCODE; -} -static Uint32 GetXbiosOpcode(void) -{ - if (isTrap(14)) { - return getStackOpcode(); - } - return INVALID_OPCODE; -} -static Uint32 GetAesOpcode(void) -{ - if (isTrap(2)) { - Uint16 d0 = Regs[REG_D0]; - if (d0 == 0xC8) { - return getControlOpcode(); - } else if (d0 == 0xC9) { - /* same as appl_yield() */ - return 0x11; - } - } - return INVALID_OPCODE; -} -static Uint32 GetVdiOpcode(void) -{ - if (isTrap(2)) { - Uint16 d0 = Regs[REG_D0]; - if (d0 == 0x73) { - return getControlOpcode(); - } else if (d0 == 0xFFFE) { - /* -2 = vq_[v]gdos() */ - return 0xFFFE; - } - } - return INVALID_OPCODE; -} - -static Uint32 GetNextPC(void) -{ - return Disasm_GetNextPC(M68000_GetPC()); -} - -/* sorted by variable name so that this can be bisected */ -static const var_addr_t hatari_vars[] = { - { "AesOpcode", (Uint32*)GetAesOpcode, VALUE_TYPE_FUNCTION32, 16, "by default FFFF" }, - { "Basepage", (Uint32*)DebugInfo_GetBASEPAGE, VALUE_TYPE_FUNCTION32, 0, "invalid before Desktop is up" }, - { "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 }, - { "LineAOpcode", (Uint32*)GetLineAOpcode, VALUE_TYPE_FUNCTION32, 16, "by default FFFF" }, - { "LineCycles", (Uint32*)GetLineCycles, VALUE_TYPE_FUNCTION32, 0, "is always divisable by 4" }, - { "LineFOpcode", (Uint32*)GetLineFOpcode, VALUE_TYPE_FUNCTION32, 16, "by default FFFF" }, - { "NextPC", (Uint32*)GetNextPC, VALUE_TYPE_FUNCTION32, 0, NULL }, - { "TEXT", (Uint32*)DebugInfo_GetTEXT, VALUE_TYPE_FUNCTION32, 0, "invalid before Desktop is up" }, - { "TEXTEnd", (Uint32*)DebugInfo_GetTEXTEnd, VALUE_TYPE_FUNCTION32, 0, "invalid before Desktop is up" }, - { "VBL", (Uint32*)&nVBLs, VALUE_TYPE_VAR32, sizeof(nVBLs)*8, NULL }, - { "VdiOpcode", (Uint32*)GetVdiOpcode, VALUE_TYPE_FUNCTION32, 16, "by default FFFF" }, - { "XbiosOpcode", (Uint32*)GetXbiosOpcode, VALUE_TYPE_FUNCTION32, 16, "by default FFFF" } -}; - - -/** - * Readline match callback for CPU variable/symbol name completion. - * STATE = 0 -> different text from previous one. - * Return next match or NULL if no matches. - */ -char *BreakCond_MatchCpuVariable(const char *text, int state) -{ - static int i, len; - const char *name; - - if (!state) { - /* first match */ - len = strlen(text); - i = 0; - } - /* next match */ - while (i < ARRAYSIZE(hatari_vars)) { - name = hatari_vars[i++].name; - if (strncasecmp(name, text, len) == 0) - return (strdup(name)); - } - /* no variable match, check all CPU symbols */ - return Symbols_MatchCpuAddress(text, state); -} - -/** - * Readline match callback for DSP variable/symbol name completion. - * STATE = 0 -> different text from previous one. - * Return next match or NULL if no matches. - */ -char *BreakCond_MatchDspVariable(const char *text, int state) -{ - /* currently no DSP variables, check all DSP symbols */ - return Symbols_MatchDspAddress(text, state); -} - - /** * If given string is a Hatari variable name, set bc_value * fields accordingly and return true, otherwise return false. @@ -625,51 +427,21 @@ char *BreakCond_MatchDspVariable(const c static bool BreakCond_ParseVariable(const char *name, bc_value_t *bc_value) { const var_addr_t *hvar; - /* left, right, middle, direction */ - int l, r, m, dir; ENTERFUNC(("BreakCond_ParseVariable('%s')\n", name)); - /* bisect */ - l = 0; - r = ARRAYSIZE(hatari_vars) - 1; - do { - m = (l+r) >> 1; - hvar = hatari_vars + m; - dir = strcasecmp(name, hvar->name); - if (dir == 0) { - bc_value->value.reg32 = hvar->addr; - bc_value->valuetype = hvar->vtype; - bc_value->bits = hvar->bits; - assert(bc_value->bits == 32 || bc_value->valuetype != VALUE_TYPE_VAR32); - EXITFUNC(("-> true\n")); - return true; - } - if (dir < 0) { - r = m-1; - } else { - l = m+1; - } - } while (l <= r); + hvar = Vars_ParseVariable(name); + if (hvar) { + bc_value->value.reg32 = hvar->addr; + bc_value->valuetype = hvar->vtype; + bc_value->bits = hvar->bits; + assert(bc_value->bits == 32 || bc_value->valuetype != VALUE_TYPE_VAR32); + EXITFUNC(("-> true\n")); + return true; + } EXITFUNC(("-> false\n")); return false; } -/** - * If given string is a Hatari variable name, set value to given - * variable value and return true, otherwise return false. - */ -bool BreakCond_GetHatariVariable(const char *name, Uint32 *value) -{ - bc_value_t bc_value; - if (!BreakCond_ParseVariable(name, &bc_value)) { - return false; - } - bc_value.mask = 0xffffffff; - bc_value.is_indirect = false; - *value = BreakCond_GetValue(&bc_value); - return true; -} - /** * If given string matches a suitable symbol, set bc_value @@ -1510,6 +1282,9 @@ static void BreakCond_Print(bc_breakpoin if (bp->options.once) { fprintf(stderr, " :once"); } + if (bp->options.quiet) { + fprintf(stderr, " :quiet"); + } if (bp->options.trace) { if (bp->options.lock) { fprintf(stderr, " :lock"); @@ -1607,13 +1382,9 @@ static void BreakCond_RemoveAll(bc_break } /** - * Do delayed actions (remove breakpoints and old array alloc) - * - * If those removals affect the triggered breakpoint index, update it. - * - * Return updated breakpoint index. + * Do delayed breakpoint actions, remove breakpoints and old array alloc */ -static int BreakCond_DoDelayedActions(bc_breakpoints_t *bps, int triggered) +static void BreakCond_DoDelayedActions(bc_breakpoints_t *bps) { bc_options_t *options; bool removed; @@ -1630,12 +1401,8 @@ static int BreakCond_DoDelayedActions(bc options->deleted = false; removed = BreakCond_Remove(bps, i); ASSERT_VARIABLE(removed); - if (triggered >= i) { - triggered--; - } } } - return triggered; } @@ -1655,14 +1422,9 @@ int BreakCond_MatchCpuExpression(int pos } -/** - * help - */ -static void BreakCond_Help(void) -{ - Uint32 value; - int i; - fputs( +/* ------------- breakpoint condition parsing, public API ------------ */ + +static const char BreakCond_Help[] = " condition = [.mode] [& ] [.mode]\n" "\n" " where:\n" @@ -1685,38 +1447,13 @@ static void BreakCond_Help(void) " DSP addresses belong to different address spaces: P, X or Y. Note that\n" " on DSP only R0-R7 registers can be used for memory addressing.\n" "\n" -" Valid Hatari variable names (and their current values) are:\n", stderr); - for (i = 0; i < ARRAYSIZE(hatari_vars); i++) { - const var_addr_t *hvar = hatari_vars + i; - switch (hvar->vtype) { - case VALUE_TYPE_FUNCTION32: - value = ((Uint32(*)(void))(hvar->addr))(); - break; - case VALUE_TYPE_VAR32: - value = *(hvar->addr); - break; - default: - fprintf(stderr, "ERROR: variable '%s' has unsupported type '%d'\n", - hvar->name, hvar->vtype); - continue; - } - fprintf(stderr, " - %s ($%x)", hvar->name, value); - if (hvar->constraints) { - fprintf(stderr, ", %s\n", hvar->constraints); - } else { - fprintf(stderr, "\n"); - } - } - fputs( -"\n" " Examples:\n" " pc = $64543 && ($ff820).w & 3 = (a0) && d0 = %1100\n" " ($ffff9202).w ! ($ffff9202).w :trace\n" -" (r0).x = 1 && (r0).y = 2\n", stderr); -} - +" (r0).x = 1 && (r0).y = 2\n" +"\n" +" For breakpoint options, see 'help b'.\n"; -/* ------------- breakpoint condition parsing, public API ------------ */ const char BreakCond_Description[] = " [&& ...] [: