1 //===- StringTable.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_STRINGTABLE_H
11 #define LLVM_DEBUGINFO_GSYM_STRINGTABLE_H
13 #include "llvm/ADT/Optional.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/DebugInfo/GSYM/Range.h"
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.
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);
37 void clear() { Data = StringRef(); }
40 inline raw_ostream &operator<<(raw_ostream &OS, const StringTable &S) {
41 OS << "String table:\n";
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;
54 #endif // #ifndef LLVM_DEBUGINFO_GSYM_STRINGTABLE_H