File indexing completed on 2026-05-10 08:43:44
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_DEBUGINFO_PDB_NATIVE_FORMATUTIL_H
0010 #define LLVM_DEBUGINFO_PDB_NATIVE_FORMATUTIL_H
0011
0012 #include "llvm/ADT/ArrayRef.h"
0013 #include "llvm/ADT/STLForwardCompat.h"
0014 #include "llvm/ADT/StringRef.h"
0015 #include "llvm/DebugInfo/CodeView/CodeView.h"
0016 #include "llvm/Support/Endian.h"
0017 #include "llvm/Support/FormatAdapters.h"
0018 #include "llvm/Support/FormatVariadic.h"
0019
0020 #include <string>
0021 #include <type_traits>
0022
0023 namespace llvm {
0024 namespace pdb {
0025
0026 #define PUSH_MASKED_FLAG(Enum, Mask, TheOpt, Value, Text) \
0027 if (Enum::TheOpt == (Value & Mask)) \
0028 Opts.push_back(Text);
0029
0030 #define PUSH_FLAG(Enum, TheOpt, Value, Text) \
0031 PUSH_MASKED_FLAG(Enum, Enum::TheOpt, TheOpt, Value, Text)
0032
0033 #define RETURN_CASE(Enum, X, Ret) \
0034 case Enum::X: \
0035 return Ret;
0036
0037 template <typename T> std::string formatUnknownEnum(T Value) {
0038 return formatv("unknown ({0})", llvm::to_underlying(Value)).str();
0039 }
0040
0041 std::string formatSegmentOffset(uint16_t Segment, uint32_t Offset);
0042
0043 enum class CharacteristicStyle {
0044 HeaderDefinition,
0045 Descriptive,
0046 };
0047 std::string formatSectionCharacteristics(
0048 uint32_t IndentLevel, uint32_t C, uint32_t FlagsPerLine,
0049 StringRef Separator,
0050 CharacteristicStyle Style = CharacteristicStyle::HeaderDefinition);
0051
0052 std::string typesetItemList(ArrayRef<std::string> Opts, uint32_t IndentLevel,
0053 uint32_t GroupSize, StringRef Sep);
0054
0055 std::string typesetStringList(uint32_t IndentLevel,
0056 ArrayRef<StringRef> Strings);
0057
0058 std::string formatChunkKind(codeview::DebugSubsectionKind Kind,
0059 bool Friendly = true);
0060 std::string formatSymbolKind(codeview::SymbolKind K);
0061 std::string formatTypeLeafKind(codeview::TypeLeafKind K);
0062
0063
0064 inline int NumDigits(uint64_t N) {
0065 if (N < 10ULL)
0066 return 1;
0067 if (N < 100ULL)
0068 return 2;
0069 if (N < 1000ULL)
0070 return 3;
0071 if (N < 10000ULL)
0072 return 4;
0073 if (N < 100000ULL)
0074 return 5;
0075 if (N < 1000000ULL)
0076 return 6;
0077 if (N < 10000000ULL)
0078 return 7;
0079 if (N < 100000000ULL)
0080 return 8;
0081 if (N < 1000000000ULL)
0082 return 9;
0083 if (N < 10000000000ULL)
0084 return 10;
0085 if (N < 100000000000ULL)
0086 return 11;
0087 if (N < 1000000000000ULL)
0088 return 12;
0089 if (N < 10000000000000ULL)
0090 return 13;
0091 if (N < 100000000000000ULL)
0092 return 14;
0093 if (N < 1000000000000000ULL)
0094 return 15;
0095 if (N < 10000000000000000ULL)
0096 return 16;
0097 if (N < 100000000000000000ULL)
0098 return 17;
0099 if (N < 1000000000000000000ULL)
0100 return 18;
0101 if (N < 10000000000000000000ULL)
0102 return 19;
0103 return 20;
0104 }
0105
0106 namespace detail {
0107 template <typename T>
0108 struct EndianAdapter final
0109 : public FormatAdapter<support::detail::packed_endian_specific_integral<
0110 T, llvm::endianness::little, support::unaligned>> {
0111 using EndianType = support::detail::packed_endian_specific_integral<
0112 T, llvm::endianness::little, support::unaligned>;
0113
0114 explicit EndianAdapter(EndianType &&Item)
0115 : FormatAdapter<EndianType>(std::move(Item)) {}
0116
0117 void format(llvm::raw_ostream &Stream, StringRef Style) override {
0118 format_provider<T>::format(static_cast<T>(this->Item), Stream, Style);
0119 }
0120 };
0121 }
0122
0123 template <typename T>
0124 detail::EndianAdapter<T> fmtle(support::detail::packed_endian_specific_integral<
0125 T, llvm::endianness::little, support::unaligned>
0126 Value) {
0127 return detail::EndianAdapter<T>(std::move(Value));
0128 }
0129 }
0130 }
0131 #endif