LLVM  10.0.0svn
StringTable.h
Go to the documentation of this file.
1 //===- StringTable.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_STRINGTABLE_H
10 #define LLVM_DEBUGINFO_GSYM_STRINGTABLE_H
11 
12 #include "llvm/ADT/Optional.h"
13 #include "llvm/ADT/StringRef.h"
15 #include <stdint.h>
16 #include <string>
17 
18 
19 namespace llvm {
20 namespace gsym {
21 
22 /// String tables in GSYM files are required to start with an empty
23 /// string at offset zero. Strings must be UTF8 NULL terminated strings.
24 struct StringTable {
26  StringTable() : Data() {}
27  StringTable(StringRef D) : Data(D) {}
28  StringRef operator[](size_t Offset) const { return getString(Offset); }
30  if (Offset < Data.size()) {
31  auto End = Data.find('\0', Offset);
32  return Data.substr(Offset, End - Offset);
33  }
34  return StringRef();
35  }
36  void clear() { Data = StringRef(); }
37 };
38 
40  OS << "String table:\n";
41  uint32_t Offset = 0;
42  const size_t Size = S.Data.size();
43  while (Offset < Size) {
44  StringRef Str = S.getString(Offset);
45  OS << HEX32(Offset) << ": \"" << Str << "\"\n";
46  Offset += Str.size() + 1;
47  }
48  return OS;
49 }
50 
51 } // namespace gsym
52 } // namespace llvm
53 #endif // #ifndef LLVM_DEBUGINFO_GSYM_STRINGTABLE_H
StringRef operator[](size_t Offset) const
Definition: StringTable.h:28
This class represents lattice values for constants.
Definition: AllocatorList.h:23
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:592
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:144
StringTable(StringRef D)
Definition: StringTable.h:27
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition: StringRef.h:299
String tables in GSYM files are required to start with an empty string at offset zero.
Definition: StringTable.h:24
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
uint32_t Size
Definition: Profile.cpp:46
#define HEX32(v)
Definition: Range.h:19
StringRef getString(uint32_t Offset) const
Definition: StringTable.h:29
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
raw_ostream & operator<<(raw_ostream &OS, const FunctionInfo &R)