1//===- LookupResult.h -------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_DEBUGINFO_GSYM_LOOKUPRESULT_H
10#define LLVM_DEBUGINFO_GSYM_LOOKUPRESULT_H
11
12#include "llvm/ADT/AddressRanges.h"
13#include "llvm/ADT/StringRef.h"
14#include "llvm/Support/Compiler.h"
15#include <inttypes.h>
16#include <vector>
17
18namespace llvm {
19class raw_ostream;
20namespace gsym {
21
22struct SourceLocation {
23 StringRef Name; ///< Function or symbol name.
24 StringRef Dir; ///< Line entry source file directory path.
25 StringRef Base; ///< Line entry source file basename.
26 uint32_t Line = 0; ///< Source file line number.
27 uint32_t Offset = 0; ///< Byte size offset within the named function.
28};
29
30inline bool operator==(const SourceLocation &LHS, const SourceLocation &RHS) {
31 return LHS.Name == RHS.Name && LHS.Dir == RHS.Dir && LHS.Base == RHS.Base &&
32 LHS.Line == RHS.Line && LHS.Offset == RHS.Offset;
33}
34
35LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const SourceLocation &R);
36
37using SourceLocations = std::vector<SourceLocation>;
38
39struct LookupResult {
40 uint64_t LookupAddr = 0; ///< The address that this lookup pertains to.
41 AddressRange FuncRange; ///< The concrete function address range.
42 StringRef FuncName; ///< The concrete function name that contains LookupAddr.
43 /// The source locations that match this address. This information will only
44 /// be filled in if the FunctionInfo contains a line table. If an address is
45 /// for a concrete function with no inlined functions, this array will have
46 /// one entry. If an address points to an inline function, there will be one
47 /// SourceLocation for each inlined function with the last entry pointing to
48 /// the concrete function itself. This allows one address to generate
49 /// multiple locations and allows unwinding of inline call stacks. The
50 /// deepest inline function will appear at index zero in the source locations
51 /// array, and the concrete function will appear at the end of the array.
52 SourceLocations Locations;
53
54 /// Function name regex patterns associated with a call site at the lookup
55 /// address. This vector will be populated when:
56 /// 1. The lookup address matches a call site's return address in a function
57 /// 2. The call site has associated regex patterns that describe what
58 /// functions can be called from that location
59 ///
60 /// The regex patterns can be used to validate function calls during runtime
61 /// checking or symbolication. For example:
62 /// - Patterns like "^foo$" indicate the call site can only call function
63 /// "foo"
64 /// - Patterns like "^std::" indicate the call site can call any function in
65 /// the std namespace
66 /// - Multiple patterns allow matching against a set of allowed functions
67 ///
68 /// The patterns are stored as string references into the GSYM string table.
69 /// This information is typically loaded from:
70 /// - DWARF debug info call site entries
71 /// - External YAML files specifying call site patterns
72 /// - Other debug info formats that encode call site constraints
73 ///
74 /// The patterns will be empty if:
75 /// - The lookup address is not at the return address of a call site
76 /// - The call site has no associated function name constraints
77 /// - Call site info was not included when creating the GSYM file
78 std::vector<StringRef> CallSiteFuncRegex;
79
80 LLVM_ABI std::string getSourceFile(uint32_t Index) const;
81};
82
83inline bool operator==(const LookupResult &LHS, const LookupResult &RHS) {
84 if (LHS.LookupAddr != RHS.LookupAddr)
85 return false;
86 if (LHS.FuncRange != RHS.FuncRange)
87 return false;
88 if (LHS.FuncName != RHS.FuncName)
89 return false;
90 if (LHS.CallSiteFuncRegex != RHS.CallSiteFuncRegex)
91 return false;
92 return LHS.Locations == RHS.Locations;
93}
94
95LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const LookupResult &R);
96
97} // namespace gsym
98} // namespace llvm
99
100#endif // LLVM_DEBUGINFO_GSYM_LOOKUPRESULT_H
101