LLVM: lib/Support/ELFAttrParserCompact.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

16

17using namespace llvm;

19

25

29 if (value >= strings.size()) {

33 " value: " + Twine(value));

34 }

37}

38

43 attributes.insert(std::make_pair(tag, value));

44

45 if (sw) {

47 sw->printNumber("Tag", tag);

48 if (!tagName.empty())

49 sw->printString("TagName", tagName);

50 sw->printNumber("Value", value);

51 }

53}

54

60

61 if (sw) {

63 sw->printNumber("Tag", tag);

64 if (!tagName.empty())

65 sw->printString("TagName", tagName);

66 sw->printString("Value", desc);

67 }

69}

70

73 attributes.insert(std::make_pair(tag, value));

74

75 if (sw) {

77 false);

79 sw->printNumber("Tag", tag);

80 sw->printNumber("Value", value);

81 if (!tagName.empty())

82 sw->printString("TagName", tagName);

83 if (!valueDesc.empty())

84 sw->printString("Description", valueDesc);

85 }

86}

87

89 for (;;) {

91 if (cursor || !value)

92 break;

94 }

95}

96

100 while ((pos = cursor.tell()) < end) {

102 bool handled;

103 if (Error e = handler(tag, handled))

104 return e;

105

106 if (!handled) {

107 if (tag < 32) {

111 }

112

113 if (tag % 2 == 0) {

115 return e;

116 } else {

118 return e;

119 }

120 }

121 }

123}

124

126 uint64_t end = cursor.tell() - sizeof(length) + length;

128 if (sw) {

129 sw->printNumber("SectionLength", length);

130 sw->printString("Vendor", vendorName);

131 }

132

133

134

135

136

137 if (vendorName.lower() != vendor) {

140 }

141

142 while (cursor.tell() < end) {

143

147 return cursor.takeError();

148

149 if (sw) {

151 sw->printNumber("Size", size);

152 }

153 if (size < 5)

155 "invalid attribute size " + Twine(size) +

156 " at offset 0x" +

158

161 switch (tag) {

163 scopeName = "FileAttributes";

164 break;

166 scopeName = "SectionAttributes";

167 indexName = "Sections";

169 break;

171 scopeName = "SymbolAttributes";

172 indexName = "Symbols";

174 break;

175 default:

178 " at offset 0x" +

180 }

181

182 if (sw) {

184 if (!indices.empty())

185 sw->printList(indexName, indices);

187 return e;

189 return e;

190 }

192}

193

196 unsigned sectionNumber = 0;

198

199

200

201 struct ClearCursorError {

205

206

210 "unrecognized format-version: 0x" +

212

216 return cursor.takeError();

217

218 if (sw) {

219 sw->startLine() << "Section " << ++sectionNumber << " {\n";

220 sw->indent();

221 }

222

223 if (sectionLength < 4 || cursor.tell() - 4 + sectionLength > section.size())

225 "invalid section length " +

226 Twine(sectionLength) + " at offset 0x" +

228

230 return e;

231 if (sw) {

232 sw->unindent();

233 sw->startLine() << "}\n";

234 }

235 }

236

237 return cursor.takeError();

238}

static constexpr EnumEntry< unsigned > tagNames[]

Definition ELFAttrParserCompact.cpp:20

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

size_t size() const

size - Get the array size.

void setAttributeString(unsigned tag, StringRef value)

Error integerAttribute(unsigned tag)

Definition ELFAttrParserCompact.cpp:39

TagNameMap tagToStringMap

void parseIndexList(SmallVectorImpl< uint8_t > &indexList)

Definition ELFAttrParserCompact.cpp:88

Error stringAttribute(unsigned tag)

Definition ELFAttrParserCompact.cpp:55

Error parseAttributeList(uint32_t length)

Definition ELFAttrParserCompact.cpp:97

void printAttribute(unsigned tag, unsigned value, StringRef valueDesc)

Definition ELFAttrParserCompact.cpp:71

DataExtractor::Cursor cursor

Error parseSubsection(uint32_t length)

Definition ELFAttrParserCompact.cpp:125

Error parse(ArrayRef< uint8_t > section, llvm::endianness endian) override

Definition ELFAttrParserCompact.cpp:194

Error parseStringAttribute(const char *name, unsigned tag, ArrayRef< const char * > strings)

Definition ELFAttrParserCompact.cpp:26

Lightweight error class with error context and mandatory checking.

static ErrorSuccess success()

Create a success value.

This class consists of common code factored out of the SmallVector class to reduce code duplication b...

void push_back(const T &Elt)

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

StringRef - Represent a constant reference to a string, i.e.

constexpr bool empty() const

empty - Check if the string is empty.

LLVM_ABI std::string lower() const

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

static Twine utohexstr(uint64_t Val)

LLVM_ABI StringRef attrTypeAsString(unsigned attr, TagNameMap tagNameMap, bool hasTagPrefix=true)

This is an optimization pass for GlobalISel generic memory operations.

auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)

Get the size of a range.

std::string utohexstr(uint64_t X, bool LowerCase=false, unsigned Width=0)

Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)

Create formatted StringError object.

ArrayRef(const T &OneElt) -> ArrayRef< T >

void consumeError(Error Err)

Consume a Error without doing anything.