debug.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright 2010-2017 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  4. */
  5. #include <bx/bx.h>
  6. #if BX_PLATFORM_ANDROID
  7. # include <android/log.h>
  8. #elif BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT || BX_PLATFORM_XBOX360 || BX_PLATFORM_XBOXONE
  9. extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char* _str);
  10. #elif BX_PLATFORM_IOS || BX_PLATFORM_OSX
  11. # if defined(__OBJC__)
  12. # import <Foundation/NSObjCRuntime.h>
  13. # else
  14. # include <CoreFoundation/CFString.h>
  15. extern "C" void NSLog(CFStringRef _format, ...);
  16. # endif // defined(__OBJC__)
  17. #elif 0 // BX_PLATFORM_EMSCRIPTEN
  18. # include <emscripten.h>
  19. #else
  20. # include <stdio.h>
  21. #endif // BX_PLATFORM_WINDOWS
  22. namespace bx
  23. {
  24. void debugBreak()
  25. {
  26. #if BX_COMPILER_MSVC
  27. __debugbreak();
  28. #elif BX_CPU_ARM
  29. __builtin_trap();
  30. // asm("bkpt 0");
  31. #elif !BX_PLATFORM_NACL && BX_CPU_X86 && (BX_COMPILER_GCC || BX_COMPILER_CLANG)
  32. // NaCl doesn't like int 3:
  33. // NativeClient: NaCl module load failed: Validation failure. File violates Native Client safety rules.
  34. __asm__ ("int $3");
  35. #else // cross platform implementation
  36. int* int3 = (int*)3L;
  37. *int3 = 3;
  38. #endif // BX
  39. }
  40. void debugOutput(const char* _out)
  41. {
  42. #if BX_PLATFORM_ANDROID
  43. # ifndef BX_ANDROID_LOG_TAG
  44. # define BX_ANDROID_LOG_TAG ""
  45. # endif // BX_ANDROID_LOG_TAG
  46. __android_log_write(ANDROID_LOG_DEBUG, BX_ANDROID_LOG_TAG, _out);
  47. #elif BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT || BX_PLATFORM_XBOX360 || BX_PLATFORM_XBOXONE
  48. OutputDebugStringA(_out);
  49. #elif BX_PLATFORM_IOS || BX_PLATFORM_OSX
  50. # if defined(__OBJC__)
  51. NSLog(@"%s", _out);
  52. # else
  53. NSLog(__CFStringMakeConstantString("%s"), _out);
  54. # endif // defined(__OBJC__)
  55. #elif 0 // BX_PLATFORM_EMSCRIPTEN
  56. emscripten_log(EM_LOG_CONSOLE, "%s", _out);
  57. #else
  58. fputs(_out, stdout);
  59. fflush(stdout);
  60. #endif // BX_PLATFORM_
  61. }
  62. } // namespace bx