Play-/Source/ui_qt/DebugSupport/CallStackWnd.cpp

62 lines
1.5 KiB
C++
Raw Permalink Normal View History

#include "CallStackWnd.h"
#include "string_cast.h"
#include "lexical_cast_ex.h"
#include "DebugUtils.h"
#include "MIPS.h"
#include "BiosDebugInfoProvider.h"
#include <QVBoxLayout>
#include <QLabel>
2020-02-05 21:33:18 +00:00
CCallStackWnd::CCallStackWnd(QWidget* parent, CMIPS* context, CBiosDebugInfoProvider* biosDebugInfoProvider)
: QListWidget(parent)
2019-12-19 21:37:47 +00:00
, m_context(context)
, m_biosDebugInfoProvider(biosDebugInfoProvider)
{
resize(320, 750);
2020-02-05 21:33:18 +00:00
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
connect(this, &QListWidget::itemDoubleClicked, this, &CCallStackWnd::listDoubleClick);
2019-12-09 20:33:21 +00:00
Update();
}
void CCallStackWnd::HandleMachineStateChange()
{
Update();
}
void CCallStackWnd::Update()
{
uint32 nPC = m_context->m_State.nPC;
uint32 nRA = m_context->m_State.nGPR[CMIPS::RA].nV[0];
uint32 nSP = m_context->m_State.nGPR[CMIPS::SP].nV[0];
2020-02-05 21:33:18 +00:00
clear();
auto callStackItems = CMIPSAnalysis::GetCallStack(m_context, nPC, nSP, nRA);
if(callStackItems.size() == 0)
{
2020-02-05 21:33:18 +00:00
addItem("Call stack unavailable at this state");
return;
}
auto modules = m_biosDebugInfoProvider ? m_biosDebugInfoProvider->GetModulesDebugInfo() : BiosDebugModuleInfoArray();
for(const auto& callStackItem : callStackItems)
{
auto locationString = DebugUtils::PrintAddressLocation(callStackItem, m_context, modules);
2020-02-05 21:33:18 +00:00
addItem(locationString.c_str());
}
}
2019-12-19 21:37:47 +00:00
void CCallStackWnd::listDoubleClick(QListWidgetItem* item)
2019-12-09 20:33:21 +00:00
{
std::string addressStr = item->text().toStdString();
uint32 nAddress = lexical_cast_hex(addressStr);
if(nAddress != MIPS_INVALID_PC)
{
OnFunctionDblClick(nAddress);
}
}