Lines Matching defs:lnd

58 #define read_16(p) (lnd->little_endian		\
61 #define read_32(p) (lnd->little_endian \
64 #define read_64(p) (lnd->little_endian \
132 line_free (struct line_reader_data * lnd)
134 if (! lnd)
136 if (lnd->dirnames)
137 free (lnd->dirnames);
138 if (lnd->filenames)
139 free (lnd->filenames);
140 free (lnd);
147 line_file (struct line_reader_data *lnd, uint64_t n)
149 const uint8_t * prev_pos = lnd->cpos;
156 || n > lnd->numfile)
159 filelen = strlen ((const char *)lnd->filenames[n - 1]);
160 lnd->cpos = lnd->filenames[n - 1] + filelen + 1;
161 dir = read_uleb128 (lnd);
162 lnd->cpos = prev_pos;
164 || lnd->filenames[n - 1][0] == '/')
165 return strdup ((const char *)lnd->filenames[n - 1]);
166 else if (dir > lnd->numdir)
169 dirlen = strlen ((const char *) lnd->dirnames[dir - 1]);
171 memcpy (result, lnd->dirnames[dir - 1], dirlen);
173 memcpy (result + dirlen + 1, lnd->filenames[n - 1], filelen);
196 struct line_reader_data * lnd = NULL;
205 lnd = malloc (sizeof (struct line_reader_data));
206 if (! lnd)
209 lnd->little_endian = little_endian;
210 lnd->cpos = debug_line;
212 lnd_length = read_32 (lnd->cpos);
213 lnd->cpos += 4;
216 lnd_length = read_64 (lnd->cpos);
217 lnd->cpos += 8;
231 if (read_16 (lnd->cpos) != 2)
234 lnd->cpos += 2;
236 header_length = dwarf_size_64 ? read_64(lnd->cpos) : read_32(lnd->cpos);
237 lnd->cpos += dwarf_size_64 ? 8 : 4;
238 if (lnd_length < header_length + (lnd->cpos - debug_line)
242 lnd->minimum_instruction_length = lnd->cpos[0];
244 lnd->line_base = lnd->cpos[2];
245 lnd->line_range = lnd->cpos[3];
246 lnd->opcode_base = lnd->cpos[4];
248 if (lnd->opcode_base == 0)
253 lnd->standard_opcode_lengths = lnd->cpos + 5;
254 if (header_length < 5 + (lnd->opcode_base - 1))
257 lnd->cpos += 5 + lnd->opcode_base - 1;
258 lnd->end = debug_line + header_length + (dwarf_size_64 ? 22 : 10);
261 table_start = lnd->cpos;
262 lnd->numdir = 0;
263 while (lnd->cpos != lnd->end && *lnd->cpos)
265 lnd->cpos = memchr (lnd->cpos, 0, lnd->end - lnd->cpos);
266 if (! lnd->cpos)
268 lnd->cpos++;
269 lnd->numdir++;
271 if (lnd->cpos == lnd->end)
273 lnd->dirnames = malloc (lnd->numdir * sizeof (const uint8_t *));
274 if (! lnd->dirnames)
276 lnd->numdir = 0;
277 lnd->cpos = table_start;
278 while (*lnd->cpos)
280 lnd->dirnames[lnd->numdir++] = lnd->cpos;
281 lnd->cpos = memchr (lnd->cpos, 0, lnd->end - lnd->cpos) + 1;
283 lnd->cpos++;
286 table_start = lnd->cpos;
287 lnd->numfile = 0;
288 while (lnd->cpos != lnd->end && *lnd->cpos)
290 lnd->cpos = memchr (lnd->cpos, 0, lnd->end - lnd->cpos);
291 if (! lnd->cpos)
293 lnd->cpos++;
294 skip_leb128 (lnd);
295 skip_leb128 (lnd);
296 skip_leb128 (lnd);
297 lnd->numfile++;
299 if (lnd->cpos == lnd->end)
301 lnd->filenames = malloc (lnd->numfile * sizeof (const uint8_t *));
302 if (! lnd->filenames)
304 lnd->numfile = 0;
305 lnd->cpos = table_start;
306 while (*lnd->cpos)
308 lnd->filenames[lnd->numfile++] = lnd->cpos;
309 lnd->cpos = memchr (lnd->cpos, 0, lnd->end - lnd->cpos) + 1;
310 skip_leb128 (lnd);
311 skip_leb128 (lnd);
312 skip_leb128 (lnd);
314 lnd->cpos++;
316 lnd->numfile_orig = lnd->numfile;
317 lnd->cpos = lnd->init = lnd->end;
318 lnd->end = debug_line + lnd_length + (dwarf_size_64 ? 12 : 4);
320 init_state (&lnd->cur);
322 return lnd;
325 line_free (lnd);
331 line_reset (struct line_reader_data * lnd)
333 lnd->cpos = lnd->init;
334 lnd->numfile = lnd->numfile_orig;
335 init_state (&lnd->cur);
340 line_at_eof (struct line_reader_data * lnd)
342 return lnd->cpos == lnd->end;
346 next_state (struct line_reader_data *lnd)
348 if (lnd->cur.end_of_sequence)
349 init_state (&lnd->cur);
356 if (lnd->cpos == lnd->end)
358 op = *lnd->cpos++;
359 if (op >= lnd->opcode_base)
361 op -= lnd->opcode_base;
363 lnd->cur.line += op % lnd->line_range + lnd->line_base;
364 lnd->cur.pc += (op / lnd->line_range
365 * lnd->minimum_instruction_length);
372 uint64_t sz = read_uleb128 (lnd);
373 const uint8_t * op = lnd->cpos;
375 if (lnd->end - op < sz || sz == 0)
377 lnd->cpos += sz;
381 lnd->cur.end_of_sequence = true;
386 lnd->cur.pc = read_64 (op);
388 lnd->cur.pc = read_32 (op);
397 (lnd->filenames,
398 (lnd->numfile + 1) * sizeof (const uint8_t *));
402 if (! memchr (op, 0, lnd->cpos - op))
404 filenames[lnd->numfile++] = op;
405 lnd->filenames = filenames;
422 tmp = read_uleb128 (lnd);
425 lnd->cur.pc += tmp * lnd->minimum_instruction_length;
428 lnd->cur.line += read_sleb128 (lnd);
431 lnd->cur.file = read_uleb128 (lnd);
434 lnd->cur.col = read_uleb128 (lnd);
437 lnd->cur.pc += ((255 - lnd->opcode_base) / lnd->line_range
438 * lnd->minimum_instruction_length);
441 if (lnd->end - lnd->cpos < 2)
443 lnd->cur.pc += read_16 (lnd->cpos);
444 lnd->cpos += 2;
450 for (i = 0; i < lnd->standard_opcode_lengths[op - 1]; i++)
451 skip_leb128 (lnd);
463 line_next (struct line_reader_data * lnd,
469 struct line_info prev = lnd->cur;
471 if (! next_state (lnd))
474 if (lnd->cur.end_of_sequence)
478 if ((stop & line_stop_pc) && lnd->cur.pc != prev.pc)
480 if ((stop & line_stop_pos_mask) && lnd->cur.file != prev.file)
483 && lnd->cur.line != prev.line)
486 && lnd->cur.col != prev.col)
489 *result = lnd->cur;
504 line_find_addr (struct line_reader_data * lnd,
512 if (lnd->cur.end_of_sequence && lnd->cpos == lnd->end)
513 line_reset (lnd);
515 startpos = lnd->cpos;
518 prev = lnd->cur;
519 if (! next_state (lnd))
524 if (lnd->cur.end_of_sequence && lnd->cpos == lnd->end)
525 line_reset (lnd);
526 if (lnd->cpos == startpos)
531 } while (lnd->cur.pc <= pc || prev.pc > pc || prev.end_of_sequence);
533 *end = lnd->cur;