1*03ce13f7SAndroid Build Coastguard Worker // Copyright 2020 The SwiftShader Authors. All Rights Reserved. 2*03ce13f7SAndroid Build Coastguard Worker // 3*03ce13f7SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License"); 4*03ce13f7SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License. 5*03ce13f7SAndroid Build Coastguard Worker // You may obtain a copy of the License at 6*03ce13f7SAndroid Build Coastguard Worker // 7*03ce13f7SAndroid Build Coastguard Worker // http://www.apache.org/licenses/LICENSE-2.0 8*03ce13f7SAndroid Build Coastguard Worker // 9*03ce13f7SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software 10*03ce13f7SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS, 11*03ce13f7SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*03ce13f7SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and 13*03ce13f7SAndroid Build Coastguard Worker // limitations under the License. 14*03ce13f7SAndroid Build Coastguard Worker 15*03ce13f7SAndroid Build Coastguard Worker #ifndef rr_ReactorDebugInfo_hpp 16*03ce13f7SAndroid Build Coastguard Worker #define rr_ReactorDebugInfo_hpp 17*03ce13f7SAndroid Build Coastguard Worker 18*03ce13f7SAndroid Build Coastguard Worker #ifdef ENABLE_RR_DEBUG_INFO 19*03ce13f7SAndroid Build Coastguard Worker 20*03ce13f7SAndroid Build Coastguard Worker # include <vector> 21*03ce13f7SAndroid Build Coastguard Worker # include <string> 22*03ce13f7SAndroid Build Coastguard Worker 23*03ce13f7SAndroid Build Coastguard Worker namespace rr { 24*03ce13f7SAndroid Build Coastguard Worker 25*03ce13f7SAndroid Build Coastguard Worker struct FunctionLocation 26*03ce13f7SAndroid Build Coastguard Worker { 27*03ce13f7SAndroid Build Coastguard Worker std::string name; 28*03ce13f7SAndroid Build Coastguard Worker std::string file; 29*03ce13f7SAndroid Build Coastguard Worker operator ==rr::FunctionLocation30*03ce13f7SAndroid Build Coastguard Worker bool operator==(const FunctionLocation &rhs) const { return name == rhs.name && file == rhs.file; } operator !=rr::FunctionLocation31*03ce13f7SAndroid Build Coastguard Worker bool operator!=(const FunctionLocation &rhs) const { return !(*this == rhs); } 32*03ce13f7SAndroid Build Coastguard Worker 33*03ce13f7SAndroid Build Coastguard Worker struct Hash 34*03ce13f7SAndroid Build Coastguard Worker { operator ()rr::FunctionLocation::Hash35*03ce13f7SAndroid Build Coastguard Worker std::size_t operator()(const FunctionLocation &l) const noexcept 36*03ce13f7SAndroid Build Coastguard Worker { 37*03ce13f7SAndroid Build Coastguard Worker return std::hash<std::string>()(l.file) * 31 + 38*03ce13f7SAndroid Build Coastguard Worker std::hash<std::string>()(l.name); 39*03ce13f7SAndroid Build Coastguard Worker } 40*03ce13f7SAndroid Build Coastguard Worker }; 41*03ce13f7SAndroid Build Coastguard Worker }; 42*03ce13f7SAndroid Build Coastguard Worker 43*03ce13f7SAndroid Build Coastguard Worker struct Location 44*03ce13f7SAndroid Build Coastguard Worker { 45*03ce13f7SAndroid Build Coastguard Worker FunctionLocation function; 46*03ce13f7SAndroid Build Coastguard Worker unsigned int line = 0; 47*03ce13f7SAndroid Build Coastguard Worker operator ==rr::Location48*03ce13f7SAndroid Build Coastguard Worker bool operator==(const Location &rhs) const { return function == rhs.function && line == rhs.line; } operator !=rr::Location49*03ce13f7SAndroid Build Coastguard Worker bool operator!=(const Location &rhs) const { return !(*this == rhs); } 50*03ce13f7SAndroid Build Coastguard Worker 51*03ce13f7SAndroid Build Coastguard Worker struct Hash 52*03ce13f7SAndroid Build Coastguard Worker { operator ()rr::Location::Hash53*03ce13f7SAndroid Build Coastguard Worker std::size_t operator()(const Location &l) const noexcept 54*03ce13f7SAndroid Build Coastguard Worker { 55*03ce13f7SAndroid Build Coastguard Worker return FunctionLocation::Hash()(l.function) * 31 + 56*03ce13f7SAndroid Build Coastguard Worker std::hash<unsigned int>()(l.line); 57*03ce13f7SAndroid Build Coastguard Worker } 58*03ce13f7SAndroid Build Coastguard Worker }; 59*03ce13f7SAndroid Build Coastguard Worker }; 60*03ce13f7SAndroid Build Coastguard Worker 61*03ce13f7SAndroid Build Coastguard Worker using Backtrace = std::vector<Location>; 62*03ce13f7SAndroid Build Coastguard Worker 63*03ce13f7SAndroid Build Coastguard Worker // Returns the backtrace for the callstack, starting at the first 64*03ce13f7SAndroid Build Coastguard Worker // non-Reactor file. If limit is non-zero, then a maximum of limit 65*03ce13f7SAndroid Build Coastguard Worker // frames will be returned. 66*03ce13f7SAndroid Build Coastguard Worker Backtrace getCallerBacktrace(size_t limit = 0); 67*03ce13f7SAndroid Build Coastguard Worker 68*03ce13f7SAndroid Build Coastguard Worker // Emits a print location for the top of the input backtrace. 69*03ce13f7SAndroid Build Coastguard Worker void emitPrintLocation(const Backtrace &backtrace); 70*03ce13f7SAndroid Build Coastguard Worker 71*03ce13f7SAndroid Build Coastguard Worker } // namespace rr 72*03ce13f7SAndroid Build Coastguard Worker 73*03ce13f7SAndroid Build Coastguard Worker #endif // ENABLE_RR_DEBUG_INFO 74*03ce13f7SAndroid Build Coastguard Worker 75*03ce13f7SAndroid Build Coastguard Worker #endif // rr_ReactorDebugInfo_hpp 76