Commit d61ac5fa by Greg Hartman

Set up Android-specific debugging

Change-Id: I293568f0d0ee42dd64ee869e3c3ba28810e4883a Reviewed-on: https://swiftshader-review.googlesource.com/2824Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarGreg Hartman <ghartman@google.com>
parent 2a1c5693
...@@ -11,38 +11,23 @@ ...@@ -11,38 +11,23 @@
#include "Debug.hpp" #include "Debug.hpp"
#ifdef __ANDROID__
#include <utils/String8.h>
#include <cutils/log.h>
#endif
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#ifdef __ANDROID__ void trace(const char *format, ...)
void trace(const char *format, ...) {
{ if(false)
va_list vararg;
va_start(vararg, format);
ALOGI("%s", android::String8::formatV(format, vararg).string());
va_end(vararg);
}
#else
void trace(const char *format, ...)
{ {
if(false) FILE *file = fopen("debug.txt", "a");
{
FILE *file = fopen("debug.txt", "a");
if(file) if(file)
{ {
va_list vararg; va_list vararg;
va_start(vararg, format); va_start(vararg, format);
vfprintf(file, format, vararg); vfprintf(file, format, vararg);
va_end(vararg); va_end(vararg);
fclose(file); fclose(file);
}
} }
} }
#endif }
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
#define Debug_hpp #define Debug_hpp
#ifdef __ANDROID__ #ifdef __ANDROID__
#include <cutils/log.h> #include "DebugAndroid.hpp"
#endif #else
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
...@@ -30,30 +30,10 @@ void trace(const char *format, ...); ...@@ -30,30 +30,10 @@ void trace(const char *format, ...);
#define TRACE(...) ((void)0) #define TRACE(...) ((void)0)
#endif #endif
#ifdef __ANDROID__ #ifndef NDEBUG
// On Android Virtual Devices we heavily depend on logging, even in #define UNIMPLEMENTED() {trace("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); ASSERT(false);}
// 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.
#define UNIMPLEMENTED() {ALOGE("Unimplemented: %s %s:%d", __FUNCTION__, __FILE__, __LINE__); }
#else #else
#ifndef NDEBUG #define UNIMPLEMENTED() ((void)0)
#define UNIMPLEMENTED() {trace("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); ASSERT(false);}
#else
#define UNIMPLEMENTED() ((void)0)
#endif
#endif #endif
#ifndef NDEBUG #ifndef NDEBUG
...@@ -62,4 +42,5 @@ void trace(const char *format, ...); ...@@ -62,4 +42,5 @@ void trace(const char *format, ...);
#define ASSERT assert #define ASSERT assert
#endif #endif
#endif // __ANDROID__
#endif // Debug_hpp #endif // Debug_hpp
#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);
}
#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
...@@ -15,9 +15,8 @@ ...@@ -15,9 +15,8 @@
#define COMMON_DEBUG_H_ #define COMMON_DEBUG_H_
#ifdef __ANDROID__ #ifdef __ANDROID__
#include <cutils/log.h> #include "../../Common/DebugAndroid.hpp"
#endif #else
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
...@@ -64,33 +63,13 @@ namespace es ...@@ -64,33 +63,13 @@ namespace es
#endif #endif
// A macro to indicate unimplemented functionality // A macro to indicate unimplemented functionality
#ifdef __ANDROID__ #if !defined(NDEBUG)
// On Android Virtual Devices we heavily depend on logging, even in #define UNIMPLEMENTED() do { \
// production builds. We do this because AVDs are components of larger FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); \
// systems, and may be configured in ways that are difficult to assert(false); \
// reproduce locally. For example some system run tests against } while(0)
// 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.
#define UNIMPLEMENTED() {ALOGE("Unimplemented: %s %s:%d", __FUNCTION__, __FILE__, __LINE__); }
#else #else
#if !defined(NDEBUG) #define UNIMPLEMENTED() FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__)
#define UNIMPLEMENTED() do { \
FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); \
assert(false); \
} while(0)
#else
#define UNIMPLEMENTED() FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__)
#endif
#endif #endif
// A macro for code which is not expected to be reached under valid assumptions // A macro for code which is not expected to be reached under valid assumptions
...@@ -104,6 +83,8 @@ namespace es ...@@ -104,6 +83,8 @@ namespace es
#define UNREACHABLE() ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__) #define UNREACHABLE() ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__)
#endif #endif
#endif // __ANDROID__
// A macro functioning as a compile-time assert to validate constant conditions // A macro functioning as a compile-time assert to validate constant conditions
#define META_ASSERT(condition) typedef int COMPILE_TIME_ASSERT_##__LINE__[static_cast<bool>(condition) ? 1 : -1] #define META_ASSERT(condition) typedef int COMPILE_TIME_ASSERT_##__LINE__[static_cast<bool>(condition) ? 1 : -1]
......
...@@ -7,7 +7,11 @@ ...@@ -7,7 +7,11 @@
#ifndef _CONSTANT_UNION_INCLUDED_ #ifndef _CONSTANT_UNION_INCLUDED_
#define _CONSTANT_UNION_INCLUDED_ #define _CONSTANT_UNION_INCLUDED_
#ifndef __ANDROID__
#include <assert.h> #include <assert.h>
#else
#include "../../Common/DebugAndroid.hpp"
#endif
class ConstantUnion { class ConstantUnion {
public: public:
......
...@@ -30,7 +30,11 @@ ...@@ -30,7 +30,11 @@
// are tracked in the intermediate representation, not the symbol table. // are tracked in the intermediate representation, not the symbol table.
// //
#ifndef __ANDROID__
#include <assert.h> #include <assert.h>
#else
#include "../../Common/DebugAndroid.hpp"
#endif
#include "InfoSink.h" #include "InfoSink.h"
#include "intermediate.h" #include "intermediate.h"
......
...@@ -9,6 +9,12 @@ ...@@ -9,6 +9,12 @@
#ifndef COMPILER_DEBUG_H_ #ifndef COMPILER_DEBUG_H_
#define COMPILER_DEBUG_H_ #define COMPILER_DEBUG_H_
#ifdef __ANDROID__
#include "../../Common/DebugAndroid.hpp"
#define Trace(...) ((void)0)
#else
#include <assert.h> #include <assert.h>
#ifdef _DEBUG #ifdef _DEBUG
...@@ -49,5 +55,6 @@ void Trace(const char* format, ...); ...@@ -49,5 +55,6 @@ void Trace(const char* format, ...);
assert(false); \ assert(false); \
} while(0) } while(0)
#endif // __ANDROID__
#endif // COMPILER_DEBUG_H_ #endif // COMPILER_DEBUG_H_
...@@ -8,7 +8,7 @@ LOCAL_MODULE := libEGL_swiftshader ...@@ -8,7 +8,7 @@ LOCAL_MODULE := libEGL_swiftshader
LOCAL_SRC_FILES += \ LOCAL_SRC_FILES += \
../common/Object.cpp \ ../common/Object.cpp \
../common/debug.cpp \ ../../Common/DebugAndroid.cpp \
Config.cpp \ Config.cpp \
Display.cpp \ Display.cpp \
Surface.cpp \ Surface.cpp \
...@@ -19,7 +19,7 @@ LOCAL_CFLAGS += -DLOG_TAG=\"libEGL_swiftshader\" ...@@ -19,7 +19,7 @@ LOCAL_CFLAGS += -DLOG_TAG=\"libEGL_swiftshader\"
# Android's make system also uses NDEBUG, so we need to set/unset it forcefully # Android's make system also uses NDEBUG, so we need to set/unset it forcefully
# Uncomment for ON: # Uncomment for ON:
LOCAL_CFLAGS += -UNDEBUG -g LOCAL_CFLAGS += -UNDEBUG -g -O0
# Uncomment for OFF: # Uncomment for OFF:
#LOCAL_CFLAGS += -DANGLE_DISABLE_TRACE #LOCAL_CFLAGS += -DANGLE_DISABLE_TRACE
......
...@@ -8,7 +8,11 @@ ...@@ -8,7 +8,11 @@
#include <system/window.h> #include <system/window.h>
#endif #endif
#ifdef __ANDROID__
#include "../../Common/DebugAndroid.hpp"
#else
#include <assert.h> #include <assert.h>
#endif
namespace egl namespace egl
{ {
......
...@@ -70,7 +70,7 @@ CONSTRUCTOR static void eglAttachProcess() ...@@ -70,7 +70,7 @@ CONSTRUCTOR static void eglAttachProcess()
{ {
TRACE("()"); TRACE("()");
#if !defined(ANGLE_DISABLE_TRACE) #if !defined(ANGLE_DISABLE_TRACE) && defined(TRACE_OUTPUT_FILE)
FILE *debug = fopen(TRACE_OUTPUT_FILE, "rt"); FILE *debug = fopen(TRACE_OUTPUT_FILE, "rt");
if(debug) if(debug)
......
...@@ -9,7 +9,7 @@ LOCAL_MODULE := libGLESv1_CM_swiftshader ...@@ -9,7 +9,7 @@ LOCAL_MODULE := libGLESv1_CM_swiftshader
LOCAL_SRC_FILES := \ LOCAL_SRC_FILES := \
../../Common/CPUID.cpp \ ../../Common/CPUID.cpp \
../../Common/Configurator.cpp \ ../../Common/Configurator.cpp \
../../Common/Debug.cpp \ ../../Common/DebugAndroid.cpp \
../../Common/Half.cpp \ ../../Common/Half.cpp \
../../Common/Math.cpp \ ../../Common/Math.cpp \
../../Common/Memory.cpp \ ../../Common/Memory.cpp \
...@@ -68,7 +68,6 @@ LOCAL_SRC_FILES += \ ...@@ -68,7 +68,6 @@ LOCAL_SRC_FILES += \
LOCAL_SRC_FILES += \ LOCAL_SRC_FILES += \
../common/NameSpace.cpp \ ../common/NameSpace.cpp \
../common/Object.cpp \ ../common/Object.cpp \
../common/debug.cpp \
../common/MatrixStack.cpp \ ../common/MatrixStack.cpp \
LOCAL_SRC_FILES += \ LOCAL_SRC_FILES += \
...@@ -93,7 +92,7 @@ LOCAL_CFLAGS += -fvisibility=protected ...@@ -93,7 +92,7 @@ LOCAL_CFLAGS += -fvisibility=protected
# Android's make system also uses NDEBUG, so we need to set/unset it forcefully # Android's make system also uses NDEBUG, so we need to set/unset it forcefully
# Uncomment for ON: # Uncomment for ON:
LOCAL_CFLAGS += -UNDEBUG -g LOCAL_CFLAGS += -UNDEBUG -g -O0
# Uncomment for OFF: # Uncomment for OFF:
#LOCAL_CFLAGS += -fomit-frame-pointer -ffunction-sections -fdata-sections -DANGLE_DISABLE_TRACE #LOCAL_CFLAGS += -fomit-frame-pointer -ffunction-sections -fdata-sections -DANGLE_DISABLE_TRACE
......
...@@ -9,7 +9,7 @@ LOCAL_MODULE := libGLESv2_swiftshader ...@@ -9,7 +9,7 @@ LOCAL_MODULE := libGLESv2_swiftshader
LOCAL_SRC_FILES := \ LOCAL_SRC_FILES := \
../../Common/CPUID.cpp \ ../../Common/CPUID.cpp \
../../Common/Configurator.cpp \ ../../Common/Configurator.cpp \
../../Common/Debug.cpp \ ../../Common/DebugAndroid.cpp \
../../Common/Half.cpp \ ../../Common/Half.cpp \
../../Common/Math.cpp \ ../../Common/Math.cpp \
../../Common/Memory.cpp \ ../../Common/Memory.cpp \
...@@ -68,7 +68,6 @@ LOCAL_SRC_FILES += \ ...@@ -68,7 +68,6 @@ LOCAL_SRC_FILES += \
LOCAL_SRC_FILES += \ LOCAL_SRC_FILES += \
../common/NameSpace.cpp \ ../common/NameSpace.cpp \
../common/Object.cpp \ ../common/Object.cpp \
../common/debug.cpp \
LOCAL_SRC_FILES += \ LOCAL_SRC_FILES += \
../compiler/preprocessor/Diagnostics.cpp \ ../compiler/preprocessor/Diagnostics.cpp \
...@@ -129,7 +128,7 @@ LOCAL_CFLAGS += -DLOG_TAG=\"libGLESv2_swiftshader\" ...@@ -129,7 +128,7 @@ LOCAL_CFLAGS += -DLOG_TAG=\"libGLESv2_swiftshader\"
# Android's make system also uses NDEBUG, so we need to set/unset it forcefully # Android's make system also uses NDEBUG, so we need to set/unset it forcefully
# Uncomment for ON: # Uncomment for ON:
LOCAL_CFLAGS += -UNDEBUG -g LOCAL_CFLAGS += -UNDEBUG -g -O0
# Uncomment for OFF: # Uncomment for OFF:
#LOCAL_CFLAGS += -fomit-frame-pointer -ffunction-sections -fdata-sections -DANGLE_DISABLE_TRACE #LOCAL_CFLAGS += -fomit-frame-pointer -ffunction-sections -fdata-sections -DANGLE_DISABLE_TRACE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment