summaryrefslogtreecommitdiff
path: root/dwarflint/pri.hh
blob: a1bb8ef6d954a1932ac14ef4fe5c2352ea21d2a0 (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
/* Pedantic checking of DWARF files
   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_PRI_H
#define DWARFLINT_PRI_H

#include "../libdw/libdw.h"
#include <string>

#define PRI_NOT_ENOUGH ": not enough data for %s.\n"

namespace pri
{
  class pribase
  {
    std::string m_s;

  protected:
    pribase (std::string const &a,
	     std::string const &b = "",
	     std::string const &c = "")
      : m_s (a + b + c)
    {}
    friend std::ostream &operator << (std::ostream &os, pribase const &obj);

  public:
    operator std::string const &() const { return m_s; }
  };
  std::ostream &operator << (std::ostream &os, pribase const &obj);

  struct not_enough
    : public pribase
  {
    not_enough (std::string const &what)
      : pribase ("not enough data for ", what)
    {}
  };

  struct lacks_relocation
    : public pribase
  {
    lacks_relocation (std::string const &what)
      : pribase (what, " seems to lack a relocation")
    {}
  };

  class ref
  {
    Dwarf_Off off;
  public:
    template <class T>
    ref (T const &die)
      : off (die.offset ())
    {}
    friend std::ostream &operator << (std::ostream &os, ref const &obj);
  };
  std::ostream &operator << (std::ostream &os, ref const &obj);

  class hex
  {
    Dwarf_Off value;
    char const *const pre;
  public:
    hex (Dwarf_Off a_value, char const *a_pre = NULL)
      : value (a_value)
      , pre (a_pre)
    {}
    friend std::ostream &operator << (std::ostream &os, hex const &obj);
  };
  std::ostream &operator << (std::ostream &os, hex const &obj);

  struct addr: public hex {
    addr (Dwarf_Off off) : hex (off) {}
  };

  struct DIE: public hex {
    DIE (Dwarf_Off off) : hex (off, "DIE ") {}
  };

  struct CU: public hex {
    CU (Dwarf_Off off) : hex (off, "CU ") {}
  };

  class range
  {
    Dwarf_Off start;
    Dwarf_Off end;
  public:
    range (Dwarf_Off a_start, Dwarf_Off a_end)
      : start (a_start), end (a_end)
    {}
    friend std::ostream &operator << (std::ostream &os, range const &obj);
  };
  std::ostream &operator << (std::ostream &os, range const &obj);

  std::string attr_name (int name);
}

#endif//DWARFLINT_PRI_H