Browse Source

Added debugOutput for crt0.

Branimir Karadžić 7 years ago
parent
commit
0e54f1a398
4 changed files with 36 additions and 24 deletions
  1. 0 1
      include/bx/bx.h
  2. 4 1
      include/bx/debug.h
  3. 1 0
      src/bx_p.h
  4. 31 22
      src/debug.cpp

+ 0 - 1
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) )

+ 4 - 1
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);
 

+ 1 - 0
src/bx_p.h

@@ -40,5 +40,6 @@
 				BX_MACRO_BLOCK_END
 
 #include <bx/bx.h>
+#include <bx/debug.h>
 
 #endif // BX_P_H_HEADER_GUARD

+ 31 - 22
src/debug.cpp

@@ -9,7 +9,9 @@
 #include <bx/readerwriter.h> // WriterI
 #include <inttypes.h>        // PRIx*
 
-#if BX_PLATFORM_ANDROID
+#if BX_CRT_NONE
+#	include "crt0.h"
+#elif BX_PLATFORM_ANDROID
 #	include <android/log.h>
 #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;
 		}
 	};