blob: 12fdabf284bda4be68249d503ebc6179f2f548b3 [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* Return source file information of CU.
Mark Wielaarda4c74cc2018-05-18 00:26:56 +02002 Copyright (C) 2004, 2005, 2013, 2015, 2018 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02003 This file is part of elfutils.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00004
Mark Wielaardde2ed972012-06-05 17:15:16 +02005 This file is free software; you can redistribute it and/or modify
6 it under the terms of either
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00007
Mark Wielaardde2ed972012-06-05 17:15:16 +02008 * 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
11
12 or
13
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
17
18 or both in parallel, as here.
19
20 elfutils is distributed in the hope that it will be useful, but
Ulrich Drepper361df7d2006-04-04 21:38:57 +000021 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.
24
Mark Wielaardde2ed972012-06-05 17:15:16 +020025 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/>. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000028
29#ifdef HAVE_CONFIG_H
30# include <config.h>
31#endif
32
33#include <assert.h>
34#include <dwarf.h>
35#include "libdwP.h"
36
37
38int
39dwarf_getsrcfiles (Dwarf_Die *cudie, Dwarf_Files **files, size_t *nfiles)
40{
Petr Machata71de1d22015-04-01 21:44:32 +020041 if (cudie == NULL)
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000042 return -1;
Petr Machata71de1d22015-04-01 21:44:32 +020043 if (! is_cudie (cudie))
44 {
45 __libdw_seterrno (DWARF_E_NOT_CUDIE);
46 return -1;
47 }
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000048
49 int res = -1;
50
51 /* Get the information if it is not already known. */
52 struct Dwarf_CU *const cu = cudie->cu;
Mark Wielaarda4c74cc2018-05-18 00:26:56 +020053 if (cu->files == NULL)
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000054 {
Mark Wielaarda4c74cc2018-05-18 00:26:56 +020055 /* 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)
59 {
60 /* We tried, assume we fail... */
61 cu->files = (void *) -1;
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000062
Mark Wielaarda4c74cc2018-05-18 00:26:56 +020063 /* 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)
66 {
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,
72 &cu->files);
73 }
74 else
75 {
76 Dwarf_CU *skel = __libdw_find_split_unit (cu);
77 if (skel != NULL)
78 {
79 Dwarf_Die skeldie = CUDIE (skel);
80 res = INTUSE(dwarf_getsrcfiles) (&skeldie, files, nfiles);
81 cu->files = skel->files;
82 }
83 }
84 }
85 else
86 {
87 Dwarf_Lines *lines;
88 size_t nlines;
89
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);
93 }
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000094 }
95 else if (cu->files != (void *) -1l)
96 /* We already have the information. */
97 res = 0;
98
99 if (likely (res == 0))
100 {
101 assert (cu->files != NULL && cu->files != (void *) -1l);
102 *files = cu->files;
103 if (nfiles != NULL)
104 *nfiles = cu->files->nfiles;
105 }
106
107 // XXX Eventually: unlocking here.
108
109 return res;
110}
111INTDEF (dwarf_getsrcfiles)