--- hatari/src/debug/breakcond.c 2019/04/09 08:51:58 1.1.1.4 +++ hatari/src/debug/breakcond.c 2019/04/09 08:53:03 1.1.1.5 @@ -1,10 +1,10 @@ /* Hatari - breakcond.c - Copyright (c) 2009-2010 by Eero Tamminen + Copyright (c) 2009-2012 by Eero Tamminen - 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. breakcond.c - code for breakpoint conditions that can check variable and memory values against each other, mask them etc. before deciding @@ -94,7 +94,9 @@ typedef struct { char *filename; /* file where to read commands to do on hit */ int skip; /* how many times to hit before breaking */ bool once; /* remove after hit&break */ + bool quiet; /* no output from setting & hitting */ bool trace; /* trace mode, don't break */ + bool noinit; /* prevent debugger inits on break */ bool lock; /* tracing + show locked info */ } bc_options_t; @@ -246,9 +248,31 @@ static Uint32 BreakCond_GetValue(const b /** + * Show & update rvalue for a tracked breakpoint condition to lvalue + */ +static void BreakCond_UpdateTracked(bc_condition_t *condition, Uint32 value) +{ + Uint32 addr; + + /* next monitor changes to this new value */ + condition->rvalue.value.number = value; + + if (condition->lvalue.is_indirect && + condition->lvalue.valuetype == VALUE_TYPE_NUMBER) { + /* simple memory address */ + addr = condition->lvalue.value.number; + fprintf(stderr, " $%x = $%x\n", addr, value); + } else { + /* register tms. */ + fprintf(stderr, " $%x\n", value); + } +} + + +/** * Return true if all of the given breakpoint's conditions match */ -static bool BreakCond_MatchConditions(const bc_condition_t *condition, int count) +static bool BreakCond_MatchConditions(bc_condition_t *condition, int count) { Uint32 lvalue, rvalue; bool hit = false; @@ -271,6 +295,9 @@ static bool BreakCond_MatchConditions(co 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", @@ -287,61 +314,31 @@ static bool BreakCond_MatchConditions(co /** - * Show values for the tracked breakpoint conditions - */ -static void BreakCond_ShowTracked(bc_condition_t *condition, int count) -{ - Uint32 addr, value; - char sep; - int i; - - sep = ' '; - for (i = 0; i < count; condition++, i++) { - if (!condition->track) { - continue; - } - - /* get the new value in address */ - value = BreakCond_GetValue(&(condition->lvalue)); - /* next monitor changes to this new value */ - condition->rvalue.value.number = value; - - if (condition->lvalue.is_indirect && - condition->lvalue.valuetype == VALUE_TYPE_NUMBER) { - /* simple memory address */ - addr = condition->lvalue.value.number; - fprintf(stderr, "%c $%x = $%x", sep, addr, value); - } else { - /* register tms. */ - fprintf(stderr, "%c $%x", sep, value); - } - sep = ','; - } - fprintf(stderr, "\n"); -} - - -/** - * Return which of the given condition breakpoints match - * or zero if none matched + * Show all breakpoints which conditions matched and return which matched + * @return index to last matching (non-tracing) breakpoint, + * or zero if none matched */ static int BreakCond_MatchBreakPoints(bc_breakpoint_t *bp, int count, const char *name) { - bool for_dsp; - int i, ret; - + int i, ret = 0; + for (i = 0; i < count; bp++, i++) { if (BreakCond_MatchConditions(bp->conditions, bp->ccount)) { + bool for_dsp; bp->hits++; - if (bp->options.skip && - (bp->hits % bp->options.skip) == 0) { - return 0; + if (bp->options.skip) { + if (bp->hits % bp->options.skip) { + /* check next */ + continue; + } + } + if (!bp->options.quiet) { + fprintf(stderr, "%d. %s breakpoint condition(s) matched %d times.\n", + i+1, name, bp->hits); + BreakCond_Print(bp); } - fprintf(stderr, "%d. %s breakpoint condition(s) matched %d times.\n", - i+1, name, bp->hits); - for_dsp = (bp-i == BreakPointsDsp); if (for_dsp) { History_Mark(REASON_DSP_BREAKPOINT); @@ -349,31 +346,33 @@ static int BreakCond_MatchBreakPoints(bc History_Mark(REASON_CPU_BREAKPOINT); } - if (bp->options.lock) { - DebugCpu_InitSession(); - DebugDsp_InitSession(); - DebugInfo_ShowSessionInfo(); - } - if (bp->options.filename) { - DebugUI_ParseFile(bp->options.filename); - } + if (bp->options.lock || bp->options.filename) { + bool reinit = !bp->options.noinit; - if (bp->options.trace) { - ret = 0; - } else { - /* indexes for BreakCond_Remove() start from 1 */ - ret = i + 1; + if (reinit) { + DebugCpu_InitSession(); + DebugDsp_InitSession(); + } + + if (bp->options.lock) { + DebugInfo_ShowSessionInfo(); + } + if (bp->options.filename) { + DebugUI_ParseFile(bp->options.filename, reinit); + } } - - BreakCond_Print(bp); - BreakCond_ShowTracked(bp->conditions, bp->ccount); if (bp->options.once) { BreakCond_Remove(i+1, for_dsp); + count--; } - return ret; + if (!bp->options.trace) { + /* index for current hit (BreakCond_Remove() indexes start from 1) */ + ret = i + 1; + } + /* continue checking breakpoints to make sure all relevant actions get performed */ } } - return 0; + return ret; } /* ------------- breakpoint condition checking, public API ------------- */ @@ -531,6 +530,11 @@ static Uint32 GetVdiOpcode(void) 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" }, @@ -543,7 +547,9 @@ static const var_addr_t hatari_vars[] = { "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" } @@ -1387,27 +1393,37 @@ static bool BreakCond_Parse(const char * } if (ccount > 0) { (*bcount)++; - fprintf(stderr, "%s condition breakpoint %d with %d condition(s) added:\n\t%s\n", - name, *bcount, ccount, bp->expression); - BreakCond_CheckTracking(bp); - if (options->skip) { - fprintf(stderr, "-> Break only on every %d hit.\n", options->skip); - bp->options.skip = options->skip; - } - if (options->once) { - fprintf(stderr, "-> Once, delete after breaking.\n"); - bp->options.once = true; - } - if (options->trace) { - fprintf(stderr, "-> Trace instead of breaking, but show still hits.\n"); - if (options->lock) { - fprintf(stderr, "-> Show also info selected with lock command.\n"); - bp->options.lock = true; + if (!options->quiet) { + fprintf(stderr, "%s condition breakpoint %d with %d condition(s) added:\n\t%s\n", + name, *bcount, ccount, bp->expression); + if (options->skip) { + fprintf(stderr, "-> Break only on every %d hit.\n", options->skip); + } + if (options->once) { + fprintf(stderr, "-> Once, delete after breaking.\n"); + } + if (options->trace) { + fprintf(stderr, "-> Trace instead of breaking, but show still hits.\n"); + if (options->lock) { + fprintf(stderr, "-> Show also info selected with lock command.\n"); + } + if (options->noinit) { + fprintf(stderr, "-> Skip debugger inits on hit.\n"); + } + } + if (options->filename) { + fprintf(stderr, "-> Execute debugger commands from '%s' file on hit.\n", options->filename); } - bp->options.trace = true; } + BreakCond_CheckTracking(bp); + + bp->options.quiet = options->quiet; + bp->options.skip = options->skip; + bp->options.once = options->once; + bp->options.trace = options->trace; + bp->options.lock = options->lock; + bp->options.noinit = options->noinit; if (options->filename) { - fprintf(stderr, "-> Execute debugger commands from '%s' file on hit.\n", options->filename); bp->options.filename = strdup(options->filename); } } else { @@ -1457,6 +1473,9 @@ static void BreakCond_Print(bc_breakpoin } else { fprintf(stderr, " :trace"); } + if (bp->options.noinit) { + fprintf(stderr, " :noinit"); + } } if (bp->options.filename) { fprintf(stderr, " :file %s", bp->options.filename); @@ -1506,8 +1525,10 @@ static bool BreakCond_Remove(int positio return false; } offset = position - 1; - fprintf(stderr, "Removed %s breakpoint %d:\n", name, position); - BreakCond_Print(&(bp[offset])); + if (!bp[offset].options.quiet) { + fprintf(stderr, "Removed %s breakpoint %d:\n", name, position); + BreakCond_Print(&(bp[offset])); + } free(bp[offset].expression); if (bp[offset].options.filename) { free(bp[offset].options.filename); @@ -1623,8 +1644,10 @@ const char BreakCond_Description[] = "\tthe breakpoint condition(s):\n" "\t- 'trace', print the breakpoint match without stopping\n" "\t- 'lock', print the debugger entry info without stopping\n" + "\t- 'noinit', no debugger inits on hit, useful for stack tracing\n" "\t- 'file ', execute debugger commands from given \n" "\t- 'once', delete the breakpoint after it's hit\n" + "\t- 'quiet', no output from setting & hitting breakpoint\n" "\t- '', break only on every hit"; /** @@ -1655,11 +1678,16 @@ static bool BreakCond_Options(char *str, if (strcmp(option, "once") == 0) { options->once = true; + } else if (strcmp(option, "quiet") == 0) { + options->quiet = true; } else if (strcmp(option, "trace") == 0) { options->trace = true; } else if (strcmp(option, "lock") == 0) { options->trace = true; options->lock = true; + } else if (strcmp(option, "noinit") == 0) { + options->trace = true; + options->noinit = true; } else if (strncmp(option, "file ", 5) == 0) { filename = Str_Trim(option+4); if (!File_Exists(filename)) { @@ -1754,6 +1782,7 @@ const char BreakAddr_Description[] = "\t- 'trace', print the breakpoint match without stopping\n" "\t- 'lock', print the debugger entry info without stopping\n" "\t- 'once', delete the breakpoint after it's hit\n" + "\t- 'quiet', no output from setting & hitting breakpoint\n" "\t- '', break only on every hit\n" "\n" "\tUse conditional breakpoint commands to manage the created\n" @@ -1805,10 +1834,10 @@ bool BreakAddr_Command(char *args, bool /* on success, show on what instruction it was added */ if (bForDsp) { - DSP_DisasmAddress(addr, addr); + DSP_DisasmAddress(stderr, addr, addr); } else { uaecptr dummy; - Disasm(stderr, (uaecptr)addr, &dummy, 1, DISASM_ENGINE_EXT); + Disasm(stderr, (uaecptr)addr, &dummy, 1); } return true; }