1 //===- StringTable.h --------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_DEBUGINFO_GSYM_STRINGTABLE_H
10 #define LLVM_DEBUGINFO_GSYM_STRINGTABLE_H
12 #include "llvm/ADT/Optional.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/DebugInfo/GSYM/Range.h"
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.
26 StringTable() : Data() {}
27 StringTable(StringRef D
) : Data(D
) {}
28 StringRef
operator[](size_t Offset
) const { return getString(Offset
); }
29 StringRef
getString(uint32_t Offset
) const {
30 if (Offset
< Data
.size()) {
31 auto End
= Data
.find('\0', Offset
);
32 return Data
.substr(Offset
, End
- Offset
);
36 void clear() { Data
= StringRef(); }
39 inline raw_ostream
&operator<<(raw_ostream
&OS
, const StringTable
&S
) {
40 OS
<< "String table:\n";
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;
53 #endif // #ifndef LLVM_DEBUGINFO_GSYM_STRINGTABLE_H