| 1 | //===- GlobalData.cpp -----------------------------------------------------===// |
|---|---|
| 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 | #include "llvm/DebugInfo/GSYM/GlobalData.h" |
| 10 | #include "llvm/DebugInfo/GSYM/FileWriter.h" |
| 11 | #include "llvm/DebugInfo/GSYM/GsymDataExtractor.h" |
| 12 | #include <inttypes.h> |
| 13 | |
| 14 | using namespace llvm; |
| 15 | using namespace gsym; |
| 16 | |
| 17 | void GlobalData::encode(FileWriter &O) const { |
| 18 | O.writeU32(Value: static_cast<uint32_t>(Type)); |
| 19 | O.writeU64(Value: FileOffset); |
| 20 | O.writeU64(Value: FileSize); |
| 21 | } |
| 22 | |
| 23 | llvm::Expected<GlobalData> GlobalData::decode(GsymDataExtractor &GsymData, |
| 24 | uint64_t &Offset) { |
| 25 | if (!GsymData.isValidOffsetForDataOfSize(offset: Offset, length: 20)) |
| 26 | return createStringError(EC: std::errc::invalid_argument, |
| 27 | Fmt: "not enough data for a GlobalData entry"); |
| 28 | GlobalData GD; |
| 29 | GD.Type = static_cast<GlobalInfoType>(GsymData.getU32(offset_ptr: &Offset)); |
| 30 | GD.FileOffset = GsymData.getU64(offset_ptr: &Offset); |
| 31 | GD.FileSize = GsymData.getU64(offset_ptr: &Offset); |
| 32 | return GD; |
| 33 | } |
| 34 | |
| 35 | StringRef llvm::gsym::getNameForGlobalInfoType(GlobalInfoType Type) { |
| 36 | switch (Type) { |
| 37 | case GlobalInfoType::EndOfList: |
| 38 | return "EndOfList"; |
| 39 | case GlobalInfoType::AddrOffsets: |
| 40 | return "AddrOffsets"; |
| 41 | case GlobalInfoType::AddrInfoOffsets: |
| 42 | return "AddrInfoOffsets"; |
| 43 | case GlobalInfoType::StringTable: |
| 44 | return "StringTable"; |
| 45 | case GlobalInfoType::FileTable: |
| 46 | return "FileTable"; |
| 47 | case GlobalInfoType::FunctionInfo: |
| 48 | return "FunctionInfo"; |
| 49 | case GlobalInfoType::UUID: |
| 50 | return "UUID"; |
| 51 | } |
| 52 | return "Unknown"; |
| 53 | } |
| 54 |