--- hatari/src/debug/debugcpu.c 2019/04/09 08:48:37 1.1.1.1 +++ hatari/src/debug/debugcpu.c 2019/04/09 08:50:20 1.1.1.3 @@ -21,12 +21,15 @@ const char DebugCpu_fileid[] = "Hatari d #include "debugcpu.h" #include "evaluate.h" #include "hatari-glue.h" +#include "history.h" #include "log.h" #include "m68000.h" #include "memorySnapShot.h" +#include "profile.h" #include "stMemory.h" #include "str.h" #include "symbols.h" +#include "68kDisass.h" #define MEMDUMP_COLS 16 /* memdump, number of bytes per row */ #define NON_PRINT_CHAR '.' /* character to display for non-printables */ @@ -34,6 +37,7 @@ const char DebugCpu_fileid[] = "Hatari d static Uint32 disasm_addr; /* disasm address */ static Uint32 memdump_addr; /* memdump address */ +static bool bCpuProfiling; /* Whether CPU profiling is activated */ static int nCpuActiveCBs = 0; /* Amount of active conditional breakpoints */ static int nCpuSteps = 0; /* Amount of steps for CPU single-stepping */ @@ -130,14 +134,29 @@ static int DebugCpu_SaveBin(int nArgc, c /** - * Check whether given address matches any CPU symbol, if yes, - * show the symbol information. + * Check whether given address matches any CPU symbol and whether + * there's profiling information available for it. If yes, show it. */ -static void DebugCpu_ShowMatchedSymbol(Uint32 addr) +static void DebugCpu_ShowAddressInfo(Uint32 addr) { - const char *symbol = Symbols_GetByCpuAddress(addr); + Uint32 count, cycles; + const char *symbol; + bool shown = false; + + symbol = Symbols_GetByCpuAddress(addr); if (symbol) - fprintf(debugOutput, "%s:\n", symbol); + { + fprintf(debugOutput, "%s", symbol); + shown = true; + } + if (Profile_CpuAddressData(addr, &count, &cycles)) + { + fprintf(debugOutput, "%s%d/%d times/cycles", + (shown ? ", " : ""), count, cycles); + shown = true; + } + if (shown) + fprintf(debugOutput, ":\n"); } /** @@ -151,7 +170,7 @@ int DebugCpu_DisAsm(int nArgc, char *psA if (nArgc > 1) { - switch (Eval_Range(psArgs[1], &disasm_addr, &disasm_upper)) + switch (Eval_Range(psArgs[1], &disasm_addr, &disasm_upper, false)) { case -1: /* invalid value(s) */ @@ -187,8 +206,8 @@ int DebugCpu_DisAsm(int nArgc, char *psA /* output a range */ for (insts = 0; insts < max_insts && disasm_addr < disasm_upper; insts++) { - DebugCpu_ShowMatchedSymbol(disasm_addr); - m68k_disasm(debugOutput, (uaecptr)disasm_addr, &nextpc, 1); + DebugCpu_ShowAddressInfo(disasm_addr); + Disasm(debugOutput, (uaecptr)disasm_addr, &nextpc, 1, DISASM_ENGINE_EXT); disasm_addr = nextpc; } fflush(debugOutput); @@ -340,7 +359,7 @@ error_msg: /** - * CPU wrapper for BreakAddr_Command/BreakPointCount. + * CPU wrapper for BreakAddr_Command(). */ static int DebugCpu_BreakAddr(int nArgc, char *psArgs[]) { @@ -349,7 +368,7 @@ static int DebugCpu_BreakAddr(int nArgc, } /** - * CPU wrapper for BreakCond_Command/BreakPointCount. + * CPU wrapper for BreakCond_Command(). */ static int DebugCpu_BreakCond(int nArgc, char *psArgs[]) { @@ -357,6 +376,15 @@ static int DebugCpu_BreakCond(int nArgc, return DEBUGGER_CMDDONE; } +/** + * CPU wrapper for Profile_Command(). + */ +static int DebugCpu_Profile(int nArgc, char *psArgs[]) +{ + Profile_Command(nArgc, psArgs, false); + return DEBUGGER_CMDDONE; +} + /** * Do a memory dump, args = starting address. @@ -369,7 +397,7 @@ int DebugCpu_MemDump(int nArgc, char *ps if (nArgc > 1) { - switch (Eval_Range(psArgs[1], &memdump_addr, &memdump_upper)) + switch (Eval_Range(psArgs[1], &memdump_addr, &memdump_upper, false)) { case -1: /* invalid value(s) */ @@ -485,20 +513,28 @@ static int DebugCpu_Continue(int nArgc, */ void DebugCpu_Check(void) { + if (bCpuProfiling) + { + Profile_CpuUpdate(); + } if (LOG_TRACE_LEVEL(TRACE_CPU_DISASM)) { - DebugCpu_ShowMatchedSymbol(M68000_GetPC()); + DebugCpu_ShowAddressInfo(M68000_GetPC()); } if (nCpuActiveCBs) { if (BreakCond_MatchCpu()) - DebugUI(); + DebugUI(REASON_CPU_BREAKPOINT); } if (nCpuSteps) { nCpuSteps -= 1; if (nCpuSteps == 0) - DebugUI(); + DebugUI(REASON_CPU_STEPS); + } + if (bHistoryEnabled) + { + History_AddCpu(); } } @@ -509,8 +545,10 @@ void DebugCpu_Check(void) */ void DebugCpu_SetDebugging(void) { + bCpuProfiling = Profile_CpuStart(); nCpuActiveCBs = BreakCond_BreakPointCount(false); - if (nCpuActiveCBs || nCpuSteps) + + if (nCpuActiveCBs || nCpuSteps || bCpuProfiling || bHistoryEnabled) M68000_SetSpecial(SPCFLAG_DEBUGGER); else M68000_UnsetSpecial(SPCFLAG_DEBUGGER); @@ -538,6 +576,11 @@ static const dbgcommand_t cpucommands[] "\tIf no address is given, this command disassembles from the last\n" "\tposition or from current PC if no last position is available.", false }, + { DebugCpu_Profile, Profile_Match, + "profile", "", + "profile CPU code", + Profile_Description, + false }, { DebugCpu_Register, DebugCpu_MatchRegister, "cpureg", "r", "dump register values or set register to value", @@ -612,4 +655,5 @@ int DebugCpu_Init(const dbgcommand_t **t void DebugCpu_InitSession(void) { disasm_addr = M68000_GetPC(); + Profile_CpuStop(); }