xref: /freebsd-src/contrib/llvm-project/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
18bcb0991SDimitry Andric //===- GsymCreator.cpp ----------------------------------------------------===//
28bcb0991SDimitry Andric //
38bcb0991SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
48bcb0991SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
58bcb0991SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
68bcb0991SDimitry Andric //===----------------------------------------------------------------------===//
78bcb0991SDimitry Andric 
88bcb0991SDimitry Andric #include "llvm/DebugInfo/GSYM/GsymCreator.h"
98bcb0991SDimitry Andric #include "llvm/DebugInfo/GSYM/FileWriter.h"
108bcb0991SDimitry Andric #include "llvm/DebugInfo/GSYM/Header.h"
118bcb0991SDimitry Andric #include "llvm/DebugInfo/GSYM/LineTable.h"
128bcb0991SDimitry Andric #include "llvm/MC/StringTableBuilder.h"
138bcb0991SDimitry Andric #include "llvm/Support/raw_ostream.h"
148bcb0991SDimitry Andric 
158bcb0991SDimitry Andric #include <algorithm>
168bcb0991SDimitry Andric #include <cassert>
178bcb0991SDimitry Andric #include <functional>
188bcb0991SDimitry Andric #include <vector>
198bcb0991SDimitry Andric 
208bcb0991SDimitry Andric using namespace llvm;
218bcb0991SDimitry Andric using namespace gsym;
228bcb0991SDimitry Andric 
23fe6060f1SDimitry Andric GsymCreator::GsymCreator(bool Quiet)
24fe6060f1SDimitry Andric     : StrTab(StringTableBuilder::ELF), Quiet(Quiet) {
258bcb0991SDimitry Andric   insertFile(StringRef());
268bcb0991SDimitry Andric }
278bcb0991SDimitry Andric 
28fe6060f1SDimitry Andric uint32_t GsymCreator::insertFile(StringRef Path, llvm::sys::path::Style Style) {
298bcb0991SDimitry Andric   llvm::StringRef directory = llvm::sys::path::parent_path(Path, Style);
308bcb0991SDimitry Andric   llvm::StringRef filename = llvm::sys::path::filename(Path, Style);
315ffd83dbSDimitry Andric   // We must insert the strings first, then call the FileEntry constructor.
325ffd83dbSDimitry Andric   // If we inline the insertString() function call into the constructor, the
335ffd83dbSDimitry Andric   // call order is undefined due to parameter lists not having any ordering
345ffd83dbSDimitry Andric   // requirements.
355ffd83dbSDimitry Andric   const uint32_t Dir = insertString(directory);
365ffd83dbSDimitry Andric   const uint32_t Base = insertString(filename);
375ffd83dbSDimitry Andric   FileEntry FE(Dir, Base);
388bcb0991SDimitry Andric 
39fe6060f1SDimitry Andric   std::lock_guard<std::mutex> Guard(Mutex);
408bcb0991SDimitry Andric   const auto NextIndex = Files.size();
418bcb0991SDimitry Andric   // Find FE in hash map and insert if not present.
428bcb0991SDimitry Andric   auto R = FileEntryToIndex.insert(std::make_pair(FE, NextIndex));
438bcb0991SDimitry Andric   if (R.second)
448bcb0991SDimitry Andric     Files.emplace_back(FE);
458bcb0991SDimitry Andric   return R.first->second;
468bcb0991SDimitry Andric }
478bcb0991SDimitry Andric 
488bcb0991SDimitry Andric llvm::Error GsymCreator::save(StringRef Path,
498bcb0991SDimitry Andric                               llvm::support::endianness ByteOrder) const {
508bcb0991SDimitry Andric   std::error_code EC;
518bcb0991SDimitry Andric   raw_fd_ostream OutStrm(Path, EC);
528bcb0991SDimitry Andric   if (EC)
538bcb0991SDimitry Andric     return llvm::errorCodeToError(EC);
548bcb0991SDimitry Andric   FileWriter O(OutStrm, ByteOrder);
558bcb0991SDimitry Andric   return encode(O);
568bcb0991SDimitry Andric }
578bcb0991SDimitry Andric 
588bcb0991SDimitry Andric llvm::Error GsymCreator::encode(FileWriter &O) const {
59fe6060f1SDimitry Andric   std::lock_guard<std::mutex> Guard(Mutex);
608bcb0991SDimitry Andric   if (Funcs.empty())
618bcb0991SDimitry Andric     return createStringError(std::errc::invalid_argument,
628bcb0991SDimitry Andric                              "no functions to encode");
638bcb0991SDimitry Andric   if (!Finalized)
648bcb0991SDimitry Andric     return createStringError(std::errc::invalid_argument,
658bcb0991SDimitry Andric                              "GsymCreator wasn't finalized prior to encoding");
668bcb0991SDimitry Andric 
678bcb0991SDimitry Andric   if (Funcs.size() > UINT32_MAX)
688bcb0991SDimitry Andric     return createStringError(std::errc::invalid_argument,
698bcb0991SDimitry Andric                              "too many FunctionInfos");
705ffd83dbSDimitry Andric 
71fe6060f1SDimitry Andric   const uint64_t MinAddr =
72fe6060f1SDimitry Andric       BaseAddress ? *BaseAddress : Funcs.front().startAddress();
738bcb0991SDimitry Andric   const uint64_t MaxAddr = Funcs.back().startAddress();
748bcb0991SDimitry Andric   const uint64_t AddrDelta = MaxAddr - MinAddr;
758bcb0991SDimitry Andric   Header Hdr;
768bcb0991SDimitry Andric   Hdr.Magic = GSYM_MAGIC;
778bcb0991SDimitry Andric   Hdr.Version = GSYM_VERSION;
788bcb0991SDimitry Andric   Hdr.AddrOffSize = 0;
798bcb0991SDimitry Andric   Hdr.UUIDSize = static_cast<uint8_t>(UUID.size());
808bcb0991SDimitry Andric   Hdr.BaseAddress = MinAddr;
818bcb0991SDimitry Andric   Hdr.NumAddresses = static_cast<uint32_t>(Funcs.size());
828bcb0991SDimitry Andric   Hdr.StrtabOffset = 0; // We will fix this up later.
835ffd83dbSDimitry Andric   Hdr.StrtabSize = 0;   // We will fix this up later.
848bcb0991SDimitry Andric   memset(Hdr.UUID, 0, sizeof(Hdr.UUID));
858bcb0991SDimitry Andric   if (UUID.size() > sizeof(Hdr.UUID))
868bcb0991SDimitry Andric     return createStringError(std::errc::invalid_argument,
878bcb0991SDimitry Andric                              "invalid UUID size %u", (uint32_t)UUID.size());
888bcb0991SDimitry Andric   // Set the address offset size correctly in the GSYM header.
898bcb0991SDimitry Andric   if (AddrDelta <= UINT8_MAX)
908bcb0991SDimitry Andric     Hdr.AddrOffSize = 1;
918bcb0991SDimitry Andric   else if (AddrDelta <= UINT16_MAX)
928bcb0991SDimitry Andric     Hdr.AddrOffSize = 2;
938bcb0991SDimitry Andric   else if (AddrDelta <= UINT32_MAX)
948bcb0991SDimitry Andric     Hdr.AddrOffSize = 4;
958bcb0991SDimitry Andric   else
968bcb0991SDimitry Andric     Hdr.AddrOffSize = 8;
978bcb0991SDimitry Andric   // Copy the UUID value if we have one.
988bcb0991SDimitry Andric   if (UUID.size() > 0)
998bcb0991SDimitry Andric     memcpy(Hdr.UUID, UUID.data(), UUID.size());
1008bcb0991SDimitry Andric   // Write out the header.
1018bcb0991SDimitry Andric   llvm::Error Err = Hdr.encode(O);
1028bcb0991SDimitry Andric   if (Err)
1038bcb0991SDimitry Andric     return Err;
1048bcb0991SDimitry Andric 
1058bcb0991SDimitry Andric   // Write out the address offsets.
1068bcb0991SDimitry Andric   O.alignTo(Hdr.AddrOffSize);
1078bcb0991SDimitry Andric   for (const auto &FuncInfo : Funcs) {
1088bcb0991SDimitry Andric     uint64_t AddrOffset = FuncInfo.startAddress() - Hdr.BaseAddress;
1098bcb0991SDimitry Andric     switch (Hdr.AddrOffSize) {
110fe6060f1SDimitry Andric     case 1:
111fe6060f1SDimitry Andric       O.writeU8(static_cast<uint8_t>(AddrOffset));
112fe6060f1SDimitry Andric       break;
113fe6060f1SDimitry Andric     case 2:
114fe6060f1SDimitry Andric       O.writeU16(static_cast<uint16_t>(AddrOffset));
115fe6060f1SDimitry Andric       break;
116fe6060f1SDimitry Andric     case 4:
117fe6060f1SDimitry Andric       O.writeU32(static_cast<uint32_t>(AddrOffset));
118fe6060f1SDimitry Andric       break;
119fe6060f1SDimitry Andric     case 8:
120fe6060f1SDimitry Andric       O.writeU64(AddrOffset);
121fe6060f1SDimitry Andric       break;
1228bcb0991SDimitry Andric     }
1238bcb0991SDimitry Andric   }
1248bcb0991SDimitry Andric 
1258bcb0991SDimitry Andric   // Write out all zeros for the AddrInfoOffsets.
1268bcb0991SDimitry Andric   O.alignTo(4);
1278bcb0991SDimitry Andric   const off_t AddrInfoOffsetsOffset = O.tell();
1288bcb0991SDimitry Andric   for (size_t i = 0, n = Funcs.size(); i < n; ++i)
1298bcb0991SDimitry Andric     O.writeU32(0);
1308bcb0991SDimitry Andric 
1318bcb0991SDimitry Andric   // Write out the file table
1328bcb0991SDimitry Andric   O.alignTo(4);
1338bcb0991SDimitry Andric   assert(!Files.empty());
1348bcb0991SDimitry Andric   assert(Files[0].Dir == 0);
1358bcb0991SDimitry Andric   assert(Files[0].Base == 0);
1368bcb0991SDimitry Andric   size_t NumFiles = Files.size();
1378bcb0991SDimitry Andric   if (NumFiles > UINT32_MAX)
138fe6060f1SDimitry Andric     return createStringError(std::errc::invalid_argument, "too many files");
1398bcb0991SDimitry Andric   O.writeU32(static_cast<uint32_t>(NumFiles));
1408bcb0991SDimitry Andric   for (auto File : Files) {
1418bcb0991SDimitry Andric     O.writeU32(File.Dir);
1428bcb0991SDimitry Andric     O.writeU32(File.Base);
1438bcb0991SDimitry Andric   }
1448bcb0991SDimitry Andric 
1458bcb0991SDimitry Andric   // Write out the sting table.
1468bcb0991SDimitry Andric   const off_t StrtabOffset = O.tell();
1478bcb0991SDimitry Andric   StrTab.write(O.get_stream());
1488bcb0991SDimitry Andric   const off_t StrtabSize = O.tell() - StrtabOffset;
1498bcb0991SDimitry Andric   std::vector<uint32_t> AddrInfoOffsets;
1508bcb0991SDimitry Andric 
1518bcb0991SDimitry Andric   // Write out the address infos for each function info.
1528bcb0991SDimitry Andric   for (const auto &FuncInfo : Funcs) {
1538bcb0991SDimitry Andric     if (Expected<uint64_t> OffsetOrErr = FuncInfo.encode(O))
1548bcb0991SDimitry Andric       AddrInfoOffsets.push_back(OffsetOrErr.get());
1558bcb0991SDimitry Andric     else
1568bcb0991SDimitry Andric       return OffsetOrErr.takeError();
1578bcb0991SDimitry Andric   }
1588bcb0991SDimitry Andric   // Fixup the string table offset and size in the header
1598bcb0991SDimitry Andric   O.fixup32((uint32_t)StrtabOffset, offsetof(Header, StrtabOffset));
1608bcb0991SDimitry Andric   O.fixup32((uint32_t)StrtabSize, offsetof(Header, StrtabSize));
1618bcb0991SDimitry Andric 
1628bcb0991SDimitry Andric   // Fixup all address info offsets
1638bcb0991SDimitry Andric   uint64_t Offset = 0;
1648bcb0991SDimitry Andric   for (auto AddrInfoOffset : AddrInfoOffsets) {
1658bcb0991SDimitry Andric     O.fixup32(AddrInfoOffset, AddrInfoOffsetsOffset + Offset);
1668bcb0991SDimitry Andric     Offset += 4;
1678bcb0991SDimitry Andric   }
1688bcb0991SDimitry Andric   return ErrorSuccess();
1698bcb0991SDimitry Andric }
1708bcb0991SDimitry Andric 
171fe6060f1SDimitry Andric // Similar to std::remove_if, but the predicate is binary and it is passed both
172fe6060f1SDimitry Andric // the previous and the current element.
173fe6060f1SDimitry Andric template <class ForwardIt, class BinaryPredicate>
174fe6060f1SDimitry Andric static ForwardIt removeIfBinary(ForwardIt FirstIt, ForwardIt LastIt,
175fe6060f1SDimitry Andric                                 BinaryPredicate Pred) {
176fe6060f1SDimitry Andric   if (FirstIt != LastIt) {
177fe6060f1SDimitry Andric     auto PrevIt = FirstIt++;
178fe6060f1SDimitry Andric     FirstIt = std::find_if(FirstIt, LastIt, [&](const auto &Curr) {
179fe6060f1SDimitry Andric       return Pred(*PrevIt++, Curr);
180fe6060f1SDimitry Andric     });
181fe6060f1SDimitry Andric     if (FirstIt != LastIt)
182fe6060f1SDimitry Andric       for (ForwardIt CurrIt = FirstIt; ++CurrIt != LastIt;)
183fe6060f1SDimitry Andric         if (!Pred(*PrevIt, *CurrIt)) {
184fe6060f1SDimitry Andric           PrevIt = FirstIt;
185fe6060f1SDimitry Andric           *FirstIt++ = std::move(*CurrIt);
186fe6060f1SDimitry Andric         }
187fe6060f1SDimitry Andric   }
188fe6060f1SDimitry Andric   return FirstIt;
189fe6060f1SDimitry Andric }
190fe6060f1SDimitry Andric 
1918bcb0991SDimitry Andric llvm::Error GsymCreator::finalize(llvm::raw_ostream &OS) {
192fe6060f1SDimitry Andric   std::lock_guard<std::mutex> Guard(Mutex);
1938bcb0991SDimitry Andric   if (Finalized)
194fe6060f1SDimitry Andric     return createStringError(std::errc::invalid_argument, "already finalized");
1958bcb0991SDimitry Andric   Finalized = true;
1968bcb0991SDimitry Andric 
1978bcb0991SDimitry Andric   // Sort function infos so we can emit sorted functions.
198e8d8bef9SDimitry Andric   llvm::sort(Funcs);
1998bcb0991SDimitry Andric 
2008bcb0991SDimitry Andric   // Don't let the string table indexes change by finalizing in order.
2018bcb0991SDimitry Andric   StrTab.finalizeInOrder();
2028bcb0991SDimitry Andric 
2038bcb0991SDimitry Andric   // Remove duplicates function infos that have both entries from debug info
2048bcb0991SDimitry Andric   // (DWARF or Breakpad) and entries from the SymbolTable.
2058bcb0991SDimitry Andric   //
2068bcb0991SDimitry Andric   // Also handle overlapping function. Usually there shouldn't be any, but they
2078bcb0991SDimitry Andric   // can and do happen in some rare cases.
2088bcb0991SDimitry Andric   //
2098bcb0991SDimitry Andric   // (a)          (b)         (c)
2108bcb0991SDimitry Andric   //     ^  ^       ^            ^
2118bcb0991SDimitry Andric   //     |X |Y      |X ^         |X
2128bcb0991SDimitry Andric   //     |  |       |  |Y        |  ^
2138bcb0991SDimitry Andric   //     |  |       |  v         v  |Y
2148bcb0991SDimitry Andric   //     v  v       v               v
2158bcb0991SDimitry Andric   //
2168bcb0991SDimitry Andric   // In (a) and (b), Y is ignored and X will be reported for the full range.
2178bcb0991SDimitry Andric   // In (c), both functions will be included in the result and lookups for an
2188bcb0991SDimitry Andric   // address in the intersection will return Y because of binary search.
2198bcb0991SDimitry Andric   //
2208bcb0991SDimitry Andric   // Note that in case of (b), we cannot include Y in the result because then
2218bcb0991SDimitry Andric   // we wouldn't find any function for range (end of Y, end of X)
2228bcb0991SDimitry Andric   // with binary search
2238bcb0991SDimitry Andric   auto NumBefore = Funcs.size();
224fe6060f1SDimitry Andric   Funcs.erase(
225fe6060f1SDimitry Andric       removeIfBinary(Funcs.begin(), Funcs.end(),
226fe6060f1SDimitry Andric                      [&](const auto &Prev, const auto &Curr) {
227fe6060f1SDimitry Andric                        // Empty ranges won't intersect, but we still need to
228fe6060f1SDimitry Andric                        // catch the case where we have multiple symbols at the
229fe6060f1SDimitry Andric                        // same address and coalesce them.
230fe6060f1SDimitry Andric                        const bool ranges_equal = Prev.Range == Curr.Range;
231fe6060f1SDimitry Andric                        if (ranges_equal || Prev.Range.intersects(Curr.Range)) {
232fe6060f1SDimitry Andric                          // Overlapping ranges or empty identical ranges.
233fe6060f1SDimitry Andric                          if (ranges_equal) {
234fe6060f1SDimitry Andric                            // Same address range. Check if one is from debug
235fe6060f1SDimitry Andric                            // info and the other is from a symbol table. If
236fe6060f1SDimitry Andric                            // so, then keep the one with debug info. Our
237fe6060f1SDimitry Andric                            // sorting guarantees that entries with matching
238fe6060f1SDimitry Andric                            // address ranges that have debug info are last in
239fe6060f1SDimitry Andric                            // the sort.
240fe6060f1SDimitry Andric                            if (Prev == Curr) {
241fe6060f1SDimitry Andric                              // FunctionInfo entries match exactly (range,
242fe6060f1SDimitry Andric                              // lines, inlines)
243fe6060f1SDimitry Andric 
244fe6060f1SDimitry Andric                              // We used to output a warning here, but this was
245fe6060f1SDimitry Andric                              // so frequent on some binaries, in particular
246fe6060f1SDimitry Andric                              // when those were built with GCC, that it slowed
247fe6060f1SDimitry Andric                              // down processing extremely.
248fe6060f1SDimitry Andric                              return true;
2498bcb0991SDimitry Andric                            } else {
250fe6060f1SDimitry Andric                              if (!Prev.hasRichInfo() && Curr.hasRichInfo()) {
251fe6060f1SDimitry Andric                                // Same address range, one with no debug info
252fe6060f1SDimitry Andric                                // (symbol) and the next with debug info. Keep
253fe6060f1SDimitry Andric                                // the latter.
254fe6060f1SDimitry Andric                                return true;
2558bcb0991SDimitry Andric                              } else {
256fe6060f1SDimitry Andric                                if (!Quiet) {
257fe6060f1SDimitry Andric                                  OS << "warning: same address range contains "
258fe6060f1SDimitry Andric                                        "different debug "
2598bcb0991SDimitry Andric                                     << "info. Removing:\n"
260fe6060f1SDimitry Andric                                     << Prev << "\nIn favor of this one:\n"
261fe6060f1SDimitry Andric                                     << Curr << "\n";
262fe6060f1SDimitry Andric                                }
263fe6060f1SDimitry Andric                                return true;
2648bcb0991SDimitry Andric                              }
2658bcb0991SDimitry Andric                            }
2668bcb0991SDimitry Andric                          } else {
267fe6060f1SDimitry Andric                            if (!Quiet) { // print warnings about overlaps
2688bcb0991SDimitry Andric                              OS << "warning: function ranges overlap:\n"
269fe6060f1SDimitry Andric                                 << Prev << "\n"
270fe6060f1SDimitry Andric                                 << Curr << "\n";
2718bcb0991SDimitry Andric                            }
272fe6060f1SDimitry Andric                          }
273fe6060f1SDimitry Andric                        } else if (Prev.Range.size() == 0 &&
274*81ad6265SDimitry Andric                                   Curr.Range.contains(Prev.Range.start())) {
275fe6060f1SDimitry Andric                          if (!Quiet) {
2768bcb0991SDimitry Andric                            OS << "warning: removing symbol:\n"
277fe6060f1SDimitry Andric                               << Prev << "\nKeeping:\n"
278fe6060f1SDimitry Andric                               << Curr << "\n";
2798bcb0991SDimitry Andric                          }
280fe6060f1SDimitry Andric                          return true;
2818bcb0991SDimitry Andric                        }
282fe6060f1SDimitry Andric 
283fe6060f1SDimitry Andric                        return false;
284fe6060f1SDimitry Andric                      }),
285fe6060f1SDimitry Andric       Funcs.end());
2868bcb0991SDimitry Andric 
2875ffd83dbSDimitry Andric   // If our last function info entry doesn't have a size and if we have valid
2885ffd83dbSDimitry Andric   // text ranges, we should set the size of the last entry since any search for
2895ffd83dbSDimitry Andric   // a high address might match our last entry. By fixing up this size, we can
2905ffd83dbSDimitry Andric   // help ensure we don't cause lookups to always return the last symbol that
2915ffd83dbSDimitry Andric   // has no size when doing lookups.
2925ffd83dbSDimitry Andric   if (!Funcs.empty() && Funcs.back().Range.size() == 0 && ValidTextRanges) {
293fe6060f1SDimitry Andric     if (auto Range =
294*81ad6265SDimitry Andric             ValidTextRanges->getRangeThatContains(Funcs.back().Range.start())) {
295*81ad6265SDimitry Andric       Funcs.back().Range = {Funcs.back().Range.start(), Range->end()};
2965ffd83dbSDimitry Andric     }
2975ffd83dbSDimitry Andric   }
2988bcb0991SDimitry Andric   OS << "Pruned " << NumBefore - Funcs.size() << " functions, ended with "
2998bcb0991SDimitry Andric      << Funcs.size() << " total\n";
3008bcb0991SDimitry Andric   return Error::success();
3018bcb0991SDimitry Andric }
3028bcb0991SDimitry Andric 
3035ffd83dbSDimitry Andric uint32_t GsymCreator::insertString(StringRef S, bool Copy) {
3048bcb0991SDimitry Andric   if (S.empty())
3058bcb0991SDimitry Andric     return 0;
306fe6060f1SDimitry Andric 
307fe6060f1SDimitry Andric   // The hash can be calculated outside the lock.
308fe6060f1SDimitry Andric   CachedHashStringRef CHStr(S);
309fe6060f1SDimitry Andric   std::lock_guard<std::mutex> Guard(Mutex);
3105ffd83dbSDimitry Andric   if (Copy) {
3115ffd83dbSDimitry Andric     // We need to provide backing storage for the string if requested
3125ffd83dbSDimitry Andric     // since StringTableBuilder stores references to strings. Any string
3135ffd83dbSDimitry Andric     // that comes from a section in an object file doesn't need to be
3145ffd83dbSDimitry Andric     // copied, but any string created by code will need to be copied.
3155ffd83dbSDimitry Andric     // This allows GsymCreator to be really fast when parsing DWARF and
3165ffd83dbSDimitry Andric     // other object files as most strings don't need to be copied.
3175ffd83dbSDimitry Andric     if (!StrTab.contains(CHStr))
318fe6060f1SDimitry Andric       CHStr = CachedHashStringRef{StringStorage.insert(S).first->getKey(),
319fe6060f1SDimitry Andric                                   CHStr.hash()};
3205ffd83dbSDimitry Andric   }
321fe6060f1SDimitry Andric   return StrTab.add(CHStr);
3228bcb0991SDimitry Andric }
3238bcb0991SDimitry Andric 
3248bcb0991SDimitry Andric void GsymCreator::addFunctionInfo(FunctionInfo &&FI) {
325fe6060f1SDimitry Andric   std::lock_guard<std::mutex> Guard(Mutex);
3265ffd83dbSDimitry Andric   Ranges.insert(FI.Range);
327fe6060f1SDimitry Andric   Funcs.emplace_back(std::move(FI));
3288bcb0991SDimitry Andric }
3298bcb0991SDimitry Andric 
3308bcb0991SDimitry Andric void GsymCreator::forEachFunctionInfo(
3318bcb0991SDimitry Andric     std::function<bool(FunctionInfo &)> const &Callback) {
332fe6060f1SDimitry Andric   std::lock_guard<std::mutex> Guard(Mutex);
3338bcb0991SDimitry Andric   for (auto &FI : Funcs) {
3348bcb0991SDimitry Andric     if (!Callback(FI))
3358bcb0991SDimitry Andric       break;
3368bcb0991SDimitry Andric   }
3378bcb0991SDimitry Andric }
3388bcb0991SDimitry Andric 
3398bcb0991SDimitry Andric void GsymCreator::forEachFunctionInfo(
3408bcb0991SDimitry Andric     std::function<bool(const FunctionInfo &)> const &Callback) const {
341fe6060f1SDimitry Andric   std::lock_guard<std::mutex> Guard(Mutex);
3428bcb0991SDimitry Andric   for (const auto &FI : Funcs) {
3438bcb0991SDimitry Andric     if (!Callback(FI))
3448bcb0991SDimitry Andric       break;
3458bcb0991SDimitry Andric   }
3468bcb0991SDimitry Andric }
3475ffd83dbSDimitry Andric 
3485ffd83dbSDimitry Andric size_t GsymCreator::getNumFunctionInfos() const {
349fe6060f1SDimitry Andric   std::lock_guard<std::mutex> Guard(Mutex);
3505ffd83dbSDimitry Andric   return Funcs.size();
3515ffd83dbSDimitry Andric }
3525ffd83dbSDimitry Andric 
3535ffd83dbSDimitry Andric bool GsymCreator::IsValidTextAddress(uint64_t Addr) const {
3545ffd83dbSDimitry Andric   if (ValidTextRanges)
3555ffd83dbSDimitry Andric     return ValidTextRanges->contains(Addr);
3565ffd83dbSDimitry Andric   return true; // No valid text ranges has been set, so accept all ranges.
3575ffd83dbSDimitry Andric }
3585ffd83dbSDimitry Andric 
3595ffd83dbSDimitry Andric bool GsymCreator::hasFunctionInfoForAddress(uint64_t Addr) const {
360fe6060f1SDimitry Andric   std::lock_guard<std::mutex> Guard(Mutex);
3615ffd83dbSDimitry Andric   return Ranges.contains(Addr);
3625ffd83dbSDimitry Andric }
363