blob: 6472bf4474c808905aefdc03b62cf87aa77189ca [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* Return source file information of CU.
2 Copyright (C) 2004, 2005 Red Hat, Inc.
3 Written by Ulrich Drepper <drepper@redhat.com>, 2004.
4
5 This program is Open Source software; you can redistribute it and/or
6 modify it under the terms of the Open Software License version 1.0 as
7 published by the Open Source Initiative.
8
9 You should have received a copy of the Open Software License along
10 with this program; if not, you may obtain a copy of the Open Software
11 License version 1.0 from http://www.opensource.org/licenses/osl.php or
12 by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
13 3001 King Ranch Road, Ukiah, CA 95482. */
14
15#ifdef HAVE_CONFIG_H
16# include <config.h>
17#endif
18
19#include <assert.h>
20#include <dwarf.h>
21#include "libdwP.h"
22
23
24int
25dwarf_getsrcfiles (Dwarf_Die *cudie, Dwarf_Files **files, size_t *nfiles)
26{
27 if (unlikely (cudie == NULL
28 || INTUSE(dwarf_tag) (cudie) != DW_TAG_compile_unit))
29 return -1;
30
31 int res = -1;
32
33 /* Get the information if it is not already known. */
34 struct Dwarf_CU *const cu = cudie->cu;
35 if (cu->lines == NULL)
36 {
37 Dwarf_Lines *lines;
38 size_t nlines;
39
40 /* Let the more generic function do the work. It'll create more
41 data but that will be needed in an real program anyway. */
42 res = INTUSE(dwarf_getsrclines) (cudie, &lines, &nlines);
43 }
44 else if (cu->files != (void *) -1l)
45 /* We already have the information. */
46 res = 0;
47
48 if (likely (res == 0))
49 {
50 assert (cu->files != NULL && cu->files != (void *) -1l);
51 *files = cu->files;
52 if (nfiles != NULL)
53 *nfiles = cu->files->nfiles;
54 }
55
56 // XXX Eventually: unlocking here.
57
58 return res;
59}
60INTDEF (dwarf_getsrcfiles)