1361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper/* Convenience functions for handling DWARF descriptions of inline functions.
2daf278fda6d9bd329b517757f9ba2d74619f3be7Mark Wielaard   Copyright (C) 2005,2006,2015 Red Hat, Inc.
3de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   This file is part of elfutils.
4361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper
5de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   This file is free software; you can redistribute it and/or modify
6de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   it under the terms of either
7361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper
8de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard     * the GNU Lesser General Public License as published by the Free
9de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard       Software Foundation; either version 3 of the License, or (at
10de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard       your option) any later version
11de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard
12de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   or
13de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard
14de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard     * the GNU General Public License as published by the Free
15de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard       Software Foundation; either version 2 of the License, or (at
16de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard       your option) any later version
17de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard
18de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   or both in parallel, as here.
19de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard
20de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   elfutils is distributed in the hope that it will be useful, but
21361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   WITHOUT ANY WARRANTY; without even the implied warranty of
22361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   General Public License for more details.
24361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper
25de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   You should have received copies of the GNU General Public License and
26de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   the GNU Lesser General Public License along with this program.  If
27de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   not, see <http://www.gnu.org/licenses/>.  */
28361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper
29104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath#ifdef HAVE_CONFIG_H
30104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath# include <config.h>
31104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath#endif
32104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath
33104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath#include "libdwP.h"
34104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath#include <dwarf.h>
35104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath
36104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrathstruct visitor_info
37104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath{
38104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath  void *die_addr;
39104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath  int (*callback) (Dwarf_Die *, void *);
40104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath  void *arg;
41104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath};
42104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath
43104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrathstatic int
44104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrathscope_visitor (unsigned int depth __attribute__ ((unused)),
4571e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath	       struct Dwarf_Die_Chain *die, void *arg)
46104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath{
47104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath  struct visitor_info *const v = arg;
48104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath
4971e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath  if (INTUSE(dwarf_tag) (&die->die) != DW_TAG_inlined_subroutine)
50104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath    return DWARF_CB_OK;
51104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath
52104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath  Dwarf_Attribute attr_mem;
5371e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath  Dwarf_Attribute *attr = INTUSE(dwarf_attr) (&die->die, DW_AT_abstract_origin,
54104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath					      &attr_mem);
55104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath  if (attr == NULL)
56104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath    return DWARF_CB_OK;
57104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath
58104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath  Dwarf_Die origin_mem;
59104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath  Dwarf_Die *origin = INTUSE(dwarf_formref_die) (attr, &origin_mem);
60104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath  if (origin == NULL)
61104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath    return DWARF_CB_ABORT;
62104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath
63104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath  if (origin->addr != v->die_addr)
64104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath    return DWARF_CB_OK;
65104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath
6671e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath  return (*v->callback) (&die->die, v->arg);
67104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath}
68104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath
69104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrathint
706724c90d02659f7466b67b357563042e403d154eRoland McGrathdwarf_func_inline (Dwarf_Die *func)
71104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath{
72104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath  Dwarf_Attribute attr_mem;
73104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath  Dwarf_Word val;
746724c90d02659f7466b67b357563042e403d154eRoland McGrath  if (INTUSE(dwarf_formudata) (INTUSE(dwarf_attr) (func, DW_AT_inline,
75104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath						   &attr_mem),
76104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath			       &val) == 0)
77104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath  switch (val)
78104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath    {
79104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath    case DW_INL_not_inlined:
80104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath      return 0;
81104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath
82104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath    case DW_INL_declared_not_inlined:
83104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath      return -1;
84104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath
85104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath    case DW_INL_inlined:
86104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath    case DW_INL_declared_inlined:
87104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath      return 1;
88104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath    }
89104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath
90104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath  return 0;
91104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath}
92104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath
93104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrathint
946724c90d02659f7466b67b357563042e403d154eRoland McGrathdwarf_func_inline_instances (Dwarf_Die *func,
95104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath			     int (*callback) (Dwarf_Die *, void *),
96104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath			     void *arg)
97104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath{
986724c90d02659f7466b67b357563042e403d154eRoland McGrath  struct visitor_info v = { func->addr, callback, arg };
996724c90d02659f7466b67b357563042e403d154eRoland McGrath  struct Dwarf_Die_Chain cu = { .die = CUDIE (func->cu), .parent = NULL };
100daf278fda6d9bd329b517757f9ba2d74619f3be7Mark Wielaard  return __libdw_visit_scopes (0, &cu, NULL, &scope_visitor, NULL, &v);
101104532fcdb87e769d8ebf5771b9c4370e4361a7bRoland McGrath}
102