LLVM 23.0.0git
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/StringRef.h"
15#include <stdint.h>
16
17namespace llvm {
18namespace gsym {
19
20/// String tables in GSYM files are required to start with an empty
21/// string at offset zero. Strings must be UTF8 NULL terminated strings.
24 StringTable() = default;
26 StringRef operator[](size_t Offset) const { return getString(Offset); }
28 if (Offset < Data.size()) {
29 auto End = Data.find('\0', Offset);
30 return Data.substr(Offset, End - Offset);
31 }
32 return StringRef();
33 }
34 void clear() { Data = StringRef(); }
35};
36
37inline void dump(raw_ostream &OS, const StringTable &S,
38 uint8_t StringOffsetSize) {
39 OS << "String table:\n";
41 const size_t Size = S.Data.size();
42 while (Offset < Size) {
43 StringRef Str = S.getString(Offset);
44 switch (StringOffsetSize) {
45 case 1:
46 OS << HEX8(Offset);
47 break;
48 case 2:
49 OS << HEX16(Offset);
50 break;
51 case 4:
52 OS << HEX32(Offset);
53 break;
54 case 8:
55 OS << HEX64(Offset);
56 break;
57 default:
58 OS << HEX64(Offset);
59 }
60 OS << ": \"" << Str << "\"\n";
61 Offset += Str.size() + 1;
62 }
63}
64
65} // namespace gsym
66} // namespace llvm
67#endif // LLVM_DEBUGINFO_GSYM_STRINGTABLE_H
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define HEX8(v)
#define HEX16(v)
#define HEX64(v)
#define HEX32(v)
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
constexpr size_t size() const
size - Get the string size.
Definition StringRef.h:143
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
uint64_t gsym_strp_t
The type of string offset used in the code.
Definition GsymTypes.h:21
void dump(raw_ostream &OS, const StringTable &S, uint8_t StringOffsetSize)
Definition StringTable.h:37
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:532
String tables in GSYM files are required to start with an empty string at offset zero.
Definition StringTable.h:22
StringRef getString(gsym_strp_t Offset) const
Definition StringTable.h:27
StringTable(StringRef D)
Definition StringTable.h:25
StringRef operator[](size_t Offset) const
Definition StringTable.h:26