1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2011 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker #ifndef ART_LIBARTBASE_BASE_RUNTIME_DEBUG_H_ 18*795d594fSAndroid Build Coastguard Worker #define ART_LIBARTBASE_BASE_RUNTIME_DEBUG_H_ 19*795d594fSAndroid Build Coastguard Worker 20*795d594fSAndroid Build Coastguard Worker namespace art { 21*795d594fSAndroid Build Coastguard Worker 22*795d594fSAndroid Build Coastguard Worker // Runtime debug flags are flags that have a runtime component, that is, their value can be changed. 23*795d594fSAndroid Build Coastguard Worker // This is meant to implement fast vs slow debug builds, in that certain debug flags can be turned 24*795d594fSAndroid Build Coastguard Worker // on and off. To that effect, expose two macros to help implement and globally drive these flags: 25*795d594fSAndroid Build Coastguard Worker // 26*795d594fSAndroid Build Coastguard Worker // In the header, declare a (class) flag like this: 27*795d594fSAndroid Build Coastguard Worker // 28*795d594fSAndroid Build Coastguard Worker // class C { 29*795d594fSAndroid Build Coastguard Worker // DECLARE_RUNTIME_DEBUG_FLAG(kFlag); 30*795d594fSAndroid Build Coastguard Worker // }; 31*795d594fSAndroid Build Coastguard Worker // 32*795d594fSAndroid Build Coastguard Worker // This will declare a flag kFlag that is a constexpr false in release builds, and a static field 33*795d594fSAndroid Build Coastguard Worker // in debug builds. Usage is than uniform as C::kFlag. 34*795d594fSAndroid Build Coastguard Worker // 35*795d594fSAndroid Build Coastguard Worker // In the cc file, define the flag like this: 36*795d594fSAndroid Build Coastguard Worker // 37*795d594fSAndroid Build Coastguard Worker // DEFINE_RUNTIME_DEBUG_FLAG(C, kFlag); 38*795d594fSAndroid Build Coastguard Worker // 39*795d594fSAndroid Build Coastguard Worker // This will define the static storage, as necessary, and register the flag with the runtime 40*795d594fSAndroid Build Coastguard Worker // infrastructure to toggle the value. 41*795d594fSAndroid Build Coastguard Worker 42*795d594fSAndroid Build Coastguard Worker #ifdef NDEBUG 43*795d594fSAndroid Build Coastguard Worker #define DECLARE_RUNTIME_DEBUG_FLAG(x) \ 44*795d594fSAndroid Build Coastguard Worker static constexpr bool x = false; 45*795d594fSAndroid Build Coastguard Worker // Note: the static_assert in the following only works for public flags. Fix this when we cross 46*795d594fSAndroid Build Coastguard Worker // the line at some point. 47*795d594fSAndroid Build Coastguard Worker #define DEFINE_RUNTIME_DEBUG_FLAG(C, x) \ 48*795d594fSAndroid Build Coastguard Worker static_assert(!C::x, "Unexpected enabled flag in release build"); 49*795d594fSAndroid Build Coastguard Worker #else 50*795d594fSAndroid Build Coastguard Worker #define DECLARE_RUNTIME_DEBUG_FLAG(x) \ 51*795d594fSAndroid Build Coastguard Worker static bool x; 52*795d594fSAndroid Build Coastguard Worker #define DEFINE_RUNTIME_DEBUG_FLAG(C, x) \ 53*795d594fSAndroid Build Coastguard Worker bool C::x = RegisterRuntimeDebugFlag(&C::x); 54*795d594fSAndroid Build Coastguard Worker #endif // NDEBUG 55*795d594fSAndroid Build Coastguard Worker 56*795d594fSAndroid Build Coastguard Worker bool RegisterRuntimeDebugFlag(bool* runtime_debug_flag); 57*795d594fSAndroid Build Coastguard Worker void SetRuntimeDebugFlagsEnabled(bool enabled); 58*795d594fSAndroid Build Coastguard Worker 59*795d594fSAndroid Build Coastguard Worker } // namespace art 60*795d594fSAndroid Build Coastguard Worker 61*795d594fSAndroid Build Coastguard Worker #endif // ART_LIBARTBASE_BASE_RUNTIME_DEBUG_H_ 62