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 20 // On Android Virtual Devices we heavily depend on logging, even in 21 // production builds. We do this because AVDs are components of larger 22 // systems, and may be configured in ways that are difficult to 23 // reproduce locally. For example some system run tests against 24 // third-party code that we cannot access. Aborting (cf. assert) on 25 // unimplemented functionality creates two problems. First, it produces 26 // a service failure where none is needed. Second, it puts the 27 // customer on the critical path for notifying us of a problem. 28 // The alternative, skipping unimplemented functionality silently, is 29 // arguably worse: neither the service provider nor the customer will 30 // learn that unimplemented functionality may have compromised the test 31 // results. 32 // Logging invocations of unimplemented functionality is useful to both 33 // service provider and the customer. The service provider can learn 34 // that the functionality is needed. The customer learns that the test 35 // results may be compromised. 36 37 /** 38 * Enter the debugger with a memory fault iff debuggerd is set to capture this 39 * process. Otherwise return. 40 */ 41 void AndroidEnterDebugger(); 42 43 #define ASSERT(E) do { \ 44 if (!(E)) { \ 45 ALOGE("badness: assertion_failed %s in %s at %s:%d", #E, \ 46 __FUNCTION__, __FILE__, __LINE__); \ 47 AndroidEnterDebugger(); \ 48 } \ 49 } while(0) 50 51 #undef assert 52 #define assert(E) ASSERT(E) 53 54 #define ERR(format, ...) \ 55 do { \ 56 ALOGE("badness: err %s %s:%d (" format ")", __FUNCTION__, __FILE__, \ 57 __LINE__, ##__VA_ARGS__); \ 58 AndroidEnterDebugger(); \ 59 } while(0) 60 61 #define FIXME(format, ...) \ 62 do { \ 63 ALOGE("badness: fixme %s %s:%d (" format ")", __FUNCTION__, __FILE__, \ 64 __LINE__, ##__VA_ARGS__); \ 65 AndroidEnterDebugger(); \ 66 } while(0) 67 68 #define UNIMPLEMENTED() do { \ 69 ALOGE("badness: unimplemented: %s %s:%d", \ 70 __FUNCTION__, __FILE__, __LINE__); \ 71 AndroidEnterDebugger(); \ 72 } while(0) 73 74 #define UNREACHABLE(value) do { \ 75 ALOGE("badness: unreachable case reached: %s %s:%d. %s: %d", \ 76 __FUNCTION__, __FILE__, __LINE__, #value, value); \ 77 AndroidEnterDebugger(); \ 78 } while(0) 79 80 #ifndef NDEBUG 81 #define TRACE(format, ...) \ 82 ALOGV("%s %s:%d (" format ")", __FUNCTION__, __FILE__, \ 83 __LINE__, ##__VA_ARGS__) 84 #else 85 #define TRACE(...) ((void)0) 86 #endif 87 88 void trace(const char *format, ...); 89 90 #endif // DebugAndroid_hpp 91