2019-12-10 12:39:39 +00:00
|
|
|
#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)
|
2019-12-10 12:39:39 +00:00
|
|
|
, m_biosDebugInfoProvider(biosDebugInfoProvider)
|
|
|
|
{
|
2019-12-09 21:33:04 +00:00
|
|
|
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
|
|
|
|
2019-12-10 12:39:39 +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();
|
2019-12-10 12:39:39 +00:00
|
|
|
|
|
|
|
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");
|
2019-12-10 12:39:39 +00:00
|
|
|
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-10 12:39:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|