summaryrefslogtreecommitdiffstats
path: root/dwarflint/check_debug_info.hh
blob: 8febc2d5d5bc61d10f4d13939507fdda38e5b731 (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
/* Low-level checking of .debug_info.
   Copyright (C) 2009, 2010, 2011 Red Hat, Inc.
   This file is part of Red Hat elfutils.

   Red Hat elfutils 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; version 2 of the License.

   Red Hat 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 Red Hat elfutils; if not, write to the Free Software Foundation,
   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.

   Red Hat elfutils is an included package of the Open Invention Network.
   An included package of the Open Invention Network is a package for which
   Open Invention Network licensees cross-license their patents.  No patent
   license is granted, either expressly or impliedly, by designation as an
   included package.  Should you wish to participate in the Open Invention
   Network licensing program, please visit www.openinventionnetwork.com
   <http://www.openinventionnetwork.com>.  */

#ifndef DWARFLINT_CHECK_DEBUG_INFO_HH
#define DWARFLINT_CHECK_DEBUG_INFO_HH

#include <libdw.h>
#include "addr-record.hh"
#include "elf_file.ii"
#include "coverage.hh"
#include "checks.hh"
#include "check_debug_abbrev.ii"
#include "check_debug_line.ii"
#include "check_debug_aranges.ii"
#include "sections.ii"

struct cu_head
{
  uint64_t offset;
  Dwarf_Off size;               // Size of this CU.
  Dwarf_Off head_size;          // Size from begin to 1st byte of CU.
  Dwarf_Off total_size;         // size + head_size

  int offset_size;		  // Offset size in this CU.
  struct where where;           // Where this section was defined.
  Dwarf_Off abbrev_offset;      // Abbreviation section that this CU uses.
  int version;                  // CU version
  int address_size;             // Address size in bytes on the target machine.
};

struct cu
{
  struct cu *next;              // For compatibility with C level.
                                // xxx will probably go away eventually
  struct cu_head const *head;
  uint64_t cudie_offset;
  uint64_t low_pc;              // DW_AT_low_pc value of CU DIE, -1 if not present.
  struct ref stmt_list;
  struct addr_record die_addrs; // Addresses where DIEs begin in this CU.
  struct ref_record die_refs;   // DIE references into other CUs from this CU.
  struct ref_record loc_refs;   // references into .debug_loc from this CU.
  struct ref_record range_refs; // references into .debug_ranges from this CU.
  struct ref_record decl_file_refs;  // values of DW_AT_decl_file in this CU.
  bool has_arange;              // Whether we saw arange section pointing at this CU.
  bool has_pubnames;            // Likewise for pubnames.
  bool has_pubtypes;            // Likewise for pubtypes.
};

/** The pass for reading basic .debug_info data -- the layout of
    sections and their headers.  */
class read_cu_headers
  : public check<read_cu_headers>
{
  section<sec_info> *_m_sec_info;

public:
  static checkdescriptor const *descriptor ();
  std::vector<cu_head> const cu_headers;
  read_cu_headers (checkstack &stack, dwarflint &lint);
};

/** The pass for in-depth structural analysis of .debug_info.  */
class check_debug_info
  : public check<check_debug_info>
{
  section<sec_info> *_m_sec_info;
  section<sec_str> *_m_sec_str;
  elf_file const &_m_file;
  check_debug_abbrev *_m_abbrevs;
  read_cu_headers *_m_cu_headers;

  // Abbreviation table with that offset had user(s) that failed
  // validation.  Check for unused abbrevs should be skipped.
  std::vector< ::Dwarf_Off> _m_abbr_skip;

  // The check pass adds all low_pc/high_pc ranges loaded from DIE
  // tree into this coverage structure.
  coverage _m_cov;

  // If, during the check, we find any rangeptr-class attributes, we
  // set need_ranges to true.  cu_ranges pass then uses this as a hint
  // whether to request .debug_ranges or not.
  bool _m_need_ranges;

  bool check_cu_structural (struct read_ctx *ctx,
			    struct cu *const cu,
			    Elf_Data *strings,
			    struct coverage *strings_coverage,
			    struct relocation_data *reloc);

public:
  static checkdescriptor const *descriptor ();

  coverage const &cov () const { return _m_cov; }
  bool need_ranges () const { return _m_need_ranges; }

  // This is where the loaded CUs are stored.
  std::vector<cu> cus;

  check_debug_info (checkstack &stack, dwarflint &lint);
  ~check_debug_info ();

  cu *find_cu (::Dwarf_Off offset);
};

/** Check pending references that need other sections to be validated
    first.  */
class check_debug_info_refs
  : public check<check_debug_info_refs>
{
  check_debug_info *_m_info;
  check_debug_line *_m_line;
  check_debug_aranges *_m_aranges;

public:
  static checkdescriptor const *descriptor ();
  check_debug_info_refs (checkstack &stack, dwarflint &lint);
};

#endif//DWARFLINT_CHECK_DEBUG_INFO_HH