1 /* 2 * Copyright 2019 WebAssembly Community Group participants 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "support/debug.h" 18 19 #include <cstring> 20 #include <set> 21 #include <string> 22 23 #ifndef NDEBUG 24 25 static bool debugEnabled = false; 26 static std::set<std::string> debugTypesEnabled; 27 isDebugEnabled(const char * type)28bool wasm::isDebugEnabled(const char* type) { 29 if (!debugEnabled) { 30 return false; 31 } 32 if (debugTypesEnabled.empty()) { 33 return true; 34 } 35 return debugTypesEnabled.count(type) > 0; 36 } 37 setDebugEnabled(const char * types)38void wasm::setDebugEnabled(const char* types) { 39 debugEnabled = true; 40 // split types on comma and add each string to debugTypesEnabled 41 size_t start = 0; 42 size_t end = strlen(types); 43 while (start < end) { 44 const char* type_end = strchr(types + start, ','); 45 if (type_end == nullptr) { 46 type_end = types + end; 47 } 48 size_t type_size = type_end - (types + start); 49 std::string type(types + start, type_size); 50 debugTypesEnabled.insert(type); 51 start += type_size + 1; 52 } 53 } 54 55 #endif 56