Pierre Bourdon e149ad4f0a
treewide: convert GPLv2+ license info to SPDX tags
SPDX standardizes how source code conveys its copyright and licensing
information. See https://spdx.github.io/spdx-spec/1-rationale/ . SPDX
tags are adopted in many large projects, including things like the Linux
kernel.
2021-07-05 04:35:56 +02:00

66 lines
1.1 KiB
C++

// Copyright 2008 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "Core/Debugger/Dump.h"
#include <cstdio>
#include <string>
#include "Common/CommonTypes.h"
#include "Common/IOFile.h"
CDump::CDump(const std::string& filename) : m_pData(nullptr)
{
File::IOFile pStream(filename, "rb");
if (pStream)
{
m_size = (size_t)pStream.GetSize();
m_pData = new u8[m_size];
pStream.ReadArray(m_pData, m_size);
}
}
CDump::~CDump()
{
if (m_pData != nullptr)
{
delete[] m_pData;
m_pData = nullptr;
}
}
int CDump::GetNumberOfSteps()
{
return (int)(m_size / STRUCTUR_SIZE);
}
u32 CDump::GetGPR(int _step, int _gpr)
{
u32 offset = _step * STRUCTUR_SIZE;
if (offset >= m_size)
return UINT32_MAX;
return Read32(offset + OFFSET_GPR + (_gpr * 4));
}
u32 CDump::GetPC(int _step)
{
u32 offset = _step * STRUCTUR_SIZE;
if (offset >= m_size)
return UINT32_MAX;
return Read32(offset + OFFSET_PC);
}
u32 CDump::Read32(u32 _pos)
{
u32 result = (m_pData[_pos + 0] << 24) | (m_pData[_pos + 1] << 16) | (m_pData[_pos + 2] << 8) |
(m_pData[_pos + 3] << 0);
return result;
}