libcsdbg  1.28
C++ exception (and generic) stack trace debug library
tracer.hpp
Go to the documentation of this file.
1 #ifndef _CSDBG_TRACER
2 #define _CSDBG_TRACER 1
3 
10 #include "./process.hpp"
11 #include "./string.hpp"
12 #ifdef CSDBG_WITH_PLUGIN
13 #include "./plugin.hpp"
14 #endif
15 #ifdef CSDBG_WITH_FILTER
16 #include "./filter.hpp"
17 #endif
18 
19 namespace csdbg {
20 
34 class tracer: virtual public object
35 {
36 protected:
37 
38  /* Protected static variables */
39 
40  static tracer *m_iface;
43  /* Protected variables */
44 
47 #ifdef CSDBG_WITH_PLUGIN
49 #endif
50 #ifdef CSDBG_WITH_FILTER
52 #endif
53 
54 
55  /* Protected static methods */
56 
57  static void on_lib_load() __attribute((constructor));
58 
59  static void on_lib_unload() __attribute((destructor));
60 
61  static i32 on_dso_load(dl_phdr_info*, size_t, void*);
62 
63  static string& addr2line(string&, const i8*, mem_addr_t);
64 
65 
66  /* Protected constructors, copy constructors and destructor */
67 
68  tracer();
69 
70  tracer(const tracer&);
71 
72  virtual ~tracer();
73 
74  virtual tracer* clone() const;
75 
76 
77  /* Protected operator overloading methods */
78 
79  virtual tracer& operator=(const tracer&);
80 
81 
82  /* Protected generic methods */
83 
84  virtual tracer& destroy();
85 
86 public:
87 
88  /* Friend classes and functions */
89 
90  friend std::ostream& operator<<(std::ostream&, tracer&);
91 
92 
93  /* Accessor methods */
94 
95  virtual process* proc() const;
96 
97  static tracer* interface();
98 
99 
100  /* Generic methods */
101 
102  /* Trace producing methods */
103 
104  virtual tracer& trace(string&);
105 
106  virtual tracer& trace(string&, pthread_t) const;
107 
108  virtual tracer& unwind();
109 
110  virtual tracer& dump(string&) const;
111 
112 
113  /* Plugin handling methods */
114 
115 #ifdef CSDBG_WITH_PLUGIN
116  virtual u32 plugin_count() const;
117 
118  virtual const plugin* add_plugin(const i8*, const i8* = NULL);
119 
120  virtual const plugin* add_plugin(modsym_t, modsym_t);
121 
122  virtual tracer& remove_plugin(const i8*);
123 
124  virtual tracer& remove_plugin(u32);
125 
126  virtual const plugin* get_plugin(const i8*) const;
127 
128  virtual const plugin* get_plugin(u32) const;
129 #endif
130 
131 
132  /* Filter handling methods */
133 
134 #ifdef CSDBG_WITH_FILTER
135  virtual u32 filter_count() const;
136 
137  virtual filter* add_filter(const i8*, bool, bool = true);
138 
139  virtual tracer& remove_filter(u32);
140 
141  virtual filter* get_filter(u32) const;
142 #endif
143 };
144 
145 }
146 
147 #endif
148 
This abstract class serves as the root of the class hierarchy tree.
Definition: object.hpp:17
virtual const plugin * get_plugin(const i8 *) const
Get a registered plugin module (DSO)
Definition: tracer.cpp:967
virtual tracer & destroy()
Release object resources.
Definition: tracer.cpp:561
Lightweight, templated, doubly-linked list (using XOR linking)
Definition: chain.hpp:33
char i8
8-bit signed integer
Definition: config.hpp:72
virtual u32 filter_count() const
Get the number of registered filters.
Definition: tracer.cpp:1024
Function instrumentation plugin.
Definition: plugin.hpp:42
static tracer * interface()
Get the interface object.
Definition: tracer.cpp:629
A tracer object is the default interface to libcsdbg for the instrumentation functions and for the li...
Definition: tracer.hpp:34
static i32 on_dso_load(dl_phdr_info *, size_t, void *)
This is a dl_iterate_phdr (libdl) callback, called for each linked shared object. It loads the symbol...
Definition: tracer.cpp:323
virtual filter * get_filter(u32) const
Get a registered filter.
Definition: tracer.cpp:1085
chain< plugin > * m_plugins
Instrumentation plugins.
Definition: tracer.hpp:48
process * m_proc
Process handle.
Definition: tracer.hpp:45
virtual tracer * clone() const
Object virtual copy constructor.
Definition: tracer.cpp:527
virtual tracer & trace(string &)
Create an exception stack trace using the simulated call stack of the current thread. The trace is appended to a string and the simulated stack is unwinded.
Definition: tracer.cpp:658
virtual filter * add_filter(const i8 *, bool, bool=true)
Register a filter.
Definition: tracer.cpp:1044
static void on_lib_load() __attribute((constructor))
Library constructor.
Definition: tracer.cpp:253
virtual tracer & unwind()
Unwind the simulated call stack of the current thread.
Definition: tracer.cpp:778
virtual tracer & remove_plugin(const i8 *)
Unregister a plugin module (DSO)
Definition: tracer.cpp:910
Class csdbg::string definition.
void(* modsym_t)(void *, void *)
Plugin callback.
Definition: config.hpp:152
Instrumentation filter.
Definition: filter.hpp:23
This class represents a process, its entire namespace and thread group.
Definition: process.hpp:29
virtual const plugin * add_plugin(const i8 *, const i8 *=NULL)
Register a plugin module (DSO)
Definition: tracer.cpp:854
virtual u32 plugin_count() const
Get the number of registered plugins.
Definition: tracer.cpp:836
unsigned int u32
32-bit unsigned integer
Definition: config.hpp:102
static string & addr2line(string &, const i8 *, mem_addr_t)
Given an address in an objective code file, extract from the gdb-related debug information, the equivalent source code file name and line and append it to a string buffer.
Definition: tracer.cpp:398
int i32
32-bit signed integer
Definition: config.hpp:82
virtual tracer & remove_filter(u32)
Unregister a filter.
Definition: tracer.cpp:1069
virtual tracer & dump(string &) const
Create multiple stack traces using the simulated call stack of each thread. The traces are appended t...
Definition: tracer.cpp:806
chain< filter > * m_filters
Instrumentation filters.
Definition: tracer.hpp:51
virtual process * proc() const
Get the process handle.
Definition: tracer.cpp:618
Class csdbg::process definition.
unsigned long long mem_addr_t
64-bit memory address
Definition: config.hpp:120
Class csdbg::plugin definition.
Class csdbg::filter definition.
static void on_lib_unload() __attribute((destructor))
Library destructor.
Definition: tracer.cpp:290
static tracer * m_iface
Interface object.
Definition: tracer.hpp:40