blob: 6018691a5783f6302f08ec931035989a556c7169 [file] [log] [blame]
Ulrich Drepper361df7d2006-04-04 21:38:57 +00001/* Convenience functions for handling DWARF descriptions of inline functions.
2 Copyright (C) 2005,2006 Red Hat, Inc.
3 This file is part of Red Hat elfutils.
4
5 Red Hat elfutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by the
7 Free Software Foundation; version 2 of the License.
8
9 Red Hat elfutils is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with Red Hat elfutils; if not, write to the Free Software Foundation,
Ulrich Drepper1e9ef502006-04-04 22:29:06 +000016 Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
Ulrich Drepper361df7d2006-04-04 21:38:57 +000017
18 In addition, as a special exception, Red Hat, Inc. gives You the
19 additional right to link the code of Red Hat elfutils with code licensed
20 under an Open Source Initiative certified open source license
21 (http://www.opensource.org/licenses/index.php) and to distribute linked
22 combinations including the two. Non-GPL Code permitted under this
23 exception must only link to the code of Red Hat elfutils through those
24 well defined interfaces identified in the file named EXCEPTION found in
25 the source code files (the "Approved Interfaces"). The files of Non-GPL
26 Code may instantiate templates or use macros or inline functions from
27 the Approved Interfaces without causing the resulting work to be covered
28 by the GNU General Public License. Only Red Hat, Inc. may make changes
29 or additions to the list of Approved Interfaces. Red Hat's grant of
30 this exception is conditioned upon your not adding any new exceptions.
31 If you wish to add a new Approved Interface or exception, please contact
32 Red Hat. You must obey the GNU General Public License in all respects
33 for all of the Red Hat elfutils code and other code used in conjunction
34 with Red Hat elfutils except the Non-GPL Code covered by this exception.
35 If you modify this file, you may extend this exception to your version
36 of the file, but you are not obligated to do so. If you do not wish to
37 provide this exception without modification, you must delete this
38 exception statement from your version and license this file solely under
39 the GPL without exception.
40
41 Red Hat elfutils is an included package of the Open Invention Network.
42 An included package of the Open Invention Network is a package for which
43 Open Invention Network licensees cross-license their patents. No patent
44 license is granted, either expressly or impliedly, by designation as an
45 included package. Should you wish to participate in the Open Invention
46 Network licensing program, please visit www.openinventionnetwork.com
47 <http://www.openinventionnetwork.com>. */
48
Roland McGrath104532f2005-08-15 09:53:48 +000049#ifdef HAVE_CONFIG_H
50# include <config.h>
51#endif
52
53#include "libdwP.h"
54#include <dwarf.h>
55
56struct visitor_info
57{
58 void *die_addr;
59 int (*callback) (Dwarf_Die *, void *);
60 void *arg;
61};
62
63static int
64scope_visitor (unsigned int depth __attribute__ ((unused)),
Roland McGrath71e15a02005-08-27 10:33:26 +000065 struct Dwarf_Die_Chain *die, void *arg)
Roland McGrath104532f2005-08-15 09:53:48 +000066{
67 struct visitor_info *const v = arg;
68
Roland McGrath71e15a02005-08-27 10:33:26 +000069 if (INTUSE(dwarf_tag) (&die->die) != DW_TAG_inlined_subroutine)
Roland McGrath104532f2005-08-15 09:53:48 +000070 return DWARF_CB_OK;
71
72 Dwarf_Attribute attr_mem;
Roland McGrath71e15a02005-08-27 10:33:26 +000073 Dwarf_Attribute *attr = INTUSE(dwarf_attr) (&die->die, DW_AT_abstract_origin,
Roland McGrath104532f2005-08-15 09:53:48 +000074 &attr_mem);
75 if (attr == NULL)
76 return DWARF_CB_OK;
77
78 Dwarf_Die origin_mem;
79 Dwarf_Die *origin = INTUSE(dwarf_formref_die) (attr, &origin_mem);
80 if (origin == NULL)
81 return DWARF_CB_ABORT;
82
83 if (origin->addr != v->die_addr)
84 return DWARF_CB_OK;
85
Roland McGrath71e15a02005-08-27 10:33:26 +000086 return (*v->callback) (&die->die, v->arg);
Roland McGrath104532f2005-08-15 09:53:48 +000087}
88
89int
Roland McGrath6724c902005-10-28 07:07:19 +000090dwarf_func_inline (Dwarf_Die *func)
Roland McGrath104532f2005-08-15 09:53:48 +000091{
92 Dwarf_Attribute attr_mem;
93 Dwarf_Word val;
Roland McGrath6724c902005-10-28 07:07:19 +000094 if (INTUSE(dwarf_formudata) (INTUSE(dwarf_attr) (func, DW_AT_inline,
Roland McGrath104532f2005-08-15 09:53:48 +000095 &attr_mem),
96 &val) == 0)
97 switch (val)
98 {
99 case DW_INL_not_inlined:
100 return 0;
101
102 case DW_INL_declared_not_inlined:
103 return -1;
104
105 case DW_INL_inlined:
106 case DW_INL_declared_inlined:
107 return 1;
108 }
109
110 return 0;
111}
112
113int
Roland McGrath6724c902005-10-28 07:07:19 +0000114dwarf_func_inline_instances (Dwarf_Die *func,
Roland McGrath104532f2005-08-15 09:53:48 +0000115 int (*callback) (Dwarf_Die *, void *),
116 void *arg)
117{
Roland McGrath6724c902005-10-28 07:07:19 +0000118 struct visitor_info v = { func->addr, callback, arg };
119 struct Dwarf_Die_Chain cu = { .die = CUDIE (func->cu), .parent = NULL };
Roland McGrath71e15a02005-08-27 10:33:26 +0000120 return __libdw_visit_scopes (0, &cu, &scope_visitor, NULL, &v);
Roland McGrath104532f2005-08-15 09:53:48 +0000121}