1 //===- FunctionInfo.h -------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_DEBUGINFO_GSYM_FUNCTIONINFO_H
11 #define LLVM_DEBUGINFO_GSYM_FUNCTIONINFO_H
13 #include "llvm/DebugInfo/GSYM/InlineInfo.h"
14 #include "llvm/DebugInfo/GSYM/LineEntry.h"
15 #include "llvm/DebugInfo/GSYM/Range.h"
16 #include "llvm/DebugInfo/GSYM/StringTable.h"
24 /// Function information in GSYM files encodes information for one
25 /// contiguous address range. The name of the function is encoded as
26 /// a string table offset and allows multiple functions with the same
27 /// name to share the name string in the string table. Line tables are
28 /// stored in a sorted vector of gsym::LineEntry objects and are split
29 /// into line tables for each function. If a function has a discontiguous
30 /// range, it will be split into two gsym::FunctionInfo objects. If the
31 /// function has inline functions, the information will be encoded in
32 /// the "Inline" member, see gsym::InlineInfo for more information.
35 uint32_t Name; ///< String table offset in the string table.
36 std::vector<gsym::LineEntry> Lines;
39 FunctionInfo(uint64_t Addr = 0, uint64_t Size = 0, uint32_t N = 0)
40 : Range(Addr, Addr + Size), Name(N) {}
42 bool hasRichInfo() const {
43 /// Returns whether we have something else than range and name. When
44 /// converting information from a symbol table and from debug info, we
45 /// might end up with multiple FunctionInfo objects for the same range
46 /// and we need to be able to tell which one is the better object to use.
47 return !Lines.empty() || Inline.isValid();
50 bool isValid() const {
51 /// Address and size can be zero and there can be no line entries for a
52 /// symbol so the only indication this entry is valid is if the name is
53 /// not zero. This can happen when extracting information from symbol
54 /// tables that do not encode symbol sizes. In that case only the
55 /// address and name will be filled in.
59 uint64_t startAddress() const { return Range.Start; }
60 uint64_t endAddress() const { return Range.End; }
61 uint64_t size() const { return Range.size(); }
62 void setStartAddress(uint64_t Addr) { Range.Start = Addr; }
63 void setEndAddress(uint64_t Addr) { Range.End = Addr; }
64 void setSize(uint64_t Size) { Range.End = Range.Start + Size; }
74 inline bool operator==(const FunctionInfo &LHS, const FunctionInfo &RHS) {
75 return LHS.Range == RHS.Range && LHS.Name == RHS.Name &&
76 LHS.Lines == RHS.Lines && LHS.Inline == RHS.Inline;
78 inline bool operator!=(const FunctionInfo &LHS, const FunctionInfo &RHS) {
81 /// This sorting will order things consistently by address range first, but then
82 /// followed by inlining being valid and line tables. We might end up with a
83 /// FunctionInfo from debug info that will have the same range as one from the
84 /// symbol table, but we want to quickly be able to sort and use the best version
85 /// when creating the final GSYM file.
86 inline bool operator<(const FunctionInfo &LHS, const FunctionInfo &RHS) {
87 // First sort by address range
88 if (LHS.Range != RHS.Range)
89 return LHS.Range < RHS.Range;
91 // Then sort by inline
92 if (LHS.Inline.isValid() != RHS.Inline.isValid())
93 return RHS.Inline.isValid();
95 // If the number of lines is the same, then compare line table entries
96 if (LHS.Lines.size() == RHS.Lines.size())
97 return LHS.Lines < RHS.Lines;
98 // Then sort by number of line table entries (more is better)
99 return LHS.Lines.size() < RHS.Lines.size();
102 raw_ostream &operator<<(raw_ostream &OS, const FunctionInfo &R);
107 #endif // #ifndef LLVM_DEBUGINFO_GSYM_FUNCTIONINFO_H