blob: d5302df02deb94bb903c630878b45996d16cb5e6 [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* Return file name containing definition of the given function.
2 Copyright (C) 2005 Red Hat, Inc.
3 Written by Ulrich Drepper <drepper@redhat.com>, 2005.
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
24const char *
25dwarf_func_file (Dwarf_Func *func)
26{
27 Dwarf_Attribute attr_mem;
28 Dwarf_Sword idx = 0;
29 Dwarf_Die *die = func->die;
30
31 if (INTUSE(dwarf_formsdata) (INTUSE(dwarf_attr) (die, DW_AT_decl_file,
32 &attr_mem), &idx) != 0)
33 return NULL;
34
35 /* Zero means no source file information available. */
36 if (idx == 0)
37 {
38 __libdw_seterrno (DWARF_E_NO_ENTRY);
39 return NULL;
40 }
41
42 /* Get the array of source files for the CU. */
43 struct Dwarf_CU *cu = die->cu;
44 if (cu->lines == NULL)
45 {
46 Dwarf_Lines *lines;
47 size_t nlines;
48
49 /* Let the more generic function do the work. It'll create more
50 data but that will be needed in an real program anyway. */
51 (void) INTUSE(dwarf_getsrclines) (func->cudie, &lines, &nlines);
52 assert (cu->lines != NULL);
53 }
54
55 if (cu->lines == (void *) -1l)
56 {
57 /* If the file index is not zero, there must be file information
58 available. */
59 __libdw_seterrno (DWARF_E_INVALID_DWARF);
60 return NULL;
61 }
62
63 assert (cu->files != NULL && cu->files != (void *) -1l);
64
65 if (idx >= cu->files->nfiles)
66 {
67 __libdw_seterrno (DWARF_E_INVALID_DWARF);
68 return NULL;
69 }
70
71 return cu->files->info[idx].name;
72}