LLVM: lib/DebugInfo/GSYM/LineTable.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

12

13using namespace llvm;

14using namespace gsym;

15

23

29

31 return LHS.Delta < Delta;

32}

33

34static bool encodeSpecial(int64_t MinLineDelta, int64_t MaxLineDelta,

35 int64_t LineDelta, uint64_t AddrDelta,

37 if (LineDelta < MinLineDelta)

38 return false;

39 if (LineDelta > MaxLineDelta)

40 return false;

41 int64_t LineRange = MaxLineDelta - MinLineDelta + 1;

42 int64_t AdjustedOp = ((LineDelta - MinLineDelta) + AddrDelta * LineRange);

44 if (Op < 0)

45 return false;

46 if (Op > 255)

47 return false;

49 return true;

50}

51

53

59 "0x%8.8" PRIx64 ": missing LineTable MinDelta", Offset);

60 int64_t MinDelta = Data.getSLEB128(&Offset);

63 "0x%8.8" PRIx64 ": missing LineTable MaxDelta", Offset);

64 int64_t MaxDelta = Data.getSLEB128(&Offset);

65 int64_t LineRange = MaxDelta - MinDelta + 1;

68 "0x%8.8" PRIx64 ": missing LineTable FirstLine", Offset);

70 LineEntry Row(BaseAddr, 1, FirstLine);

71 bool Done = false;

72 while (Done) {

75 "0x%8.8" PRIx64 ": EOF found before EndSequence", Offset);

77 switch (Op) {

80 break;

84 "0x%8.8" PRIx64 ": EOF found before SetFile value",

87 break;

91 "0x%8.8" PRIx64 ": EOF found before AdvancePC value",

94

95 if (Callback(Row) == false)

97 break;

101 "0x%8.8" PRIx64 ": EOF found before AdvanceLine value",

103 Row.Line += Data.getSLEB128(&Offset);

104 break;

105 default: {

106

108 int64_t LineDelta = MinDelta + (AdjustedOp % LineRange);

109 uint64_t AddrDelta = (AdjustedOp / LineRange);

110 Row.Line += LineDelta;

111 Row.Addr += AddrDelta;

112

113 if (Callback(Row) == false)

115 break;

116 }

117 }

118 }

120}

121

123

124

125

128 "attempted to encode invalid LineTable object");

129

130 int64_t MinLineDelta = INT64_MAX;

131 int64_t MaxLineDelta = INT64_MIN;

132 std::vector DeltaInfos;

133 if (Lines.size() == 1) {

134 MinLineDelta = 0;

135 MaxLineDelta = 0;

136 } else {

137 int64_t PrevLine = 1;

138 bool First = true;

139 for (const auto &line_entry : Lines) {

142 else {

143 int64_t LineDelta = (int64_t)line_entry.Line - PrevLine;

144 auto End = DeltaInfos.end();

145 auto Pos = std::lower_bound(DeltaInfos.begin(), End, LineDelta);

146 if (Pos != End && Pos->Delta == LineDelta)

147 ++Pos->Count;

148 else

149 DeltaInfos.insert(Pos, DeltaInfo(LineDelta, 1));

150 if (LineDelta < MinLineDelta)

151 MinLineDelta = LineDelta;

152 if (LineDelta > MaxLineDelta)

153 MaxLineDelta = LineDelta;

154 }

155 PrevLine = (int64_t)line_entry.Line;

156 }

157 assert(MinLineDelta <= MaxLineDelta);

158 }

159

160

161 const int64_t MaxLineRange = 14;

162 if (MaxLineDelta - MinLineDelta > MaxLineRange) {

166 const size_t NumDeltaInfos = DeltaInfos.size();

167 for (uint32_t I = 0; I < NumDeltaInfos; ++I) {

168 const int64_t FirstDelta = DeltaInfos[I].Delta;

171 for (J = I; J < NumDeltaInfos; ++J) {

172 auto LineRange = DeltaInfos[J].Delta - FirstDelta;

173 if (LineRange > MaxLineRange)

174 break;

175 CurrCount += DeltaInfos[J].Count;

176 }

177 if (CurrCount > BestCount) {

178 BestIndex = I;

179 BestEndIndex = J - 1;

180 BestCount = CurrCount;

181 }

182 }

183 MinLineDelta = DeltaInfos[BestIndex].Delta;

184 MaxLineDelta = DeltaInfos[BestEndIndex].Delta;

185 }

186 if (MinLineDelta == MaxLineDelta && MinLineDelta > 0 &&

187 MinLineDelta < MaxLineRange)

188 MinLineDelta = 0;

189 assert(MinLineDelta <= MaxLineDelta);

190

191

192

193 LineEntry Prev(BaseAddr, 1, Lines.front().Line);

194

195

198

200

