]>
Commit | Line | Data |
---|---|---|
86bf665e TM |
1 | // -*- C++ -*- |
2 | // Copyright (C) 2008 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 | |
6a38401c JS |
11 | |
12 | #include "config.h" | |
13 | ||
14 | extern "C" { | |
86bf665e | 15 | #include <elfutils/libdw.h> |
6a38401c JS |
16 | #ifdef HAVE_ELFUTILS_VERSION_H |
17 | #include <elfutils/version.h> | |
18 | #endif | |
19 | } | |
86bf665e TM |
20 | |
21 | #include <string> | |
22 | ||
6a38401c JS |
23 | #if !defined(_ELFUTILS_PREREQ) |
24 | // make a dummy PREREQ check for elfutils < 0.138 | |
25 | #define _ELFUTILS_PREREQ(major, minor) (0 >= 1) | |
26 | #endif | |
27 | ||
55d8c5d4 FCE |
28 | #if ! _ELFUTILS_PREREQ(0,142) |
29 | #define DW_TAG_rvalue_reference_type 0x42 | |
30 | #endif | |
31 | ||
32 | ||
86bf665e TM |
33 | // NB: "rc == 0" means OK in this case |
34 | void dwfl_assert(const std::string& desc, int rc); | |
35 | ||
ba53ea9f | 36 | // Throw error if pointer is NULL. |
86bf665e TM |
37 | template <typename T> |
38 | void dwfl_assert(const std::string& desc, T* ptr) | |
39 | { | |
40 | if (!ptr) | |
41 | dwfl_assert(desc, -1); | |
42 | } | |
43 | ||
ba53ea9f | 44 | // Throw error if pointer is NULL |
86bf665e TM |
45 | template <typename T> |
46 | void dwfl_assert(const std::string& desc, const T* ptr) | |
47 | { | |
48 | if (!ptr) | |
49 | dwfl_assert(desc, -1); | |
50 | } | |
51 | ||
ba53ea9f TM |
52 | // Throw error if condition is false |
53 | void dwfl_assert(const std::string& desc, bool condition); | |
54 | ||
86bf665e TM |
55 | // NB: "rc == 0" means OK in this case |
56 | void dwarf_assert(const std::string& desc, int rc); | |
57 | ||
ba53ea9f | 58 | // Throw error if pointer is NULL |
86bf665e TM |
59 | template <typename T> |
60 | void dwarf_assert(const std::string& desc, T* ptr) | |
61 | { | |
62 | if (!ptr) | |
63 | dwarf_assert(desc, -1); | |
64 | } | |
65 | ||
66 | ||
67 | class dwarf_line_t | |
68 | { | |
69 | public: | |
70 | const Dwarf_Line* line; | |
71 | dwarf_line_t() : line(0) {} | |
72 | dwarf_line_t(const Dwarf_Line* line_) : line(line_) {} | |
73 | ||
74 | dwarf_line_t& operator= (const Dwarf_Line* line_) | |
75 | { | |
76 | line = (line_); | |
77 | return *this; | |
78 | } | |
79 | ||
80 | operator bool() const | |
81 | { | |
82 | return line != 0; | |
83 | } | |
dff50e09 | 84 | |
86bf665e TM |
85 | int lineno() const |
86 | { | |
87 | int lineval; | |
88 | if (!line) | |
89 | dwarf_assert("dwarf_line_t::lineno", -1); | |
90 | dwarf_lineno(const_cast<Dwarf_Line*>(line), &lineval); | |
91 | return lineval; | |
92 | } | |
93 | Dwarf_Addr addr() const | |
94 | { | |
95 | Dwarf_Addr addrval; | |
96 | if (!line) | |
97 | dwarf_assert("dwarf_line_t::addr", -1); | |
98 | dwarf_lineaddr(const_cast<Dwarf_Line*>(line), &addrval); | |
99 | return addrval; | |
100 | } | |
101 | const char* linesrc(Dwarf_Word* mtime = 0, Dwarf_Word* length = 0) | |
102 | { | |
103 | const char* retval = dwarf_linesrc(const_cast<Dwarf_Line*>(line), mtime, | |
104 | length); | |
105 | dwarf_assert("dwarf_line_t::linesrc", retval); | |
106 | return retval; | |
107 | } | |
108 | }; | |
109 | ||
110 | ||
3d1ad340 JS |
111 | // Look up the DIE for a reference-form attribute name |
112 | inline Dwarf_Die * | |
113 | dwarf_attr_die (Dwarf_Die *die, unsigned int attr, Dwarf_Die *result) | |
114 | { | |
115 | Dwarf_Attribute attr_mem; | |
116 | return dwarf_formref_die (dwarf_attr_integrate (die, attr, &attr_mem), | |
117 | result); | |
118 | } | |
119 | ||
120 | ||
7f17af5c JS |
121 | #if !_ELFUTILS_PREREQ(0, 143) |
122 | // Elfutils prior to 0.143 didn't use attr_integrate when looking up the | |
123 | // decl_file or decl_line, so the attributes would sometimes be missed. For | |
124 | // those old versions, we define custom implementations to do the integration. | |
125 | ||
126 | const char *dwarf_decl_file_integrate (Dwarf_Die *die); | |
127 | #define dwarf_decl_file dwarf_decl_file_integrate | |
128 | ||
129 | int dwarf_decl_line_integrate (Dwarf_Die *die, int *linep) | |
130 | __nonnull_attribute__ (2); | |
131 | #define dwarf_decl_line dwarf_decl_line_integrate | |
132 | ||
133 | #endif // !_ELFUTILS_PREREQ(0, 143) | |
134 | ||
135 | ||
f1c8f8a5 JS |
136 | // Resolve a full name for dwarf types |
137 | bool dwarf_type_name(Dwarf_Die *type_die, std::string& type_name); | |
138 | std::string dwarf_type_name(Dwarf_Die *type_die); | |
139 | ||
140 | ||
86bf665e | 141 | #endif |
73267b89 JS |
142 | |
143 | /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */ |