shadps4-emu / shadPS4

PS4 emulator for Windows,Linux,MacOS
https://shadps4.net/
GNU General Public License v2.0
11.14k stars 712 forks source link

[Debug] <Critical> scalar_memory.cpp: unreachable code #1582

Open gandalth opened 1 week ago

gandalth commented 1 week ago

CUSA16194 DIRT 5: shadps4 crashes on startup with this debug information:

[Render.Vulkan] vk_pipeline_cache.cpp:CompileModule:405: Compiling cs shader 0xf69de71c [Render.Vulkan] vk_pipeline_cache.cpp:CompileModule:405: Compiling cs shader 0x394fe8e8 [Core] stubs.cpp:CommonStub:42: Stub: scePthreadSetaffinity (nid: bt3CTBKmGyI) called, returning zero to 0x90068ae09 [Render.Vulkan] vk_pipeline_cache.cpp:CompileModule:405: Compiling cs shader 0x385a8cf7 [Render.Vulkan] vk_pipeline_cache.cpp:CompileModule:405: Compiling cs shader 0x385a8cf7

[Debug] \<Critical> scalar_memory.cpp:operator():49: Unreachable code! Trace/breakpoint trap

polybiusproxy commented 1 week ago

https://github.com/shadps4-emu/shadPS4/blob/main/src/shader_recompiler/frontend/translate/scalar_memory.cpp#L41 Can you debug what is smrd at the time of the unreachable?

gandalth commented 1 week ago

Sure, happy to help!

Would I have to recompile in order to do that? My current build (on Linux Debian Testing) has been compiled like this:

cmake .. -DCMAKE_C_COMPILER=clang-19 -DCMAKE_CXX_COMPILER=clang++-19 -DENABLE_DISCORD_RPC=OFF -DENABLE_QT_GUI=ON

Can I use gdb to debug or do you recommend something else?

polybiusproxy commented 1 week ago

I'm not quite knowledgeable about Linux, but I'd recommend setting up Visual Studio Code and GDB to make debugging (and most things over all) easier

gandalth commented 1 week ago

I recompiled with -DCMAKE_BUILD_TYPE=DEBUG and used ddd/gdb to add a breakpoint.

In ddd, shadps4 receives a SEGFAULT in GAME_MainThread before I reach the UNREACHABLE(). The last smrd I see before that (but does not lead to the UNREACHABLE()) has offset=0, imm=1, count=8.

polybiusproxy commented 1 week ago

That one looks correct, but I'm interested in the one that leads to the UNREACHABLE()

gandalth commented 1 week ago

This one leads to UNREACHABLE():

smrd.offset = 1 smrd.imm = 0 smrd.count = 4

SQ_SRC_LITERAL = 255

gandalth commented 3 days ago

@polybiusproxy : can I help more in finding how we got into the incorrect smrd? I can easily add more debug output in my local copy.