LLVM  14.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/Optional.h"
13 #include "llvm/ADT/StringRef.h"
15 #include <stdint.h>
16 
17 namespace llvm {
18 namespace 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.
22 struct StringTable {
24  StringTable() : Data() {}
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 
38  OS << "String table:\n";
39  uint32_t Offset = 0;
40  const size_t Size = S.Data.size();
41  while (Offset < Size) {
42  StringRef Str = S.getString(Offset);
43  OS << HEX32(Offset) << ": \"" << Str << "\"\n";
44  Offset += Str.size() + 1;
45  }
46  return OS;
47 }
48 
49 } // namespace gsym
50 } // namespace llvm
51 #endif // LLVM_DEBUGINFO_GSYM_STRINGTABLE_H
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::gsym::StringTable::operator[]
StringRef operator[](size_t Offset) const
Definition: StringTable.h:26
Optional.h
StringRef.h
llvm::gsym::StringTable::clear
void clear()
Definition: StringTable.h:34
llvm::StringRef::find
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition: StringRef.h:315
llvm::gsym::StringTable::StringTable
StringTable(StringRef D)
Definition: StringTable.h:25
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::StringRef::substr
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:611
llvm::gsym::operator<<
raw_ostream & operator<<(raw_ostream &OS, const FunctionInfo &R)
Definition: FunctionInfo.cpp:27
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Range.h
llvm::gsym::StringTable::Data
StringRef Data
Definition: StringTable.h:23
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
uint32_t
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
HEX32
#define HEX32(v)
Definition: Range.h:20
llvm::gsym::StringTable::StringTable
StringTable()
Definition: StringTable.h:24
llvm::gsym::StringTable
String tables in GSYM files are required to start with an empty string at offset zero.
Definition: StringTable.h:22
llvm::gsym::StringTable::getString
StringRef getString(uint32_t Offset) const
Definition: StringTable.h:27
llvm::StringRef::size
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:157