201 for (const auto &Curr : Lines) {

202 if (Curr.Addr < BaseAddr)

204 "LineEntry has address 0x%" PRIx64 " which is "

205 "less than the function start address 0x%"

206 PRIx64, Curr.Addr, BaseAddr);

207 if (Curr.Addr < Prev.Addr)

209 "LineEntry in LineTable not in ascending order");

210 const uint64_t AddrDelta = Curr.Addr - Prev.Addr;

211 int64_t LineDelta = 0;

212 if (Curr.Line > Prev.Line)

213 LineDelta = Curr.Line - Prev.Line;

214 else if (Prev.Line > Curr.Line)

215 LineDelta = -((int32_t)(Prev.Line - Curr.Line));

216

217

218 if (Curr.File != Prev.File) {

221 }

222

224 if (encodeSpecial(MinLineDelta, MaxLineDelta, LineDelta, AddrDelta,

225 SpecialOp)) {

226

228 } else {

229

230

231

232

233 if (LineDelta != 0) {

236 }

237

238

241 }

242 Prev = Curr;

243 }

246}

247

248

249

250

255 LT.Lines.push_back(Row);

256 return true;

257 });

258 if (Err)

259 return std::move(Err);

260 return LT;

261}

262

263

264

265

269 [Addr, &Result](const LineEntry &Row) -> bool {

270 if (Addr < Row.Addr)

271 return false;

272 Result = Row;

273 return true;

274 });

275 if (Err)

276 return std::move(Err);

277 if (Result.isValid())

278 return Result;

280 "address 0x%" PRIx64 " is not in the line table",

281 Addr);

282}

283

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")

static llvm::Error parse(DataExtractor &Data, uint64_t BaseAddr, LineEntryCallback const &Callback)

Definition LineTable.cpp:54

LineTableOpCode

Definition LineTable.cpp:16

@ SetFile

Set LineTableRow.file_idx, don't push a row.

Definition LineTable.cpp:18

@ FirstSpecial

All special opcodes push a row.

Definition LineTable.cpp:21

@ AdvanceLine

Set LineTableRow.file_line, don't push a row.

Definition LineTable.cpp:20

@ EndSequence

End of the line table.

Definition LineTable.cpp:17

@ AdvancePC

Increment LineTableRow.address, and push a row.

Definition LineTable.cpp:19

static bool encodeSpecial(int64_t MinLineDelta, int64_t MaxLineDelta, int64_t LineDelta, uint64_t AddrDelta, uint8_t &SpecialOp)

Definition LineTable.cpp:34

std::function< bool(const LineEntry &Row)> LineEntryCallback

Definition LineTable.cpp:52

Lightweight error class with error context and mandatory checking.

static ErrorSuccess success()

Create a success value.

Tagged union holding either a T or a Error.

A simplified binary data writer class that doesn't require targets, target definitions,...

LLVM_ABI void writeULEB(uint64_t Value)

Write the value into the stream encoded using unsigned LEB128 at the current file position.

LLVM_ABI void writeSLEB(int64_t Value)

Write the value into the stream encoded using signed LEB128 at the current file position.

LLVM_ABI void writeU8(uint8_t Value)

Write a single uint8_t value into the stream at the current file position.

LineTable class contains deserialized versions of line tables for each function's address ranges.

LLVM_ABI llvm::Error encode(FileWriter &O, uint64_t BaseAddr) const

Encode this LineTable object into FileWriter stream.

Definition LineTable.cpp:122

static LLVM_ABI llvm::Expected< LineTable > decode(DataExtractor &Data, uint64_t BaseAddr)

Decode an LineTable object from a binary data stream.

Definition LineTable.cpp:251

static LLVM_ABI Expected< LineEntry > lookup(DataExtractor &Data, uint64_t BaseAddr, uint64_t Addr)

Lookup a single address within a line table's data.

Definition LineTable.cpp:266

This class implements an extremely fast bulk output stream that can only output to a stream.

@ C

The default llvm calling convention, compatible with C.

LLVM_ABI raw_ostream & operator<<(raw_ostream &OS, const CallSiteInfo &CSI)

This is an optimization pass for GlobalISel generic memory operations.

bool operator<(int64_t V1, const APSInt &V2)

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

Create formatted StringError object.

@ First

Helpers to iterate all locations in the MemoryEffectsBase class.

FunctionAddr VTableAddr uintptr_t uintptr_t Data

DWARFExpression::Operation Op

Definition LineTable.cpp:24

uint32_t Count

Definition LineTable.cpp:26

DeltaInfo(int64_t D, uint32_t C)

Definition LineTable.cpp:27

int64_t Delta

Definition LineTable.cpp:25

Line entries are used to encode the line tables in FunctionInfo objects.

uint32_t File

1 based index of file in FileTable

uint32_t Line

Source line number.

uint64_t Addr

Start address of this line entry.