libdw/
[platform/upstream/elfutils.git] / libdwfl / lines.c
1 /* Fetch source line info for CU.
2    Copyright (C) 2005 Red Hat, Inc.
3
4    This program is Open Source software; you can redistribute it and/or
5    modify it under the terms of the Open Software License version 1.0 as
6    published by the Open Source Initiative.
7
8    You should have received a copy of the Open Software License along
9    with this program; if not, you may obtain a copy of the Open Software
10    License version 1.0 from http://www.opensource.org/licenses/osl.php or
11    by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
12    3001 King Ranch Road, Ukiah, CA 95482.   */
13
14 #include "libdwflP.h"
15 #include "../libdw/libdwP.h"
16
17 Dwfl_Error
18 internal_function_def
19 __libdwfl_cu_getsrclines (struct dwfl_cu *cu)
20 {
21   if (cu->lines == NULL)
22     {
23       Dwarf_Lines *lines;
24       size_t nlines;
25       if (INTUSE(dwarf_getsrclines) (&cu->die, &lines, &nlines) != 0)
26         return DWFL_E_LIBDW;
27
28       cu->lines = malloc (offsetof (struct Dwfl_Lines, idx[nlines]));
29       if (cu->lines == NULL)
30         return DWFL_E_NOMEM;
31       cu->lines->cu = cu;
32       for (unsigned int i = 0; i < nlines; ++i)
33         cu->lines->idx[i].idx = i;
34     }
35
36   return DWFL_E_NOERROR;
37 }