#include "Debug.hpp"
-#ifdef __ANDROID__
-#include <utils/String8.h>
-#include <cutils/log.h>
-#endif
-
#include <stdio.h>
#include <stdarg.h>
-#ifdef __ANDROID__
- void trace(const char *format, ...)
- {
- va_list vararg;
- va_start(vararg, format);
- ALOGI("%s", android::String8::formatV(format, vararg).string());
- va_end(vararg);
- }
-#else
- void trace(const char *format, ...)
+void trace(const char *format, ...)
+{
+ if(false)
{
- if(false)
- {
- FILE *file = fopen("debug.txt", "a");
+ FILE *file = fopen("debug.txt", "a");
- if(file)
- {
- va_list vararg;
- va_start(vararg, format);
- vfprintf(file, format, vararg);
- va_end(vararg);
+ if(file)
+ {
+ va_list vararg;
+ va_start(vararg, format);
+ vfprintf(file, format, vararg);
+ va_end(vararg);
- fclose(file);
- }
+ fclose(file);
}
}
-#endif
+}
#define Debug_hpp\r
\r
#ifdef __ANDROID__\r
-#include <cutils/log.h>\r
-#endif\r
+#include "DebugAndroid.hpp"\r
+#else\r
\r
#include <assert.h>\r
#include <stdio.h>\r
#define TRACE(...) ((void)0)\r
#endif\r
\r
-#ifdef __ANDROID__\r
- // On Android Virtual Devices we heavily depend on logging, even in\r
- // production builds. We do this because AVDs are components of larger\r
- // systems, and may be configured in ways that are difficult to\r
- // reproduce locally. For example some system run tests against\r
- // third-party code that we cannot access. Aborting (cf. assert) on\r
- // unimplemented functionality creates two problems. First, it produces\r
- // a service failure where none is needed. Second, it puts the\r
- // customer on the critical path for notifying us of a problem.\r
- // The alternative, skipping unimplemented functionality silently, is\r
- // arguably worse: neither the service provider nor the customer will\r
- // learn that unimplemented functionality may have compromised the test\r
- // results.\r
- // Logging invocations of unimplemented functionality is useful to both\r
- // service provider and the customer. The service provider can learn\r
- // that the functionality is needed. The customer learns that the test\r
- // results may be compromised.\r
- #define UNIMPLEMENTED() {ALOGE("Unimplemented: %s %s:%d", __FUNCTION__, __FILE__, __LINE__); }\r
+#ifndef NDEBUG\r
+ #define UNIMPLEMENTED() {trace("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); ASSERT(false);}\r
#else\r
- #ifndef NDEBUG\r
- #define UNIMPLEMENTED() {trace("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); ASSERT(false);}\r
- #else\r
- #define UNIMPLEMENTED() ((void)0)\r
- #endif\r
+ #define UNIMPLEMENTED() ((void)0)\r
#endif\r
\r
#ifndef NDEBUG\r
#define ASSERT assert\r
#endif\r
\r
+#endif // __ANDROID__\r
#endif // Debug_hpp\r
--- /dev/null
+#include "DebugAndroid.hpp"
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <cutils/properties.h>
+
+void AndroidEnterDebugger()
+{
+ ALOGE(__FUNCTION__);
+#ifndef NDEBUG
+ static volatile int * const makefault = nullptr;
+ char value[PROPERTY_VALUE_MAX];
+ property_get("debug.db.uid", value, "-1");
+ int debug_uid = atoi(value);
+ if ((debug_uid >= 0) && (geteuid() < static_cast<uid_t>(debug_uid)))
+ {
+ ALOGE("Waiting for debugger: gdbserver :${PORT} --attach %u", gettid());
+ while (1) {
+ pause();
+ }
+ } else {
+ ALOGE("No debugger");
+ }
+#endif
+}
+
+void trace(const char *format, ...)
+{
+ va_list vararg;
+ va_start(vararg, format);
+ android_vprintLog(ANDROID_LOG_VERBOSE, NULL, LOG_TAG, format, vararg);
+ va_end(vararg);
+}
--- /dev/null
+#ifndef DebugAndroid_hpp
+#define DebugAndroid_hpp
+
+#include <cutils/log.h>
+
+// On Android Virtual Devices we heavily depend on logging, even in
+// production builds. We do this because AVDs are components of larger
+// systems, and may be configured in ways that are difficult to
+// reproduce locally. For example some system run tests against
+// third-party code that we cannot access. Aborting (cf. assert) on
+// unimplemented functionality creates two problems. First, it produces
+// a service failure where none is needed. Second, it puts the
+// customer on the critical path for notifying us of a problem.
+// The alternative, skipping unimplemented functionality silently, is
+// arguably worse: neither the service provider nor the customer will
+// learn that unimplemented functionality may have compromised the test
+// results.
+// Logging invocations of unimplemented functionality is useful to both
+// service provider and the customer. The service provider can learn
+// that the functionality is needed. The customer learns that the test
+// results may be compromised.
+
+/**
+ * Enter the debugger with a memory fault iff debuggerd is set to capture this
+ * process. Otherwise return.
+ */
+void AndroidEnterDebugger();
+
+#define ASSERT(E) do { \
+ if (!(E)) { \
+ ALOGE("badness: assertion_failed %s in %s at %s:%d", #E, \
+ __FUNCTION__, __FILE__, __LINE__); \
+ AndroidEnterDebugger(); \
+ } \
+ } while(0)
+
+#define assert(E) ASSERT(E)
+
+#define ERR(format, ...) \
+ do { \
+ ALOGE("badness: err %s %s:%d (" format ")", __FUNCTION__, __FILE__, \
+ __LINE__, ##__VA_ARGS__); \
+ AndroidEnterDebugger(); \
+ } while(0)
+
+#define FIXME(format, ...) \
+ do { \
+ ALOGE("badness: fixme %s %s:%d (" format ")", __FUNCTION__, __FILE__, \
+ __LINE__, ##__VA_ARGS__); \
+ AndroidEnterDebugger(); \
+ } while(0)
+
+#define UNIMPLEMENTED() do { \
+ ALOGE("badness: unimplemented: %s %s:%d", \
+ __FUNCTION__, __FILE__, __LINE__); \
+ AndroidEnterDebugger(); \
+ } while(0)
+
+#define UNREACHABLE() do { \
+ ALOGE("badness: unreachable reached: %s %s:%d", \
+ __FUNCTION__, __FILE__, __LINE__); \
+ AndroidEnterDebugger(); \
+ } while(0)
+
+#ifndef NDEBUG
+ #define TRACE(format, ...) \
+ ALOGV("%s %s:%d (" format ")", __FUNCTION__, __FILE__, \
+ __LINE__, ##__VA_ARGS__)
+#else
+ #define TRACE(...) ((void)0)
+#endif
+
+void trace(const char *format, ...);
+
+#endif // DebugAndroid_hpp
#define COMMON_DEBUG_H_\r
\r
#ifdef __ANDROID__\r
-#include <cutils/log.h>\r
-#endif\r
-\r
+#include "../../Common/DebugAndroid.hpp"\r
+#else\r
#include <stdio.h>\r
#include <assert.h>\r
\r
#endif\r
\r
// A macro to indicate unimplemented functionality\r
-#ifdef __ANDROID__\r
- // On Android Virtual Devices we heavily depend on logging, even in\r
- // production builds. We do this because AVDs are components of larger\r
- // systems, and may be configured in ways that are difficult to\r
- // reproduce locally. For example some system run tests against\r
- // third-party code that we cannot access. Aborting (cf. assert) on\r
- // unimplemented functionality creates two problems. First, it produces\r
- // a service failure where none is needed. Second, it puts the\r
- // customer on the critical path for notifying us of a problem.\r
- // The alternative, skipping unimplemented functionality silently, is\r
- // arguably worse: neither the service provider nor the customer will\r
- // learn that unimplemented functionality may have compromised the test\r
- // results.\r
- // Logging invocations of unimplemented functionality is useful to both\r
- // service provider and the customer. The service provider can learn\r
- // that the functionality is needed. The customer learns that the test\r
- // results may be compromised.\r
- #define UNIMPLEMENTED() {ALOGE("Unimplemented: %s %s:%d", __FUNCTION__, __FILE__, __LINE__); }\r
+#if !defined(NDEBUG)\r
+#define UNIMPLEMENTED() do { \\r
+ FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); \\r
+ assert(false); \\r
+ } while(0)\r
#else\r
- #if !defined(NDEBUG)\r
- #define UNIMPLEMENTED() do { \\r
- FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); \\r
- assert(false); \\r
- } while(0)\r
- #else\r
- #define UNIMPLEMENTED() FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__)\r
- #endif\r
+ #define UNIMPLEMENTED() FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__)\r
#endif\r
\r
// A macro for code which is not expected to be reached under valid assumptions\r
#define UNREACHABLE() ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__)\r
#endif\r
\r
+#endif // __ANDROID__\r
+\r
// A macro functioning as a compile-time assert to validate constant conditions\r
#define META_ASSERT(condition) typedef int COMPILE_TIME_ASSERT_##__LINE__[static_cast<bool>(condition) ? 1 : -1]\r
\r
#ifndef _CONSTANT_UNION_INCLUDED_
#define _CONSTANT_UNION_INCLUDED_
+#ifndef __ANDROID__
#include <assert.h>
+#else
+#include "../../Common/DebugAndroid.hpp"
+#endif
class ConstantUnion {
public:
// are tracked in the intermediate representation, not the symbol table.
//
+#ifndef __ANDROID__
#include <assert.h>
+#else
+#include "../../Common/DebugAndroid.hpp"
+#endif
#include "InfoSink.h"
#include "intermediate.h"
#ifndef COMPILER_DEBUG_H_
#define COMPILER_DEBUG_H_
+#ifdef __ANDROID__
+#include "../../Common/DebugAndroid.hpp"
+
+#define Trace(...) ((void)0)
+#else
+
#include <assert.h>
#ifdef _DEBUG
assert(false); \
} while(0)
+#endif // __ANDROID__
#endif // COMPILER_DEBUG_H_
LOCAL_SRC_FILES += \
../common/Object.cpp \
- ../common/debug.cpp \
+ ../../Common/DebugAndroid.cpp \
Config.cpp \
Display.cpp \
Surface.cpp \
# Android's make system also uses NDEBUG, so we need to set/unset it forcefully
# Uncomment for ON:
-LOCAL_CFLAGS += -UNDEBUG -g
+LOCAL_CFLAGS += -UNDEBUG -g -O0
# Uncomment for OFF:
#LOCAL_CFLAGS += -DANGLE_DISABLE_TRACE
#include <system/window.h>\r
#endif\r
\r
+#ifdef __ANDROID__\r
+#include "../../Common/DebugAndroid.hpp"\r
+#else\r
#include <assert.h>\r
+#endif\r
\r
namespace egl\r
{\r
{\r
TRACE("()");\r
\r
- #if !defined(ANGLE_DISABLE_TRACE)\r
+ #if !defined(ANGLE_DISABLE_TRACE) && defined(TRACE_OUTPUT_FILE)\r
FILE *debug = fopen(TRACE_OUTPUT_FILE, "rt");\r
\r
if(debug)\r
LOCAL_SRC_FILES := \
../../Common/CPUID.cpp \
../../Common/Configurator.cpp \
- ../../Common/Debug.cpp \
+ ../../Common/DebugAndroid.cpp \
../../Common/Half.cpp \
../../Common/Math.cpp \
../../Common/Memory.cpp \
LOCAL_SRC_FILES += \
../common/NameSpace.cpp \
../common/Object.cpp \
- ../common/debug.cpp \
../common/MatrixStack.cpp \
LOCAL_SRC_FILES += \
# Android's make system also uses NDEBUG, so we need to set/unset it forcefully
# Uncomment for ON:
-LOCAL_CFLAGS += -UNDEBUG -g
+LOCAL_CFLAGS += -UNDEBUG -g -O0
# Uncomment for OFF:
#LOCAL_CFLAGS += -fomit-frame-pointer -ffunction-sections -fdata-sections -DANGLE_DISABLE_TRACE
LOCAL_SRC_FILES := \
../../Common/CPUID.cpp \
../../Common/Configurator.cpp \
- ../../Common/Debug.cpp \
+ ../../Common/DebugAndroid.cpp \
../../Common/Half.cpp \
../../Common/Math.cpp \
../../Common/Memory.cpp \
LOCAL_SRC_FILES += \
../common/NameSpace.cpp \
../common/Object.cpp \
- ../common/debug.cpp \
LOCAL_SRC_FILES += \
../compiler/preprocessor/Diagnostics.cpp \
# Android's make system also uses NDEBUG, so we need to set/unset it forcefully
# Uncomment for ON:
-LOCAL_CFLAGS += -UNDEBUG -g
+LOCAL_CFLAGS += -UNDEBUG -g -O0
# Uncomment for OFF:
#LOCAL_CFLAGS += -fomit-frame-pointer -ffunction-sections -fdata-sections -DANGLE_DISABLE_TRACE