mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2026-01-31 01:35:20 +01:00
The full GSYM patch started with: https://reviews.llvm.org/D53379 This patch add the ability to encode data using the new llvm::gsym::FileWriter class. FileWriter is a simplified binary data writer class that doesn't require targets, target definitions, architectures, or require any other optional compile time libraries to be enabled via the build process. This class needs the ability to seek to different spots in the binary data that it produces to fix up offsets and sizes in GSYM data. It currently uses std::ostream over llvm::raw_ostream because llvm::raw_ostream doesn't support seeking which is required when encoding and decoding GSYM data. AddressRange objects are encoded and decoded to be relative to a base address. This will be the FunctionInfo's start address if the AddressRange is directly contained in a FunctionInfo, or a base address of the containing parent AddressRange or AddressRanges. This allows address ranges to be efficiently encoded using ULEB128 encodings as we encode the offset and size of each range instead of full addresses. This also makes encoded addresses easy to relocate as we just need to relocate one base address. Differential Revision: https://reviews.llvm.org/D63828 llvm-svn: 369587
54 lines
1.6 KiB
C++
54 lines
1.6 KiB
C++
//===- StringTable.h --------------------------------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_DEBUGINFO_GSYM_STRINGTABLE_H
|
|
#define LLVM_DEBUGINFO_GSYM_STRINGTABLE_H
|
|
|
|
#include "llvm/ADT/Optional.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "llvm/DebugInfo/GSYM/Range.h"
|
|
#include <stdint.h>
|
|
#include <string>
|
|
|
|
|
|
namespace llvm {
|
|
namespace gsym {
|
|
|
|
/// String tables in GSYM files are required to start with an empty
|
|
/// string at offset zero. Strings must be UTF8 NULL terminated strings.
|
|
struct StringTable {
|
|
StringRef Data;
|
|
StringTable() : Data() {}
|
|
StringTable(StringRef D) : Data(D) {}
|
|
StringRef operator[](size_t Offset) const { return getString(Offset); }
|
|
StringRef getString(uint32_t Offset) const {
|
|
if (Offset < Data.size()) {
|
|
auto End = Data.find('\0', Offset);
|
|
return Data.substr(Offset, End - Offset);
|
|
}
|
|
return StringRef();
|
|
}
|
|
void clear() { Data = StringRef(); }
|
|
};
|
|
|
|
inline raw_ostream &operator<<(raw_ostream &OS, const StringTable &S) {
|
|
OS << "String table:\n";
|
|
uint32_t Offset = 0;
|
|
const size_t Size = S.Data.size();
|
|
while (Offset < Size) {
|
|
StringRef Str = S.getString(Offset);
|
|
OS << HEX32(Offset) << ": \"" << Str << "\"\n";
|
|
Offset += Str.size() + 1;
|
|
}
|
|
return OS;
|
|
}
|
|
|
|
} // namespace gsym
|
|
} // namespace llvm
|
|
#endif // #ifndef LLVM_DEBUGINFO_GSYM_STRINGTABLE_H
|