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