summaryrefslogtreecommitdiffstats
path: root/dwarflint/check_debug_abbrev.hh
blob: ef5531ab805b73309e35a881b9d1084624304364 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* Low-level checking of .debug_abbrev.
   Copyright (C) 2009, 2010, 2011 Red Hat, Inc.
   This file is part of elfutils.

   This file is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   elfutils is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#ifndef DWARFLINT_CHECK_DEBUG_ABBREV_HH
#define DWARFLINT_CHECK_DEBUG_ABBREV_HH

#include "checks.hh"
#include "sections_i.hh"
#include "check_debug_info_i.hh"
#include "dwarf_version_i.hh"

namespace locus_simple_fmt
{
  char const *abbr_offset_n ();
}

typedef fixed_locus<sec_abbrev,
		    locus_simple_fmt::abbr_offset_n,
		    locus_simple_fmt::hex> abbrev_locus;

class abbrev_attrib_locus
  : public locus
{
  uint64_t _m_abbr_offset;
  uint64_t _m_attr_offset;
  int _m_name;

public:
  explicit abbrev_attrib_locus (uint64_t abbr_offset = -1,
				uint64_t attr_offset = -1,
				int name = -1);

  abbrev_attrib_locus (abbrev_attrib_locus const &copy);

  abbrev_attrib_locus non_symbolic ();

  void set_name (int name);
  std::string format (bool brief = false) const;
  std::string name () const;
};

struct abbrev_attrib
{
  abbrev_attrib_locus where;
  uint16_t name;
  uint8_t form;

  abbrev_attrib ()
    : where ()
    , name (0)
    , form (0)
  {}
};

struct abbrev
{
  abbrev_locus where;
  uint64_t code;

  /* Attributes.  */
  abbrev_attrib *attribs;
  size_t size;
  size_t alloc;

  /* While ULEB128 can hold numbers > 32bit, these are not legal
     values of many enum types.  So just use as large type as
     necessary to cover valid values.  */
  uint16_t tag;
  bool has_children;

  /* Whether some DIE uses this abbrev.  */
  bool used;

  explicit abbrev (abbrev_locus const &loc)
    : where (loc)
    , code (0)
    , attribs (0)
    , size (0)
    , alloc (0)
    , tag (0)
    , has_children (false)
    , used (false)
  {}
};

struct abbrev_table
{
  struct abbrev_table *next;
  struct abbrev *abbr;
  uint64_t offset;
  size_t size;
  size_t alloc;
  bool used;		/* There are CUs using this table.  */

  abbrev *find_abbrev (uint64_t abbrev_code) const;

  abbrev_table ()
    : next (NULL)
    , abbr (NULL)
    , offset (0)
    , size (0)
    , alloc (0)
    , used (false)
  {}
};

class check_debug_abbrev
  : public check<check_debug_abbrev>
{
  section<sec_abbrev> *_m_sec_abbr;
  read_cu_headers *_m_cu_headers;

public:
  static checkdescriptor const *descriptor ();

  // offset -> abbreviations
  typedef std::map< ::Dwarf_Off, abbrev_table> abbrev_map;
  abbrev_map const abbrevs;

  check_debug_abbrev (checkstack &stack, dwarflint &lint);
  static form const *check_form (dwarf_version const *ver,
				 attribute const *attr,
				 int form_name,
				 locus const &loc,
				 bool indirect);

  ~check_debug_abbrev ();
};

#endif//DWARFLINT_CHECK_DEBUG_ABBREV_HH