Branch data Line data Source code
1 : : // -*- C++ -*-
2 : : // Copyright (C) 2008-2011 Red Hat Inc.
3 : : //
4 : : // This file is part of systemtap, and is free software. You can
5 : : // redistribute it and/or modify it under the terms of the GNU General
6 : : // Public License (GPL); either version 2, or (at your option) any
7 : : // later version.
8 : :
9 : : #ifndef DWARF_WRAPPERS_H
10 : : #define DWARF_WRAPPERS_H 1
11 : :
12 : : #include "config.h"
13 : :
14 : : extern "C" {
15 : : #include <elfutils/libdw.h>
16 : : #include <elfutils/version.h>
17 : : #include <dwarf.h>
18 : : }
19 : :
20 : : #include <string>
21 : :
22 : : #if ! _ELFUTILS_PREREQ(0, 148)
23 : : #define DW_AT_linkage_name 0x6e
24 : : #endif
25 : :
26 : : #if ! _ELFUTILS_PREREQ(0, 155)
27 : : #define DW_ATE_UTF 0x10
28 : : #endif
29 : :
30 : :
31 : : // NB: "rc == 0" means OK in this case
32 : : void dwfl_assert(const std::string& desc, int rc);
33 : :
34 : : // Throw error if pointer is NULL
35 : : inline void
36 : 1521 : dwfl_assert(const std::string& desc, const void* ptr)
37 : : {
38 [ - + ]: 1521 : if (!ptr)
39 : 0 : dwfl_assert(desc, -1);
40 : 1521 : }
41 : :
42 : : // Throw error if condition is false
43 : : inline void
44 : 1413285 : dwfl_assert(const std::string& desc, bool condition)
45 : : {
46 [ - + ]: 1413285 : if (!condition)
47 : 0 : dwfl_assert(desc, -1);
48 : 1413285 : }
49 : :
50 : : // NB: "rc == 0" means OK in this case
51 : : void dwarf_assert(const std::string& desc, int rc);
52 : :
53 : : // Throw error if pointer is NULL
54 : : inline void
55 : 18522 : dwarf_assert(const std::string& desc, const void* ptr)
56 : : {
57 [ - + ]: 18522 : if (!ptr)
58 : 0 : dwarf_assert(desc, -1);
59 : 18522 : }
60 : :
61 : :
62 : : class dwarf_line_t
63 : : {
64 : : public:
65 : : const Dwarf_Line* line;
66 : 11611 : dwarf_line_t() : line(0) {}
67 : 147253 : dwarf_line_t(const Dwarf_Line* line_) : line(line_) {}
68 : :
69 : : dwarf_line_t& operator= (const Dwarf_Line* line_)
70 : : {
71 : : line = (line_);
72 : : return *this;
73 : : }
74 : :
75 : 11637 : operator bool() const
76 : : {
77 : 11637 : return line != 0;
78 : : }
79 : :
80 : 19284 : int lineno() const
81 : : {
82 : : int lineval;
83 [ - + ]: 19284 : if (!line)
84 [ # # ][ # # ]: 0 : dwarf_assert("dwarf_line_t::lineno", -1);
[ # # ]
85 [ + - ]: 19284 : dwarf_lineno(const_cast<Dwarf_Line*>(line), &lineval);
86 : 19284 : return lineval;
87 : : }
88 : 147229 : Dwarf_Addr addr() const
89 : : {
90 : : Dwarf_Addr addrval;
91 [ - + ]: 147229 : if (!line)
92 [ # # ][ # # ]: 0 : dwarf_assert("dwarf_line_t::addr", -1);
[ # # ]
93 [ + - ]: 147229 : dwarf_lineaddr(const_cast<Dwarf_Line*>(line), &addrval);
94 : 147229 : return addrval;
95 : : }
96 : 18522 : const char* linesrc(Dwarf_Word* mtime = 0, Dwarf_Word* length = 0)
97 : : {
98 : : const char* retval = dwarf_linesrc(const_cast<Dwarf_Line*>(line), mtime,
99 : 18522 : length);
100 [ + - ][ + - ]: 18522 : dwarf_assert("dwarf_line_t::linesrc", retval);
[ + - ]
101 : 18522 : return retval;
102 : : }
103 : : };
104 : :
105 : :
106 : : // Look up the DIE for a reference-form attribute name
107 : : inline Dwarf_Die *
108 : 711911 : dwarf_attr_die (Dwarf_Die *die, unsigned int attr, Dwarf_Die *result)
109 : : {
110 : : Dwarf_Attribute attr_mem;
111 : : return dwarf_formref_die (dwarf_attr_integrate (die, attr, &attr_mem),
112 [ + - ][ + - ]: 711911 : result);
113 : : }
114 : :
115 : :
116 : : // Retrieve the linkage name of a die, either by the MIPS vendor extension or
117 : : // DWARF4's standardized attribute.
118 : : inline const char *
119 : 44 : dwarf_linkage_name (Dwarf_Die *die)
120 : : {
121 : : Dwarf_Attribute attr_mem;
122 : : return dwarf_formstring
123 [ + - ]: 44 : (dwarf_attr_integrate (die, DW_AT_MIPS_linkage_name, &attr_mem)
124 [ - + ][ + - ]: 44 : ?: dwarf_attr_integrate (die, DW_AT_linkage_name, &attr_mem));
[ + - ]
125 : : }
126 : :
127 : :
128 : : #if !_ELFUTILS_PREREQ(0, 143)
129 : : // Elfutils prior to 0.143 didn't use attr_integrate when looking up the
130 : : // decl_file or decl_line, so the attributes would sometimes be missed. For
131 : : // those old versions, we define custom implementations to do the integration.
132 : :
133 : : const char *dwarf_decl_file_integrate (Dwarf_Die *die);
134 : : #define dwarf_decl_file dwarf_decl_file_integrate
135 : :
136 : : int dwarf_decl_line_integrate (Dwarf_Die *die, int *linep)
137 : : __nonnull_attribute__ (2);
138 : : #define dwarf_decl_line dwarf_decl_line_integrate
139 : :
140 : : #endif // !_ELFUTILS_PREREQ(0, 143)
141 : :
142 : :
143 : : // Resolve a full name for dwarf types
144 : : bool dwarf_type_name(Dwarf_Die *type_die, std::string& type_name);
145 : : std::string dwarf_type_name(Dwarf_Die *type_die);
146 : :
147 : :
148 : : #endif
149 : :
150 : : /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */
|