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
This commit is contained in:
hrydgard
2009-06-21 08:39:21 +00:00
parent 80217a6ed7
commit aecaf271f1
76 changed files with 1895 additions and 794 deletions

View File

@ -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;
}
}
}

View File

@ -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");

View File

@ -45,7 +45,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../Core/DSPCore/Src;../../Core/Common/Src;../../PluginSpecs;../../Core/AudioCommon/Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc"
AdditionalIncludeDirectories="../../Core/DSPCore/Src;../../Core/Common/Src;../../PluginSpecs;../../Core/AudioCommon/Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc;..\..\Core\Debugger\Src;../../Core/DebuggerUICommon/Src"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;DSP_LLE_TEST_EXPORTS;_SECURE_SCL=0"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@ -132,7 +132,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../Core/DSPCore/Src;../../Core/Common/Src;../../PluginSpecs;../../Core/AudioCommon/Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc"
AdditionalIncludeDirectories="../../Core/DSPCore/Src;../../Core/Common/Src;../../PluginSpecs;../../Core/AudioCommon/Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc;..\..\Core\Debugger\Src;../../Core/DebuggerUICommon/Src"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;DSP_LLE_TEST_EXPORTS;_SECURE_SCL=0"
MinimalRebuild="false"
BasicRuntimeChecks="0"
@ -222,7 +222,7 @@
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="../../Core/DSPCore/Src;../../Core/Common/Src;../../PluginSpecs;../../Core/AudioCommon/Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc"
AdditionalIncludeDirectories="../../Core/DSPCore/Src;../../Core/Common/Src;../../PluginSpecs;../../Core/AudioCommon/Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc;..\..\Core\Debugger\Src;../../Core/DebuggerUICommon/Src"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;DSP_LLE_TEST_EXPORTS;_SECURE_SCL=0"
RuntimeLibrary="0"
EnableEnhancedInstructionSet="2"
@ -314,7 +314,7 @@
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="../../Core/DSPCore/Src;../../Core/Common/Src;../../PluginSpecs;../../Core/AudioCommon/Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc"
AdditionalIncludeDirectories="../../Core/DSPCore/Src;../../Core/Common/Src;../../PluginSpecs;../../Core/AudioCommon/Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc;..\..\Core\Debugger\Src;../../Core/DebuggerUICommon/Src"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;DSP_LLE_TEST_EXPORTS;_SECURE_SCL=0"
RuntimeLibrary="0"
UsePrecompiledHeader="2"
@ -403,8 +403,8 @@
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="../../Core/DSPCore/Src;../../Core/Common/Src;../../PluginSpecs;../../Core/AudioCommon/Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;DSP_LLE_TEST_EXPORTS;DEBUGFAST;_SECURE_SCL=0"
AdditionalIncludeDirectories="../../Core/DSPCore/Src;../../Core/Common/Src;../../PluginSpecs;../../Core/AudioCommon/Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc;..\..\Core\Debugger\Src;../../Core/DebuggerUICommon/Src"
PreprocessorDefinitions="LOGGING;WIN32;NDEBUG;_WINDOWS;_USRDLL;DSP_LLE_TEST_EXPORTS;DEBUGFAST;_SECURE_SCL=0"
RuntimeLibrary="0"
EnableEnhancedInstructionSet="2"
UsePrecompiledHeader="2"
@ -495,8 +495,8 @@
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="../../Core/DSPCore/Src;../../Core/Common/Src;../../PluginSpecs;../../Core/AudioCommon/Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;DSP_LLE_TEST_EXPORTS;DEBUGFAST;_SECURE_SCL=0"
AdditionalIncludeDirectories="../../Core/DSPCore/Src;../../Core/Common/Src;../../PluginSpecs;../../Core/AudioCommon/Src;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc;..\..\Core\Debugger\Src;../../Core/DebuggerUICommon/Src"
PreprocessorDefinitions="LOGGING;WIN32;NDEBUG;_WINDOWS;_USRDLL;DSP_LLE_TEST_EXPORTS;DEBUGFAST;_SECURE_SCL=0"
RuntimeLibrary="0"
UsePrecompiledHeader="2"
AssemblerListingLocation="$(IntDir)\"
@ -826,6 +826,14 @@
RelativePath=".\Src\Debugger\DSPRegisterView.h"
>
</File>
<File
RelativePath=".\Src\DSPSymbols.cpp"
>
</File>
<File
RelativePath=".\Src\DSPSymbols.h"
>
</File>
</Filter>
<File
RelativePath=".\Src\Config.cpp"
@ -835,14 +843,6 @@
RelativePath=".\Src\Config.h"
>
</File>
<File
RelativePath="..\..\Core\DSPCore\Src\DSPConfigDlgLLE.cpp"
>
</File>
<File
RelativePath="..\..\Core\DSPCore\Src\DSPConfigDlgLLE.h"
>
</File>
<File
RelativePath=".\Src\DSPHost.cpp"
>

View File

@ -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, "<unknown>");
}*/
// 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, "<unknwn>"); // 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()

View File

@ -3,7 +3,7 @@
#include <string>
#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);

View File

@ -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;
}

View File

@ -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 <iostream> // I hope this doesn't break anything
#include <stdio.h>
#include <stdarg.h>
#include <list>
#include <map>
#include <string>
#include "Common.h"
#include "StringUtil.h"
#include "DSPCore.h"
#include "DSPSymbols.h"
#include "disassemble.h"
namespace DSPSymbols {
DSPSymbolDB g_dsp_symbol_db;
std::map<u16, int> addr_to_line;
std::map<int, u16> line_to_addr;
std::map<int, const char *> line_to_symbol;
std::vector<std::string> lines;
int line_counter = 0;
int Addr2Line(u16 address) // -1 for not found
{
std::map<u16, int>::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<int, u16>::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

View File

@ -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 <stdio.h>
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

View File

@ -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<u16>(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<u16>(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<u16>(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<Symbol *>(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<u16>(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<u16, SSymbol>(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;
}

View File

@ -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::list<u16>CBreakPointList;
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::map<u16, SSymbol>CSymbolMap;
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();

View File

@ -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
}