--- hatari/src/debug/debugdsp.c 2019/04/09 08:48:37 1.1.1.1 +++ hatari/src/debug/debugdsp.c 2019/04/09 08:50:22 1.1.1.3 @@ -21,7 +21,9 @@ const char DebugDsp_fileid[] = "Hatari d #include "debugdsp.h" #include "dsp.h" #include "evaluate.h" +#include "history.h" #include "memorySnapShot.h" +#include "profile.h" #include "str.h" #include "symbols.h" @@ -29,6 +31,7 @@ static Uint16 dsp_disasm_addr; /* DSP static Uint16 dsp_memdump_addr; /* DSP memdump address */ static char dsp_mem_space = 'P'; /* X, Y, P */ +static bool bDspProfiling; /* Whether profiling is enabled */ static int nDspActiveCBs = 0; /* Amount of active conditional breakpoints */ static int nDspSteps = 0; /* Amount of steps for DSP single-stepping */ @@ -110,14 +113,29 @@ error_msg: /** - * Check whether given address matches any DSP symbol, if yes, - * show the matching symbol information. + * Check whether given address matches any DSP symbol and whether + * there's profiling information available for it. If yes, show it. */ -static void DebugDsp_ShowMatchedSymbol(Uint32 addr) +static void DebugDsp_ShowAddressInfo(Uint16 addr) { - const char *symbol = Symbols_GetByDspAddress(addr); + Uint32 count, cycles; + const char *symbol; + bool shown = false; + + symbol = Symbols_GetByDspAddress(addr); if (symbol) - fprintf(debugOutput, "%s:\n", symbol); + { + fprintf(debugOutput, "%s", symbol); + shown = true; + } + if (Profile_DspAddressData(addr, &count, &cycles)) + { + fprintf(debugOutput, "%s%d/%d times/cycles", + (shown ? ", " : ""), count, cycles); + shown = true; + } + if (shown) + fprintf(debugOutput, ":\n"); } @@ -137,7 +155,7 @@ int DebugDsp_DisAsm(int nArgc, char *psA if (nArgc > 1) { - switch (Eval_Range(psArgs[1], &lower, &upper)) + switch (Eval_Range(psArgs[1], &lower, &upper, true)) { case -1: /* invalid value(s) */ @@ -181,7 +199,7 @@ int DebugDsp_DisAsm(int nArgc, char *psA } printf("DSP disasm 0x%hx-0x%hx:\n", dsp_disasm_addr, dsp_disasm_upper); while (dsp_disasm_addr < dsp_disasm_upper) { - DebugDsp_ShowMatchedSymbol(dsp_disasm_addr); + DebugDsp_ShowAddressInfo(dsp_disasm_addr); dsp_disasm_addr = DSP_DisasmAddress(dsp_disasm_addr, dsp_disasm_addr); } @@ -224,7 +242,7 @@ int DebugDsp_MemDump(int nArgc, char *ps fprintf(stderr,"Invalid DSP address space '%c'!\n", space); return DEBUGGER_CMDDONE; } - switch (Eval_Range(psArgs[2], &lower, &upper)) + switch (Eval_Range(psArgs[2], &lower, &upper, true)) { case -1: /* invalid value(s) */ @@ -291,7 +309,7 @@ static int DebugDsp_Continue(int nArgc, /** - * DSP wrapper for BreakAddr_Command/BreakPointCount, returns DEBUGGER_END + * DSP wrapper for BreakAddr_Command(). */ static int DebugDsp_BreakAddr(int nArgc, char *psArgs[]) { @@ -300,7 +318,7 @@ static int DebugDsp_BreakAddr(int nArgc, } /** - * DSP wrapper for BreakCond_Command/BreakPointCount, returns DEBUGGER_END + * DSP wrapper for BreakCond_Command(). */ static int DebugDsp_BreakCond(int nArgc, char *psArgs[]) { @@ -308,23 +326,40 @@ static int DebugDsp_BreakCond(int nArgc, return DEBUGGER_CMDDONE; } +/** + * DSP wrapper for Profile_Command(). + */ +static int DebugDsp_Profile(int nArgc, char *psArgs[]) +{ + Profile_Command(nArgc, psArgs, true); + return DEBUGGER_CMDDONE; +} + /** * This function is called after each DSP instruction when debugging is enabled. */ void DebugDsp_Check(void) { + if (bDspProfiling) + { + Profile_DspUpdate(); + } /* TODO: show symbols while disassembling DSP instructions */ if (nDspActiveCBs) { if (BreakCond_MatchDsp()) - DebugUI(); + DebugUI(REASON_DSP_BREAKPOINT); } if (nDspSteps) { nDspSteps -= 1; if (nDspSteps == 0) - DebugUI(); + DebugUI(REASON_DSP_STEPS); + } + if (bHistoryEnabled) + { + History_AddDsp(); } } @@ -336,8 +371,10 @@ void DebugDsp_Check(void) */ void DebugDsp_SetDebugging(void) { + bDspProfiling = Profile_DspStart(); nDspActiveCBs = BreakCond_BreakPointCount(true); - if (nDspActiveCBs || nDspSteps) + + if (nDspActiveCBs || nDspSteps || bDspProfiling || bHistoryEnabled) DSP_SetDebugging(true); else DSP_SetDebugging(false); @@ -375,6 +412,11 @@ static const dbgcommand_t dspcommands[] "load DSP symbols & their addresses", Symbols_Description, false }, + { DebugDsp_Profile, Profile_Match, + "dspprofile", "dp", + "profile DSP code", + Profile_Description, + false }, { DebugDsp_Register, DebugDsp_MatchRegister, "dspreg", "dr", "read/write DSP registers", @@ -418,4 +460,5 @@ int DebugDsp_Init(const dbgcommand_t **t void DebugDsp_InitSession(void) { dsp_disasm_addr = DSP_GetPC(); + Profile_DspStop(); }