Nicolas Capens | 80d6f17 | 2016-05-13 19:30:12 -0400 | [diff] [blame] | 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 | |
Greg Hartman | d61ac5f | 2015-04-09 18:48:53 -0700 | [diff] [blame] | 15 | #ifndef DebugAndroid_hpp |
| 16 | #define DebugAndroid_hpp |
| 17 | |
Merck Hung | 720aec1 | 2018-09-29 05:21:57 +0800 | [diff] [blame] | 18 | #if ANDROID_PLATFORM_SDK_VERSION < 27 |
Greg Hartman | d61ac5f | 2015-04-09 18:48:53 -0700 | [diff] [blame] | 19 | #include <cutils/log.h> |
Merck Hung | 720aec1 | 2018-09-29 05:21:57 +0800 | [diff] [blame] | 20 | #elif ANDROID_PLATFORM_SDK_VERSION >= 27 |
| 21 | #include <log/log.h> |
| 22 | #else |
| 23 | #error "ANDROID_PLATFORM_SDK_VERSION is not defined" |
| 24 | #endif |
| 25 | |
Nicolas Capens | 4dd1eff | 2017-08-04 09:33:04 -0400 | [diff] [blame] | 26 | #include <cassert> |
Greg Hartman | d61ac5f | 2015-04-09 18:48:53 -0700 | [diff] [blame] | 27 | |
| 28 | // On Android Virtual Devices we heavily depend on logging, even in |
| 29 | // production builds. We do this because AVDs are components of larger |
| 30 | // systems, and may be configured in ways that are difficult to |
| 31 | // reproduce locally. For example some system run tests against |
| 32 | // third-party code that we cannot access. Aborting (cf. assert) on |
| 33 | // unimplemented functionality creates two problems. First, it produces |
| 34 | // a service failure where none is needed. Second, it puts the |
| 35 | // customer on the critical path for notifying us of a problem. |
| 36 | // The alternative, skipping unimplemented functionality silently, is |
| 37 | // arguably worse: neither the service provider nor the customer will |
| 38 | // learn that unimplemented functionality may have compromised the test |
| 39 | // results. |
| 40 | // Logging invocations of unimplemented functionality is useful to both |
| 41 | // service provider and the customer. The service provider can learn |
| 42 | // that the functionality is needed. The customer learns that the test |
| 43 | // results may be compromised. |
| 44 | |
| 45 | /** |
| 46 | * Enter the debugger with a memory fault iff debuggerd is set to capture this |
| 47 | * process. Otherwise return. |
| 48 | */ |
| 49 | void AndroidEnterDebugger(); |
| 50 | |
| 51 | #define ASSERT(E) do { \ |
| 52 | if (!(E)) { \ |
| 53 | ALOGE("badness: assertion_failed %s in %s at %s:%d", #E, \ |
| 54 | __FUNCTION__, __FILE__, __LINE__); \ |
| 55 | AndroidEnterDebugger(); \ |
| 56 | } \ |
| 57 | } while(0) |
| 58 | |
Nicolas Capens | 50f1a73 | 2016-01-01 23:24:01 -0500 | [diff] [blame] | 59 | #undef assert |
Greg Hartman | d61ac5f | 2015-04-09 18:48:53 -0700 | [diff] [blame] | 60 | #define assert(E) ASSERT(E) |
| 61 | |
| 62 | #define ERR(format, ...) \ |
| 63 | do { \ |
| 64 | ALOGE("badness: err %s %s:%d (" format ")", __FUNCTION__, __FILE__, \ |
| 65 | __LINE__, ##__VA_ARGS__); \ |
| 66 | AndroidEnterDebugger(); \ |
| 67 | } while(0) |
| 68 | |
| 69 | #define FIXME(format, ...) \ |
| 70 | do { \ |
| 71 | ALOGE("badness: fixme %s %s:%d (" format ")", __FUNCTION__, __FILE__, \ |
| 72 | __LINE__, ##__VA_ARGS__); \ |
| 73 | AndroidEnterDebugger(); \ |
| 74 | } while(0) |
| 75 | |
Nicolas Capens | a5dfd97d | 2018-09-28 15:27:08 -0400 | [diff] [blame] | 76 | // TODO: Handle __VA_ARGS__ (can be empty) |
| 77 | #define UNIMPLEMENTED(...) do { \ |
Greg Hartman | d61ac5f | 2015-04-09 18:48:53 -0700 | [diff] [blame] | 78 | ALOGE("badness: unimplemented: %s %s:%d", \ |
| 79 | __FUNCTION__, __FILE__, __LINE__); \ |
| 80 | AndroidEnterDebugger(); \ |
| 81 | } while(0) |
| 82 | |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 83 | #define UNREACHABLE(value) do { \ |
Greg Hartman | 5b9d7eb | 2015-07-06 15:27:41 -0700 | [diff] [blame] | 84 | ALOGE("badness: unreachable case reached: %s %s:%d. %s: %d", \ |
| 85 | __FUNCTION__, __FILE__, __LINE__, #value, value); \ |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 86 | AndroidEnterDebugger(); \ |
Greg Hartman | d61ac5f | 2015-04-09 18:48:53 -0700 | [diff] [blame] | 87 | } while(0) |
| 88 | |
| 89 | #ifndef NDEBUG |
| 90 | #define TRACE(format, ...) \ |
| 91 | ALOGV("%s %s:%d (" format ")", __FUNCTION__, __FILE__, \ |
| 92 | __LINE__, ##__VA_ARGS__) |
| 93 | #else |
| 94 | #define TRACE(...) ((void)0) |
| 95 | #endif |
| 96 | |
| 97 | void trace(const char *format, ...); |
| 98 | |
| 99 | #endif // DebugAndroid_hpp |