From 2b9aaff641a13c0482581e6918ee467d38055bcf Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 24 Jul 2023 13:05:57 +0300 Subject: [PATCH] portable debugbreak MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ευχαριστώ ροδάκινε Co-Authored-By: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> --- CMakeLists.txt | 2 +- src/Core/PS4/HLE/Kernel/ThreadManagement.cpp | 7 +++--- src/Core/PS4/HLE/LibC.cpp | 13 +++++------ src/Core/PS4/HLE/LibKernel.cpp | 17 ++++++++------- src/Core/PS4/HLE/LibSceVideoOut.cpp | 23 ++++++++++---------- src/Debug.h | 7 ++++++ 6 files changed, 39 insertions(+), 30 deletions(-) create mode 100644 src/Debug.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d6acb9db..2f08fc90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,7 @@ add_executable(shadps4 src/Core/Memory.h src/Core/PS4/Linker.cpp src/Core/PS4/Linker.h - "src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Util/StringUtil.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceVideoOut.cpp" "src/Core/PS4/HLE/LibSceVideoOut.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h") + "src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Util/StringUtil.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceVideoOut.cpp" "src/Core/PS4/HLE/LibSceVideoOut.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h" "src/Debug.h") find_package(OpenGL REQUIRED) target_link_libraries(shadps4 PUBLIC fmt spdlog IMGUI SDL3-shared ${OPENGL_LIBRARY}) diff --git a/src/Core/PS4/HLE/Kernel/ThreadManagement.cpp b/src/Core/PS4/HLE/Kernel/ThreadManagement.cpp index 31a380da..bf0029fb 100644 --- a/src/Core/PS4/HLE/Kernel/ThreadManagement.cpp +++ b/src/Core/PS4/HLE/Kernel/ThreadManagement.cpp @@ -1,5 +1,6 @@ #include "ThreadManagement.h" #include "../ErrorCodes.h" +#include "../../../../Debug.h" namespace HLE::Libs::LibKernel::ThreadManagement { @@ -50,7 +51,7 @@ int scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate) { case 0: pstate = PTHREAD_CREATE_JOINABLE; break; case 1: pstate = PTHREAD_CREATE_DETACHED; break; default: - __debugbreak(); //unknown state + BREAKPOINT(); // unknown state } int result = pthread_attr_setdetachstate(&(*attr)->pth_attr, pstate); @@ -73,7 +74,7 @@ int scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched) { switch (inheritSched) { case 0: pinherit_sched = PTHREAD_EXPLICIT_SCHED; break; case 4: pinherit_sched = PTHREAD_INHERIT_SCHED; break; - default: __debugbreak(); // unknown inheritSched + default: BREAKPOINT(); // unknown inheritSched } int result = pthread_attr_setinheritsched(&(*attr)->pth_attr, pinherit_sched); @@ -115,7 +116,7 @@ int scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) { if (policy!= SCHED_OTHER) { - __debugbreak();//invest if policy is other and if winpthreadlibrary support it + BREAKPOINT(); // invest if policy is other and if winpthreadlibrary support it } (*attr)->policy = policy; diff --git a/src/Core/PS4/HLE/LibC.cpp b/src/Core/PS4/HLE/LibC.cpp index 49e9e586..4cb874db 100644 --- a/src/Core/PS4/HLE/LibC.cpp +++ b/src/Core/PS4/HLE/LibC.cpp @@ -1,6 +1,7 @@ #include "LibC.h" #include "Libs.h" #include "../Loader/Elf.h" +#include "../../../Debug.h" namespace HLE::Libs::LibC { @@ -13,13 +14,13 @@ namespace HLE::Libs::LibC { int PS4_SYSV_ABI __cxa_guard_acquire(u64* guard_object) { - __debugbreak(); + BREAKPOINT(); return 0; } int PS4_SYSV_ABI __cxa_guard_release(u64* guard_object) { - __debugbreak(); + BREAKPOINT(); return 0; } @@ -31,18 +32,16 @@ namespace HLE::Libs::LibC { return ::memcpy(dest, src, n); } - static PS4_SYSV_ABI void catchReturnFromMain(int status) - { __debugbreak(); + static PS4_SYSV_ABI void catchReturnFromMain(int status) { BREAKPOINT(); } - static PS4_SYSV_ABI void exit(int code) - { __debugbreak(); + static PS4_SYSV_ABI void exit(int code) { BREAKPOINT(); } static PS4_SYSV_ABI int atexit(void (*func)()) { int rt = ::atexit(func); if (rt != 0) { - __debugbreak(); + BREAKPOINT(); } return rt; } diff --git a/src/Core/PS4/HLE/LibKernel.cpp b/src/Core/PS4/HLE/LibKernel.cpp index 379eeeb0..081be066 100644 --- a/src/Core/PS4/HLE/LibKernel.cpp +++ b/src/Core/PS4/HLE/LibKernel.cpp @@ -1,6 +1,7 @@ #include "../Loader/Elf.h" #include "LibKernel.h" #include "Libs.h" +#include "../../../Debug.h" namespace HLE::Libs::LibKernel { @@ -8,39 +9,39 @@ namespace HLE::Libs::LibKernel { int PS4_SYSV_ABI sceKernelAllocateDirectMemory(off_t searchStart, off_t searchEnd, size_t len, size_t alignment, int memoryType, off_t* physAddrOut) { - __debugbreak(); + BREAKPOINT(); return 0; // OK } size_t PS4_SYSV_ABI sceKernelGetDirectMemorySize() { - __debugbreak(); + BREAKPOINT(); return 0; } int32_t PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, size_t len, int prot, int flags, off_t directMemoryStart, size_t alignment) { - __debugbreak(); + BREAKPOINT(); return 0; } int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len) { - __debugbreak(); + BREAKPOINT(); return 0; } int PS4_SYSV_ABI sceKernelCreateEqueue(/* SceKernelEqueue* eq*/ int eq, const char* name) { - __debugbreak(); + BREAKPOINT(); return 0; } int PS4_SYSV_ABI sceKernelWaitEqueue(/*SceKernelEqueue eq, SceKernelEvent* ev,*/ int num, int* out /*, SceKernelUseconds* timo*/) { - __debugbreak(); + BREAKPOINT(); return 0; } int PS4_SYSV_ABI sceKernelIsNeoMode() { - __debugbreak(); + BREAKPOINT(); return 0; } - static PS4_SYSV_ABI void stack_chk_fail() { __debugbreak(); + static PS4_SYSV_ABI void stack_chk_fail() { BREAKPOINT(); } void LibKernel_Register(SymbolsResolver* sym) { //obj diff --git a/src/Core/PS4/HLE/LibSceVideoOut.cpp b/src/Core/PS4/HLE/LibSceVideoOut.cpp index ff05a3b4..3b97cfaa 100644 --- a/src/Core/PS4/HLE/LibSceVideoOut.cpp +++ b/src/Core/PS4/HLE/LibSceVideoOut.cpp @@ -1,39 +1,40 @@ #include "LibSceVideoOut.h" #include "Libs.h" #include "../Loader/Elf.h" +#include "../../../Debug.h" namespace HLE::Libs::LibSceVideoOut { int32_t PS4_SYSV_ABI sceVideoOutGetFlipStatus(int32_t handle /*, SceVideoOutFlipStatus* status*/) { - __debugbreak(); + BREAKPOINT(); return 0; } int32_t PS4_SYSV_ABI sceVideoOutSubmitFlip(int32_t handle, int32_t bufferIndex, int32_t flipMode, int64_t flipArg) { - __debugbreak(); + BREAKPOINT(); return 0; } int32_t PS4_SYSV_ABI sceVideoOutRegisterBuffers(int32_t handle, int32_t startIndex, void* const* addresses, int32_t bufferNum /*, const SceVideoOutBufferAttribute* attribute*/) { - __debugbreak(); + BREAKPOINT(); return 0; } int32_t PS4_SYSV_ABI sceVideoOutAddFlipEvent(/*SceKernelEqueue eq,*/ int32_t handle, void* udata) { - __debugbreak(); + BREAKPOINT(); return 0; } int32_t PS4_SYSV_ABI sceVideoOutSetFlipRate(int32_t handle, int32_t rate) { - __debugbreak(); + BREAKPOINT(); return 0; } void PS4_SYSV_ABI sceVideoOutSetBufferAttribute(/* SceVideoOutBufferAttribute* attribute,*/ uint32_t pixelFormat, uint32_t tilingMode, uint32_t aspectRatio, uint32_t width, uint32_t height, uint32_t pitchInPixel) { - __debugbreak(); + BREAKPOINT(); } int32_t PS4_SYSV_ABI sceVideoOutGetResolutionStatus(int32_t handle /*, SceVideoOutResolutionStatus* status*/) { - __debugbreak(); + BREAKPOINT(); return 0; } @@ -42,15 +43,15 @@ namespace HLE::Libs::LibSceVideoOut { { if (busType != 0) { - __debugbreak(); + BREAKPOINT(); } if (index != 0) { - __debugbreak(); + BREAKPOINT(); } if (param != nullptr) { - __debugbreak(); + BREAKPOINT(); } for (;;) { printf("videoopen\n"); @@ -58,7 +59,7 @@ namespace HLE::Libs::LibSceVideoOut { return 0; } int32_t PS4_SYSV_ABI sceVideoOutIsFlipPending(int32_t handle) { - __debugbreak(); + BREAKPOINT(); return 0; } void LibSceVideoOut_Register(SymbolsResolver* sym) diff --git a/src/Debug.h b/src/Debug.h new file mode 100644 index 00000000..a8d1cb12 --- /dev/null +++ b/src/Debug.h @@ -0,0 +1,7 @@ +#ifdef _MSC_VER +#define BREAKPOINT __debugbreak +#elif defined(__GNUC__) +#define BREAKPOINT __builtin_trap +#else +#error What the fuck is this compiler +#endif \ No newline at end of file