2017-08-18 05:08:22 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
|
|
|
* Project64 - A Nintendo 64 emulator. *
|
|
|
|
* http://www.pj64-emu.com/ *
|
|
|
|
* Copyright (C) 2012 Project64. All rights reserved. *
|
|
|
|
* *
|
|
|
|
* License: *
|
|
|
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "DebuggerUI.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <Common/path.h>
|
|
|
|
|
|
|
|
#include "Symbols.h"
|
|
|
|
|
2020-02-11 02:36:30 +00:00
|
|
|
const CSetValueDlg::ComboItem CDebugSymbols::ModalChangeTypeItems[] = {
|
|
|
|
{ "code", SYM_CODE},
|
|
|
|
{ "uint8", SYM_U8 },
|
|
|
|
{ "int8", SYM_S8 },
|
|
|
|
{ "uint16", SYM_U16 },
|
|
|
|
{ "int16", SYM_S16 },
|
|
|
|
{ "uint32", SYM_U32 },
|
|
|
|
{ "int32", SYM_S32 },
|
|
|
|
{ "uint64", SYM_U64 },
|
|
|
|
{ "int64", SYM_S64 },
|
|
|
|
{ "float", SYM_FLOAT },
|
|
|
|
{ "double", SYM_DOUBLE },
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const char* CDebugSymbols::GetTypeName(int m_Type)
|
|
|
|
{
|
|
|
|
switch (m_Type)
|
|
|
|
{
|
|
|
|
case SYM_CODE: return "code";
|
|
|
|
case SYM_DATA: return "data";
|
|
|
|
case SYM_U8: return "uint8";
|
|
|
|
case SYM_U16: return "uint16";
|
|
|
|
case SYM_U32: return "uint32";
|
|
|
|
case SYM_U64: return "uint64";
|
|
|
|
case SYM_S8: return "int8";
|
|
|
|
case SYM_S16: return "int16";
|
|
|
|
case SYM_S32: return "int32";
|
|
|
|
case SYM_S64: return "int64";
|
|
|
|
case SYM_FLOAT: return "float";
|
|
|
|
case SYM_DOUBLE: return "double";
|
|
|
|
case SYM_INVALID: return "invalid";
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-08-18 05:08:22 +00:00
|
|
|
CDebugSymbols::CDebugSymbols(CDebuggerUI * debugger) :
|
2017-09-13 12:00:53 +00:00
|
|
|
CDebugDialog<CDebugSymbols>(debugger)
|
|
|
|
{
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
LRESULT CDebugSymbols::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
DlgResize_Init(false, true);
|
2019-01-14 07:06:01 +00:00
|
|
|
DlgSavePos_Init(DebuggerUI_SymbolsPos);
|
2019-01-13 08:13:59 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
m_SymbolsListView.Attach(GetDlgItem(IDC_SYMBOLS_LIST));
|
|
|
|
m_SymbolsListView.SetExtendedListViewStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
m_SymbolsListView.AddColumn("Address", 0);
|
|
|
|
m_SymbolsListView.AddColumn("Type", 1);
|
|
|
|
m_SymbolsListView.AddColumn("Name", 2);
|
|
|
|
m_SymbolsListView.AddColumn("Value", 3);
|
|
|
|
m_SymbolsListView.AddColumn("Description", 4);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
m_SymbolsListView.SetColumnWidth(0, 70);
|
|
|
|
m_SymbolsListView.SetColumnWidth(1, 40);
|
|
|
|
m_SymbolsListView.SetColumnWidth(2, 120);
|
|
|
|
m_SymbolsListView.SetColumnWidth(3, 100);
|
|
|
|
m_SymbolsListView.SetColumnWidth(4, 120);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
Refresh();
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2019-12-25 00:41:20 +00:00
|
|
|
SetTimer(TIMER_ID_AUTO_REFRESH, 100, NULL);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2019-12-25 00:41:20 +00:00
|
|
|
LoadWindowPos();
|
|
|
|
WindowCreated();
|
2017-09-13 12:00:53 +00:00
|
|
|
return 0;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 05:55:19 +00:00
|
|
|
void CDebugSymbols::OnExitSizeMove(void)
|
|
|
|
{
|
2019-04-19 01:18:55 +00:00
|
|
|
SaveWindowPos(true);
|
2019-01-14 05:55:19 +00:00
|
|
|
}
|
|
|
|
|
2017-08-18 05:08:22 +00:00
|
|
|
LRESULT CDebugSymbols::OnDestroy(void)
|
|
|
|
{
|
2019-12-25 00:41:20 +00:00
|
|
|
KillTimer(TIMER_ID_AUTO_REFRESH);
|
2017-09-13 12:00:53 +00:00
|
|
|
m_SymbolsListView.Detach();
|
|
|
|
return 0;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2019-12-25 00:41:20 +00:00
|
|
|
void CDebugSymbols::OnTimer(UINT_PTR nIDEvent)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2019-12-25 00:41:20 +00:00
|
|
|
if (nIDEvent == TIMER_ID_AUTO_REFRESH)
|
2017-09-13 12:00:53 +00:00
|
|
|
{
|
2019-12-25 00:41:20 +00:00
|
|
|
RefreshValues();
|
2017-09-13 12:00:53 +00:00
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CDebugSymbols::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
switch (wID)
|
|
|
|
{
|
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(0);
|
|
|
|
break;
|
|
|
|
case IDC_ADDSYMBOL_BTN:
|
|
|
|
m_AddSymbolDlg.DoModal(m_Debugger);
|
|
|
|
break;
|
|
|
|
case IDC_REMOVESYMBOL_BTN:
|
|
|
|
{
|
2019-12-25 00:41:20 +00:00
|
|
|
int nItem = m_SymbolsListView.GetSelectedIndex();
|
|
|
|
if (nItem != -1)
|
|
|
|
{
|
|
|
|
int id = m_SymbolsListView.GetItemData(nItem);
|
|
|
|
m_Debugger->SymbolTable()->RemoveSymbolById(id);
|
|
|
|
m_Debugger->SymbolTable()->Save();
|
|
|
|
Refresh();
|
|
|
|
}
|
2017-09-13 12:00:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2019-12-25 00:41:20 +00:00
|
|
|
LRESULT CDebugSymbols::OnListDblClicked(NMHDR* pNMHDR)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2020-02-11 02:36:30 +00:00
|
|
|
if (g_MMU == NULL)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2020-02-11 02:36:30 +00:00
|
|
|
LONG iItem = m_SymbolsListView.GetNextItem(-1, LVNI_SELECTED);
|
|
|
|
if (iItem == -1)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2020-02-11 02:36:30 +00:00
|
|
|
int nSelectedCol = -1;
|
2019-12-25 00:41:20 +00:00
|
|
|
|
2020-02-11 02:36:30 +00:00
|
|
|
// hit test for column
|
|
|
|
|
|
|
|
POINT mousePt;
|
|
|
|
RECT listRect;
|
|
|
|
GetCursorPos(&mousePt);
|
|
|
|
m_SymbolsListView.GetWindowRect(&listRect);
|
|
|
|
|
|
|
|
int mouseX = mousePt.x - listRect.left;
|
|
|
|
|
|
|
|
for (int nCol = 0, colX = 0; nCol < m_SymbolsListView_Num_Columns; nCol++)
|
|
|
|
{
|
|
|
|
int colWidth = m_SymbolsListView.GetColumnWidth(nCol);
|
|
|
|
if (mouseX >= colX && mouseX <= colX + colWidth)
|
|
|
|
{
|
|
|
|
nSelectedCol = nCol;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
colX += colWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
NMITEMACTIVATE* pIA = reinterpret_cast<NMITEMACTIVATE*>(pNMHDR);
|
|
|
|
int nItem = pIA->iItem;
|
|
|
|
int id = m_SymbolsListView.GetItemData(nItem);
|
|
|
|
|
|
|
|
CSymbol symbol;
|
|
|
|
if (!m_Debugger->SymbolTable()->GetSymbolById(id, &symbol))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (nSelectedCol)
|
|
|
|
{
|
|
|
|
case m_SymbolsListView_Col_Address:
|
|
|
|
// Open it in memory viewer/commands viewer
|
|
|
|
if (symbol.m_Type == SYM_CODE) // code
|
|
|
|
{
|
|
|
|
m_Debugger->Debug_ShowCommandsLocation(symbol.m_Address, true);
|
|
|
|
}
|
|
|
|
else // data/number
|
|
|
|
{
|
|
|
|
m_Debugger->Debug_ShowMemoryLocation(symbol.m_Address, true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case m_SymbolsListView_Col_Type:
|
|
|
|
if (m_SetValueDlg.DoModal("Change type", "New type:", symbol.m_Type, ModalChangeTypeItems))
|
|
|
|
{
|
|
|
|
ValueType t = (ValueType)m_SetValueDlg.GetEnteredData();
|
|
|
|
|
|
|
|
//Is there a better way?
|
|
|
|
m_Debugger->SymbolTable()->RemoveSymbolById(id);
|
|
|
|
m_Debugger->SymbolTable()->AddSymbol(t, symbol.m_Address, symbol.m_Name, symbol.m_Description);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case m_SymbolsListView_Col_Name:
|
|
|
|
if (m_SetValueDlg.DoModal("Set name", "New name:", symbol.m_Name))
|
|
|
|
{
|
|
|
|
char* szEnteredString = m_SetValueDlg.GetEnteredString();
|
|
|
|
m_Debugger->SymbolTable()->RemoveSymbolById(id);
|
|
|
|
m_Debugger->SymbolTable()->AddSymbol(symbol.m_Type, symbol.m_Address, szEnteredString, symbol.m_Description);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case m_SymbolsListView_Col_Value:
|
|
|
|
char szValue[64];
|
|
|
|
m_Debugger->SymbolTable()->GetValueString(szValue, &symbol);
|
|
|
|
if (m_SetValueDlg.DoModal("Change value", "New value:", szValue))
|
|
|
|
{
|
|
|
|
switch (symbol.m_Type)
|
|
|
|
{
|
|
|
|
case SYM_U8:
|
|
|
|
m_Debugger->DebugStore_VAddr<uint8_t>(symbol.m_Address, atoi(m_SetValueDlg.GetEnteredString()));
|
|
|
|
break;
|
|
|
|
case SYM_U16:
|
|
|
|
m_Debugger->DebugStore_VAddr<uint16_t>(symbol.m_Address, atoi(m_SetValueDlg.GetEnteredString()));
|
|
|
|
break;
|
|
|
|
case SYM_U32:
|
|
|
|
m_Debugger->DebugStore_VAddr<uint32_t>(symbol.m_Address, atoi(m_SetValueDlg.GetEnteredString()));
|
|
|
|
break;
|
|
|
|
case SYM_U64:
|
|
|
|
m_Debugger->DebugStore_VAddr<uint64_t>(symbol.m_Address, atoll(m_SetValueDlg.GetEnteredString()));
|
|
|
|
break;
|
|
|
|
case SYM_S8:
|
|
|
|
m_Debugger->DebugStore_VAddr<int8_t>(symbol.m_Address, atoi(m_SetValueDlg.GetEnteredString()));
|
|
|
|
break;
|
|
|
|
case SYM_S16:
|
|
|
|
m_Debugger->DebugStore_VAddr<int16_t>(symbol.m_Address, atoi(m_SetValueDlg.GetEnteredString()));
|
|
|
|
break;
|
|
|
|
case SYM_S32:
|
|
|
|
m_Debugger->DebugStore_VAddr<int>(symbol.m_Address, atoi(m_SetValueDlg.GetEnteredString()));
|
|
|
|
break;
|
|
|
|
case SYM_S64:
|
|
|
|
m_Debugger->DebugStore_VAddr<int64_t>(symbol.m_Address, atoll(m_SetValueDlg.GetEnteredString()));
|
|
|
|
break;
|
|
|
|
case SYM_FLOAT:
|
|
|
|
m_Debugger->DebugStore_VAddr<float>(symbol.m_Address, atof(m_SetValueDlg.GetEnteredString()));
|
|
|
|
break;
|
|
|
|
case SYM_DOUBLE:
|
|
|
|
m_Debugger->DebugStore_VAddr<double>(symbol.m_Address, atof(m_SetValueDlg.GetEnteredString()));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case m_SymbolsListView_Col_Description:
|
|
|
|
if (m_SetValueDlg.DoModal("Set description", "New description:", symbol.m_Description))
|
|
|
|
{
|
|
|
|
char* szEnteredString = m_SetValueDlg.GetEnteredString();
|
|
|
|
m_Debugger->SymbolTable()->RemoveSymbolById(id);
|
|
|
|
m_Debugger->SymbolTable()->AddSymbol(symbol.m_Type, symbol.m_Address, symbol.m_Name, szEnteredString);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Debugger->SymbolTable()->Save();
|
|
|
|
Refresh();
|
2017-09-13 12:00:53 +00:00
|
|
|
|
|
|
|
return 0;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugSymbols::Refresh()
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (m_SymbolsListView.m_hWnd == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_SymbolsListView.SetRedraw(FALSE);
|
|
|
|
m_SymbolsListView.DeleteAllItems();
|
|
|
|
|
2019-12-25 00:41:20 +00:00
|
|
|
CSymbol symbol;
|
|
|
|
int nItem = 0;
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2019-12-25 00:41:20 +00:00
|
|
|
while (m_Debugger->SymbolTable()->GetSymbolByIndex(nItem, &symbol))
|
2017-09-13 12:00:53 +00:00
|
|
|
{
|
2019-12-25 00:41:20 +00:00
|
|
|
char szValue[64];
|
|
|
|
m_Debugger->SymbolTable()->GetValueString(szValue, &symbol);
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2019-12-25 00:41:20 +00:00
|
|
|
stdstr strAddr = stdstr_f("%08X", symbol.m_Address);
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2019-12-25 00:41:20 +00:00
|
|
|
m_SymbolsListView.AddItem(nItem, 0, strAddr.c_str());
|
|
|
|
m_SymbolsListView.AddItem(nItem, 1, symbol.TypeName());
|
|
|
|
m_SymbolsListView.AddItem(nItem, 2, symbol.m_Name);
|
|
|
|
m_SymbolsListView.AddItem(nItem, 4, symbol.m_Description);
|
|
|
|
m_SymbolsListView.AddItem(nItem, 5, szValue);
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2019-12-25 00:41:20 +00:00
|
|
|
m_SymbolsListView.SetItemData(nItem, symbol.m_Id);
|
|
|
|
nItem++;
|
2017-09-13 12:00:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_SymbolsListView.SetRedraw(TRUE);
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugSymbols::RefreshValues()
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (g_MMU == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
int count = m_SymbolsListView.GetItemCount();
|
2019-12-25 00:41:20 +00:00
|
|
|
|
|
|
|
CSymbol symbol;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
int symbolId = m_SymbolsListView.GetItemData(i);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2019-12-25 00:41:20 +00:00
|
|
|
if (!m_Debugger->SymbolTable()->GetSymbolById(symbolId, &symbol))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
char szValue[64];
|
2019-12-25 00:41:20 +00:00
|
|
|
m_Debugger->SymbolTable()->GetValueString(szValue, &symbol);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
m_SymbolsListView.SetItemText(i, 3, szValue);
|
|
|
|
}
|
2019-12-25 00:41:20 +00:00
|
|
|
}
|