]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/DebugInfo/GSYM/StringTable.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / DebugInfo / GSYM / StringTable.h
1 //===- StringTable.h --------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_DEBUGINFO_GSYM_STRINGTABLE_H
11 #define LLVM_DEBUGINFO_GSYM_STRINGTABLE_H
12
13 #include "llvm/ADT/Optional.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/DebugInfo/GSYM/Range.h"
16 #include <stdint.h>
17 #include <string>
18
19
20 namespace llvm {
21 namespace gsym {
22
23 /// String tables in GSYM files are required to start with an empty
24 /// string at offset zero. Strings must be UTF8 NULL terminated strings.
25 struct StringTable {
26   StringRef Data;
27   StringTable() : Data() {}
28   StringTable(StringRef D) : Data(D) {}
29   StringRef operator[](size_t Offset) const { return getString(Offset); }
30   StringRef getString(uint32_t Offset) const {
31     if (Offset < Data.size()) {
32       auto End = Data.find('\0', Offset);
33       return Data.substr(Offset, End - Offset);
34     }
35     return StringRef();
36   }
37   void clear() { Data = StringRef(); }
38 };
39
40 inline raw_ostream &operator<<(raw_ostream &OS, const StringTable &S) {
41   OS << "String table:\n";
42   uint32_t Offset = 0;
43   const size_t Size = S.Data.size();
44   while (Offset < Size) {
45     StringRef Str = S.getString(Offset);
46     OS << HEX32(Offset) << ": \"" << Str << "\"\n";
47     Offset += Str.size() + 1;
48   }
49   return OS;
50 }
51
52 } // namespace gsym
53 } // namespace llvm
54 #endif // #ifndef LLVM_DEBUGINFO_GSYM_STRINGTABLE_H