Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:42

0001 //===- StringTable.h --------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_DEBUGINFO_GSYM_STRINGTABLE_H
0010 #define LLVM_DEBUGINFO_GSYM_STRINGTABLE_H
0011 
0012 #include "llvm/ADT/StringRef.h"
0013 #include "llvm/DebugInfo/GSYM/ExtractRanges.h"
0014 #include <stdint.h>
0015 
0016 namespace llvm {
0017 namespace gsym {
0018 
0019 /// String tables in GSYM files are required to start with an empty
0020 /// string at offset zero. Strings must be UTF8 NULL terminated strings.
0021 struct StringTable {
0022   StringRef Data;
0023   StringTable() = default;
0024   StringTable(StringRef D) : Data(D) {}
0025   StringRef operator[](size_t Offset) const { return getString(Offset); }
0026   StringRef getString(uint32_t Offset) const {
0027     if (Offset < Data.size()) {
0028       auto End = Data.find('\0', Offset);
0029       return Data.substr(Offset, End - Offset);
0030     }
0031     return StringRef();
0032   }
0033   void clear() { Data = StringRef(); }
0034 };
0035 
0036 inline raw_ostream &operator<<(raw_ostream &OS, const StringTable &S) {
0037   OS << "String table:\n";
0038   uint32_t Offset = 0;
0039   const size_t Size = S.Data.size();
0040   while (Offset < Size) {
0041     StringRef Str = S.getString(Offset);
0042     OS << HEX32(Offset) << ": \"" << Str << "\"\n";
0043     Offset += Str.size() + 1;
0044   }
0045   return OS;
0046 }
0047 
0048 } // namespace gsym
0049 } // namespace llvm
0050 #endif // LLVM_DEBUGINFO_GSYM_STRINGTABLE_H