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"
|
2017-08-30 04:54:06 +00:00
|
|
|
#include "Symbols.h"
|
2017-08-18 05:08:22 +00:00
|
|
|
|
|
|
|
CDebugStackTrace::CDebugStackTrace(CDebuggerUI* debugger) :
|
2017-08-30 04:54:06 +00:00
|
|
|
CDebugDialog<CDebugStackTrace>(debugger),
|
|
|
|
m_EntriesIndex(0)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CDebugStackTrace::~CDebugStackTrace()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-08-30 04:54:06 +00:00
|
|
|
void CDebugStackTrace::PushEntry(uint32_t routineAddress, uint32_t callingAddress)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-08-30 04:54:06 +00:00
|
|
|
if (m_EntriesIndex < STACKTRACE_MAX_ENTRIES)
|
|
|
|
{
|
|
|
|
m_Entries[m_EntriesIndex] = { routineAddress, callingAddress };
|
|
|
|
m_EntriesIndex++;
|
|
|
|
}
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-08-30 04:54:06 +00:00
|
|
|
void CDebugStackTrace::PopEntry()
|
|
|
|
{
|
|
|
|
if (m_EntriesIndex > 0)
|
|
|
|
{
|
|
|
|
m_EntriesIndex--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugStackTrace::ClearEntries()
|
|
|
|
{
|
|
|
|
m_EntriesIndex = 0;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-08-30 04:54:06 +00:00
|
|
|
LRESULT CDebugStackTrace::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
|
|
|
{
|
|
|
|
DlgResize_Init();
|
|
|
|
|
2017-08-18 05:08:22 +00:00
|
|
|
m_List.Attach(GetDlgItem(IDC_STACKTRACE_LIST));
|
2017-08-30 04:54:06 +00:00
|
|
|
m_List.AddColumn("Caller", 0);
|
|
|
|
m_List.AddColumn("Routine", 1);
|
|
|
|
m_List.AddColumn("Name", 2);
|
|
|
|
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-08-30 04:54:06 +00:00
|
|
|
m_List.SetColumnWidth(0, 70);
|
|
|
|
m_List.SetColumnWidth(1, 70);
|
|
|
|
m_List.SetColumnWidth(2, 160);
|
|
|
|
|
|
|
|
m_List.SetExtendedListViewStyle(LVS_EX_FULLROWSELECT);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
|
|
|
WindowCreated();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-01-18 06:53:07 +00:00
|
|
|
LRESULT CDebugStackTrace::OnActivate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-08-30 04:54:06 +00:00
|
|
|
Refresh();
|
2017-08-18 05:08:22 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CDebugStackTrace::OnDestroy(void)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
m_List.Detach();
|
2017-08-18 05:08:22 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CDebugStackTrace::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
|
|
|
|
{
|
|
|
|
switch (wID)
|
|
|
|
{
|
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CDebugStackTrace::OnListDblClicked(NMHDR* pNMHDR)
|
|
|
|
{
|
|
|
|
NMITEMACTIVATE* pIA = reinterpret_cast<NMITEMACTIVATE*>(pNMHDR);
|
|
|
|
int nItem = pIA->iItem;
|
|
|
|
|
|
|
|
uint32_t address = m_List.GetItemData(nItem);
|
|
|
|
|
|
|
|
m_Debugger->Debug_ShowCommandsLocation(address, true);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-30 04:54:06 +00:00
|
|
|
void CDebugStackTrace::Refresh()
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2018-01-15 21:14:15 +00:00
|
|
|
if (!isStepping())
|
2017-08-30 04:54:06 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetWindowText(stdstr_f("Stack Trace (%d)", m_EntriesIndex).c_str());
|
2017-08-18 05:08:22 +00:00
|
|
|
|
|
|
|
m_List.SetRedraw(FALSE);
|
|
|
|
m_List.DeleteAllItems();
|
|
|
|
|
2017-08-30 04:54:06 +00:00
|
|
|
CSymbols::EnterCriticalSection();
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-08-30 04:54:06 +00:00
|
|
|
for (int i = 0; i < m_EntriesIndex; i++)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-08-30 04:54:06 +00:00
|
|
|
uint32_t routineAddress = m_Entries[i].routineAddress;
|
|
|
|
uint32_t callingAddress = m_Entries[i].callingAddress;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-08-30 04:54:06 +00:00
|
|
|
char szAddress[9];
|
|
|
|
sprintf(szAddress, "%08X", callingAddress);
|
2017-08-18 05:08:22 +00:00
|
|
|
m_List.AddItem(i, 0, szAddress);
|
|
|
|
|
2017-08-30 04:54:06 +00:00
|
|
|
sprintf(szAddress, "%08X", routineAddress);
|
|
|
|
m_List.AddItem(i, 1, szAddress);
|
|
|
|
|
|
|
|
CSymbolEntry* symbol = CSymbols::GetEntryByAddress(routineAddress);
|
|
|
|
if(symbol != NULL)
|
|
|
|
{
|
|
|
|
m_List.AddItem(i, 2, symbol->m_Name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_List.AddItem(i, 2, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
m_List.SetItemData(i, routineAddress);
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2017-08-30 04:54:06 +00:00
|
|
|
CSymbols::LeaveCriticalSection();
|
|
|
|
|
2017-08-18 05:08:22 +00:00
|
|
|
m_List.SetRedraw(TRUE);
|
|
|
|
}
|