• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef DebugAndroid_hpp
16 #define DebugAndroid_hpp
17 
18 #include <cutils/log.h>
19 #include <cassert>
20 
21 // On Android Virtual Devices we heavily depend on logging, even in
22 // production builds. We do this because AVDs are components of larger
23 // systems, and may be configured in ways that are difficult to
24 // reproduce locally. For example some system run tests against
25 // third-party code that we cannot access.  Aborting (cf. assert) on
26 // unimplemented functionality creates two problems. First, it produces
27 // a service failure where none is needed. Second, it puts the
28 // customer on the critical path for notifying us of a problem.
29 // The alternative, skipping unimplemented functionality silently, is
30 // arguably worse: neither the service provider nor the customer will
31 // learn that unimplemented functionality may have compromised the test
32 // results.
33 // Logging invocations of unimplemented functionality is useful to both
34 // service provider and the customer. The service provider can learn
35 // that the functionality is needed. The customer learns that the test
36 // results may be compromised.
37 
38 /**
39  * Enter the debugger with a memory fault iff debuggerd is set to capture this
40  * process. Otherwise return.
41  */
42 void AndroidEnterDebugger();
43 
44 #define ASSERT(E) do { \
45 		if (!(E)) { \
46 			ALOGE("badness: assertion_failed %s in %s at %s:%d", #E,	\
47 				  __FUNCTION__, __FILE__, __LINE__);					\
48 			AndroidEnterDebugger();										\
49 		}																\
50 	} while(0)
51 
52 #undef assert
53 #define assert(E) ASSERT(E)
54 
55 #define ERR(format, ...)												\
56 	do {																\
57 		ALOGE("badness: err %s %s:%d (" format ")", __FUNCTION__, __FILE__, \
58 			  __LINE__, ##__VA_ARGS__);									\
59 		AndroidEnterDebugger();											\
60 	} while(0)
61 
62 #define FIXME(format, ...)												\
63 	do {																\
64 		ALOGE("badness: fixme %s %s:%d (" format ")", __FUNCTION__, __FILE__, \
65 			  __LINE__, ##__VA_ARGS__);									\
66 		AndroidEnterDebugger();											\
67 	} while(0)
68 
69 #define UNIMPLEMENTED() do {						\
70 		ALOGE("badness: unimplemented: %s %s:%d",	\
71 			  __FUNCTION__, __FILE__, __LINE__);	\
72 		AndroidEnterDebugger();						\
73 	} while(0)
74 
75 #define UNREACHABLE(value) do {                                         \
76 		ALOGE("badness: unreachable case reached: %s %s:%d. %s: %d", \
77 			  __FUNCTION__, __FILE__, __LINE__, #value, value);			\
78 		AndroidEnterDebugger();                                         \
79 	} while(0)
80 
81 #ifndef NDEBUG
82 	#define TRACE(format, ...)								   \
83 		ALOGV("%s %s:%d (" format ")", __FUNCTION__, __FILE__, \
84 			  __LINE__, ##__VA_ARGS__)
85 #else
86 	#define TRACE(...) ((void)0)
87 #endif
88 
89 void trace(const char *format, ...);
90 
91 #endif   // DebugAndroid_hpp
92