mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-05-10 04:01:18 +02:00

This fixes a problem I was having where using frame advance with the debugger open would frequently cause panic alerts about invalid addresses due to the CPU thread changing MSR.DR while the host thread was trying to access memory. To aid in tracking down all the places where we weren't properly locking the CPU, I've created a new type (in Core.h) that you have to pass as a reference or pointer to functions that require running as the CPU thread.
80 lines
1.4 KiB
C++
80 lines
1.4 KiB
C++
// Copyright 2020 Dolphin Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
struct expr;
|
|
struct expr_var_list;
|
|
|
|
namespace Core
|
|
{
|
|
class CPUThreadGuard;
|
|
}
|
|
|
|
struct ExprDeleter
|
|
{
|
|
void operator()(expr* expression) const;
|
|
};
|
|
|
|
using ExprPointer = std::unique_ptr<expr, ExprDeleter>;
|
|
|
|
struct ExprVarListDeleter
|
|
{
|
|
void operator()(expr_var_list* vars) const;
|
|
};
|
|
|
|
using ExprVarListPointer = std::unique_ptr<expr_var_list, ExprVarListDeleter>;
|
|
|
|
class Expression
|
|
{
|
|
public:
|
|
static std::optional<Expression> TryParse(std::string_view text);
|
|
|
|
double Evaluate() const;
|
|
|
|
std::string GetText() const;
|
|
|
|
private:
|
|
enum class SynchronizeDirection
|
|
{
|
|
From,
|
|
To,
|
|
};
|
|
|
|
enum class VarBindingType
|
|
{
|
|
Zero,
|
|
GPR,
|
|
FPR,
|
|
SPR,
|
|
PCtr,
|
|
};
|
|
|
|
struct VarBinding
|
|
{
|
|
VarBindingType type = VarBindingType::Zero;
|
|
int index = -1;
|
|
};
|
|
|
|
Expression(std::string_view text, ExprPointer ex, ExprVarListPointer vars);
|
|
|
|
void SynchronizeBindings(SynchronizeDirection dir) const;
|
|
void Reporting(const double result) const;
|
|
|
|
std::string m_text;
|
|
ExprPointer m_expr;
|
|
ExprVarListPointer m_vars;
|
|
std::vector<VarBinding> m_binds;
|
|
};
|
|
|
|
inline bool EvaluateCondition(const std::optional<Expression>& condition)
|
|
{
|
|
return !condition || condition->Evaluate() != 0.0;
|
|
}
|