summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2023-02-20 02:26:23 +0100
committerGitHub <noreply@github.com>2023-02-20 02:26:23 +0100
commitae7fc074f87a38cbeb570424693cf2635d7ada71 (patch)
tree4a8cadb24e047f3331a9e3ebd73df5aa394769f4 /Source/Core
parent45b55f7ccd19a8f71c7b98d14f00668932a3bf50 (diff)
parent4e6e5100031ad6d52207f0ca9c276e695c5e784b (diff)
Merge pull request #11398 from SeekyCt/conditional-bp-streq
Debugger: Add string comparison to conditional breakpoints
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/PowerPC/Expression.cpp40
-rw-r--r--Source/Core/DolphinQt/Debugger/BreakpointDialog.cpp5
2 files changed, 42 insertions, 3 deletions
diff --git a/Source/Core/Core/PowerPC/Expression.cpp b/Source/Core/Core/PowerPC/Expression.cpp
index 7966d75982..ce8cdcd240 100644
--- a/Source/Core/Core/PowerPC/Expression.cpp
+++ b/Source/Core/Core/PowerPC/Expression.cpp
@@ -135,7 +135,44 @@ static double CallstackFunc(expr_func* f, vec_expr_t* args, void* c)
return 0;
}
-static std::array<expr_func, 22> g_expr_funcs{{
+static std::optional<std::string> ReadStringArg(const Core::CPUThreadGuard& guard, expr* e)
+{
+ double num = expr_eval(e);
+ if (!std::isnan(num))
+ {
+ u32 address = static_cast<u32>(num);
+ return PowerPC::HostGetString(guard, address);
+ }
+
+ const char* cstr = expr_get_str(e);
+ if (cstr != nullptr)
+ {
+ return std::string(cstr);
+ }
+
+ return std::nullopt;
+}
+
+static double StreqFunc(expr_func* f, vec_expr_t* args, void* c)
+{
+ if (vec_len(args) != 2)
+ return 0;
+
+ const auto* guard = reinterpret_cast<const Core::CPUThreadGuard*>(c);
+ std::array<std::string, 2> strs;
+ for (int i = 0; i < 2; i++)
+ {
+ std::optional<std::string> arg = ReadStringArg(*guard, &vec_nth(args, i));
+ if (arg == std::nullopt)
+ return 0;
+
+ strs[i] = std::move(*arg);
+ }
+
+ return strs[0] == strs[1];
+}
+
+static std::array<expr_func, 23> g_expr_funcs{{
// For internal storage and comparisons, everything is auto-converted to Double.
// If u64 ints are added, this could produce incorrect results.
{"read_u8", HostReadFunc<u8>},
@@ -158,6 +195,7 @@ static std::array<expr_func, 22> g_expr_funcs{{
{"u32", CastFunc<u32>},
{"s32", CastFunc<s32, u32>},
{"callstack", CallstackFunc},
+ {"streq", StreqFunc},
{},
}};
diff --git a/Source/Core/DolphinQt/Debugger/BreakpointDialog.cpp b/Source/Core/DolphinQt/Debugger/BreakpointDialog.cpp
index f3472beeee..78611f7d45 100644
--- a/Source/Core/DolphinQt/Debugger/BreakpointDialog.cpp
+++ b/Source/Core/DolphinQt/Debugger/BreakpointDialog.cpp
@@ -337,6 +337,7 @@ void BreakpointDialog::ShowConditionHelp()
"Set a register: r1 = 8\n"
"Casts: s8(0xff). Available: s8, u8, s16, u16, s32, u32\n"
"Callstack: callstack(0x80123456), callstack(\"anim\")\n"
+ "Compare Strings: streq(r3, \"abc\"). Both parameters can be addresses or string constants.\n"
"Read Memory: read_u32(0x80000000). Available: u8, s8, u16, s16, u32, s32, f32, f64\n"
"Write Memory: write_u32(r3, 0x80000000). Available: u8, u16, u32, f32, f64\n"
"*currently writing will always be triggered\n"
@@ -355,8 +356,8 @@ void BreakpointDialog::ShowConditionHelp()
"Write and break: r4 = 8, 1\n"
"Write and continue: f3 = f1 + f2, 0\n"
"The condition must always be last\n\n"
- "Strings should only be used in callstack() and \"quoted\". Do not assign strings to a "
- "variable.\n"
+ "Strings should only be used in callstack() or streq() and \"quoted\". Do not assign strings "
+ "to a variable.\n"
"All variables will be printed in the Memory Interface log, if there's a hit or a NaN "
"result. To check for issues, assign a variable to your equation, so it can be printed.\n\n"
"Note: All values are internally converted to Doubles for calculations. It's possible for "