From 0e54f1a39867ed3c7b46d2e1937caaa8ffa591c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sun, 18 Feb 2018 21:13:29 -0800 Subject: [PATCH] Added debugOutput for crt0. --- include/bx/bx.h | 1 - include/bx/debug.h | 5 ++++- src/bx_p.h | 1 + src/debug.cpp | 53 +++++++++++++++++++++++++++------------------- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/include/bx/bx.h b/include/bx/bx.h index a819eca..64e57a5 100644 --- a/include/bx/bx.h +++ b/include/bx/bx.h @@ -15,7 +15,6 @@ #include "platform.h" #include "config.h" #include "macros.h" -#include "debug.h" /// #define BX_COUNTOF(_x) sizeof(bx::COUNTOF_REQUIRES_ARRAY_ARGUMENT(_x) ) diff --git a/include/bx/debug.h b/include/bx/debug.h index adba3f2..80efaf9 100644 --- a/include/bx/debug.h +++ b/include/bx/debug.h @@ -6,7 +6,7 @@ #ifndef BX_DEBUG_H_HEADER_GUARD #define BX_DEBUG_H_HEADER_GUARD -#include "bx.h" +#include "string.h" namespace bx { @@ -16,6 +16,9 @@ namespace bx /// void debugOutput(const char* _out); + /// + void debugOutput(const StringView& _str); + /// void debugPrintfVargs(const char* _format, va_list _argList); diff --git a/src/bx_p.h b/src/bx_p.h index 7c38557..d4b0008 100644 --- a/src/bx_p.h +++ b/src/bx_p.h @@ -40,5 +40,6 @@ BX_MACRO_BLOCK_END #include +#include #endif // BX_P_H_HEADER_GUARD diff --git a/src/debug.cpp b/src/debug.cpp index f4ba187..76453f3 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -9,7 +9,9 @@ #include // WriterI #include // PRIx* -#if BX_PLATFORM_ANDROID +#if BX_CRT_NONE +# include "crt0.h" +#elif BX_PLATFORM_ANDROID # include #elif BX_PLATFORM_WINDOWS \ || BX_PLATFORM_WINRT \ @@ -49,13 +51,15 @@ namespace bx void debugOutput(const char* _out) { -#if BX_PLATFORM_ANDROID +#if BX_CRT_NONE + crt0::debugOutput(_out); +#elif BX_PLATFORM_ANDROID # ifndef BX_ANDROID_LOG_TAG # define BX_ANDROID_LOG_TAG "" # endif // BX_ANDROID_LOG_TAG __android_log_write(ANDROID_LOG_DEBUG, BX_ANDROID_LOG_TAG, _out); #elif BX_PLATFORM_WINDOWS \ - || BX_PLATFORM_WINRT \ + || BX_PLATFORM_WINRT \ || BX_PLATFORM_XBOXONE OutputDebugStringA(_out); #elif BX_PLATFORM_IOS || BX_PLATFORM_OSX @@ -66,14 +70,33 @@ namespace bx # endif // defined(__OBJC__) #elif 0 // BX_PLATFORM_EMSCRIPTEN emscripten_log(EM_LOG_CONSOLE, "%s", _out); -#elif !BX_CRT_NONE +#else fputs(_out, stdout); fflush(stdout); -#else - BX_UNUSED(_out); #endif // BX_PLATFORM_ } + void debugOutput(const StringView& _str) + { +#if BX_CRT_NONE + crt0::debugOutput(_str); +#else + const char* data = _str.getPtr(); + int32_t size = _str.getLength(); + + char temp[4096]; + while (0 != size) + { + uint32_t len = uint32_min(sizeof(temp)-1, size); + memCopy(temp, data, len); + temp[len] = '\0'; + data += len; + size -= len; + debugOutput(temp); + } +#endif // BX_CRT_NONE + } + void debugPrintfVargs(const char* _format, va_list _argList) { char temp[8192]; @@ -153,22 +176,8 @@ namespace bx virtual int32_t write(const void* _data, int32_t _size, Error* _err) override { BX_UNUSED(_err); - - int32_t total = 0; - const char* data = (const char*)_data; - - char temp[4096]; - while (total != _size) - { - uint32_t len = bx::uint32_min(sizeof(temp)-1, _size-total); - memCopy(temp, data, len); - temp[len] = '\0'; - data += len; - total += len; - debugOutput(temp); - } - - return total; + debugOutput(StringView( (const char*)_data, _size) ); + return _size; } };