• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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 rr_ReactorDebugInfo_hpp
16 #define rr_ReactorDebugInfo_hpp
17 
18 #ifdef ENABLE_RR_DEBUG_INFO
19 
20 #	include <vector>
21 #	include <string>
22 
23 namespace rr {
24 
25 struct FunctionLocation
26 {
27 	std::string name;
28 	std::string file;
29 
operator ==rr::FunctionLocation30 	bool operator==(const FunctionLocation &rhs) const { return name == rhs.name && file == rhs.file; }
operator !=rr::FunctionLocation31 	bool operator!=(const FunctionLocation &rhs) const { return !(*this == rhs); }
32 
33 	struct Hash
34 	{
operator ()rr::FunctionLocation::Hash35 		std::size_t operator()(const FunctionLocation &l) const noexcept
36 		{
37 			return std::hash<std::string>()(l.file) * 31 +
38 			       std::hash<std::string>()(l.name);
39 		}
40 	};
41 };
42 
43 struct Location
44 {
45 	FunctionLocation function;
46 	unsigned int line = 0;
47 
operator ==rr::Location48 	bool operator==(const Location &rhs) const { return function == rhs.function && line == rhs.line; }
operator !=rr::Location49 	bool operator!=(const Location &rhs) const { return !(*this == rhs); }
50 
51 	struct Hash
52 	{
operator ()rr::Location::Hash53 		std::size_t operator()(const Location &l) const noexcept
54 		{
55 			return FunctionLocation::Hash()(l.function) * 31 +
56 			       std::hash<unsigned int>()(l.line);
57 		}
58 	};
59 };
60 
61 using Backtrace = std::vector<Location>;
62 
63 // Returns the backtrace for the callstack, starting at the first
64 // non-Reactor file. If limit is non-zero, then a maximum of limit
65 // frames will be returned.
66 Backtrace getCallerBacktrace(size_t limit = 0);
67 
68 // Emits a print location for the top of the input backtrace.
69 void emitPrintLocation(const Backtrace &backtrace);
70 
71 }  // namespace rr
72 
73 #endif  // ENABLE_RR_DEBUG_INFO
74 
75 #endif  // rr_ReactorDebugInfo_hpp
76