debug.h 1.7 KB

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