]> sourceware.org Git - systemtap.git/blob - dwarf_wrappers.h
trailing whitespace removal, as approved by emacs
[systemtap.git] / dwarf_wrappers.h
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
11 #include <elfutils/libdw.h>
12
13 #include <string>
14
15 // NB: "rc == 0" means OK in this case
16 void dwfl_assert(const std::string& desc, int rc);
17
18 // Throw error if pointer is NULL.
19 template <typename T>
20 void dwfl_assert(const std::string& desc, T* ptr)
21 {
22 if (!ptr)
23 dwfl_assert(desc, -1);
24 }
25
26 // Throw error if pointer is NULL
27 template <typename T>
28 void dwfl_assert(const std::string& desc, const T* ptr)
29 {
30 if (!ptr)
31 dwfl_assert(desc, -1);
32 }
33
34 // Throw error if condition is false
35 void dwfl_assert(const std::string& desc, bool condition);
36
37 // NB: "rc == 0" means OK in this case
38 void dwarf_assert(const std::string& desc, int rc);
39
40 // Throw error if pointer is NULL
41 template <typename T>
42 void dwarf_assert(const std::string& desc, T* ptr)
43 {
44 if (!ptr)
45 dwarf_assert(desc, -1);
46 }
47
48
49 class dwarf_line_t
50 {
51 public:
52 const Dwarf_Line* line;
53 dwarf_line_t() : line(0) {}
54 dwarf_line_t(const Dwarf_Line* line_) : line(line_) {}
55
56 dwarf_line_t& operator= (const Dwarf_Line* line_)
57 {
58 line = (line_);
59 return *this;
60 }
61
62 operator bool() const
63 {
64 return line != 0;
65 }
66
67 int lineno() const
68 {
69 int lineval;
70 if (!line)
71 dwarf_assert("dwarf_line_t::lineno", -1);
72 dwarf_lineno(const_cast<Dwarf_Line*>(line), &lineval);
73 return lineval;
74 }
75 Dwarf_Addr addr() const
76 {
77 Dwarf_Addr addrval;
78 if (!line)
79 dwarf_assert("dwarf_line_t::addr", -1);
80 dwarf_lineaddr(const_cast<Dwarf_Line*>(line), &addrval);
81 return addrval;
82 }
83 const char* linesrc(Dwarf_Word* mtime = 0, Dwarf_Word* length = 0)
84 {
85 const char* retval = dwarf_linesrc(const_cast<Dwarf_Line*>(line), mtime,
86 length);
87 dwarf_assert("dwarf_line_t::linesrc", retval);
88 return retval;
89 }
90 };
91
92
93 #endif
This page took 0.037425 seconds and 5 git commands to generate.