1 /* Return source file information of CU.
2 Copyright (C) 2004, 2005, 2013, 2015, 2018 Red Hat, Inc.
3 This file is part of elfutils.
5 This file is free software; you can redistribute it and/or modify
6 it under the terms of either
8 * the GNU Lesser General Public License as published by the Free
9 Software Foundation; either version 3 of the License, or (at
10 your option) any later version
14 * the GNU General Public License as published by the Free
15 Software Foundation; either version 2 of the License, or (at
16 your option) any later version
18 or both in parallel, as here.
20 elfutils is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received copies of the GNU General Public License and
26 the GNU Lesser General Public License along with this program. If
27 not, see <http://www.gnu.org/licenses/>. */
39 dwarf_getsrcfiles (Dwarf_Die *cudie, Dwarf_Files **files, size_t *nfiles)
43 if (! is_cudie (cudie))
45 __libdw_seterrno (DWARF_E_NOT_CUDIE);
51 /* Get the information if it is not already known. */
52 struct Dwarf_CU *const cu = cudie->cu;
53 if (cu->files == NULL)
55 /* For split units there might be a simple file table (without lines).
56 If not, use the one from the skeleton. */
57 if (cu->unit_type == DW_UT_split_compile
58 || cu->unit_type == DW_UT_split_type)
60 /* We tried, assume we fail... */
61 cu->files = (void *) -1;
63 /* See if there is a .debug_line section, for split CUs
64 the table is at offset zero. */
65 if (cu->dbg->sectiondata[IDX_debug_line] != NULL)
67 /* We are only interested in the files, the lines will
68 always come from the skeleton. */
69 res = __libdw_getsrclines (cu->dbg, 0,
70 __libdw_getcompdir (cudie),
71 cu->address_size, NULL,
76 Dwarf_CU *skel = __libdw_find_split_unit (cu);
79 Dwarf_Die skeldie = CUDIE (skel);
80 res = INTUSE(dwarf_getsrcfiles) (&skeldie, files, nfiles);
81 cu->files = skel->files;
90 /* Let the more generic function do the work. It'll create more
91 data but that will be needed in an real program anyway. */
92 res = INTUSE(dwarf_getsrclines) (cudie, &lines, &nlines);
95 else if (cu->files != (void *) -1l)
96 /* We already have the information. */
99 if (likely (res == 0))
101 assert (cu->files != NULL && cu->files != (void *) -1l);
104 *nfiles = cu->files->nfiles;
107 // XXX Eventually: unlocking here.
111 INTDEF (dwarf_getsrcfiles)