--- hatari/src/debug/debugcpu.c 2019/04/09 08:55:33 1.1.1.7 +++ hatari/src/debug/debugcpu.c 2019/04/09 08:58:02 1.1.1.9 @@ -11,6 +11,7 @@ const char DebugCpu_fileid[] = "Hatari d #include #include +#include #include "config.h" @@ -33,6 +34,7 @@ const char DebugCpu_fileid[] = "Hatari d #include "68kDisass.h" #include "console.h" #include "options.h" +#include "vars.h" #define MEMDUMP_COLS 16 /* memdump, number of bytes per row */ @@ -142,12 +144,18 @@ static int DebugCpu_SaveBin(int nArgc, c /** * Check whether given address matches any CPU symbol and whether * there's profiling information available for it. If yes, show it. + * + * @return true if symbol was shown, false otherwise */ -static void DebugCpu_ShowAddressInfo(Uint32 addr) +static bool DebugCpu_ShowAddressInfo(Uint32 addr, FILE *fp) { - const char *symbol = Symbols_GetByCpuAddress(addr); + const char *symbol = Symbols_GetByCpuAddress(addr, SYMTYPE_ALL); if (symbol) - fprintf(debugOutput, "%s:\n", symbol); + { + fprintf(fp, "%s:\n", symbol); + return true; + } + return false; } /** @@ -156,7 +164,7 @@ static void DebugCpu_ShowAddressInfo(Uin int DebugCpu_DisAsm(int nArgc, char *psArgs[]) { Uint32 disasm_upper = 0; - int insts, max_insts; + int shown, lines = INT_MAX; uaecptr nextpc; if (nArgc > 1) @@ -182,20 +190,17 @@ int DebugCpu_DisAsm(int nArgc, char *psA } /* limit is topmost address or instruction count */ - if (disasm_upper) - { - max_insts = INT_MAX; - } - else + if (!disasm_upper) { disasm_upper = 0xFFFFFFFF; - max_insts = ConfigureParams.Debugger.nDisasmLines; + lines = DebugUI_GetPageLines(ConfigureParams.Debugger.nDisasmLines, 8); } /* output a range */ - for (insts = 0; insts < max_insts && disasm_addr < disasm_upper; insts++) + for (shown = 0; shown < lines && disasm_addr < disasm_upper; shown++) { - DebugCpu_ShowAddressInfo(disasm_addr); + if (DebugCpu_ShowAddressInfo(disasm_addr, debugOutput)) + shown++; Disasm(debugOutput, (uaecptr)disasm_addr, &nextpc, 1); disasm_addr = nextpc; } @@ -217,7 +222,7 @@ static char *DebugCpu_MatchRegister(cons "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "pc", "sr" }; - return DebugUI_MatchHelper(regs, ARRAYSIZE(regs), text, state); + return DebugUI_MatchHelper(regs, ARRAY_SIZE(regs), text, state); } @@ -390,7 +395,8 @@ int DebugCpu_MemDump(int nArgc, char *ps if (!memdump_upper) { - memdump_upper = memdump_addr + MEMDUMP_COLS * ConfigureParams.Debugger.nMemdumpLines; + int lines = DebugUI_GetPageLines(ConfigureParams.Debugger.nMemdumpLines, 8); + memdump_upper = memdump_addr + MEMDUMP_COLS * lines; } while (memdump_addr < memdump_upper) @@ -500,7 +506,7 @@ static char *DebugCpu_MatchNext(const ch static const char* ntypes[] = { "branch", "exception", "exreturn", "return", "subcall", "subreturn" }; - return DebugUI_MatchHelper(ntypes, ARRAYSIZE(ntypes), text, state); + return DebugUI_MatchHelper(ntypes, ARRAY_SIZE(ntypes), text, state); } /** @@ -537,15 +543,25 @@ static int DebugCpu_Next(int nArgc, char Uint32 optype, nextpc; optype = DebugCpu_OpcodeType(); - /* can this instruction be stepped normally? */ - if (optype != CALL_SUBROUTINE && optype != CALL_EXCEPTION) + /* should this instruction be stepped normally, or is it + * - subroutine call + * - exception + * - loop branch backwards + */ + if (optype == CALL_SUBROUTINE || + optype == CALL_EXCEPTION || + (optype == CALL_BRANCH && + (STMemory_ReadWord(M68000_GetPC()) & 0xf0f8) == 0x50c8 && + (Sint16)STMemory_ReadWord(M68000_GetPC()+SIZE_WORD) < 0)) + { + nextpc = Disasm_GetNextPC(M68000_GetPC()); + sprintf(command, "pc=$%x :once :quiet\n", nextpc); + } + else { nCpuSteps = 1; return DEBUGGER_END; } - - nextpc = Disasm_GetNextPC(M68000_GetPC()); - sprintf(command, "pc=$%x :once :quiet\n", nextpc); } /* use breakpoint, not steps */ if (BreakCond_Command(command, false)) @@ -617,7 +633,16 @@ void DebugCpu_Check(void) } if (LOG_TRACE_LEVEL((TRACE_CPU_DISASM|TRACE_CPU_SYMBOLS))) { - DebugCpu_ShowAddressInfo(M68000_GetPC()); + DebugCpu_ShowAddressInfo(M68000_GetPC(), TraceFile); + } + if (LOG_TRACE_LEVEL(TRACE_CPU_REGS)) + { + uaecptr nextpc; +#ifdef WINUAE_FOR_HATARI + m68k_dumpstate_file(TraceFile, &nextpc); +#else + m68k_dumpstate(TraceFile, &nextpc); +#endif } if (nCpuActiveCBs) { @@ -658,7 +683,7 @@ void DebugCpu_SetDebugging(void) nCpuActiveCBs = BreakCond_CpuBreakPointCount(); if (nCpuActiveCBs || nCpuSteps || bCpuProfiling || History_TrackCpu() - || LOG_TRACE_LEVEL((TRACE_CPU_DISASM|TRACE_CPU_SYMBOLS)) + || LOG_TRACE_LEVEL((TRACE_CPU_DISASM|TRACE_CPU_SYMBOLS|TRACE_CPU_REGS)) || ConOutDevice != CONOUT_DEVICE_NONE) { M68000_SetSpecial(SPCFLAG_DEBUGGER); @@ -678,7 +703,7 @@ static const dbgcommand_t cpucommands[] "set CPU PC address breakpoints", BreakAddr_Description, true }, - { DebugCpu_BreakCond, BreakCond_MatchCpuVariable, + { DebugCpu_BreakCond, Vars_MatchCpuVariable, "breakpoint", "b", "set/remove/list conditional CPU breakpoints", BreakCond_Description, @@ -774,7 +799,7 @@ int DebugCpu_Init(const dbgcommand_t **t disasm_addr = 0; *table = cpucommands; - return ARRAYSIZE(cpucommands); + return ARRAY_SIZE(cpucommands); } /**