blob: 7f6309310f8bd2f6d269c875f177ce1c5d63139b [file] [log] [blame]
Antonio Maioranoaae33732020-02-14 14:52:34 -05001// 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
23namespace rr {
24
25struct FunctionLocation
26{
27 std::string name;
28 std::string file;
29
30 bool operator==(const FunctionLocation &rhs) const { return name == rhs.name && file == rhs.file; }
31 bool operator!=(const FunctionLocation &rhs) const { return !(*this == rhs); }
32
33 struct Hash
34 {
35 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
43struct Location
44{
45 FunctionLocation function;
46 unsigned int line = 0;
47
48 bool operator==(const Location &rhs) const { return function == rhs.function && line == rhs.line; }
49 bool operator!=(const Location &rhs) const { return !(*this == rhs); }
50
51 struct Hash
52 {
53 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
61using 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.
66Backtrace getCallerBacktrace(size_t limit = 0);
67
68// Emits a print location for the top of the input backtrace.
69void emitPrintLocation(const Backtrace &backtrace);
70
71} // namespace rr
72
73#endif // ENABLE_RR_DEBUG_INFO
74
75#endif // rr_ReactorDebugInfo_hpp