blob: 0001b8b82743ca51a3b79e3a94fa1a8656bc9265 [file] [log] [blame]
Andrew Walbran3d2c1972020-04-07 12:24:26 +01001//===- 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
20namespace llvm {
21namespace 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.
25struct 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
40inline 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