From aecaf271f1fe98cba1ebc8228ff9eff3e39e72c5 Mon Sep 17 00:00:00 2001 From: hrydgard Date: Sun, 21 Jun 2009 08:39:21 +0000 Subject: [PATCH] New DSP debugger: step one. (not ready yet, but try loading zelda WW and look at the dsp debugger..). Had to shuffle around quite a lot of code to be able to extract the CodeView into a library nicely so it can be used from both the main dolphin and the LLE plugin... also extracted the symboldb code. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3517 8ced0084-cf51-0410-be5f-012b33b47a6e --- Externals/Bochs_disasm/Bochs_disasm.vcproj | 14 +- Source/Core/AudioCommon/AudioCommon.vcproj | 4 +- Source/Core/Common/Common.vcproj | 12 + .../Debugger => Common/Src}/DebugInterface.h | 1 + Source/Core/Common/Src/StringUtil.cpp | 29 ++ Source/Core/Common/Src/StringUtil.h | 2 + Source/Core/Common/Src/SymbolDB.cpp | 59 +++ .../Src/PowerPC => Common/Src}/SymbolDB.h | 253 +++++------ Source/Core/Core/Core.vcproj | 16 +- Source/Core/Core/Src/Boot/Boot.cpp | 4 +- Source/Core/Core/Src/Boot/ElfReader.cpp | 2 +- Source/Core/Core/Src/Console.cpp | 2 +- Source/Core/Core/Src/Core.cpp | 1 + .../Src/Debugger/Debugger_BreakPoints.cpp | 25 +- .../Core/Src/Debugger/Debugger_BreakPoints.h | 36 +- .../Core/Src/Debugger/Debugger_SymbolMap.cpp | 21 +- .../Core/Src/Debugger/Debugger_SymbolMap.h | 2 + .../Core/Src/Debugger/PPCDebugInterface.cpp | 14 +- Source/Core/Core/Src/HLE/HLE.cpp | 4 +- Source/Core/Core/Src/HW/DSP.cpp | 28 +- Source/Core/Core/Src/HW/DSP.h | 1 + Source/Core/Core/Src/HW/MemmapFunctions.cpp | 16 +- .../Src/PowerPC/Interpreter/Interpreter.cpp | 6 +- Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp | 2 +- Source/Core/Core/Src/PowerPC/PPCAnalyst.cpp | 10 +- Source/Core/Core/Src/PowerPC/PPCAnalyst.h | 4 +- .../PowerPC/{SymbolDB.cpp => PPCSymbolDB.cpp} | 63 +-- Source/Core/Core/Src/PowerPC/PPCSymbolDB.h | 56 +++ Source/Core/Core/Src/PowerPC/Profiler.cpp | 2 +- Source/Core/Core/Src/PowerPC/SignatureDB.cpp | 8 +- Source/Core/Core/Src/PowerPC/SignatureDB.h | 6 +- Source/Core/Core/Src/SConscript | 2 +- Source/Core/DSPCore/DSPCore.vcproj | 8 +- Source/Core/DSPCore/Src/DSPCore.cpp | 2 + Source/Core/DSPCore/Src/DSPHost.h | 1 + Source/Core/DSPCore/Src/DSPTables.cpp | 60 ++- Source/Core/DSPCore/Src/disassemble.cpp | 16 +- Source/Core/DSPCore/Src/disassemble.h | 4 +- Source/Core/DSPCore/Src/gdsp_aram.cpp | 12 + Source/Core/DSPCore/Src/gdsp_aram.h | 1 + Source/Core/DSPCore/Src/gdsp_interface.cpp | 39 +- Source/Core/DSPCore/Src/gdsp_interpreter.cpp | 21 +- .../DebuggerUICommon/DebuggerUICommon.vcproj | 429 ++++++++++++++++++ .../Src/CodeView.cpp | 81 ++-- .../Src/CodeView.h | 17 +- .../DebuggerUICommon/Src/DebuggerUIUtil.cpp | 23 + .../DebuggerUICommon/Src/DebuggerUIUtil.h | 36 ++ Source/Core/DebuggerUICommon/Src/SConscript | 13 + Source/Core/DebuggerWX/DebuggerWX.vcproj | 23 +- Source/Core/DebuggerWX/Src/BreakPointDlg.cpp | 2 +- Source/Core/DebuggerWX/Src/BreakpointView.cpp | 10 +- .../Core/DebuggerWX/Src/BreakpointWindow.cpp | 6 +- Source/Core/DebuggerWX/Src/CodeWindow.cpp | 9 +- Source/Core/DebuggerWX/Src/CodeWindowSJP.cpp | 5 +- Source/Core/DebuggerWX/Src/Debugger.h | 17 +- Source/Core/DebuggerWX/Src/MemoryCheckDlg.cpp | 2 +- Source/Core/DebuggerWX/Src/MemoryView.h | 2 +- Source/Core/DebuggerWX/Src/MemoryWindow.cpp | 2 +- Source/Core/DebuggerWX/Src/SConscript | 2 - Source/DSPSpy/Stubs.cpp | 3 + Source/DSPTool/Src/main.cpp | 1 + Source/Dolphin.sln | 41 +- Source/PluginSpecs/pluginspecs_dsp.h | 2 + .../Plugin_DSP_HLE/Src/UCodes/UCode_Zelda.cpp | 33 +- .../Plugin_DSP_HLE/Src/UCodes/UCodes.cpp | 2 +- .../Plugin_DSP_LLE/Plugin_DSP_LLE.vcproj | 32 +- .../Plugin_DSP_LLE/Src/DSPDebugInterface.cpp | 111 ++--- .../Plugin_DSP_LLE/Src/DSPDebugInterface.h | 4 +- Source/Plugins/Plugin_DSP_LLE/Src/DSPHost.cpp | 30 ++ .../Plugins/Plugin_DSP_LLE/Src/DSPSymbols.cpp | 287 ++++++++++++ .../Plugins/Plugin_DSP_LLE/Src/DSPSymbols.h | 54 +++ .../Plugin_DSP_LLE/Src/Debugger/Debugger.cpp | 330 +++----------- .../Plugin_DSP_LLE/Src/Debugger/Debugger.h | 48 +- Source/Plugins/Plugin_DSP_LLE/Src/main.cpp | 7 +- Source/UnitTests/UnitTests.cpp | 1 + Source/UnitTests/UnitTests.vcproj | 155 +++++++ 76 files changed, 1895 insertions(+), 794 deletions(-) rename Source/Core/{Core/Src/Debugger => Common/Src}/DebugInterface.h (93%) create mode 100644 Source/Core/Common/Src/SymbolDB.cpp rename Source/Core/{Core/Src/PowerPC => Common/Src}/SymbolDB.h (73%) rename Source/Core/Core/Src/PowerPC/{SymbolDB.cpp => PPCSymbolDB.cpp} (85%) create mode 100644 Source/Core/Core/Src/PowerPC/PPCSymbolDB.h create mode 100644 Source/Core/DebuggerUICommon/DebuggerUICommon.vcproj rename Source/Core/{DebuggerWX => DebuggerUICommon}/Src/CodeView.cpp (89%) rename Source/Core/{DebuggerWX => DebuggerUICommon}/Src/CodeView.h (85%) create mode 100644 Source/Core/DebuggerUICommon/Src/DebuggerUIUtil.cpp create mode 100644 Source/Core/DebuggerUICommon/Src/DebuggerUIUtil.h create mode 100644 Source/Core/DebuggerUICommon/Src/SConscript create mode 100644 Source/Plugins/Plugin_DSP_LLE/Src/DSPSymbols.cpp create mode 100644 Source/Plugins/Plugin_DSP_LLE/Src/DSPSymbols.h diff --git a/Externals/Bochs_disasm/Bochs_disasm.vcproj b/Externals/Bochs_disasm/Bochs_disasm.vcproj index f52d322f58..7e56456c84 100644 --- a/Externals/Bochs_disasm/Bochs_disasm.vcproj +++ b/Externals/Bochs_disasm/Bochs_disasm.vcproj @@ -1,7 +1,7 @@ + + @@ -780,6 +784,14 @@ RelativePath=".\Src\StringUtil.h" > + + + + diff --git a/Source/Core/Core/Src/Debugger/DebugInterface.h b/Source/Core/Common/Src/DebugInterface.h similarity index 93% rename from Source/Core/Core/Src/Debugger/DebugInterface.h rename to Source/Core/Common/Src/DebugInterface.h index 574d41ffbe..804125b8dd 100644 --- a/Source/Core/Core/Src/Debugger/DebugInterface.h +++ b/Source/Core/Common/Src/DebugInterface.h @@ -20,6 +20,7 @@ public: virtual void clearAllBreakpoints() {} virtual void toggleBreakpoint(unsigned int /*address*/){} virtual unsigned int readMemory(unsigned int /*address*/){return 0;} + virtual void writeExtraMemory(int memory, unsigned int value, unsigned int /*address*/) {} virtual unsigned int readExtraMemory(int memory, unsigned int address){return 0;} virtual unsigned int readInstruction(unsigned int /*address*/){return 0;} virtual unsigned int getPC() {return 0;} diff --git a/Source/Core/Common/Src/StringUtil.cpp b/Source/Core/Common/Src/StringUtil.cpp index 0233c5e841..b7cb1adb1c 100644 --- a/Source/Core/Common/Src/StringUtil.cpp +++ b/Source/Core/Common/Src/StringUtil.cpp @@ -460,3 +460,32 @@ void NormalizeDirSep(std::string* str) } #endif } + +std::string TabsToSpaces(int tab_size, const std::string &in) +{ + std::string out; + int len = 0; + // First, compute the size of the new string. + for (int i = 0; i < in.size(); i++) + { + if (in[i] == '\t') + len += tab_size; + else + len += 1; + } + out.resize(len); + int out_ctr = 0; + for (int i = 0; i < in.size(); i++) + { + if (in[i] == '\t') + { + for (int j = 0; j < tab_size; j++) + out[out_ctr++] = ' '; + } + else + { + out[out_ctr++] = in[i]; + } + } + return out; +} \ No newline at end of file diff --git a/Source/Core/Common/Src/StringUtil.h b/Source/Core/Common/Src/StringUtil.h index 4dbcc7ff8e..44d56b32f7 100644 --- a/Source/Core/Common/Src/StringUtil.h +++ b/Source/Core/Common/Src/StringUtil.h @@ -66,6 +66,8 @@ bool AsciiToHex(const char* _szValue, u32& result); u32 Ascii2Hex(std::string _Text); std::string Hex2Ascii(u32 _Text); +std::string TabsToSpaces(int tab_size, const std::string &in); + void SplitString(const std::string& str, const std::string& delim, std::vector& output); int ChooseStringFrom(const char* str, const char* * items); diff --git a/Source/Core/Common/Src/SymbolDB.cpp b/Source/Core/Common/Src/SymbolDB.cpp new file mode 100644 index 0000000000..86161b6b9c --- /dev/null +++ b/Source/Core/Common/Src/SymbolDB.cpp @@ -0,0 +1,59 @@ +// Copyright (C) 2003-2008 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#include "SymbolDB.h" + + +void SymbolDB::List() +{ + for (XFuncMap::iterator iter = functions.begin(); iter != functions.end(); iter++) + { + DEBUG_LOG(HLE,"%s @ %08x: %i bytes (hash %08x) : %i calls", iter->second.name.c_str(), iter->second.address, iter->second.size, iter->second.hash,iter->second.numCalls); + } + INFO_LOG(HLE,"%i functions known in this program above.", functions.size()); +} + +void SymbolDB::Clear(const char *prefix) +{ + // TODO: honor prefix + functions.clear(); + checksumToFunction.clear(); +} + +void SymbolDB::Index() +{ + int i = 0; + for (XFuncMap::iterator iter = functions.begin(); iter != functions.end(); iter++) + { + iter->second.index = i++; + } +} + +Symbol *SymbolDB::GetSymbolFromName(const char *name) +{ + for (XFuncMap::iterator iter = functions.begin(); iter != functions.end(); iter++) + { + if (!strcmp(iter->second.name.c_str(), name)) + return &iter->second; + } + return 0; +} + +void SymbolDB::AddCompleteSymbol(const Symbol &symbol) +{ + functions.insert(std::pair(symbol.address, symbol)); +} diff --git a/Source/Core/Core/Src/PowerPC/SymbolDB.h b/Source/Core/Common/Src/SymbolDB.h similarity index 73% rename from Source/Core/Core/Src/PowerPC/SymbolDB.h rename to Source/Core/Common/Src/SymbolDB.h index 831fdf1fb0..dc6ba56f23 100644 --- a/Source/Core/Core/Src/PowerPC/SymbolDB.h +++ b/Source/Core/Common/Src/SymbolDB.h @@ -1,131 +1,122 @@ -// Copyright (C) 2003-2009 Dolphin Project. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, version 2.0. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License 2.0 for more details. - -// A copy of the GPL 2.0 should have been included with the program. -// If not, see http://www.gnu.org/licenses/ - -// Official SVN repository and contact information can be found at -// http://code.google.com/p/dolphin-emu/ - -#include "Common.h" - -#include -#include -#include -#include "../Debugger/PPCDebugInterface.h" -#include "../Debugger/DebugInterface.h" - -struct SCall -{ - SCall(u32 a, u32 b) : - function(a), - callAddress(b) - {} - u32 function; - u32 callAddress; -}; - -struct Symbol -{ - enum { - SYMBOL_FUNCTION = 0, - SYMBOL_DATA = 1, - }; - - Symbol() : - hash(0), - address(0), - flags(0), - size(0), - numCalls(0), - type(SYMBOL_FUNCTION), - analyzed(0) - {} - - std::string name; - std::vector callers; //addresses of functions that call this function - std::vector calls; //addresses of functions that are called by this function - u32 hash; //use for HLE function finding - u32 address; - u32 flags; - int size; - int numCalls; - int type; - int index; // only used for coloring the disasm view - int analyzed; -}; - -enum -{ - FFLAG_TIMERINSTRUCTIONS=(1<<0), - FFLAG_LEAF=(1<<1), - FFLAG_ONLYCALLSNICELEAFS=(1<<2), - FFLAG_EVIL=(1<<3), - FFLAG_RFI=(1<<4), - FFLAG_STRAIGHT=(1<<5) -}; - - -// This has functionality overlapping Debugger_Symbolmap. Should merge that stuff in here later. -class SymbolDB -{ -public: - typedef std::map XFuncMap; - typedef std::map XFuncPtrMap; - -private: - XFuncMap functions; - XFuncPtrMap checksumToFunction; - DebugInterface* debugger; - -public: - typedef void (*functionGetterCallback)(Symbol *f); - - SymbolDB(); - ~SymbolDB(); - - Symbol *AddFunction(u32 startAddr); - void AddKnownSymbol(u32 startAddr, u32 size, const char *name, int type = Symbol::SYMBOL_FUNCTION); - - Symbol *GetSymbolFromAddr(u32 addr); - Symbol *GetSymbolFromName(const char *name); - Symbol *GetSymbolFromHash(u32 hash) { - XFuncPtrMap::iterator iter = checksumToFunction.find(hash); - if (iter != checksumToFunction.end()) - return iter->second; - else - return 0; - } - - const XFuncMap &Symbols() const {return functions;} - XFuncMap &AccessSymbols() {return functions;} - - // deprecated - XFuncMap::iterator GetIterator() { return functions.begin(); } - XFuncMap::const_iterator GetConstIterator() { return functions.begin(); } - XFuncMap::iterator End() { return functions.end(); } - - const char *GetDescription(u32 addr); - - void Clear(const char *prefix = ""); - void List(); - void Index(); - void FillInCallers(); - - bool LoadMap(const char *filename); - bool SaveMap(const char *filename, bool WithCodes = false) const; - - void PrintCalls(u32 funcAddr) const; - void PrintCallers(u32 funcAddr) const; - void LogFunctionCall(u32 addr); -}; - -extern SymbolDB g_symbolDB; +// Copyright (C) 2003-2008 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + + +// This file contains a generic symbol map implementation. For CPU-specific +// magic, derive and extend. + +#ifndef _SYMBOL_DB_H +#define _SYMBOL_DB_H + +#include +#include + +#include "Common.h" + +struct SCall +{ + SCall(u32 a, u32 b) : + function(a), + callAddress(b) + {} + u32 function; + u32 callAddress; +}; + +struct Symbol +{ + enum { + SYMBOL_FUNCTION = 0, + SYMBOL_DATA = 1, + }; + + Symbol() : + hash(0), + address(0), + flags(0), + size(0), + numCalls(0), + type(SYMBOL_FUNCTION), + analyzed(0) + {} + + std::string name; + std::vector callers; //addresses of functions that call this function + std::vector calls; //addresses of functions that are called by this function + u32 hash; //use for HLE function finding + u32 address; + u32 flags; + int size; + int numCalls; + int type; + int index; // only used for coloring the disasm view + int analyzed; +}; + +enum +{ + FFLAG_TIMERINSTRUCTIONS=(1<<0), + FFLAG_LEAF=(1<<1), + FFLAG_ONLYCALLSNICELEAFS=(1<<2), + FFLAG_EVIL=(1<<3), + FFLAG_RFI=(1<<4), + FFLAG_STRAIGHT=(1<<5) +}; + + + +class SymbolDB +{ +public: + typedef std::map XFuncMap; + typedef std::map XFuncPtrMap; + +protected: + XFuncMap functions; + XFuncPtrMap checksumToFunction; + +public: + SymbolDB() {} + virtual ~SymbolDB() {} + virtual Symbol *GetSymbolFromAddr(u32 addr) { return 0; } + virtual Symbol *AddFunction(u32 startAddr) { return 0;} + + void AddCompleteSymbol(const Symbol &symbol); + + Symbol *GetSymbolFromName(const char *name); + Symbol *GetSymbolFromHash(u32 hash) { + XFuncPtrMap::iterator iter = checksumToFunction.find(hash); + if (iter != checksumToFunction.end()) + return iter->second; + else + return 0; + } + + const XFuncMap &Symbols() const {return functions;} + XFuncMap &AccessSymbols() {return functions;} + + // deprecated + XFuncMap::iterator GetIterator() { return functions.begin(); } + XFuncMap::const_iterator GetConstIterator() { return functions.begin(); } + XFuncMap::iterator End() { return functions.end(); } + + void Clear(const char *prefix = ""); + void List(); + void Index(); +}; + +#endif diff --git a/Source/Core/Core/Core.vcproj b/Source/Core/Core/Core.vcproj index b4ccfa4923..2551d8603b 100644 --- a/Source/Core/Core/Core.vcproj +++ b/Source/Core/Core/Core.vcproj @@ -963,6 +963,14 @@ RelativePath=".\Src\PowerPC\PPCAnalyst.h" > + + + + @@ -987,14 +995,6 @@ RelativePath=".\Src\PowerPC\SignatureDB.h" > - - - - diff --git a/Source/Core/Core/Src/Boot/Boot.cpp b/Source/Core/Core/Src/Boot/Boot.cpp index 588386bf5a..63c26e0490 100644 --- a/Source/Core/Core/Src/Boot/Boot.cpp +++ b/Source/Core/Core/Src/Boot/Boot.cpp @@ -41,7 +41,7 @@ #include "../VolumeHandler.h" #include "../PatchEngine.h" #include "../PowerPC/SignatureDB.h" -#include "../PowerPC/SymbolDB.h" +#include "../PowerPC/PPCSymbolDB.h" #include "../MemTools.h" #include "../ConfigManager.h" @@ -314,7 +314,7 @@ bool CBoot::BootUp() Boot_ELF(_StartupPara.m_strFilename.c_str()); UpdateDebugger_MapLoaded(); - BreakPoints::AddAutoBreakpoints(); + Debugger::AddAutoBreakpoints(); } break; diff --git a/Source/Core/Core/Src/Boot/ElfReader.cpp b/Source/Core/Core/Src/Boot/ElfReader.cpp index 12502c183f..42c3c9c46c 100644 --- a/Source/Core/Core/Src/Boot/ElfReader.cpp +++ b/Source/Core/Core/Src/Boot/ElfReader.cpp @@ -20,7 +20,7 @@ #include "Common.h" #include "../Debugger/Debugger_SymbolMap.h" #include "../HW/Memmap.h" -#include "../PowerPC/SymbolDB.h" +#include "../PowerPC/PPCSymbolDB.h" #include "ElfReader.h" void bswap(Elf32_Word &w) {w = Common::swap32(w);} diff --git a/Source/Core/Core/Src/Console.cpp b/Source/Core/Core/Src/Console.cpp index d0d74f9136..956278000b 100644 --- a/Source/Core/Core/Src/Console.cpp +++ b/Source/Core/Core/Src/Console.cpp @@ -26,7 +26,7 @@ #include "CoreTiming.h" #include "Core.h" #include "PowerPC/Jit64/Jit.h" -#include "PowerPC/SymbolDB.h" +#include "PowerPC/PPCSymbolDB.h" #include "PowerPCDisasm.h" #include "Console.h" diff --git a/Source/Core/Core/Src/Core.cpp b/Source/Core/Core/Src/Core.cpp index c67d186111..7558f2bcaa 100644 --- a/Source/Core/Core/Src/Core.cpp +++ b/Source/Core/Core/Src/Core.cpp @@ -399,6 +399,7 @@ THREAD_RETURN EmuThread(void *pArg) DSPInitialize dspInit; dspInit.hWnd = g_pWindowHandle; dspInit.pARAM_Read_U8 = (u8 (__cdecl *)(const u32))DSP::ReadARAM; + dspInit.pARAM_Write_U8 = (void (__cdecl *)(const u8, const u32))DSP::WriteARAM; dspInit.pGetARAMPointer = DSP::GetARAMPtr; dspInit.pGetMemoryPointer = Memory::GetPointer; dspInit.pLog = Callback_DSPLog; diff --git a/Source/Core/Core/Src/Debugger/Debugger_BreakPoints.cpp b/Source/Core/Core/Src/Debugger/Debugger_BreakPoints.cpp index 4570ffc2ca..eb3e457ace 100644 --- a/Source/Core/Core/Src/Debugger/Debugger_BreakPoints.cpp +++ b/Source/Core/Core/Src/Debugger/Debugger_BreakPoints.cpp @@ -19,12 +19,11 @@ #include "../HW/CPU.h" #include "../Host.h" -#include "../PowerPC/SymbolDB.h" +#include "../PowerPC/PPCSymbolDB.h" #include "Debugger_BreakPoints.h" -BreakPoints::TBreakPoints BreakPoints::m_BreakPoints; - -MemChecks::TMemChecks MemChecks::m_MemChecks; +BreakPoints g_breakpoints; +MemChecks g_memchecks; void TMemCheck::Action(u32 iValue, u32 addr, bool write, int size, u32 pc) { @@ -99,24 +98,6 @@ void BreakPoints::Clear() Host_UpdateBreakPointView(); } -void BreakPoints::AddAutoBreakpoints() -{ -#if defined(_DEBUG) || defined(DEBUGFAST) -#if 1 - const char *bps[] = { - "PPCHalt", - }; - - for (u32 i = 0; i < sizeof(bps) / sizeof(const char *); i++) - { - Symbol *symbol = g_symbolDB.GetSymbolFromName(bps[i]); - if (symbol) - BreakPoints::Add(symbol->address, false); - } -#endif -#endif -} - void BreakPoints::DeleteByAddress(u32 _Address) { // first check breakpoints diff --git a/Source/Core/Core/Src/Debugger/Debugger_BreakPoints.h b/Source/Core/Core/Src/Debugger/Debugger_BreakPoints.h index 7e29f88727..582b8c5724 100644 --- a/Source/Core/Core/Src/Debugger/Debugger_BreakPoints.h +++ b/Source/Core/Core/Src/Debugger/Debugger_BreakPoints.h @@ -51,52 +51,52 @@ struct TMemCheck void Action(u32 _iValue, u32 addr, bool write, int size, u32 pc); }; - // Code breakpoints. class BreakPoints { public: typedef std::vector TBreakPoints; - static const TBreakPoints& GetBreakPoints() { return m_BreakPoints; } + const TBreakPoints& GetBreakPoints() { return m_BreakPoints; } // is address breakpoint - static bool IsAddressBreakPoint(u32 _iAddress); - static bool IsTempBreakPoint(u32 _iAddress); + bool IsAddressBreakPoint(u32 _iAddress); + bool IsTempBreakPoint(u32 _iAddress); // AddBreakPoint - static bool Add(u32 em_address, bool temp=false); + bool Add(u32 em_address, bool temp=false); // Remove Breakpoint - static bool Remove(u32 _iAddress); - static void Clear(); + bool Remove(u32 _iAddress); + void Clear(); - static void UpdateBreakPointView(); - - static void AddAutoBreakpoints(); - static void DeleteByAddress(u32 _Address); + void DeleteByAddress(u32 _Address); private: - static TBreakPoints m_BreakPoints; - static u32 m_iBreakOnCount; + TBreakPoints m_BreakPoints; + u32 m_iBreakOnCount; }; +extern BreakPoints g_breakpoints; + // Memory breakpoints class MemChecks { public: typedef std::vector TMemChecks; - static TMemChecks m_MemChecks; - static const TMemChecks& GetMemChecks() { return m_MemChecks; } - static void Add(const TMemCheck& _rMemoryCheck); + TMemChecks m_MemChecks; + const TMemChecks& GetMemChecks() { return m_MemChecks; } + void Add(const TMemCheck& _rMemoryCheck); //memory breakpoint - static TMemCheck *GetMemCheck(u32 address); - static void DeleteByAddress(u32 _Address); + TMemCheck *GetMemCheck(u32 address); + void DeleteByAddress(u32 _Address); void Clear(); }; +extern MemChecks g_memchecks; + #endif diff --git a/Source/Core/Core/Src/Debugger/Debugger_SymbolMap.cpp b/Source/Core/Core/Src/Debugger/Debugger_SymbolMap.cpp index b49d6b88c1..7fb5d25eb1 100644 --- a/Source/Core/Core/Src/Debugger/Debugger_SymbolMap.cpp +++ b/Source/Core/Core/Src/Debugger/Debugger_SymbolMap.cpp @@ -18,16 +18,35 @@ #include "Common.h" #include "StringUtil.h" #include "Debugger_SymbolMap.h" +#include "Debugger_Breakpoints.h" #include "../Core.h" #include "../HW/Memmap.h" #include "../PowerPC/PowerPC.h" #include "../PowerPC/PPCAnalyst.h" -#include "../PowerPC/SymbolDB.h" +#include "../PowerPC/PPCSymbolDB.h" #include "../../../../Externals/Bochs_disasm/PowerPCDisasm.h" namespace Debugger { +void AddAutoBreakpoints() +{ +#if defined(_DEBUG) || defined(DEBUGFAST) +#if 1 + const char *bps[] = { + "PPCHalt", + }; + + for (u32 i = 0; i < sizeof(bps) / sizeof(const char *); i++) + { + Symbol *symbol = g_symbolDB.GetSymbolFromName(bps[i]); + if (symbol) + g_breakpoints.Add(symbol->address, false); + } +#endif +#endif +} + bool GetCallstack(std::vector &output) { if (Core::GetState() == Core::CORE_UNINITIALIZED) diff --git a/Source/Core/Core/Src/Debugger/Debugger_SymbolMap.h b/Source/Core/Core/Src/Debugger/Debugger_SymbolMap.h index 54c03f0754..9e5b5376fb 100644 --- a/Source/Core/Core/Src/Debugger/Debugger_SymbolMap.h +++ b/Source/Core/Core/Src/Debugger/Debugger_SymbolMap.h @@ -36,6 +36,8 @@ bool GetCallstack(std::vector &output); void PrintCallstack(); void PrintCallstack(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level); void PrintDataBuffer(LogTypes::LOG_TYPE _Log, u8* _pData, size_t _Size, const char* _title); +void AddAutoBreakpoints(); + } // end of namespace Debugger diff --git a/Source/Core/Core/Src/Debugger/PPCDebugInterface.cpp b/Source/Core/Core/Src/Debugger/PPCDebugInterface.cpp index 9919a1307a..dbae37526e 100644 --- a/Source/Core/Core/Src/Debugger/PPCDebugInterface.cpp +++ b/Source/Core/Core/Src/Debugger/PPCDebugInterface.cpp @@ -25,7 +25,7 @@ #include "../HW/Memmap.h" #include "../PowerPC/PowerPC.h" #include "../PowerPC/Jit64/Jit.h" -#include "../PowerPC/SymbolDB.h" +#include "../PowerPC/PPCSymbolDB.h" void PPCDebugInterface::disasm(unsigned int address, char *dest, int max_size) { @@ -104,18 +104,18 @@ bool PPCDebugInterface::isAlive() bool PPCDebugInterface::isBreakpoint(unsigned int address) { - return BreakPoints::IsAddressBreakPoint(address); + return g_breakpoints.IsAddressBreakPoint(address); } void PPCDebugInterface::setBreakpoint(unsigned int address) { - if (BreakPoints::Add(address)) + if (g_breakpoints.Add(address)) jit.NotifyBreakpoint(address, true); } void PPCDebugInterface::clearBreakpoint(unsigned int address) { - if (BreakPoints::Remove(address)) + if (g_breakpoints.Remove(address)) jit.NotifyBreakpoint(address, false); } @@ -123,10 +123,10 @@ void PPCDebugInterface::clearAllBreakpoints() {} void PPCDebugInterface::toggleBreakpoint(unsigned int address) { - if (BreakPoints::IsAddressBreakPoint(address)) - BreakPoints::Remove(address); + if (g_breakpoints.IsAddressBreakPoint(address)) + g_breakpoints.Remove(address); else - BreakPoints::Add(address); + g_breakpoints.Add(address); } void PPCDebugInterface::insertBLR(unsigned int address, unsigned int value) diff --git a/Source/Core/Core/Src/HLE/HLE.cpp b/Source/Core/Core/Src/HLE/HLE.cpp index 448a8e97f1..fd22f8a671 100644 --- a/Source/Core/Core/Src/HLE/HLE.cpp +++ b/Source/Core/Core/Src/HLE/HLE.cpp @@ -21,7 +21,7 @@ #include "HLE.h" #include "../PowerPC/PowerPC.h" -#include "../PowerPC/SymbolDB.h" +#include "../PowerPC/PPCSymbolDB.h" #include "../HW/Memmap.h" #include "../Debugger/Debugger_SymbolMap.h" #include "../Debugger/Debugger_BreakPoints.h" @@ -132,7 +132,7 @@ void PatchFunctions() Symbol *symbol = g_symbolDB.GetSymbolFromName(OSPatches[i].m_szPatchName); if (symbol > 0) { - BreakPoints::Add(symbol->address, false); + g_breakpoints.Add(symbol->address, false); INFO_LOG(HLE,"Adding BP to %s %08x", OSBreakPoints[i].m_szPatchName, symbol->address); } } diff --git a/Source/Core/Core/Src/HW/DSP.cpp b/Source/Core/Core/Src/HW/DSP.cpp index de0c6db11a..2b1435311d 100644 --- a/Source/Core/Core/Src/HW/DSP.cpp +++ b/Source/Core/Core/Src/HW/DSP.cpp @@ -474,7 +474,7 @@ void UpdateAudioDMA() // Latch new parameters g_audioDMA.BlocksLeft = g_audioDMA.AudioDMAControl.NumBlocks; g_audioDMA.ReadAddress = g_audioDMA.SourceAddress; - DEBUG_LOG(DSPLLE, "ADMA read addresses: %08x", g_audioDMA.ReadAddress); + // DEBUG_LOG(DSPLLE, "ADMA read addresses: %08x", g_audioDMA.ReadAddress); GenerateDSPInterrupt(DSP::INT_AID); } } else { @@ -647,11 +647,35 @@ u8 ReadARAM(u32 _iAddress) return g_ARAM[_iAddress & ARAM_MASK]; } +void WriteARAM(u8 value, u32 _uAddress) +{ + if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii) + { + //LOGV(DSPINTERFACE, 0, "ARAM (w) 0x%08x 0x%08x 0x%08x", WII_MASK, _iAddress, (_iAddress & WII_MASK)); + + // Does this make any sense? + if (_uAddress > WII_MASK) + { + if (_uAddress > WII_MEM2) + _uAddress = (_uAddress & WII_MEM2); + g_MEM2[_uAddress] = value; + } + else + { + g_ARAM[_uAddress] = value; + } + } + else + g_ARAM[_uAddress & ARAM_MASK] = value; +} + + u8 *GetARAMPtr() { return g_ARAM; } +/* // Should this really be a function? The hardware only supports block DMA. void WriteARAM(u8 _iValue, u32 _iAddress) { @@ -661,7 +685,7 @@ void WriteARAM(u8 _iValue, u32 _iAddress) // rouge leader writes WAY outside // not really surprising since it uses a totally different memory model :P g_ARAM[_iAddress & ARAM_MASK] = _iValue; -} +}*/ } // end of namespace DSP // =================== diff --git a/Source/Core/Core/Src/HW/DSP.h b/Source/Core/Core/Src/HW/DSP.h index 39d7a8bf87..1449dabe16 100644 --- a/Source/Core/Core/Src/HW/DSP.h +++ b/Source/Core/Core/Src/HW/DSP.h @@ -48,6 +48,7 @@ void Write32(const u32 _uValue, const u32 _uAddress); // Audio/DSP Plugin Helper u8 ReadARAM(const u32 _uAddress); +void WriteARAM(u8 value, u32 _uAddress); // Debugger Helper u8* GetARAMPtr(); diff --git a/Source/Core/Core/Src/HW/MemmapFunctions.cpp b/Source/Core/Core/Src/HW/MemmapFunctions.cpp index 99ddecfe61..5bdadd112e 100644 --- a/Source/Core/Core/Src/HW/MemmapFunctions.cpp +++ b/Source/Core/Core/Src/HW/MemmapFunctions.cpp @@ -254,7 +254,7 @@ u8 Read_U8(const u32 _Address) u8 _var = 0; ReadFromHardware(_var, _Address, _Address, FLAG_READ); #ifndef NOCHECK - TMemCheck *mc = MemChecks::GetMemCheck(_Address); + TMemCheck *mc = g_memchecks.GetMemCheck(_Address); if (mc) { mc->numHits++; @@ -269,7 +269,7 @@ u16 Read_U16(const u32 _Address) u16 _var = 0; ReadFromHardware(_var, _Address, _Address, FLAG_READ); #ifndef NOCHECK - TMemCheck *mc = MemChecks::GetMemCheck(_Address); + TMemCheck *mc = g_memchecks.GetMemCheck(_Address); if (mc) { mc->numHits++; @@ -291,7 +291,7 @@ u32 Read_U32(const u32 _Address) u32 _var = 0; ReadFromHardware(_var, _Address, _Address, FLAG_READ); #ifndef NOCHECK - TMemCheck *mc = MemChecks::GetMemCheck(_Address); + TMemCheck *mc = g_memchecks.GetMemCheck(_Address); if (mc) { mc->numHits++; @@ -307,7 +307,7 @@ u64 Read_U64(const u32 _Address) u64 _var = 0; ReadFromHardware(_var, _Address, _Address, FLAG_READ); #ifndef NOCHECK - TMemCheck *mc = MemChecks::GetMemCheck(_Address); + TMemCheck *mc = g_memchecks.GetMemCheck(_Address); if (mc) { mc->numHits++; @@ -321,7 +321,7 @@ u64 Read_U64(const u32 _Address) void Write_U8(const u8 _Data, const u32 _Address) { #ifndef NOCHECK - TMemCheck *mc = MemChecks::GetMemCheck(_Address); + TMemCheck *mc = g_memchecks.GetMemCheck(_Address); if (mc) { mc->numHits++; @@ -335,7 +335,7 @@ void Write_U8(const u8 _Data, const u32 _Address) void Write_U16(const u16 _Data, const u32 _Address) { #ifndef NOCHECK - TMemCheck *mc = MemChecks::GetMemCheck(_Address); + TMemCheck *mc = g_memchecks.GetMemCheck(_Address); if (mc) { mc->numHits++; @@ -350,7 +350,7 @@ void Write_U16(const u16 _Data, const u32 _Address) void Write_U32(const u32 _Data, const u32 _Address) { #ifndef NOCHECK - TMemCheck *mc = MemChecks::GetMemCheck(_Address); + TMemCheck *mc = g_memchecks.GetMemCheck(_Address); if (mc) { mc->numHits++; @@ -364,7 +364,7 @@ void Write_U32(const u32 _Data, const u32 _Address) void Write_U64(const u64 _Data, const u32 _Address) { #ifndef NOCHECK - TMemCheck *mc = MemChecks::GetMemCheck(_Address); + TMemCheck *mc = g_memchecks.GetMemCheck(_Address); if (mc) { mc->numHits++; diff --git a/Source/Core/Core/Src/PowerPC/Interpreter/Interpreter.cpp b/Source/Core/Core/Src/PowerPC/Interpreter/Interpreter.cpp index bd762f6346..9d09d5c345 100644 --- a/Source/Core/Core/Src/PowerPC/Interpreter/Interpreter.cpp +++ b/Source/Core/Core/Src/PowerPC/Interpreter/Interpreter.cpp @@ -166,7 +166,7 @@ void Run() #endif //2: check for breakpoint - if (BreakPoints::IsAddressBreakPoint(PC)) + if (g_breakpoints.IsAddressBreakPoint(PC)) { #ifdef SHOW_HISTORY NOTICE_LOG(POWERPC, "----------------------------"); @@ -187,8 +187,8 @@ void Run() #endif INFO_LOG(POWERPC, "Hit Breakpoint - %08x", PC); CCPU::Break(); - if (BreakPoints::IsTempBreakPoint(PC)) - BreakPoints::Remove(PC); + if (g_breakpoints.IsTempBreakPoint(PC)) + g_breakpoints.Remove(PC); Host_UpdateDisasmDialog(); return; diff --git a/Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp b/Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp index 69face8f63..6a27d0c22f 100644 --- a/Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp +++ b/Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp @@ -550,7 +550,7 @@ const u8* Jit64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buffer, JitB } // If starting from the breakpointed instruction, we don't break. - if (em_address != ops[i].address && BreakPoints::IsAddressBreakPoint(ops[i].address)) + if (em_address != ops[i].address && g_breakpoints.IsAddressBreakPoint(ops[i].address)) { } diff --git a/Source/Core/Core/Src/PowerPC/PPCAnalyst.cpp b/Source/Core/Core/Src/PowerPC/PPCAnalyst.cpp index 0d5eb37fa8..272417b497 100644 --- a/Source/Core/Core/Src/PowerPC/PPCAnalyst.cpp +++ b/Source/Core/Core/Src/PowerPC/PPCAnalyst.cpp @@ -21,7 +21,7 @@ #include "Interpreter/Interpreter.h" #include "../HW/Memmap.h" #include "PPCTables.h" -#include "SymbolDB.h" +#include "PPCSymbolDB.h" #include "SignatureDB.h" #include "PPCAnalyst.h" @@ -582,11 +582,11 @@ void FindFunctionsFromBranches(u32 startAddr, u32 endAddr, SymbolDB *func_db) } } -void FindFunctionsAfterBLR(SymbolDB *func_db) +void FindFunctionsAfterBLR(PPCSymbolDB *func_db) { vector funcAddrs; - for (SymbolDB::XFuncMap::iterator iter = func_db->GetIterator(); iter != func_db->End(); iter++) + for (PPCSymbolDB::XFuncMap::iterator iter = func_db->GetIterator(); iter != func_db->End(); iter++) funcAddrs.push_back(iter->second.address + iter->second.size); for (vector::iterator iter = funcAddrs.begin(); iter != funcAddrs.end(); iter++) @@ -609,7 +609,7 @@ void FindFunctionsAfterBLR(SymbolDB *func_db) } } -void FindFunctions(u32 startAddr, u32 endAddr, SymbolDB *func_db) +void FindFunctions(u32 startAddr, u32 endAddr, PPCSymbolDB *func_db) { //Step 1: Find all functions FindFunctionsFromBranches(startAddr, endAddr, func_db); @@ -621,7 +621,7 @@ void FindFunctions(u32 startAddr, u32 endAddr, SymbolDB *func_db) int numLeafs = 0, numNice = 0, numUnNice = 0; int numTimer = 0, numRFI = 0, numStraightLeaf = 0; int leafSize = 0, niceSize = 0, unniceSize = 0; - for (SymbolDB::XFuncMap::iterator iter = func_db->GetIterator(); iter != func_db->End(); iter++) + for (PPCSymbolDB::XFuncMap::iterator iter = func_db->GetIterator(); iter != func_db->End(); iter++) { if (iter->second.address == 4) { diff --git a/Source/Core/Core/Src/PowerPC/PPCAnalyst.h b/Source/Core/Core/Src/PowerPC/PPCAnalyst.h index 34f9a99f93..2682c6fcad 100644 --- a/Source/Core/Core/Src/PowerPC/PPCAnalyst.h +++ b/Source/Core/Core/Src/PowerPC/PPCAnalyst.h @@ -26,7 +26,7 @@ #include "Common.h" #include "Gekko.h" -class SymbolDB; +class PPCSymbolDB; struct Symbol; namespace PPCAnalyst @@ -94,7 +94,7 @@ public: bool Flatten(u32 address, int *realsize, BlockStats *st, BlockRegStats *gpa, BlockRegStats *fpa, CodeBuffer *buffer); void LogFunctionCall(u32 addr); -void FindFunctions(u32 startAddr, u32 endAddr, SymbolDB *func_db); +void FindFunctions(u32 startAddr, u32 endAddr, PPCSymbolDB *func_db); bool AnalyzeFunction(u32 startAddr, Symbol &func, int max_size = 0); } // namespace diff --git a/Source/Core/Core/Src/PowerPC/SymbolDB.cpp b/Source/Core/Core/Src/PowerPC/PPCSymbolDB.cpp similarity index 85% rename from Source/Core/Core/Src/PowerPC/SymbolDB.cpp rename to Source/Core/Core/Src/PowerPC/PPCSymbolDB.cpp index f2c8cfffb3..26ea34cf96 100644 --- a/Source/Core/Core/Src/PowerPC/SymbolDB.cpp +++ b/Source/Core/Core/Src/PowerPC/PPCSymbolDB.cpp @@ -22,49 +22,24 @@ #include #include "../HW/Memmap.h" -#include "SymbolDB.h" +#include "PPCSymbolDB.h" #include "SignatureDB.h" #include "PPCAnalyst.h" -SymbolDB g_symbolDB; +PPCSymbolDB g_symbolDB; -SymbolDB::SymbolDB() +PPCSymbolDB::PPCSymbolDB() { // Get access to the disasm() fgnction debugger = new PPCDebugInterface(); } -SymbolDB::~SymbolDB() +PPCSymbolDB::~PPCSymbolDB() { } -void SymbolDB::List() -{ - for (XFuncMap::iterator iter = functions.begin(); iter != functions.end(); iter++) - { - DEBUG_LOG(HLE,"%s @ %08x: %i bytes (hash %08x) : %i calls", iter->second.name.c_str(), iter->second.address, iter->second.size, iter->second.hash,iter->second.numCalls); - } - INFO_LOG(HLE,"%i functions known in this program above.", functions.size()); -} - -void SymbolDB::Clear(const char *prefix) -{ - // TODO: honor prefix - functions.clear(); - checksumToFunction.clear(); -} - -void SymbolDB::Index() -{ - int i = 0; - for (XFuncMap::iterator iter = functions.begin(); iter != functions.end(); iter++) - { - iter->second.index = i++; - } -} - // Adds the function to the list, unless it's already there -Symbol *SymbolDB::AddFunction(u32 startAddr) +Symbol *PPCSymbolDB::AddFunction(u32 startAddr) { if (startAddr < 0x80000010) return 0; @@ -88,7 +63,7 @@ Symbol *SymbolDB::AddFunction(u32 startAddr) } } -void SymbolDB::AddKnownSymbol(u32 startAddr, u32 size, const char *name, int type) +void PPCSymbolDB::AddKnownSymbol(u32 startAddr, u32 size, const char *name, int type) { XFuncMap::iterator iter = functions.find(startAddr); if (iter != functions.end()) @@ -116,7 +91,7 @@ void SymbolDB::AddKnownSymbol(u32 startAddr, u32 size, const char *name, int typ } } -Symbol *SymbolDB::GetSymbolFromAddr(u32 addr) +Symbol *PPCSymbolDB::GetSymbolFromAddr(u32 addr) { if (!Memory::IsRAMAddress(addr)) return 0; @@ -134,17 +109,7 @@ Symbol *SymbolDB::GetSymbolFromAddr(u32 addr) return 0; } -Symbol *SymbolDB::GetSymbolFromName(const char *name) -{ - for (XFuncMap::iterator iter = functions.begin(); iter != functions.end(); iter++) - { - if (!strcmp(iter->second.name.c_str(), name)) - return &iter->second; - } - return 0; -} - -const char *SymbolDB::GetDescription(u32 addr) +const char *PPCSymbolDB::GetDescription(u32 addr) { Symbol *symbol = GetSymbolFromAddr(addr); if (symbol) @@ -153,7 +118,7 @@ const char *SymbolDB::GetDescription(u32 addr) return " --- "; } -void SymbolDB::FillInCallers() +void PPCSymbolDB::FillInCallers() { for (XFuncMap::iterator iter = functions.begin(); iter != functions.end(); iter++) { @@ -183,7 +148,7 @@ void SymbolDB::FillInCallers() } } -void SymbolDB::PrintCalls(u32 funcAddr) const +void PPCSymbolDB::PrintCalls(u32 funcAddr) const { XFuncMap::const_iterator iter = functions.find(funcAddr); if (iter != functions.end()) @@ -205,7 +170,7 @@ void SymbolDB::PrintCalls(u32 funcAddr) const } } -void SymbolDB::PrintCallers(u32 funcAddr) const +void PPCSymbolDB::PrintCallers(u32 funcAddr) const { XFuncMap::const_iterator iter = functions.find(funcAddr); if (iter != functions.end()) @@ -223,7 +188,7 @@ void SymbolDB::PrintCallers(u32 funcAddr) const } } -void SymbolDB::LogFunctionCall(u32 addr) +void PPCSymbolDB::LogFunctionCall(u32 addr) { //u32 from = PC; XFuncMap::iterator iter = functions.find(addr); @@ -236,7 +201,7 @@ void SymbolDB::LogFunctionCall(u32 addr) // This one can load both leftover map files on game discs (like Zelda), and mapfiles // produced by SaveSymbolMap below. -bool SymbolDB::LoadMap(const char *filename) +bool PPCSymbolDB::LoadMap(const char *filename) { FILE *f = fopen(filename, "r"); if (!f) @@ -302,7 +267,7 @@ bool SymbolDB::LoadMap(const char *filename) // =================================================== /* Save the map file and save a code file */ // ---------------- -bool SymbolDB::SaveMap(const char *filename, bool WithCodes) const +bool PPCSymbolDB::SaveMap(const char *filename, bool WithCodes) const { // Format the name for the codes version std::string mapFile = filename; diff --git a/Source/Core/Core/Src/PowerPC/PPCSymbolDB.h b/Source/Core/Core/Src/PowerPC/PPCSymbolDB.h new file mode 100644 index 0000000000..0030935c2c --- /dev/null +++ b/Source/Core/Core/Src/PowerPC/PPCSymbolDB.h @@ -0,0 +1,56 @@ +// Copyright (C) 2003-2009 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#include "Common.h" + +#include +#include +#include +#include "../Debugger/PPCDebugInterface.h" + +#include "SymbolDB.h" + +// This has functionality overlapping Debugger_Symbolmap. Should merge that stuff in here later. +class PPCSymbolDB : public SymbolDB +{ +private: + DebugInterface* debugger; + +public: + typedef void (*functionGetterCallback)(Symbol *f); + + PPCSymbolDB(); + ~PPCSymbolDB(); + + Symbol *AddFunction(u32 startAddr); + void AddKnownSymbol(u32 startAddr, u32 size, const char *name, int type = Symbol::SYMBOL_FUNCTION); + + Symbol *GetSymbolFromAddr(u32 addr); + + const char *GetDescription(u32 addr); + + void FillInCallers(); + + bool LoadMap(const char *filename); + bool SaveMap(const char *filename, bool WithCodes = false) const; + + void PrintCalls(u32 funcAddr) const; + void PrintCallers(u32 funcAddr) const; + void LogFunctionCall(u32 addr); +}; + +extern PPCSymbolDB g_symbolDB; diff --git a/Source/Core/Core/Src/PowerPC/Profiler.cpp b/Source/Core/Core/Src/PowerPC/Profiler.cpp index c125c1fc1d..96958e1927 100644 --- a/Source/Core/Core/Src/PowerPC/Profiler.cpp +++ b/Source/Core/Core/Src/PowerPC/Profiler.cpp @@ -20,7 +20,7 @@ #include #include -#include "SymbolDB.h" +#include "PPCSymbolDB.h" namespace Profiler { diff --git a/Source/Core/Core/Src/PowerPC/SignatureDB.cpp b/Source/Core/Core/Src/PowerPC/SignatureDB.cpp index 148fe584b2..57acc701f9 100644 --- a/Source/Core/Core/Src/PowerPC/SignatureDB.cpp +++ b/Source/Core/Core/Src/PowerPC/SignatureDB.cpp @@ -20,7 +20,7 @@ #include "../HW/Memmap.h" #include "SignatureDB.h" -#include "SymbolDB.h" +#include "PPCSymbolDB.h" namespace { @@ -111,7 +111,7 @@ void SignatureDB::Clear() database.clear(); } -void SignatureDB::Apply(SymbolDB *symbol_db) +void SignatureDB::Apply(PPCSymbolDB *symbol_db) { for (FuncDB::const_iterator iter = database.begin(); iter != database.end(); iter++) { @@ -135,10 +135,10 @@ void SignatureDB::Apply(SymbolDB *symbol_db) symbol_db->Index(); } -void SignatureDB::Initialize(SymbolDB *symbol_db, const char *prefix) +void SignatureDB::Initialize(PPCSymbolDB *symbol_db, const char *prefix) { std::string prefix_str(prefix); - for (SymbolDB::XFuncMap::const_iterator iter = symbol_db->GetConstIterator(); iter != symbol_db->End(); iter++) + for (PPCSymbolDB::XFuncMap::const_iterator iter = symbol_db->GetConstIterator(); iter != symbol_db->End(); iter++) { if (iter->second.name.substr(0, prefix_str.size()) == prefix_str) { diff --git a/Source/Core/Core/Src/PowerPC/SignatureDB.h b/Source/Core/Core/Src/PowerPC/SignatureDB.h index 8e4a8c72c5..bc1399661d 100644 --- a/Source/Core/Core/Src/PowerPC/SignatureDB.h +++ b/Source/Core/Core/Src/PowerPC/SignatureDB.h @@ -22,7 +22,7 @@ // You're not meant to keep around SignatureDB objects persistently. Use 'em, throw them away. -class SymbolDB; +class PPCSymbolDB; class SignatureDB { @@ -50,8 +50,8 @@ public: void Clear(); void List(); - void Initialize(SymbolDB *func_db, const char *prefix = ""); - void Apply(SymbolDB *func_db); + void Initialize(PPCSymbolDB *func_db, const char *prefix = ""); + void Apply(PPCSymbolDB *func_db); static u32 ComputeCodeChecksum(u32 offsetStart, u32 offsetEnd); }; diff --git a/Source/Core/Core/Src/SConscript b/Source/Core/Core/Src/SConscript index 8eae19addf..0cba5ef7c0 100644 --- a/Source/Core/Core/Src/SConscript +++ b/Source/Core/Core/Src/SConscript @@ -75,7 +75,7 @@ files = ["ActionReplay.cpp", "PowerPC/PPCTables.cpp", "PowerPC/Profiler.cpp", "PowerPC/SignatureDB.cpp", - "PowerPC/SymbolDB.cpp", + "PowerPC/PPCSymbolDB.cpp", "PowerPC/Interpreter/Interpreter.cpp", "PowerPC/Interpreter/Interpreter_Branch.cpp", "PowerPC/Interpreter/Interpreter_Integer.cpp", diff --git a/Source/Core/DSPCore/DSPCore.vcproj b/Source/Core/DSPCore/DSPCore.vcproj index 268d721ab2..520c603292 100644 --- a/Source/Core/DSPCore/DSPCore.vcproj +++ b/Source/Core/DSPCore/DSPCore.vcproj @@ -299,7 +299,7 @@ Optimization="2" EnableIntrinsicFunctions="true" AdditionalIncludeDirectories="..\Common\Src" - PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_WINDOWS;NOPCH;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE" + PreprocessorDefinitions="LOGGING;WIN32;NDEBUG;_LIB;_WINDOWS;NOPCH;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE" RuntimeLibrary="0" EnableFunctionLevelLinking="true" UsePrecompiledHeader="0" @@ -363,7 +363,7 @@ Optimization="2" EnableIntrinsicFunctions="true" AdditionalIncludeDirectories="..\Common\Src" - PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_WINDOWS;NOPCH;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE" + PreprocessorDefinitions="LOGGING;WIN32;NDEBUG;_LIB;_WINDOWS;NOPCH;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE" RuntimeLibrary="0" EnableFunctionLevelLinking="true" UsePrecompiledHeader="0" @@ -426,6 +426,10 @@ > + + diff --git a/Source/Core/DSPCore/Src/DSPCore.cpp b/Source/Core/DSPCore/Src/DSPCore.cpp index d9903871e2..692a202109 100644 --- a/Source/Core/DSPCore/Src/DSPCore.cpp +++ b/Source/Core/DSPCore/Src/DSPCore.cpp @@ -155,6 +155,8 @@ void DSPCore_CheckExternalInterrupt() { // level 7 is the interrupt exception DSPCore_SetException(7); + + // Uh, confusing. Can this really be right? g_dsp.cr &= ~0x0002; } } diff --git a/Source/Core/DSPCore/Src/DSPHost.h b/Source/Core/DSPCore/Src/DSPHost.h index 7a96fd1ff3..e154ddba19 100644 --- a/Source/Core/DSPCore/Src/DSPHost.h +++ b/Source/Core/DSPCore/Src/DSPHost.h @@ -24,6 +24,7 @@ // can be stubbed out. u8 DSPHost_ReadHostMemory(u32 addr); +void DSPHost_WriteHostMemory(u8 value, u32 addr); bool DSPHost_OnThread(); bool DSPHost_Running(); u32 DSPHost_CodeLoaded(const u8 *ptr, int size); diff --git a/Source/Core/DSPCore/Src/DSPTables.cpp b/Source/Core/DSPCore/Src/DSPTables.cpp index 8512c83296..371af34dac 100644 --- a/Source/Core/DSPCore/Src/DSPTables.cpp +++ b/Source/Core/DSPCore/Src/DSPTables.cpp @@ -364,15 +364,42 @@ const pdlabel_t pdlabels[] = {0xffad, "COEF_A2_6", "COEF_A2_6",}, {0xffae, "COEF_A1_7", "COEF_A1_7",}, {0xffaf, "COEF_A2_7", "COEF_A2_7",}, + {0xffb0, 0, 0,}, + {0xffb1, 0, 0,}, + {0xffb2, 0, 0,}, + {0xffb3, 0, 0,}, + {0xffb4, 0, 0,}, + {0xffb5, 0, 0,}, + {0xffb6, 0, 0,}, + {0xffb7, 0, 0,}, + {0xffb8, 0, 0,}, + {0xffb9, 0, 0,}, + {0xffba, 0, 0,}, + {0xffbb, 0, 0,}, + {0xffbc, 0, 0,}, + {0xffbd, 0, 0,}, + {0xffbe, 0, 0,}, + {0xffbf, 0, 0,}, + {0xffc0, 0, 0,}, + {0xffc1, 0, 0,}, + {0xffc2, 0, 0,}, + {0xffc3, 0, 0,}, + {0xffc4, 0, 0,}, + {0xffc5, 0, 0,}, + {0xffc6, 0, 0,}, + {0xffc7, 0, 0,}, + {0xffc8, 0, 0,}, {0xffc9, "DSCR", "DSP DMA Control Reg",}, + {0xffca, 0, 0,}, {0xffcb, "DSBL", "DSP DMA Block Length",}, + {0xffcc, 0, 0,}, {0xffcd, "DSPA", "DSP DMA DMEM Address",}, {0xffce, "DSMAH", "DSP DMA Mem Address H",}, {0xffcf, "DSMAL", "DSP DMA Mem Address L",}, + {0xffd0, 0,0,}, {0xffd1, "SampleFormat", "SampleFormat",}, - - {0xffd3, "Unk Zelda", "Unk Zelda writes to it",}, - + {0xffd2, 0,0,}, + {0xffd3, "UnkZelda", "Unk Zelda reads/writes from/to it",}, {0xffd4, "ACSAH", "Accelerator start address H",}, {0xffd5, "ACSAL", "Accelerator start address L",}, {0xffd6, "ACEAH", "Accelerator end address H",}, @@ -384,7 +411,34 @@ const pdlabel_t pdlabels[] = {0xffdc, "yn2", "yn2",}, {0xffdd, "ARAM", "Direct Read from ARAM (uses ADPCM)",}, {0xffde, "GAIN", "Gain",}, + {0xffdf, 0,0,}, + {0xffe0, 0,0,}, + {0xffe1, 0,0,}, + {0xffe2, 0,0,}, + {0xffe3, 0,0,}, + {0xffe4, 0,0,}, + {0xffe5, 0,0,}, + {0xffe6, 0,0,}, + {0xffe7, 0,0,}, + {0xffe8, 0,0,}, + {0xffe9, 0,0,}, + {0xffea, 0,0,}, + {0xffeb, 0,0,}, + {0xffec, 0,0,}, + {0xffed, 0,0,}, + {0xffee, 0,0,}, {0xffef, "AMDM", "ARAM DMA Request Mask",}, + {0xfff0, 0,0,}, + {0xfff1, 0,0,}, + {0xfff2, 0,0,}, + {0xfff3, 0,0,}, + {0xfff4, 0,0,}, + {0xfff5, 0,0,}, + {0xfff6, 0,0,}, + {0xfff7, 0,0,}, + {0xfff8, 0,0,}, + {0xfff9, 0,0,}, + {0xfffa, 0,0,}, {0xfffb, "DIRQ", "DSP IRQ Request",}, {0xfffc, "DMBH", "DSP Mailbox H",}, {0xfffd, "DMBL", "DSP Mailbox L",}, diff --git a/Source/Core/DSPCore/Src/disassemble.cpp b/Source/Core/DSPCore/Src/disassemble.cpp index b3ffd72ede..c58465e9fe 100644 --- a/Source/Core/DSPCore/Src/disassemble.cpp +++ b/Source/Core/DSPCore/Src/disassemble.cpp @@ -82,7 +82,7 @@ bool DSPDisassembler::Disassemble(int start_pc, const std::vector &code, in fclose(f); // Run the two passes. - return DisFile(tmp1, 1, text) && DisFile(tmp1, 2, text); + return DisFile(tmp1, base_addr, 1, text) && DisFile(tmp1, base_addr, 2, text); } char *DSPDisassembler::DisParams(const DSPOPCTemplate& opc, u16 op1, u16 op2, char *strbuf) @@ -186,7 +186,7 @@ static void MakeLowerCase(char *ptr) } } -void DSPDisassembler::DisOpcode(const u16 *binbuf, int base_addr, int pass, u16 *pc, std::string &dest) +bool DSPDisassembler::DisOpcode(const u16 *binbuf, int base_addr, int pass, u16 *pc, std::string &dest) { char buffer[256]; char *buf = buffer; @@ -200,11 +200,10 @@ void DSPDisassembler::DisOpcode(const u16 *binbuf, int base_addr, int pass, u16 { *pc++; dest.append("; outside memory"); - return; + return false; } - *pc &= 0x0fff; - const u32 op1 = binbuf[*pc]; + const u32 op1 = binbuf[*pc & 0x0fff]; const DSPOPCTemplate *opc = NULL; const DSPOPCTemplate *opc_ext = NULL; @@ -259,7 +258,7 @@ void DSPDisassembler::DisOpcode(const u16 *binbuf, int base_addr, int pass, u16 // Size 2 - the op has a large immediate. if ((opc->size & ~P_EXT) == 2) { - op2 = binbuf[*pc + 1]; + op2 = binbuf[(*pc + 1) & 0x0fff]; if (settings_.show_hex) buf += sprintf(buf, "%04x %04x ", op1, op2); } @@ -318,9 +317,10 @@ void DSPDisassembler::DisOpcode(const u16 *binbuf, int base_addr, int pass, u16 if (pass == 2) dest.append(buffer); + return true; } -bool DSPDisassembler::DisFile(const char* name, int pass, std::string &output) +bool DSPDisassembler::DisFile(const char* name, int base_addr, int pass, std::string &output) { FILE* in = fopen(name, "rb"); if (in == NULL) @@ -339,7 +339,7 @@ bool DSPDisassembler::DisFile(const char* name, int pass, std::string &output) // Actually do the disassembly. for (u16 pc = 0; pc < (size / 2);) { - DisOpcode(binbuf, 0x0000, pass, &pc, output); + DisOpcode(binbuf, base_addr, pass, &pc, output); if (pass == 2) output.append("\n"); } diff --git a/Source/Core/DSPCore/Src/disassemble.h b/Source/Core/DSPCore/Src/disassemble.h index 96f1fb7b88..c1e2689659 100644 --- a/Source/Core/DSPCore/Src/disassemble.h +++ b/Source/Core/DSPCore/Src/disassemble.h @@ -67,11 +67,11 @@ public: // Warning - this one is trickier to use right. // Use pass == 2 if you're just using it by itself. - void DisOpcode(const u16 *binbuf, int base_addr, int pass, u16 *pc, std::string &dest); + bool DisOpcode(const u16 *binbuf, int base_addr, int pass, u16 *pc, std::string &dest); private: // Moves PC forward and writes the result to dest. - bool DisFile(const char* name, int pass, std::string &output); + bool DisFile(const char* name, int base_addr, int pass, std::string &output); char* DisParams(const DSPOPCTemplate& opc, u16 op1, u16 op2, char* strbuf); std::map unk_opcodes; diff --git a/Source/Core/DSPCore/Src/gdsp_aram.cpp b/Source/Core/DSPCore/Src/gdsp_aram.cpp index d34de5515d..22fd6f7813 100644 --- a/Source/Core/DSPCore/Src/gdsp_aram.cpp +++ b/Source/Core/DSPCore/Src/gdsp_aram.cpp @@ -64,6 +64,18 @@ s16 ADPCM_Step(u32& _rSamplePos) return val; } +void dsp_write_aram_d3(u16 value) +{ + // Not sure about this one but it sure looks like Zelda is writing to ARAM + // through 0xFFd3... + + const u32 EndAddress = (gdsp_ifx_regs[DSP_ACEAH] << 16) | gdsp_ifx_regs[DSP_ACEAL]; + u32 Address = (gdsp_ifx_regs[DSP_ACCAH] << 16) | gdsp_ifx_regs[DSP_ACCAL]; + + DSPHost_WriteHostMemory(value >> 8, Address); + DSPHost_WriteHostMemory(value & 0xFF, Address + 1); +} + u16 dsp_read_aram() { const u32 EndAddress = (gdsp_ifx_regs[DSP_ACEAH] << 16) | gdsp_ifx_regs[DSP_ACEAL]; diff --git a/Source/Core/DSPCore/Src/gdsp_aram.h b/Source/Core/DSPCore/Src/gdsp_aram.h index 3c5685fc0a..e310b9858e 100644 --- a/Source/Core/DSPCore/Src/gdsp_aram.h +++ b/Source/Core/DSPCore/Src/gdsp_aram.h @@ -19,5 +19,6 @@ #define _GDSP_ARAM_H u16 dsp_read_aram(); +void dsp_write_aram_d3(u16 value); #endif diff --git a/Source/Core/DSPCore/Src/gdsp_interface.cpp b/Source/Core/DSPCore/Src/gdsp_interface.cpp index 4aae90a9ea..9a7fb823a0 100644 --- a/Source/Core/DSPCore/Src/gdsp_interface.cpp +++ b/Source/Core/DSPCore/Src/gdsp_interface.cpp @@ -30,6 +30,7 @@ #include "DSPCore.h" #include "DSPHost.h" +#include "DSPTables.h" #include "DSPAnalyzer.h" #include "gdsp_aram.h" #include "gdsp_interpreter.h" @@ -89,6 +90,8 @@ void gdsp_mbox_write_l(u8 mbx, u16 val) if (mbx == GDSP_MBOX_DSP) { DEBUG_LOG(DSPLLE, " - DSP writes mail to mbx %i: 0x%08x (pc=0x%04x)", mbx, gdsp_mbox_peek(GDSP_MBOX_DSP), g_dsp.pc); + } else { + // Trigger exception? } } @@ -138,6 +141,11 @@ void gdsp_ifx_write(u16 addr, u16 val) gdsp_ifx_regs[DSP_DSCR] &= ~0x0004; break; + case 0xd3: // ZeldaUnk (accelerator WRITE) + ERROR_LOG(DSPLLE, "Write To ZeldaUnk pc=%04x (%04x)\n", g_dsp.pc, val); + dsp_write_aram_d3(val); + break; + case 0xde: //if (val) // PanicAlert("Gain written: %04x", val); // BMX XXX does, and sounds HORRIBLE. @@ -149,10 +157,17 @@ void gdsp_ifx_write(u16 addr, u16 val) break; default: -/* if ((addr & 0xff) >= 0xa0 && reg_names[addr - 0xa0]) - DEBUG_LOG(DSPLLE, "%04x MW %s (%04x)\n", g_dsp.pc, reg_names[addr - 0xa0], val); - else - DEBUG_LOG(DSPLLE, "%04x MW %04x (%04x)\n", g_dsp.pc, addr, val);*/ + if ((addr & 0xff) >= 0xa0) { + if (pdlabels[(addr & 0xFF) - 0xa0].name) { + INFO_LOG(DSPLLE, "%04x MW %s (%04x)\n", g_dsp.pc, pdlabels[(addr & 0xFF) - 0xa0].name, val); + } + else { + ERROR_LOG(DSPLLE, "%04x MW %04x (%04x)\n", g_dsp.pc, addr, val); + } + } + else { + ERROR_LOG(DSPLLE, "%04x MW %04x (%04x)\n", g_dsp.pc, addr, val); + } gdsp_ifx_regs[addr & 0xFF] = val; break; } @@ -176,14 +191,22 @@ u16 gdsp_ifx_read(u16 addr) return gdsp_ifx_regs[addr & 0xFF]; case 0xdd: + // ERROR_LOG(DSPLLE, "Accelerator"); return dsp_read_aram(); default: + if ((addr & 0xff) >= 0xa0) { + if (pdlabels[(addr & 0xFF) - 0xa0].name) { + INFO_LOG(DSPLLE, "%04x MR %s (%04x)\n", g_dsp.pc, pdlabels[(addr & 0xFF) - 0xa0].name, gdsp_ifx_regs[addr & 0xFF]); + } + else { + ERROR_LOG(DSPLLE, "%04x MR %04x (%04x)\n", g_dsp.pc, addr, gdsp_ifx_regs[addr & 0xFF]); + } + } + else { + ERROR_LOG(DSPLLE, "%04x MR %04x (%04x)\n", g_dsp.pc, addr, gdsp_ifx_regs[addr & 0xFF]); + } return gdsp_ifx_regs[addr & 0xFF]; -/* if ((addr & 0xff) >= 0xc0 && reg_names[addr & 0x3f]) - printf("%04x MR %s (%04x)\n", g_dsp.pc, reg_names[addr & 0x3f], val); - else - printf("%04x MR %04x (%04x)\n", g_dsp.pc, addr, val);*/ } } diff --git a/Source/Core/DSPCore/Src/gdsp_interpreter.cpp b/Source/Core/DSPCore/Src/gdsp_interpreter.cpp index 733282e7f6..4b1d137425 100644 --- a/Source/Core/DSPCore/Src/gdsp_interpreter.cpp +++ b/Source/Core/DSPCore/Src/gdsp_interpreter.cpp @@ -78,10 +78,12 @@ void HandleLoop() const u16 rCallAddress = g_dsp.r[DSP_REG_ST0]; const u16 rLoopAddress = g_dsp.r[DSP_REG_ST2]; + // This does not always work correctly! + // The loop end tends to point to the second part of + // two-byte instructions! if (g_dsp.pc == (rLoopAddress + 1)) { rLoopCounter--; - if (rLoopCounter > 0) { g_dsp.pc = rCallAddress; @@ -147,6 +149,21 @@ void Run() // Used by non-thread mode. void RunCycles(int cycles) { + if (cycles < 18) + { + for (int i = 0; i < cycles; i++) + { + if (g_dsp.cr & CR_HALT) + return; + if (DSPAnalyzer::code_flags[g_dsp.pc] & DSPAnalyzer::CODE_IDLE_SKIP) + return; + Step(); + cycles--; + } + return; + } + + DSPCore_CheckExternalInterrupt(); // First, let's run a few cycles with no idle skipping so that things can progress a bit. @@ -158,7 +175,7 @@ void RunCycles(int cycles) cycles--; } - // Next, let's run a few cycles with idle skipping, so that we can skip loops. + // Next, let's run a few cycles with idle skipping, so that we can skip idle loops. for (int i = 0; i < 8; i++) { if (g_dsp.cr & CR_HALT) diff --git a/Source/Core/DebuggerUICommon/DebuggerUICommon.vcproj b/Source/Core/DebuggerUICommon/DebuggerUICommon.vcproj new file mode 100644 index 0000000000..1fb013cd53 --- /dev/null +++ b/Source/Core/DebuggerUICommon/DebuggerUICommon.vcproj @@ -0,0 +1,429 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Source/Core/DebuggerWX/Src/CodeView.cpp b/Source/Core/DebuggerUICommon/Src/CodeView.cpp similarity index 89% rename from Source/Core/DebuggerWX/Src/CodeView.cpp rename to Source/Core/DebuggerUICommon/Src/CodeView.cpp index 07aee49901..59c2590321 100644 --- a/Source/Core/DebuggerWX/Src/CodeView.cpp +++ b/Source/Core/DebuggerUICommon/Src/CodeView.cpp @@ -15,17 +15,19 @@ // Official SVN repository and contact information can be found at // http://code.google.com/p/dolphin-emu/ -//#include "Debugger.h" -#include "Debugger/PPCDebugInterface.h" -#include "PowerPC/SymbolDB.h" -#include "HW/Memmap.h" // for Write_U32 +// #include "Debugger.h" +// #include "Debugger/PPCDebugInterface.h" + +// #include "PowerPC/SymbolDB.h" #include "Common.h" #include "StringUtil.h" -#include "Debugger/DebugInterface.h" +#include "DebuggerUIUtil.h" +#include "DebugInterface.h" -#include "Host.h" +// #include "Host.h" #include "CodeView.h" -#include "JitWindow.h" +#include "SymbolDB.h" +// #include "JitWindow.h" #include #include @@ -61,9 +63,11 @@ BEGIN_EVENT_TABLE(CCodeView, wxControl) EVT_MENU(-1, CCodeView::OnPopupMenu) END_EVENT_TABLE() -CCodeView::CCodeView(DebugInterface* debuginterface, wxWindow* parent, wxWindowID Id, const wxSize& Size) +CCodeView::CCodeView(DebugInterface* debuginterface, SymbolDB *symboldb, wxWindow* parent, wxWindowID Id, const wxSize& Size) : wxControl(parent, Id, wxDefaultPosition, Size), debugger(debuginterface), + symbol_db(symboldb), + plain(false), rowHeight(13), selection(0), oldSelection(0), @@ -121,7 +125,7 @@ void CCodeView::OnMouseDown(wxMouseEvent& event) { debugger->toggleBreakpoint(YToAddress(y)); redraw(); - Host_UpdateBreakPointView(); +// Host_UpdateBreakPointView(); } event.Skip(true); @@ -202,9 +206,9 @@ void CCodeView::InsertBlrNop(int Blr) } // Save the old value - if(find >= 0) + if (find >= 0) { - Memory::Write_U32(BlrList.at(find).OldValue, selection); + debugger->writeExtraMemory(0, BlrList.at(find).OldValue, selection); BlrList.erase(BlrList.begin() + find); } else @@ -257,7 +261,7 @@ void CCodeView::OnPopupMenu(wxCommandEvent& event) case IDM_COPYFUNCTION: { - Symbol *symbol = g_symbolDB.GetSymbolFromAddr(selection); + Symbol *symbol = symbol_db->GetSymbolFromAddr(selection); if (symbol) { std::string text; text = text + symbol->name + "\r\n"; @@ -292,7 +296,7 @@ void CCodeView::OnPopupMenu(wxCommandEvent& event) break; case IDM_JITRESULTS: - CJitWindow::ViewAddr(selection); + // CJitWindow::ViewAddr(selection); break; case IDM_FOLLOWBRANCH: @@ -306,14 +310,14 @@ void CCodeView::OnPopupMenu(wxCommandEvent& event) case IDM_ADDFUNCTION: { - g_symbolDB.AddFunction(selection); - Host_NotifyMapLoaded(); + symbol_db->AddFunction(selection); +// Host_NotifyMapLoaded(); } break; case IDM_RENAMESYMBOL: { - Symbol *symbol = g_symbolDB.GetSymbolFromAddr(selection); + Symbol *symbol = symbol_db->GetSymbolFromAddr(selection); if (symbol) { wxTextEntryDialog input_symbol(this, wxString::FromAscii("Rename symbol:"), wxGetTextFromUserPromptStr, wxString::FromAscii(symbol->name.c_str())); @@ -321,7 +325,7 @@ void CCodeView::OnPopupMenu(wxCommandEvent& event) symbol->name = input_symbol.GetValue().mb_str(); } // redraw(); - Host_NotifyMapLoaded(); +// Host_NotifyMapLoaded(); } } break; @@ -342,7 +346,7 @@ void CCodeView::OnPopupMenu(wxCommandEvent& event) void CCodeView::OnMouseUpR(wxMouseEvent& event) { - bool isSymbol = g_symbolDB.GetSymbolFromAddr(selection) != 0; + bool isSymbol = symbol_db->GetSymbolFromAddr(selection) != 0; // popup menu wxMenu menu; //menu.Append(IDM_GOTOINMEMVIEW, "&Goto in mem view"); @@ -379,7 +383,9 @@ void CCodeView::OnPaint(wxPaintEvent& event) // ------------------------- wxPaintDC dc(this); wxRect rc = GetClientRect(); + dc.SetFont(DebuggerFont); + struct branch { int src, dst, srcAddr; @@ -448,9 +454,11 @@ void CCodeView::OnPaint(wxPaintEvent& event) dc.DrawRectangle(16, rowY1, width, rowY2 - rowY1 + 1); dc.SetBrush(currentBrush); - dc.SetTextForeground(_T("#600000")); // the address text is dark red - dc.DrawText(temp, 17, rowY1); - dc.SetTextForeground(_T("#000000")); + if (!plain) { + dc.SetTextForeground(_T("#600000")); // the address text is dark red + dc.DrawText(temp, 17, rowY1); + dc.SetTextForeground(_T("#000000")); + } if (debugger->isAlive()) { @@ -464,23 +472,17 @@ void CCodeView::OnPaint(wxPaintEvent& event) { *dis2 = 0; dis2++; + // look for hex strings to decode branches const char* mojs = strstr(dis2, "0x8"); - - // -------------------------------------------------------------------- - // Colors and brushes - // ------------------------- if (mojs) { for (int k = 0; k < 8; k++) { bool found = false; - for (int j = 0; j < 22; j++) { if (mojs[k + 2] == "0123456789ABCDEFabcdef"[j]) - { found = true; - } } if (!found) { @@ -489,12 +491,6 @@ void CCodeView::OnPaint(wxPaintEvent& event) } } } - // ------------ - - - // -------------------------------------------------------------------- - // Colors and brushes - // ------------------------- if (mojs) { int offs; @@ -520,20 +516,22 @@ void CCodeView::OnPaint(wxPaintEvent& event) else dc.SetTextForeground(_T("#8000FF")); // purple - dc.DrawText(wxString::FromAscii(dis), 80, rowY1); + dc.DrawText(wxString::FromAscii(dis), plain ? 25 : 80, rowY1); if (desc[0] == 0) { strcpy(desc, debugger->getDescription(address).c_str()); } - dc.SetTextForeground(_T("#0000FF")); // blue + if (!plain) { + dc.SetTextForeground(_T("#0000FF")); // blue - //char temp[256]; - //UnDecorateSymbolName(desc,temp,255,UNDNAME_COMPLETE); - if (strlen(desc)) - { - dc.DrawText(wxString::FromAscii(desc), 270, rowY1); + //char temp[256]; + //UnDecorateSymbolName(desc,temp,255,UNDNAME_COMPLETE); + if (strlen(desc)) + { + dc.DrawText(wxString::FromAscii(desc), 270, rowY1); + } } // Show red breakpoint dot @@ -541,7 +539,6 @@ void CCodeView::OnPaint(wxPaintEvent& event) { dc.SetBrush(bpBrush); dc.DrawRectangle(2, rowY1 + 1, 11, 11); - //DrawIconEx(hdc, 2, rowY1, breakPoint, 32, 32, 0, 0, DI_NORMAL); } } } // end of for diff --git a/Source/Core/DebuggerWX/Src/CodeView.h b/Source/Core/DebuggerUICommon/Src/CodeView.h similarity index 85% rename from Source/Core/DebuggerWX/Src/CodeView.h rename to Source/Core/DebuggerUICommon/Src/CodeView.h index d6692431e7..04c78ab660 100644 --- a/Source/Core/DebuggerWX/Src/CodeView.h +++ b/Source/Core/DebuggerUICommon/Src/CodeView.h @@ -18,7 +18,12 @@ #ifndef CODEVIEW_H_ #define CODEVIEW_H_ -#include "Debugger.h" +#define wxUSE_XPM_IN_MSW 1 +#define USE_XPM_BITMAPS 1 + +#include + +// #include "Debugger.h" #include "Common.h" #include @@ -26,11 +31,12 @@ DECLARE_EVENT_TYPE(wxEVT_CODEVIEW_CHANGE, -1); class DebugInterface; +class SymbolDB; class CCodeView : public wxControl { public: - CCodeView(DebugInterface* debuginterface, wxWindow* parent, wxWindowID Id = -1, const wxSize& Size = wxDefaultSize); + CCodeView(DebugInterface* debuginterface, SymbolDB *symbol_db, wxWindow* parent, wxWindowID Id = -1, const wxSize& Size = wxDefaultSize); wxSize DoGetBestSize() const; void OnPaint(wxPaintEvent& event); void OnErase(wxEraseEvent& event); @@ -57,6 +63,10 @@ public: redraw(); } + void SetPlain() { + plain = true; + } + private: void RaiseEvent(); int YToAddress(int y); @@ -66,6 +76,9 @@ private: void redraw() {Refresh();} DebugInterface* debugger; + SymbolDB* symbol_db; + + bool plain; int curAddress; int align; diff --git a/Source/Core/DebuggerUICommon/Src/DebuggerUIUtil.cpp b/Source/Core/DebuggerUICommon/Src/DebuggerUIUtil.cpp new file mode 100644 index 0000000000..6ee1e213b7 --- /dev/null +++ b/Source/Core/DebuggerUICommon/Src/DebuggerUIUtil.cpp @@ -0,0 +1,23 @@ +// Copyright (C) 2003-2008 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + + +#include "DebuggerUIUtil.h" + +// The default font +wxFont DebuggerFont = wxFont(9, wxMODERN, wxNORMAL, wxNORMAL, false, wxT("monospace")); + diff --git a/Source/Core/DebuggerUICommon/Src/DebuggerUIUtil.h b/Source/Core/DebuggerUICommon/Src/DebuggerUIUtil.h new file mode 100644 index 0000000000..fc75e9478e --- /dev/null +++ b/Source/Core/DebuggerUICommon/Src/DebuggerUIUtil.h @@ -0,0 +1,36 @@ +// Copyright (C) 2003-2008 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#ifndef _DEBUGGER_UI_UTIL_H +#define _DEBUGGER_UI_UTIL_H + +#include + +#define wxUSE_XPM_IN_MSW 1 +#define USE_XPM_BITMAPS 1 + +// Defined in CodeWindow.cpp +extern wxFont DebuggerFont; + +// define this to use XPMs everywhere (by default, BMPs are used under Win) +// BMPs use less space, but aren't compiled into the executable on other platforms + +#if USE_XPM_BITMAPS && defined (__WXMSW__) && !wxUSE_XPM_IN_MSW +#error You need to enable XPM support to use XPM bitmaps with toolbar! +#endif // USE_XPM_BITMAPS + +#endif diff --git a/Source/Core/DebuggerUICommon/Src/SConscript b/Source/Core/DebuggerUICommon/Src/SConscript new file mode 100644 index 0000000000..3f7e530e55 --- /dev/null +++ b/Source/Core/DebuggerUICommon/Src/SConscript @@ -0,0 +1,13 @@ +# -*- python -*- + +Import('env') + +files = [ + 'CodeView.cpp', + 'DebuggerUIUtil.cpp', + ] + +acenv = env.Clone() +acenv.Append(CXXFLAGS = [ '-fPIC' ]) + +acenv.StaticLibrary(env['local_libs'] + 'debugger_ui_util', files) diff --git a/Source/Core/DebuggerWX/DebuggerWX.vcproj b/Source/Core/DebuggerWX/DebuggerWX.vcproj index 9e479a75fd..3f84875fb0 100644 --- a/Source/Core/DebuggerWX/DebuggerWX.vcproj +++ b/Source/Core/DebuggerWX/DebuggerWX.vcproj @@ -1,7 +1,7 @@ - - - - diff --git a/Source/Core/DebuggerWX/Src/BreakPointDlg.cpp b/Source/Core/DebuggerWX/Src/BreakPointDlg.cpp index 86a597794e..85e8cf8b31 100644 --- a/Source/Core/DebuggerWX/Src/BreakPointDlg.cpp +++ b/Source/Core/DebuggerWX/Src/BreakPointDlg.cpp @@ -72,7 +72,7 @@ void BreakPointDlg::OnOK(wxCommandEvent& /*event*/) u32 Address = 0; if (AsciiToHex(AddressString.mb_str(), Address)) { - BreakPoints::Add(Address); + g_breakpoints.Add(Address); Host_UpdateBreakPointView(); Close(); } diff --git a/Source/Core/DebuggerWX/Src/BreakpointView.cpp b/Source/Core/DebuggerWX/Src/BreakpointView.cpp index b8257ae219..4c47987709 100644 --- a/Source/Core/DebuggerWX/Src/BreakpointView.cpp +++ b/Source/Core/DebuggerWX/Src/BreakpointView.cpp @@ -21,7 +21,7 @@ #include "BreakpointView.h" #include "Debugger/Debugger_BreakPoints.h" #include "Debugger/Debugger_SymbolMap.h" -#include "PowerPC/SymbolDB.h" +#include "PowerPC/PPCSymbolDB.h" BEGIN_EVENT_TABLE(CBreakPointView, wxListCtrl) @@ -47,7 +47,7 @@ void CBreakPointView::Update() InsertColumn(4, wxT("Flags"), wxLIST_FORMAT_CENTER, 100); char szBuffer[64]; - const BreakPoints::TBreakPoints& rBreakPoints = BreakPoints::GetBreakPoints(); + const BreakPoints::TBreakPoints& rBreakPoints = g_breakpoints.GetBreakPoints(); for (size_t i = 0; i < rBreakPoints.size(); i++) { const TBreakPoint& rBP = rBreakPoints[i]; @@ -74,7 +74,7 @@ void CBreakPointView::Update() } } - const MemChecks::TMemChecks& rMemChecks = MemChecks::GetMemChecks(); + const MemChecks::TMemChecks& rMemChecks = g_memchecks.GetMemChecks(); for (size_t i = 0; i < rMemChecks.size(); i++) { const TMemCheck& rMemCheck = rMemChecks[i]; @@ -115,8 +115,8 @@ void CBreakPointView::DeleteCurrentSelection() if (Item >= 0) { u32 Address = (u32)GetItemData(Item); - BreakPoints::DeleteByAddress(Address); - MemChecks::DeleteByAddress(Address); + g_breakpoints.DeleteByAddress(Address); + g_memchecks.DeleteByAddress(Address); Update(); } } diff --git a/Source/Core/DebuggerWX/Src/BreakpointWindow.cpp b/Source/Core/DebuggerWX/Src/BreakpointWindow.cpp index 0e009f7591..4277f6d341 100644 --- a/Source/Core/DebuggerWX/Src/BreakpointWindow.cpp +++ b/Source/Core/DebuggerWX/Src/BreakpointWindow.cpp @@ -205,7 +205,7 @@ CBreakPointWindow::OnDelete(wxCommandEvent& event) void CBreakPointWindow::OnClear(wxCommandEvent& event) { - BreakPoints::Clear(); + g_breakpoints.Clear(); } // ============ @@ -244,7 +244,7 @@ CBreakPointWindow::OnAddBreakPointMany(wxCommandEvent& event) u32 Address = 0; if (AsciiToHex(line.c_str(), Address)) { - BreakPoints::Add(Address); + g_breakpoints.Add(Address); } } // only update after we are done with the loop @@ -346,7 +346,7 @@ CBreakPointWindow::OnAddMemoryCheckMany(wxCommandEvent& event) MemCheck.Log = true; //MemCheck.Break = false; // this is also what sets Active "on" in the breakpoint window // so don't think it's off because we are only writing this to the log - MemChecks::Add(MemCheck); + g_memchecks.Add(MemCheck); } } // update after we are done with the loop diff --git a/Source/Core/DebuggerWX/Src/CodeWindow.cpp b/Source/Core/DebuggerWX/Src/CodeWindow.cpp index 145b1d0253..c202b970cb 100644 --- a/Source/Core/DebuggerWX/Src/CodeWindow.cpp +++ b/Source/Core/DebuggerWX/Src/CodeWindow.cpp @@ -54,7 +54,7 @@ #include "Debugger/Debugger_SymbolMap.h" #include "PowerPC/PPCAnalyst.h" #include "PowerPC/Profiler.h" -#include "PowerPC/SymbolDB.h" +#include "PowerPC/PPCSymbolDB.h" #include "PowerPC/SignatureDB.h" #include "PowerPC/PPCTables.h" #include "PowerPC/Jit64/Jit.h" @@ -79,9 +79,6 @@ class CPluginManager; static const long TOOLBAR_STYLE = wxTB_FLAT | wxTB_DOCKABLE | wxTB_TEXT; -// The default font -wxFont DebuggerFont = wxFont(9, wxMODERN, wxNORMAL, wxNORMAL, false, wxT("monospace")); - #define wxGetBitmapFromMemory(name) _wxGetBitmapFromMemory(name, sizeof(name)) inline wxBitmap _wxGetBitmapFromMemory(const unsigned char* data, int length) @@ -358,7 +355,7 @@ void CCodeWindow::CreateGUIControls(const SCoreStartupParameter& _LocalCoreStart DebugInterface* di = new PPCDebugInterface(); - codeview = new CCodeView(di, this, ID_CODEVIEW); + codeview = new CCodeView(di, &g_symbolDB, this, ID_CODEVIEW); sizerBig->Add(sizerLeft, 2, wxEXPAND); sizerBig->Add(codeview, 5, wxEXPAND); @@ -375,8 +372,6 @@ void CCodeWindow::CreateGUIControls(const SCoreStartupParameter& _LocalCoreStart sizerBig->Fit(this); sync_event.Init(); - - if (bRegisterWindow) { diff --git a/Source/Core/DebuggerWX/Src/CodeWindowSJP.cpp b/Source/Core/DebuggerWX/Src/CodeWindowSJP.cpp index f8bd2274a1..8eb31000be 100644 --- a/Source/Core/DebuggerWX/Src/CodeWindowSJP.cpp +++ b/Source/Core/DebuggerWX/Src/CodeWindowSJP.cpp @@ -39,6 +39,7 @@ #include "Host.h" #include "Debugger.h" +#include "DebuggerUIUtil.h" #include "RegisterWindow.h" #include "BreakpointWindow.h" @@ -59,7 +60,7 @@ #include "Debugger/Debugger_SymbolMap.h" #include "PowerPC/PPCAnalyst.h" #include "PowerPC/Profiler.h" -#include "PowerPC/SymbolDB.h" +#include "PowerPC/PPCSymbolDB.h" #include "PowerPC/SignatureDB.h" #include "PowerPC/PPCTables.h" #include "PowerPC/Jit64/Jit.h" @@ -273,7 +274,7 @@ void CCodeWindow::NotifyMapLoaded() //symbols->Show(false); // hide it for faster filling symbols->Freeze(); // HyperIris: wx style fast filling symbols->Clear(); - for (SymbolDB::XFuncMap::iterator iter = g_symbolDB.GetIterator(); iter != g_symbolDB.End(); iter++) + for (PPCSymbolDB::XFuncMap::iterator iter = g_symbolDB.GetIterator(); iter != g_symbolDB.End(); iter++) { int idx = symbols->Append(wxString::FromAscii(iter->second.name.c_str())); symbols->SetClientData(idx, (void*)&iter->second); diff --git a/Source/Core/DebuggerWX/Src/Debugger.h b/Source/Core/DebuggerWX/Src/Debugger.h index 7a32f67410..92ebe60a74 100644 --- a/Source/Core/DebuggerWX/Src/Debugger.h +++ b/Source/Core/DebuggerWX/Src/Debugger.h @@ -18,23 +18,10 @@ #ifndef _DEBUGGER_H #define _DEBUGGER_H - -#define wxUSE_XPM_IN_MSW 1 -#define USE_XPM_BITMAPS 1 - #include +#include "DebuggerUIUtil.h" + #include "IniFile.h" -// Defined in CodeWindow.cpp -extern wxFont DebuggerFont; - - -// define this to use XPMs everywhere (by default, BMPs are used under Win) -// BMPs use less space, but aren't compiled into the executable on other platforms - -#if USE_XPM_BITMAPS && defined (__WXMSW__) && !wxUSE_XPM_IN_MSW -#error You need to enable XPM support to use XPM bitmaps with toolbar! -#endif // USE_XPM_BITMAPS - #endif diff --git a/Source/Core/DebuggerWX/Src/MemoryCheckDlg.cpp b/Source/Core/DebuggerWX/Src/MemoryCheckDlg.cpp index 3008821a84..2fdf39fb4e 100644 --- a/Source/Core/DebuggerWX/Src/MemoryCheckDlg.cpp +++ b/Source/Core/DebuggerWX/Src/MemoryCheckDlg.cpp @@ -91,7 +91,7 @@ void MemoryCheckDlg::OnOK(wxCommandEvent& /*event*/) MemCheck.Log = true; MemCheck.Break = true; - MemChecks::Add(MemCheck); + g_memchecks.Add(MemCheck); Host_UpdateBreakPointView(); Close(); } diff --git a/Source/Core/DebuggerWX/Src/MemoryView.h b/Source/Core/DebuggerWX/Src/MemoryView.h index 1d42c821c9..70c1371f85 100644 --- a/Source/Core/DebuggerWX/Src/MemoryView.h +++ b/Source/Core/DebuggerWX/Src/MemoryView.h @@ -20,7 +20,7 @@ #include "Debugger.h" #include "Common.h" -#include "Debugger/DebugInterface.h" +#include "DebugInterface.h" class CMemoryView : public wxControl { diff --git a/Source/Core/DebuggerWX/Src/MemoryWindow.cpp b/Source/Core/DebuggerWX/Src/MemoryWindow.cpp index fd9711137d..a17ee545e8 100644 --- a/Source/Core/DebuggerWX/Src/MemoryWindow.cpp +++ b/Source/Core/DebuggerWX/Src/MemoryWindow.cpp @@ -29,7 +29,7 @@ #include "Host.h" #include "Debugger/PPCDebugInterface.h" -#include "PowerPC/SymbolDB.h" +#include "PowerPC/PPCSymbolDB.h" #include "Core.h" #include "LogManager.h" diff --git a/Source/Core/DebuggerWX/Src/SConscript b/Source/Core/DebuggerWX/Src/SConscript index 75b784cad7..9642d3e723 100644 --- a/Source/Core/DebuggerWX/Src/SConscript +++ b/Source/Core/DebuggerWX/Src/SConscript @@ -8,11 +8,9 @@ if not env['HAVE_WX']: files = [ "BreakPointDlg.cpp", "BreakpointView.cpp", - "CodeView.cpp", "BreakpointWindow.cpp", "CodeWindow.cpp", "CodeWindowSJP.cpp", - "CodeView.cpp", "MemoryCheckDlg.cpp", "MemoryView.cpp", "MemoryWindow.cpp", diff --git a/Source/DSPSpy/Stubs.cpp b/Source/DSPSpy/Stubs.cpp index 92d497e5f6..3771762216 100644 --- a/Source/DSPSpy/Stubs.cpp +++ b/Source/DSPSpy/Stubs.cpp @@ -54,6 +54,9 @@ u8 DSPHost_ReadHostMemory(u32 address) return *ptr; } +void DSPHost_WriteHostMemory(u8 value, u32 addr) {} + + void DSPHost_CodeLoaded(const u8 *code, int size) { } diff --git a/Source/DSPTool/Src/main.cpp b/Source/DSPTool/Src/main.cpp index b1ab0e827c..dc89544777 100644 --- a/Source/DSPTool/Src/main.cpp +++ b/Source/DSPTool/Src/main.cpp @@ -23,6 +23,7 @@ // Stub out the dsplib host stuff, since this is just a simple cmdline tools. u8 DSPHost_ReadHostMemory(u32 addr) { return 0; } +void DSPHost_WriteHostMemory(u8 value, u32 addr) {} bool DSPHost_OnThread() { return false; } bool DSPHost_Running() { return true; } u32 DSPHost_CodeLoaded(const u8 *ptr, int size) {return 0x1337c0de;} diff --git a/Source/Dolphin.sln b/Source/Dolphin.sln index 5ceeacadab..87336525e2 100644 --- a/Source/Dolphin.sln +++ b/Source/Dolphin.sln @@ -53,11 +53,17 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Dolphin", "Core\DolphinWX\DolphinWX.vcproj", "{A72606EF-C5C1-4954-90AD-F0F93A8D97D9}" ProjectSection(ProjectDependencies) = postProject {C7E5D50A-2916-464B-86A7-E10B3CC88ADA} = {C7E5D50A-2916-464B-86A7-E10B3CC88ADA} + {CFDCEE0E-FA45-4F72-9FCC-0B88F5A75160} = {CFDCEE0E-FA45-4F72-9FCC-0B88F5A75160} + {D6E56527-BBB9-4EAD-A6EC-49D4BF6AFCD8} = {D6E56527-BBB9-4EAD-A6EC-49D4BF6AFCD8} + {8D612734-FAA5-4B8A-804F-4DEA2367D495} = {8D612734-FAA5-4B8A-804F-4DEA2367D495} + {9A183B48-ECC2-4121-876A-9B3793686073} = {9A183B48-ECC2-4121-876A-9B3793686073} + {636FAD5F-02D1-4E9A-BE67-FB8EA99B9A18} = {636FAD5F-02D1-4E9A-BE67-FB8EA99B9A18} {33546D62-7F34-4EA6-A88E-D538B36E16BF} = {33546D62-7F34-4EA6-A88E-D538B36E16BF} {11F55366-12EC-4C44-A8CB-1D4E315D61ED} = {11F55366-12EC-4C44-A8CB-1D4E315D61ED} {3E03C179-8251-46E4-81F4-466F114BAC63} = {3E03C179-8251-46E4-81F4-466F114BAC63} {823DDC98-42D5-4A38-88CF-9DC06C788AE4} = {823DDC98-42D5-4A38-88CF-9DC06C788AE4} {0E231FB1-F3C9-4724-ACCB-DE8BCB3C089E} = {0E231FB1-F3C9-4724-ACCB-DE8BCB3C089E} + {521498BE-6089-4780-8223-E67C22F4E068} = {521498BE-6089-4780-8223-E67C22F4E068} {E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA} = {E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA} {29C2ABC1-ADA5-42CD-A5FC-96022D52A510} = {29C2ABC1-ADA5-42CD-A5FC-96022D52A510} {4D3CD4C5-412B-4B49-9B1B-A68A2A129C77} = {4D3CD4C5-412B-4B49-9B1B-A68A2A129C77} @@ -69,6 +75,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Dolphin", "Core\DolphinWX\D EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Debugger", "Core\DebuggerWX\DebuggerWX.vcproj", "{4D3CD4C5-412B-4B49-9B1B-A68A2A129C77}" ProjectSection(ProjectDependencies) = postProject + {F81AE75C-3D17-4D8C-A201-82FA5351C123} = {F81AE75C-3D17-4D8C-A201-82FA5351C123} {11F55366-12EC-4C44-A8CB-1D4E315D61ED} = {11F55366-12EC-4C44-A8CB-1D4E315D61ED} {0E231FB1-F3C9-4724-ACCB-DE8BCB3C089E} = {0E231FB1-F3C9-4724-ACCB-DE8BCB3C089E} {29C2ABC1-ADA5-42CD-A5FC-96022D52A510} = {29C2ABC1-ADA5-42CD-A5FC-96022D52A510} @@ -153,6 +160,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AudioCommon", "Core\AudioCo EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Plugin_DSP_LLE", "Plugins\Plugin_DSP_LLE\Plugin_DSP_LLE.vcproj", "{3D8156A9-64D1-4C8E-ADBE-1B319030E4A4}" ProjectSection(ProjectDependencies) = postProject + {F81AE75C-3D17-4D8C-A201-82FA5351C123} = {F81AE75C-3D17-4D8C-A201-82FA5351C123} {11F55366-12EC-4C44-A8CB-1D4E315D61ED} = {11F55366-12EC-4C44-A8CB-1D4E315D61ED} {FBAFB369-07EB-4460-9CAD-08BE5789DAB6} = {FBAFB369-07EB-4460-9CAD-08BE5789DAB6} {838A89A3-3AA0-4A45-ACBE-3D1E0980C2ED} = {838A89A3-3AA0-4A45-ACBE-3D1E0980C2ED} @@ -187,6 +195,14 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTests", "UnitTests\Unit {C573CAF7-EE6A-458E-8049-16C0BF34C2E9} = {C573CAF7-EE6A-458E-8049-16C0BF34C2E9} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DebuggerUICommon", "Core\DebuggerUICommon\DebuggerUICommon.vcproj", "{F81AE75C-3D17-4D8C-A201-82FA5351C123}" + ProjectSection(ProjectDependencies) = postProject + {11F55366-12EC-4C44-A8CB-1D4E315D61ED} = {11F55366-12EC-4C44-A8CB-1D4E315D61ED} + {0E231FB1-F3C9-4724-ACCB-DE8BCB3C089E} = {0E231FB1-F3C9-4724-ACCB-DE8BCB3C089E} + {1C8436C9-DBAF-42BE-83BC-CF3EC9175ABE} = {1C8436C9-DBAF-42BE-83BC-CF3EC9175ABE} + {C573CAF7-EE6A-458E-8049-16C0BF34C2E9} = {C573CAF7-EE6A-458E-8049-16C0BF34C2E9} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -629,16 +645,35 @@ Global {823DDC98-42D5-4A38-88CF-9DC06C788AE4}.Release|x64.ActiveCfg = Release|x64 {823DDC98-42D5-4A38-88CF-9DC06C788AE4}.Release|x64.Build.0 = Release|x64 {40C636FA-B5BF-4D67-ABC8-376B524A7551}.Debug|Win32.ActiveCfg = Debug|Win32 - {40C636FA-B5BF-4D67-ABC8-376B524A7551}.Debug|x64.ActiveCfg = Debug|x64 + {40C636FA-B5BF-4D67-ABC8-376B524A7551}.Debug|Win32.Build.0 = Debug|Win32 + {40C636FA-B5BF-4D67-ABC8-376B524A7551}.Debug|x64.ActiveCfg = Debug|Win32 {40C636FA-B5BF-4D67-ABC8-376B524A7551}.DebugFast|Win32.ActiveCfg = Debug|Win32 - {40C636FA-B5BF-4D67-ABC8-376B524A7551}.DebugFast|x64.ActiveCfg = Debug|x64 + {40C636FA-B5BF-4D67-ABC8-376B524A7551}.DebugFast|Win32.Build.0 = Debug|Win32 + {40C636FA-B5BF-4D67-ABC8-376B524A7551}.DebugFast|x64.ActiveCfg = DebugFast|x64 + {40C636FA-B5BF-4D67-ABC8-376B524A7551}.DebugFast|x64.Build.0 = DebugFast|x64 {40C636FA-B5BF-4D67-ABC8-376B524A7551}.Release_JITIL|Win32.ActiveCfg = Release|Win32 {40C636FA-B5BF-4D67-ABC8-376B524A7551}.Release_JITIL|Win32.Build.0 = Release|Win32 - {40C636FA-B5BF-4D67-ABC8-376B524A7551}.Release_JITIL|x64.ActiveCfg = Release|x64 + {40C636FA-B5BF-4D67-ABC8-376B524A7551}.Release_JITIL|x64.ActiveCfg = Release|Win32 {40C636FA-B5BF-4D67-ABC8-376B524A7551}.Release|Win32.ActiveCfg = Release|Win32 {40C636FA-B5BF-4D67-ABC8-376B524A7551}.Release|Win32.Build.0 = Release|Win32 {40C636FA-B5BF-4D67-ABC8-376B524A7551}.Release|x64.ActiveCfg = Release|x64 {40C636FA-B5BF-4D67-ABC8-376B524A7551}.Release|x64.Build.0 = Release|x64 + {F81AE75C-3D17-4D8C-A201-82FA5351C123}.Debug|Win32.ActiveCfg = Debug|Win32 + {F81AE75C-3D17-4D8C-A201-82FA5351C123}.Debug|Win32.Build.0 = Debug|Win32 + {F81AE75C-3D17-4D8C-A201-82FA5351C123}.Debug|x64.ActiveCfg = Debug|x64 + {F81AE75C-3D17-4D8C-A201-82FA5351C123}.Debug|x64.Build.0 = Debug|x64 + {F81AE75C-3D17-4D8C-A201-82FA5351C123}.DebugFast|Win32.ActiveCfg = Debug|Win32 + {F81AE75C-3D17-4D8C-A201-82FA5351C123}.DebugFast|Win32.Build.0 = Debug|Win32 + {F81AE75C-3D17-4D8C-A201-82FA5351C123}.DebugFast|x64.ActiveCfg = DebugFast|x64 + {F81AE75C-3D17-4D8C-A201-82FA5351C123}.DebugFast|x64.Build.0 = DebugFast|x64 + {F81AE75C-3D17-4D8C-A201-82FA5351C123}.Release_JITIL|Win32.ActiveCfg = Release|Win32 + {F81AE75C-3D17-4D8C-A201-82FA5351C123}.Release_JITIL|Win32.Build.0 = Release|Win32 + {F81AE75C-3D17-4D8C-A201-82FA5351C123}.Release_JITIL|x64.ActiveCfg = Release|x64 + {F81AE75C-3D17-4D8C-A201-82FA5351C123}.Release_JITIL|x64.Build.0 = Release|x64 + {F81AE75C-3D17-4D8C-A201-82FA5351C123}.Release|Win32.ActiveCfg = Release|Win32 + {F81AE75C-3D17-4D8C-A201-82FA5351C123}.Release|Win32.Build.0 = Release|Win32 + {F81AE75C-3D17-4D8C-A201-82FA5351C123}.Release|x64.ActiveCfg = Release|x64 + {F81AE75C-3D17-4D8C-A201-82FA5351C123}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Source/PluginSpecs/pluginspecs_dsp.h b/Source/PluginSpecs/pluginspecs_dsp.h index f9fa4ba27c..2e32070d15 100644 --- a/Source/PluginSpecs/pluginspecs_dsp.h +++ b/Source/PluginSpecs/pluginspecs_dsp.h @@ -9,6 +9,7 @@ #include "ExportProlog.h" typedef unsigned char (*TARAM_Read_U8)(const unsigned int _uAddress); +typedef void (*TARAM_Write_U8)(const unsigned char _uValue, const unsigned int _uAddress); typedef unsigned char* (*TGetMemoryPointer)(const unsigned int _uAddress); typedef unsigned char* (*TGetARAMPointer)(void); typedef void (*TLogv)(const char* _szMessage, int _v); @@ -21,6 +22,7 @@ typedef struct { void *hWnd; TARAM_Read_U8 pARAM_Read_U8; + TARAM_Write_U8 pARAM_Write_U8; TGetMemoryPointer pGetMemoryPointer; TGetARAMPointer pGetARAMPointer; TLogv pLog; diff --git a/Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCode_Zelda.cpp b/Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCode_Zelda.cpp index ef81c7e5d7..22ba810a57 100644 --- a/Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCode_Zelda.cpp +++ b/Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCode_Zelda.cpp @@ -120,19 +120,22 @@ void CUCode_Zelda::UpdatePB(ZPB& _rPB, int *templbuffer, int *temprbuffer, u32 _ { u16* pTest = (u16*)&_rPB; + // Checks at 0293 if (pTest[0x00] == 0) return; if (pTest[0x01] != 0) return; + if (pTest[0x06] != 0x00) { // probably pTest[0x06] == 0 -> AFC (and variants) + // See 02a4 } else { - switch(_rPB.type) // or Bytes per Sample + switch (_rPB.type) // or Bytes per Sample { case 0x05: case 0x09: @@ -140,6 +143,10 @@ void CUCode_Zelda::UpdatePB(ZPB& _rPB, int *templbuffer, int *temprbuffer, u32 _ // initialize "decoder" if the sample is played the first time if (pTest[0x04] != 0) { + // This is 0717_ReadOutPBStuff + + // increment 4fb + // zelda: // perhaps init or "has played before" pTest[0x32] = 0x00; @@ -151,7 +158,7 @@ void CUCode_Zelda::UpdatePB(ZPB& _rPB, int *templbuffer, int *temprbuffer, u32 _ pTest[0x3a] = pTest[0x8a]; pTest[0x3b] = pTest[0x8b]; - // copy ARAM addr from r to rw area + // Copy ARAM addr from r to rw area. pTest[0x38] = pTest[0x8c]; pTest[0x39] = pTest[0x8d]; } @@ -177,20 +184,19 @@ void CUCode_Zelda::UpdatePB(ZPB& _rPB, int *templbuffer, int *temprbuffer, u32 _ // Then, resample from this buffer to the output as you go. When it needs // wrapping, decode more. -#define USE_RESAMPLE 1 -#if USE_RESAMPLE != 1 - for (int s=0; s<(_Size/16);s++) +#define USE_RESAMPLE +#if !defined(USE_RESAMPLE) + for (int s = 0; s < _Size/16; s++) { - for (int i=0; i<9; i++) + for (int i = 0; i < 9; i++) { - inBuffer[i] = g_dspInitialize.pARAM_Read_U8(ARAMAddr); + inBuffer[i] = g_dspInitialize.pARAM_Read_U8(ARAMAddr); ARAMAddr++; } - AFCdecodebuffer((char*)inBuffer, outbuf, (short*)&pTest[0x66], (short*)&pTest[0x67]); - for (int i=0; i<16; i++) + for (int i = 0; i < 16; i++) { templbuffer[sampleCount] += outbuf[i]; temprbuffer[sampleCount] += outbuf[i]; @@ -218,7 +224,7 @@ void CUCode_Zelda::UpdatePB(ZPB& _rPB, int *templbuffer, int *temprbuffer, u32 _ { int sample = Sampler.sample_queue.front(); Sampler.sample_queue.pop(); - Sampler.m_queueSize-=1; + Sampler.m_queueSize -= 1; templbuffer[sampleCount] += sample; temprbuffer[sampleCount] += sample; @@ -273,10 +279,17 @@ void CUCode_Zelda::UpdatePB(ZPB& _rPB, int *templbuffer, int *temprbuffer, u32 _ // end of block (Zelda 03b2) if (pTest[0x06] == 0) { + // 02a4 + // + pTest[0x04] = 0; } } break; + + default: + ERROR_LOG(DSPHLE, "Zelda Ucode: Unknown PB type %i", _rPB.type); + break; } } } diff --git a/Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCodes.cpp b/Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCodes.cpp index 2f141a383c..6921a353b4 100644 --- a/Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCodes.cpp +++ b/Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCodes.cpp @@ -61,7 +61,7 @@ IUCode* UCodeFactory(u32 _CRC, CMailHandler& _rMailHandler) // return new CUCode_Zelda(_rMailHandler, false); case 0x6CA33A6D: // DK Jungle Beat - case 0x86840740: // Zelda WW + case 0x86840740: // Zelda WW - US case 0x56d36052: // Mario Sunshine case 0x2fcdf1ec: // Mario Kart, zelda 4 swords INFO_LOG(CONSOLE, "Zelda ucode chosen\n"); diff --git a/Source/Plugins/Plugin_DSP_LLE/Plugin_DSP_LLE.vcproj b/Source/Plugins/Plugin_DSP_LLE/Plugin_DSP_LLE.vcproj index 9b83e612e2..b5c26f2fce 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Plugin_DSP_LLE.vcproj +++ b/Source/Plugins/Plugin_DSP_LLE/Plugin_DSP_LLE.vcproj @@ -45,7 +45,7 @@ + + + + - - - - diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/DSPDebugInterface.cpp b/Source/Plugins/Plugin_DSP_LLE/Src/DSPDebugInterface.cpp index 1130639df4..d8385d1fd0 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Src/DSPDebugInterface.cpp +++ b/Source/Plugins/Plugin_DSP_LLE/Src/DSPDebugInterface.cpp @@ -20,69 +20,42 @@ #include "DSPCore.h" #include "disassemble.h" +#include "DSPSymbols.h" +#include "gdsp_memory.h" + void DSPDebugInterface::disasm(unsigned int address, char *dest, int max_size) { - AssemblerSettings settings; - settings.print_tabs = true; - - u16 pc = address; - DSPDisassembler dis(settings); - - u16 base = 0; - const u16 *binbuf = g_dsp.iram; - if (pc & 0x8000) - { - binbuf = g_dsp.irom; - base = 0x8000; - } - - std::string text; - dis.DisOpcode(binbuf, base, 2, &pc, text); - strncpy(dest, text.c_str(), max_size); - dest[max_size - 1] = '\0'; - - /* - if (Core::GetState() != Core::CORE_UNINITIALIZED) - { - if (Memory::IsRAMAddress(address, true)) - { - u32 op = Memory::Read_Instruction(address); - DisassembleGekko(op, address, dest, max_size); - UGeckoInstruction inst; - inst.hex = Memory::ReadUnchecked_U32(address); - if (inst.OPCD == 1) { - strcat(dest, " (hle)"); - } - } - else - { - strcpy(dest, "(No RAM here)"); - } - } - else - { - strcpy(dest, ""); - }*/ + // we'll treat addresses as line numbers. + strncpy(dest, DSPSymbols::GetLineText(address), max_size); + dest[max_size-1] = 0; } void DSPDebugInterface::getRawMemoryString(int memory, unsigned int address, char *dest, int max_size) { - /* - if (Core::GetState() != Core::CORE_UNINITIALIZED) - { - if (Memory::IsRAMAddress(address, true)) - { - snprintf(dest, max_size, "%08X", readMemory(address)); + switch (memory) { + case 0: // IMEM + switch (address >> 12) { + case 0: + case 0x8: + sprintf(dest, "%04x", dsp_imem_read(address)); + break; + default: + sprintf(dest, "----"); + break; } - else - { - strcpy(dest, "--------"); + break; + case 1: // DMEM + switch (address >> 12) { + case 0: + case 1: + sprintf(dest, "%04x", dsp_dmem_read(address)); + break; + default: + sprintf(dest, "----"); + break; } + break; } - else - { - strcpy(dest, ""); // bad spelling - 8 chars - }*/ } unsigned int DSPDebugInterface::readMemory(unsigned int address) @@ -129,19 +102,14 @@ void DSPDebugInterface::toggleBreakpoint(unsigned int address) void DSPDebugInterface::insertBLR(unsigned int address) { - // Memory::Write_U32(0x4e800020, address); + } - // ======================================================= // Separate the blocks with colors. // ------------- int DSPDebugInterface::getColor(unsigned int address) { - return 0xEEEEEE; - /* - if (!Memory::IsRAMAddress(address, true)) - return 0xeeeeee; static const int colors[6] = { 0xd0FFFF, // light cyan @@ -152,29 +120,42 @@ int DSPDebugInterface::getColor(unsigned int address) 0xFFFFd0, // light yellow }; - Symbol *symbol = g_symbolDB.GetSymbolFromAddr(address); + // Scan backwards so we don't miss it. Hm, actually, let's not - it looks pretty good. + int addr = -1; + for (int i = 0; i < 1; i++) + { + addr = DSPSymbols::Line2Addr(address - i); + if (addr >= 0) + break; + } + if (addr == -1) + return 0xFFFFFF; + + Symbol *symbol = DSPSymbols::g_dsp_symbol_db.GetSymbolFromAddr(addr); if (!symbol) return 0xFFFFFF; if (symbol->type != Symbol::SYMBOL_FUNCTION) return 0xEEEEFF; - return colors[symbol->index % 6];*/ + return colors[symbol->index % 6]; } // ============= std::string DSPDebugInterface::getDescription(unsigned int address) { - return "asdf"; // g_symbolDB.GetDescription(address); + return ""; // g_symbolDB.GetDescription(address); } unsigned int DSPDebugInterface::getPC() { - return 0; + return DSPSymbols::Addr2Line(g_dsp.pc); } void DSPDebugInterface::setPC(unsigned int address) { - //PowerPC::ppcState.pc = address; + int new_pc = DSPSymbols::Line2Addr(address); + if (new_pc > 0) + g_dsp.pc = new_pc; } void DSPDebugInterface::runToBreakpoint() diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/DSPDebugInterface.h b/Source/Plugins/Plugin_DSP_LLE/Src/DSPDebugInterface.h index c73667b89a..5fc1aa67a1 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Src/DSPDebugInterface.h +++ b/Source/Plugins/Plugin_DSP_LLE/Src/DSPDebugInterface.h @@ -3,7 +3,7 @@ #include -#include "../../../Core/Core/Src/Debugger/DebugInterface.h" +#include "DebugInterface.h" class DSPDebugInterface : public DebugInterface { @@ -11,7 +11,7 @@ public: DSPDebugInterface(){} virtual void disasm(unsigned int address, char *dest, int max_size); virtual void getRawMemoryString(int memory, unsigned int address, char *dest, int max_size); - virtual int getInstructionSize(int instruction) {return 2;} + virtual int getInstructionSize(int instruction) {return 1;} virtual bool isAlive(); virtual bool isBreakpoint(unsigned int address); virtual void setBreakpoint(unsigned int address); diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/DSPHost.cpp b/Source/Plugins/Plugin_DSP_LLE/Src/DSPHost.cpp index 2276fd6d22..d3dfca5998 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Src/DSPHost.cpp +++ b/Source/Plugins/Plugin_DSP_LLE/Src/DSPHost.cpp @@ -17,6 +17,7 @@ #include "Common.h" #include "DSPHost.h" +#include "DSPSymbols.h" #include "Tools.h" #include "pluginspecs_dsp.h" @@ -32,6 +33,11 @@ u8 DSPHost_ReadHostMemory(u32 addr) return g_dspInitialize.pARAM_Read_U8(addr); } +void DSPHost_WriteHostMemory(u8 value, u32 addr) +{ + g_dspInitialize.pARAM_Write_U8(value, addr); +} + bool DSPHost_OnThread() { return g_dspInitialize.bOnThread; @@ -46,5 +52,29 @@ u32 DSPHost_CodeLoaded(const u8 *ptr, int size) { u32 crc = GenerateCRC(ptr, size); DumpDSPCode(ptr, size, crc); + + // this crc is comparable with the HLE plugin + u32 ector_crc = 0; + for (u32 i = 0; i < size; i++) + { + ector_crc ^= ptr[i]; + //let's rol + ector_crc = (ector_crc << 3) | (ector_crc >> 29); + } + + DSPSymbols::Clear(); + + // Auto load text file - if none just disassemble. + + // TODO: Don't hardcode for Zelda. + NOTICE_LOG(DSPLLE, "CRC: %08x", ector_crc); + if (!DSPSymbols::ReadAnnotatedAssembly("../../Docs/DSP/DSP_UC_Zelda.txt")) + { + DSPSymbols::Clear(); + DSPSymbols::AutoDisassembly(0x0, 0x1000); + } + + // Always add the ROM. + DSPSymbols::AutoDisassembly(0x8000, 0x9000); return crc; } \ No newline at end of file diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/DSPSymbols.cpp b/Source/Plugins/Plugin_DSP_LLE/Src/DSPSymbols.cpp new file mode 100644 index 0000000000..7777d8df3f --- /dev/null +++ b/Source/Plugins/Plugin_DSP_LLE/Src/DSPSymbols.cpp @@ -0,0 +1,287 @@ +// Copyright (C) 2003-2009 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#include // I hope this doesn't break anything +#include +#include + +#include +#include +#include + +#include "Common.h" +#include "StringUtil.h" + +#include "DSPCore.h" +#include "DSPSymbols.h" +#include "disassemble.h" + +namespace DSPSymbols { + +DSPSymbolDB g_dsp_symbol_db; + +std::map addr_to_line; +std::map line_to_addr; +std::map line_to_symbol; +std::vector lines; +int line_counter = 0; + +int Addr2Line(u16 address) // -1 for not found +{ + std::map::iterator iter = addr_to_line.find(address); + if (iter != addr_to_line.end()) + return iter->second; + else + return -1; +} + +int Line2Addr(int line) // -1 for not found +{ + std::map::iterator iter = line_to_addr.find(line); + if (iter != line_to_addr.end()) + return iter->second; + else + return -1; +} + +const char *GetLineText(int line) +{ + if (line > 0 && line < (int)lines.size()) + { + return lines[line].c_str(); + } + else + return "----"; +} + +Symbol *DSPSymbolDB::GetSymbolFromAddr(u32 addr) +{ + XFuncMap::iterator it = functions.find(addr); + if (it != functions.end()) + return &it->second; + else + { + for (XFuncMap::iterator iter = functions.begin(); iter != functions.end(); iter++) + { + if (addr >= iter->second.address && addr < iter->second.address + iter->second.size) + return &iter->second; + } + } + return 0; +} + +// lower case only +bool IsHexDigit(char c) { + switch (c) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + return true; + default: + return false; + } +} + +bool IsAlpha(char c) { + return (c >= 'A' && c <= 'Z') || + (c >= 'a' && c <= 'z'); +} + +void DisasssembleRange(u16 start, u16 end) +{ + +} + +bool ReadAnnotatedAssembly(const char *filename) +{ + FILE *f = fopen(filename, "r"); + if (!f) { + ERROR_LOG(DSPLLE, "Bah! ReadAnnotatedAssembly couldn't find the file %s", filename); + return false; + } + char line[512]; + + int last_addr = 0; + + lines.reserve(3000); + + // Symbol generation + int brace_count = 0; + bool symbol_in_progress = false; + + int symbol_count = 0; + Symbol current_symbol; + + while (fgets(line, 512, f)) + { + // Scan string for the first 4-digit hex string. + size_t len = strlen(line); + int first_hex = -1; + bool hex_found = false; + for (unsigned int i = 0; i < strlen(line); i++) + { + const char c = line[i]; + if (IsHexDigit(c)) + { + if (first_hex == -1) + { + first_hex = i; + } + else + { + // Remove hex notation + if (i == first_hex + 3 && + (first_hex == 0 || line[first_hex - 1] != 'x') && + (i >= len - 1 || line[i + 1] == ' ')) + { + hex_found = true; + break; + } + } + } else { + if (i - first_hex < 3) + { + first_hex = -1; + } + if (IsAlpha(c)) + break; + } + } + + // Scan for function starts + if (!memcmp(line, "void", 4)) { + char temp[256]; + for (int i = 6; i < len; i++) { + if (line[i] == '(') { + // Yep, got one. + memcpy(temp, line + 5, i - 5); + temp[i - 5] = 0; + + // Mark symbol so the next hex sets the address + current_symbol.name = temp; + current_symbol.address = 0xFFFF; + current_symbol.index = symbol_count++; + symbol_in_progress = true; + + // Reset brace count. + brace_count = 0; + } + } + } + + // Scan for braces + for (int i = 0; i < (int)len; i++) { + if (line[i] == '{') + brace_count++; + if (line[i] == '}') + { + brace_count--; + if (brace_count == 0 && symbol_in_progress) { + // Commit this symbol. + current_symbol.size = last_addr - current_symbol.address + 1; + g_dsp_symbol_db.AddCompleteSymbol(current_symbol); + current_symbol.address = 0xFFFF; + symbol_in_progress = false; + } + } + } + + if (hex_found) + { + int hex = 0; + sscanf(line + first_hex, "%04x", &hex); + + // Sanity check + if (hex > last_addr + 3 || hex < last_addr - 3) { + static int errors = 0; + ERROR_LOG(DSPLLE, "Got Insane Hex Digit %04x (%04x) from %s", hex, last_addr, line); + errors++; + if (errors > 10) + { + fclose(f); + return false; + } + } + else + { + // if (line_counter >= 200 && line_counter <= 220) + // NOTICE_LOG(DSPLLE, "Got Hex Digit %04x from %s, line %i", hex, line, line_counter); + if (symbol_in_progress && current_symbol.address == 0xFFFF) + current_symbol.address = hex; + + line_to_addr[line_counter] = hex; + addr_to_line[hex] = line_counter; + last_addr = hex; + } + } + + lines.push_back(TabsToSpaces(4, line)); + line_counter++; + } + fclose(f); + return true; +} + +void AutoDisassembly(u16 start_addr, u16 end_addr) +{ + AssemblerSettings settings; + settings.show_pc = true; + settings.show_hex = true; + DSPDisassembler disasm(settings); + + u16 addr = start_addr; + const u16 *ptr = (start_addr >> 15) ? g_dsp.irom : g_dsp.iram; + while (addr < end_addr) + { + line_to_addr[line_counter] = addr; + addr_to_line[addr] = line_counter; + + std::string buf; + if (!disasm.DisOpcode(ptr, 0, 2, &addr, buf)) + { + ERROR_LOG(DSPLLE, "disasm failed at %04x", addr); + break; + } + + //NOTICE_LOG(DSPLLE, "added %04x %i %s", addr, line_counter, buf.c_str()); + lines.push_back(buf); + line_counter++; + } +} + +void Clear() +{ + addr_to_line.clear(); + line_to_addr.clear(); + lines.clear(); + line_counter = 0; +} + +} // namespace DSPSymbols diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/DSPSymbols.h b/Source/Plugins/Plugin_DSP_LLE/Src/DSPSymbols.h new file mode 100644 index 0000000000..ab91646b5d --- /dev/null +++ b/Source/Plugins/Plugin_DSP_LLE/Src/DSPSymbols.h @@ -0,0 +1,54 @@ +// Copyright (C) 2003-2009 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#ifndef _DSPSYMBOLS_H +#define _DSPSYMBOLS_H + +#include "Common.h" +#include "SymbolDB.h" +#include "AudioCommon.h" + +#include + +namespace DSPSymbols { + +class DSPSymbolDB : public SymbolDB +{ +public: + DSPSymbolDB() {} + ~DSPSymbolDB() {} + + Symbol *GetSymbolFromAddr(u32 addr); + +}; + +extern DSPSymbolDB g_dsp_symbol_db; + +bool ReadAnnotatedAssembly(const char *filename); +void AutoDisassembly(u16 start_addr, u16 end_addr); + +void Clear(); + +int Addr2Line(u16 address); +int Line2Addr(int line); // -1 for not found + +const char *GetLineText(int line); + +} // namespace DSPSymbols + +#endif + diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/Debugger/Debugger.cpp b/Source/Plugins/Plugin_DSP_LLE/Src/Debugger/Debugger.cpp index baed853928..8e4106ae15 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Src/Debugger/Debugger.cpp +++ b/Source/Plugins/Plugin_DSP_LLE/Src/Debugger/Debugger.cpp @@ -22,6 +22,8 @@ #include "Debugger.h" #include "DSPRegisterView.h" +#include "CodeView.h" +#include "../DSPSymbols.h" // Event table and class BEGIN_EVENT_TABLE(DSPDebuggerLLE, wxFrame) @@ -29,9 +31,8 @@ BEGIN_EVENT_TABLE(DSPDebuggerLLE, wxFrame) EVT_MENU_RANGE(ID_RUNTOOL, ID_STEPTOOL, DSPDebuggerLLE::OnChangeState) EVT_MENU(ID_SHOWPCTOOL, DSPDebuggerLLE::OnShowPC) - - EVT_LIST_ITEM_RIGHT_CLICK(ID_DISASM, DSPDebuggerLLE::OnRightClick) - EVT_LIST_ITEM_ACTIVATED(ID_DISASM, DSPDebuggerLLE::OnDoubleClick) + EVT_TEXT(ID_ADDRBOX, DSPDebuggerLLE::OnAddrBoxChange) + EVT_LISTBOX(ID_SYMBOLLIST, DSPDebuggerLLE::OnSymbolListChange) END_EVENT_TABLE() DSPDebuggerLLE::DSPDebuggerLLE(wxWindow *parent, wxWindowID id, const wxString &title, @@ -59,18 +60,29 @@ void DSPDebuggerLLE::CreateGUIControls() m_Toolbar = CreateToolBar(wxTB_NODIVIDER|wxTB_NOICONS|wxTB_HORZ_TEXT|wxTB_DOCKABLE, ID_TOOLBAR); m_Toolbar->AddTool(ID_RUNTOOL, wxT("Run"), wxNullBitmap, wxEmptyString, wxITEM_NORMAL); m_Toolbar->AddTool(ID_STEPTOOL, wxT("Step"), wxNullBitmap, wxT("Step Code "), wxITEM_NORMAL); - m_Toolbar->AddTool(ID_SHOWPCTOOL, wxT("Show Pc"), wxNullBitmap, wxT("Reset To PC counter"), wxITEM_NORMAL); + m_Toolbar->AddTool(ID_SHOWPCTOOL, wxT("Show Pc"), wxNullBitmap, wxT("Show where PC is"), wxITEM_NORMAL); m_Toolbar->AddTool(ID_JUMPTOTOOL, wxT("Jump"), wxNullBitmap, wxT("Jump to a specific Address"), wxITEM_NORMAL); m_Toolbar->AddSeparator(); + m_Toolbar->AddCheckTool(ID_CHECK_ASSERTINT, wxT("AssertInt"), wxNullBitmap, wxNullBitmap, wxEmptyString); m_Toolbar->AddCheckTool(ID_CHECK_HALT, wxT("Halt"), wxNullBitmap, wxNullBitmap, wxEmptyString); m_Toolbar->AddCheckTool(ID_CHECK_INIT, wxT("Init"), wxNullBitmap, wxNullBitmap, wxEmptyString); + m_Toolbar->AddSeparator(); + + m_Toolbar->AddControl(new wxTextCtrl(m_Toolbar, ID_ADDRBOX, _T(""))); + m_Toolbar->Realize(); wxBoxSizer* sMain = new wxBoxSizer(wxHORIZONTAL); + wxBoxSizer* sizerLeft = new wxBoxSizer(wxVERTICAL); + sizerLeft->Add(m_SymbolList = new wxListBox(this, ID_SYMBOLLIST, wxDefaultPosition, wxSize(90, 100), 0, NULL, wxLB_SORT), 1, wxEXPAND); - m_Disasm = new wxListCtrl(this, ID_DISASM, wxDefaultPosition, wxDefaultSize, wxLC_REPORT); - sMain->Add(m_Disasm, 4, wxALL|wxEXPAND, 5); + m_CodeView = new CCodeView(&debug_interface, &DSPSymbols::g_dsp_symbol_db, this, ID_CODEVIEW); + m_CodeView->SetPlain(); + + sMain->Add(sizerLeft, 1, wxALL|wxEXPAND, 0); + + sMain->Add(m_CodeView, 4, wxALL|wxEXPAND, 5); wxStaticLine* m_staticline = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL); sMain->Add(m_staticline, 0, wxEXPAND|wxALL, 5); @@ -80,15 +92,6 @@ void DSPDebuggerLLE::CreateGUIControls() this->SetSizer(sMain); this->Layout(); - - // Add the disasm columns - m_Disasm->InsertColumn(COLUMN_BP, wxT("BP"), wxLIST_FORMAT_LEFT, 25); - m_Disasm->InsertColumn(COLUMN_FUNCTION, wxT("Function"), wxLIST_FORMAT_LEFT, 160); - m_Disasm->InsertColumn(COLUMN_ADDRESS, wxT("Address"), wxLIST_FORMAT_LEFT, 55); - m_Disasm->InsertColumn(COLUMN_MNEMONIC, wxT("Mnemonic"), wxLIST_FORMAT_LEFT, 55); - m_Disasm->InsertColumn(COLUMN_OPCODE, wxT("Opcode"), wxLIST_FORMAT_LEFT, 60); - m_Disasm->InsertColumn(COLUMN_EXT, wxT("Ext"), wxLIST_FORMAT_LEFT, 40); - m_Disasm->InsertColumn(COLUMN_PARAM, wxT("Param"), wxLIST_FORMAT_LEFT, 500); } void DSPDebuggerLLE::OnClose(wxCloseEvent& event) @@ -110,6 +113,9 @@ void DSPDebuggerLLE::OnChangeState(wxCommandEvent& event) case ID_STEPTOOL: m_State = STEP; break; + case ID_SHOWPCTOOL: + FocusOnPC(); + break; } UpdateState(); @@ -121,27 +127,6 @@ void DSPDebuggerLLE::OnShowPC(wxCommandEvent& event) FocusOnPC(); } -void DSPDebuggerLLE::OnRightClick(wxListEvent& event) -{ - long item = m_Disasm->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); - u16 SelectedPC = static_cast(m_Disasm->GetItemData(item)); - g_dsp.pc = SelectedPC; - - Refresh(); -} - -void DSPDebuggerLLE::OnDoubleClick(wxListEvent& event) -{ - long item = m_Disasm->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); - u16 SelectedPC = static_cast(m_Disasm->GetItemData(item)); - ToggleBreakPoint(SelectedPC); - - if (IsBreakPoint(SelectedPC)) - m_Disasm->SetItem(item, COLUMN_BP, wxT("*")); - else - m_Disasm->SetItem(item, COLUMN_BP, wxT("")); -} - void DSPDebuggerLLE::Refresh() { UpdateSymbolMap(); @@ -152,26 +137,7 @@ void DSPDebuggerLLE::Refresh() void DSPDebuggerLLE::FocusOnPC() { - UnselectAll(); - - for (int i = 0; i < m_Disasm->GetItemCount(); i++) - { - if (m_Disasm->GetItemData(i) == g_dsp.pc) - { - m_Disasm->EnsureVisible(i - 5); - m_Disasm->EnsureVisible(i + 5); - m_Disasm->SetItemState(i, wxLIST_STATE_FOCUSED|wxLIST_STATE_SELECTED, wxLIST_STATE_FOCUSED|wxLIST_STATE_SELECTED); - break; - } - } -} - -void DSPDebuggerLLE::UnselectAll() -{ - for (int i = 0; i < m_Disasm->GetItemCount(); i++) - { - m_Disasm->SetItemState(i, 0, wxLIST_STATE_SELECTED); - } + JumpToAddress(g_dsp.pc); } void DSPDebuggerLLE::UpdateState() @@ -183,129 +149,14 @@ void DSPDebuggerLLE::UpdateState() m_Toolbar->Realize(); } -void DSPDebuggerLLE::RebuildDisAsmListView() -{ - m_Disasm->Freeze(); - m_Disasm->DeleteAllItems(); - - AssemblerSettings settings; - - const u16 *binbuf; - if (g_dsp.pc & 0x8000) - binbuf = g_dsp.irom; - else - binbuf = g_dsp.iram; - - settings.ext_separator = (char)0xff; - - settings.show_pc = false; - settings.show_hex = false; - settings.print_tabs = true; - settings.decode_names = true; - settings.decode_registers = true; - - for (settings.pc = 0; settings.pc < DSP_IROM_SIZE;) - { - u16 CurrentPC = settings.pc; - - if (g_dsp.pc & 0x8000) - CurrentPC |= 0x8000; - - char Temp[256]; - sprintf(Temp, "0x%04x", CurrentPC); - - char Temp2[256]; - sprintf(Temp2, "0x%04x", dsp_imem_read(CurrentPC)); - - DSPDisassembler disasm(settings); - std::string op_str; - - disasm.DisOpcode(binbuf, settings.pc & 0x8000, 2, &settings.pc, op_str); - const char* pParameter = NULL; - const char* pExtension = NULL; - - size_t WholeString = op_str.size(); - - /* - for (size_t i = 0; i < WholeString; i++) - { - if (pOpcode[i] == (char)0xff) - { - pOpcode[i] = 0x00; - pExtension = &pOpcode[i + 1]; - } - - if (pOpcode[i] == 0x09) - { - pOpcode[i] = 0x00; - pParameter = &pOpcode[i + 1]; - } - }*/ - - const char* pFunctionName = NULL; - - if (m_SymbolMap.find(CurrentPC) != m_SymbolMap.end()) - { - pFunctionName = m_SymbolMap[CurrentPC].Name.c_str(); - } - - int Item = m_Disasm->InsertItem(settings.pc, wxEmptyString); - m_Disasm->SetItem(Item, COLUMN_BP, wxEmptyString); - m_Disasm->SetItem(Item, COLUMN_FUNCTION, wxString::FromAscii(pFunctionName)); - m_Disasm->SetItem(Item, COLUMN_ADDRESS, wxString::FromAscii(Temp)); - m_Disasm->SetItem(Item, COLUMN_MNEMONIC, wxString::FromAscii(Temp2)); - m_Disasm->SetItem(Item, COLUMN_OPCODE, wxString::FromAscii(op_str.c_str())); - m_Disasm->SetItem(Item, COLUMN_EXT, wxString::FromAscii(pExtension)); - - if (!strcasecmp(op_str.c_str(), "CALL")) - { - u32 FunctionAddress = -1; - sscanf(pParameter, "0x%04x", &FunctionAddress); - - if (m_SymbolMap.find(FunctionAddress) != m_SymbolMap.end()) - { - pParameter = m_SymbolMap[FunctionAddress].Name.c_str(); - } - } - - m_Disasm->SetItem(Item, COLUMN_PARAM, wxString::FromAscii(pParameter)); - - m_Disasm->SetItemData(Item, CurrentPC); - } - -// m_Disasm->SortItems(CompareFunc, this); // TODO verify - - m_Disasm->Thaw(); -} - void DSPDebuggerLLE::UpdateDisAsmListView() { - if (g_dsp.dram == NULL) - return; - - // check if we have to rebuild the list view - if (m_Disasm->GetItemCount() == 0) - { - RebuildDisAsmListView(); - } - else - { - u16 FirstPC = static_cast(m_Disasm->GetItemData(0)); // TODO verify - - if ((FirstPC & 0x8000) != (g_dsp.pc & 0x8000)) - { - RebuildDisAsmListView(); - } - } - if (m_CachedStepCounter == g_dsp.step_counter) return; // show PC FocusOnPC(); - m_CachedStepCounter = g_dsp.step_counter; - m_Regs->Update(); } @@ -320,10 +171,36 @@ void DSPDebuggerLLE::UpdateSymbolMap() m_CachedUCodeCRC = g_dsp.iram_crc; char FileName[256]; sprintf(FileName, "%sDSP_%08x.map", FULL_MAPS_DIR, m_CachedUCodeCRC); - LoadSymbolMap(FileName); + + // LoadSymbolMap(FileName); + + m_SymbolList->Freeze(); // HyperIris: wx style fast filling + m_SymbolList->Clear(); + for (SymbolDB::XFuncMap::iterator iter = DSPSymbols::g_dsp_symbol_db.GetIterator(); + iter != DSPSymbols::g_dsp_symbol_db.End(); iter++) + { + int idx = m_SymbolList->Append(wxString::FromAscii(iter->second.name.c_str())); + m_SymbolList->SetClientData(idx, (void*)&iter->second); + } + m_SymbolList->Thaw(); // rebuild the disasm - RebuildDisAsmListView(); + // RebuildDisAsmListView(); + } +} + +void DSPDebuggerLLE::OnSymbolListChange(wxCommandEvent& event) +{ + int index = m_SymbolList->GetSelection(); + if (index >= 0) { + Symbol* pSymbol = static_cast(m_SymbolList->GetClientData(index)); + if (pSymbol != NULL) + { + if (pSymbol->type == Symbol::SYMBOL_FUNCTION) + { + JumpToAddress(pSymbol->address); + } + } } } @@ -351,13 +228,13 @@ bool DSPDebuggerLLE::CanDoStep() return true; case RUN: - + /* if (IsBreakPoint(g_dsp.pc)) { Refresh(); m_State = PAUSE; return false; - } + }*/ return true; @@ -379,89 +256,32 @@ void DSPDebuggerLLE::DebugBreak() m_State = PAUSE; } -bool DSPDebuggerLLE::IsBreakPoint(u16 _Address) +void DSPDebuggerLLE::OnAddrBoxChange(wxCommandEvent& event) { - return(std::find(m_BreakPoints.begin(), m_BreakPoints.end(), _Address) != m_BreakPoints.end()); -} + wxTextCtrl* pAddrCtrl = (wxTextCtrl*)GetToolBar()->FindControl(ID_ADDRBOX); + wxString txt = pAddrCtrl->GetValue(); -void DSPDebuggerLLE::ToggleBreakPoint(u16 _Address) -{ - if (IsBreakPoint(_Address)) - RemoveBreakPoint(_Address); - else - AddBreakPoint(_Address); -} - -void DSPDebuggerLLE::RemoveBreakPoint(u16 _Address) -{ - CBreakPointList::iterator itr = std::find(m_BreakPoints.begin(), m_BreakPoints.end(), _Address); - - if (itr != m_BreakPoints.end()) - m_BreakPoints.erase(itr); -} - -void DSPDebuggerLLE::AddBreakPoint(u16 _Address) -{ - CBreakPointList::iterator itr = std::find(m_BreakPoints.begin(), m_BreakPoints.end(), _Address); - - if (itr == m_BreakPoints.end()) - m_BreakPoints.push_back(_Address); -} - -void DSPDebuggerLLE::ClearBreakPoints() -{ - m_BreakPoints.clear(); -} - -bool DSPDebuggerLLE::LoadSymbolMap(const char* _pFileName) -{ - m_SymbolMap.clear(); - - FILE* pFile = fopen(_pFileName, "r"); - - if (!pFile) - return false; - - char Name[1024]; - u32 AddressStart, AddressEnd; - - while (!feof(pFile)) + std::string text(txt.mb_str()); + text = StripSpaces(text); + if (text.size()) { - char line[512]; - fgets(line, 511, pFile); - - if (strlen(line) < 2) - continue; - - // check for comment - if (line[0] == '.') - continue; - - // clear all breakpoints - if (line[0] == 'C') - { - ClearBreakPoints(); - continue; - } - - // add breakpoint - if (line[0] == 'B') - { - sscanf(line, "B %04x", &AddressStart); - AddBreakPoint(static_cast(AddressStart)); - continue; - } - - // default add new symbol - sscanf(line, "%04x %04x %s", &AddressStart, &AddressEnd, Name); - - if (m_SymbolMap.find(AddressStart) == m_SymbolMap.end()) - m_SymbolMap.insert(std::pair(AddressStart, SSymbol(AddressStart, AddressEnd, Name))); + u32 addr; + sscanf(text.c_str(), "%04x", &addr); + if (JumpToAddress(addr)) + pAddrCtrl->SetBackgroundColour(*wxWHITE); else - m_SymbolMap[AddressStart] = SSymbol(AddressStart, AddressEnd, Name); + pAddrCtrl->SetBackgroundColour(*wxRED); + } + event.Skip(1); +} + +bool DSPDebuggerLLE::JumpToAddress(u16 addr) +{ + int new_line = DSPSymbols::Addr2Line(addr); + if (new_line >= 0) { + m_CodeView->Center(new_line); + return true; + } else { + return false; } - - fclose(pFile); - - return true; } diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/Debugger/Debugger.h b/Source/Plugins/Plugin_DSP_LLE/Src/Debugger/Debugger.h index f88b29d36b..e0581d1fb1 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Src/Debugger/Debugger.h +++ b/Source/Plugins/Plugin_DSP_LLE/Src/Debugger/Debugger.h @@ -37,8 +37,10 @@ #include "disassemble.h" #include "gdsp_interpreter.h" #include "gdsp_memory.h" +#include "../DSPDebugInterface.h" class DSPRegisterView; +class CCodeView; class DSPDebuggerLLE : public wxFrame { @@ -66,14 +68,16 @@ private: ID_RUNTOOL, ID_STEPTOOL, ID_SHOWPCTOOL, + ID_ADDRBOX, ID_JUMPTOTOOL, ID_DISASMDUMPTOOL, ID_CHECK_ASSERTINT, ID_CHECK_HALT, ID_CHECK_INIT, + ID_SYMBOLLIST, - // Disasm view - ID_DISASM, + // Code view + ID_CODEVIEW, // Register View ID_DSP_REGS, @@ -100,58 +104,32 @@ private: }; EState m_State; + DSPDebugInterface debug_interface; u64 m_CachedStepCounter; u16 m_CachedCR; u32 m_CachedUCodeCRC; - // Break point handling - typedef std::listCBreakPointList; - CBreakPointList m_BreakPoints; - - bool IsBreakPoint(u16 _Address); - void ToggleBreakPoint(u16 _Address); - void RemoveBreakPoint(u16 _Address); - void AddBreakPoint(u16 _Address); - void ClearBreakPoints(); - - // Symbols - struct SSymbol - { - u32 AddressStart; - u32 AddressEnd; - std::string Name; - - SSymbol(u32 _AddressStart = 0, u32 _AddressEnd = 0, char* _Name = NULL) - : AddressStart(_AddressStart) - , AddressEnd(_AddressEnd) - , Name(_Name) - { - } - }; - - typedef std::mapCSymbolMap; - CSymbolMap m_SymbolMap; - - bool LoadSymbolMap(const char* _pFileName); - // GUI updaters void UpdateDisAsmListView(); void UpdateRegisterFlags(); void UpdateSymbolMap(); void UpdateState(); - void RebuildDisAsmListView(); - // GUI items wxToolBar* m_Toolbar; - wxListCtrl* m_Disasm; + CCodeView* m_CodeView; DSPRegisterView* m_Regs; + wxListBox* m_SymbolList; void OnClose(wxCloseEvent& event); void OnChangeState(wxCommandEvent& event); void OnShowPC(wxCommandEvent& event); void OnRightClick(wxListEvent& event); void OnDoubleClick(wxListEvent& event); + void OnAddrBoxChange(wxCommandEvent& event); + void OnSymbolListChange(wxCommandEvent& event); + + bool JumpToAddress(u16 addr); void CreateGUIControls(); void FocusOnPC(); diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/main.cpp b/Source/Plugins/Plugin_DSP_LLE/Src/main.cpp index f3c9f3f204..4b4dabf79d 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Src/main.cpp +++ b/Source/Plugins/Plugin_DSP_LLE/Src/main.cpp @@ -24,6 +24,7 @@ #include "gdsp_interpreter.h" #include "gdsp_interface.h" #include "disassemble.h" +#include "DSPSymbols.h" #include "Config.h" #include "AudioCommon.h" @@ -163,10 +164,10 @@ void DoState(unsigned char **ptr, int mode) void DllDebugger(HWND _hParent, bool Show) { #if defined(HAVE_WX) && HAVE_WX - if(!m_DebuggerFrame) + if (!m_DebuggerFrame) m_DebuggerFrame = new DSPDebuggerLLE(NULL); - if(Show) + if (Show) m_DebuggerFrame->Show(); else m_DebuggerFrame->Hide(); @@ -231,7 +232,7 @@ void Initialize(void *init) soundStream = AudioCommon::InitSoundStream(); #if defined(HAVE_WX) && HAVE_WX - if(m_DebuggerFrame) + if (m_DebuggerFrame) m_DebuggerFrame->Refresh(); #endif } diff --git a/Source/UnitTests/UnitTests.cpp b/Source/UnitTests/UnitTests.cpp index ff1ad824dc..06c8f2fc4c 100644 --- a/Source/UnitTests/UnitTests.cpp +++ b/Source/UnitTests/UnitTests.cpp @@ -96,6 +96,7 @@ void StringTests() EXPECT_EQ(StripNewline(" abc \n "), " abc \n "); EXPECT_EQ(StripQuotes("\"abc\""), "abc"); EXPECT_EQ(StripQuotes("\"abc\" "), "\"abc\" "); + EXPECT_EQ(TabsToSpaces(4, "a\tb"), "a b"); } int main(int argc, _TCHAR* argv[]) diff --git a/Source/UnitTests/UnitTests.vcproj b/Source/UnitTests/UnitTests.vcproj index 86a71847e8..0567258611 100644 --- a/Source/UnitTests/UnitTests.vcproj +++ b/Source/UnitTests/UnitTests.vcproj @@ -323,6 +323,161 @@ ExcludedFromBuild="true" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +