--- previous/src/debug/debugcpu.c 2018/04/24 19:25:10 1.1 +++ previous/src/debug/debugcpu.c 2018/04/24 19:32:06 1.1.1.3 @@ -10,7 +10,7 @@ const char DebugCpu_fileid[] = "Hatari debugcpu.c : " __DATE__ " " __TIME__; #include - +#include #include "config.h" #include "main.h" @@ -23,10 +23,12 @@ const char DebugCpu_fileid[] = "Hatari d #include "hatari-glue.h" #include "log.h" #include "m68000.h" -#include "memorySnapShot.h" -#include "nextMemory.h" +#include "profile.h" #include "str.h" #include "symbols.h" +#include "68kDisass.h" +#include "cpummu.h" +#include "cpummu030.h" #define MEMDUMP_COLS 16 /* memdump, number of bytes per row */ #define NON_PRINT_CHAR '.' /* character to display for non-printables */ @@ -34,9 +36,57 @@ const char DebugCpu_fileid[] = "Hatari d static Uint32 disasm_addr=0; /* disasm address */ static Uint32 memdump_addr=0; /* 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 */ +Uint32 DBGMemory_ReadLong(Uint32 addr) { + switch (ConfigureParams.System.nCpuLevel) { + case 3: return get_long_mmu030(addr); + case 4: return get_long_mmu040(addr); + default: return 0; + } +} + +Uint16 DBGMemory_ReadWord(Uint32 addr) { + switch (ConfigureParams.System.nCpuLevel) { + case 3: return get_word_mmu030(addr); + case 4: return get_word_mmu040(addr); + default: return 0; + } +} + +Uint8 DBGMemory_ReadByte(Uint32 addr) { + switch (ConfigureParams.System.nCpuLevel) { + case 3: return get_byte_mmu030(addr); + case 4: return get_byte_mmu040(addr); + default: return 0; + } +} + +void DBGMemory_WriteLong(Uint32 addr, Uint32 val) { + switch (ConfigureParams.System.nCpuLevel) { + case 3: put_long_mmu030(addr, val); break; + case 4: put_long_mmu040(addr, val); break; + default: break; + } +} + +void DBGMemory_WriteWord(Uint32 addr, Uint16 val) { + switch (ConfigureParams.System.nCpuLevel) { + case 3: put_word_mmu030(addr, val); break; + case 4: put_word_mmu040(addr, val); break; + default: break; + } +} + +void DBGMemory_WriteByte(Uint32 addr, Uint8 val) { + switch (ConfigureParams.System.nCpuLevel) { + case 3: put_byte_mmu030(addr, val); break; + case 4: put_byte_mmu040(addr, val); break; + default: break; + } +} /** * Load a binary file to a memory address. @@ -70,7 +120,7 @@ static int DebugCpu_LoadBin(int nArgc, c while (!feof(fp)) { i++; - NEXTMemory_WriteByte(address++, c); + DBGMemory_WriteByte(address++, c); c = fgetc(fp); } fprintf(stderr," Read 0x%x bytes.\n", i); @@ -116,7 +166,7 @@ static int DebugCpu_SaveBin(int nArgc, c while (i < bytes) { - c = NEXTMemory_ReadByte(address++); + c = DBGMemory_ReadByte(address++); fputc(c, fp); i++; } @@ -128,14 +178,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"); } /** @@ -150,7 +215,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) */ @@ -179,21 +244,19 @@ int DebugCpu_DisAsm(int nArgc, char *psA } /* limit is topmost address or instruction count */ - if (disasm_upper) - { + if (disasm_upper) { max_insts = INT_MAX; - } - else - { + } else { // max_insts = ConfigureParams.Debugger.nDisasmLines; - max_insts=5; + max_insts = 5; + disasm_upper = 0xFFFFFFFF; } /* output a range */ for (insts = 0; insts < max_insts && disasm_addr < disasm_upper; insts++) { - DebugCpu_ShowMatchedSymbol(disasm_addr); - m68k_disasm(mydebugOutput, (uaecptr)disasm_addr, &nextpc, 1); + DebugCpu_ShowAddressInfo(disasm_addr); + Disasm(debugOutput, (uaecptr)disasm_addr, &nextpc, 1, DISASM_ENGINE_UAE); disasm_addr = nextpc; } fflush(mydebugOutput); @@ -287,7 +350,7 @@ int DebugCpu_Register(int nArgc, char *p { uaecptr nextpc; /* use the UAE function instead */ - m68k_dumpstate(debugOutput, &nextpc); + m68k_dumpstate(&nextpc); fflush(debugOutput); return DEBUGGER_CMDDONE; } @@ -346,7 +409,7 @@ error_msg: /** - * CPU wrapper for BreakAddr_Command/BreakPointCount. + * CPU wrapper for BreakAddr_Command(). */ static int DebugCpu_BreakAddr(int nArgc, char *psArgs[]) { @@ -355,7 +418,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[]) { @@ -363,6 +426,14 @@ 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. @@ -375,7 +446,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) */ @@ -398,11 +469,11 @@ int DebugCpu_MemDump(int nArgc, char *ps { fprintf(debugOutput, "%6.6X: ", memdump_addr); /* print address */ for (i = 0; i < MEMDUMP_COLS; i++) /* print hex data */ - fprintf(debugOutput, "%2.2x ", NEXTMemory_ReadByte(memdump_addr++)); + fprintf(debugOutput, "%2.2x ", DBGMemory_ReadByte(memdump_addr++)); fprintf(debugOutput, " "); /* print ASCII data */ for (i = 0; i < MEMDUMP_COLS; i++) { - c = NEXTMemory_ReadByte(memdump_addr-MEMDUMP_COLS+i); + c = DBGMemory_ReadByte(memdump_addr-MEMDUMP_COLS+i); if(!isprint((unsigned)c)) c = NON_PRINT_CHAR; /* non-printable as dots */ fprintf(debugOutput,"%c", c); @@ -454,7 +525,7 @@ static int DebugCpu_MemWrite(int nArgc, /* write the data */ for (i = 0; i < numBytes; i++) - NEXTMemory_WriteByte(write_addr + i, bytes[i]); + DBGMemory_WriteByte(write_addr + i, bytes[i]); return DEBUGGER_CMDDONE; } @@ -488,9 +559,13 @@ 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) { @@ -512,8 +587,10 @@ void DebugCpu_Check(void) */ void DebugCpu_SetDebugging(void) { + bCpuProfiling = Profile_CpuStart(); nCpuActiveCBs = BreakCond_BreakPointCount(false); - if (nCpuActiveCBs || nCpuSteps) + + if (nCpuActiveCBs || nCpuSteps || bCpuProfiling) M68000_SetSpecial(SPCFLAG_DEBUGGER); else M68000_UnsetSpecial(SPCFLAG_DEBUGGER); @@ -541,6 +618,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", @@ -615,4 +697,5 @@ int DebugCpu_Init(const dbgcommand_t **t void DebugCpu_InitSession(void) { disasm_addr = M68000_GetPC(); + Profile_CpuStop(); }