Debian Codegraph @

stapdyn/dynutil.h

raw
1 // stapdyn utility functions
2 // Copyright (C) 2012 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 DYNUTIL_H
10 #define DYNUTIL_H
11
12 #include <ostream>
13 #include <stdexcept>
14 #include <string>
15
16 #include <dyninst/BPatch_process.h>
17
18 // Check that environment DYNINSTAPI_RT_LIB exists and is a valid file.
19 // If not, try to guess a good value and set it.
20 bool check_dyninst_rt(void);
21
22 // Check that SELinux settings are ok for Dyninst operation.
23 bool check_dyninst_sebools(bool attach=false);
24
25 // Check whether a process exited cleanly
26 bool check_dyninst_exit(BPatch_process *process);
27
28
29 // Get an untyped symbol from a dlopened module.
30 // If flagged as 'required', throw an exception if missing or NULL.
31 void* get_dlsym(void* handle, const char* symbol, bool required=true);
32
33 // Set a typed pointer by looking it up in a dlopened module.
34 // If flagged as 'required', throw an exception if missing or NULL.
35 template <typename T> void
36 set_dlsym(T*& pointer, void* handle, const char* symbol, bool required=true)
37 {
38 pointer = reinterpret_cast<T*>(get_dlsym(handle, symbol, required));
39 }
40
41
42 //
43 // Logging, warnings, and errors, oh my!
44 //
45
46 // verbosity, increased by -v
47 extern unsigned stapdyn_log_level;
48
49 // Whether to suppress warnings, set by -w
50 extern bool stapdyn_suppress_warnings;
51
52 // Output file name, set by -o
53 extern char *stapdyn_outfile_name;
54
55 // Return a stream for logging at the given verbosity level.
56 std::ostream& staplog(unsigned level=0);
57
58 // Return a stream for warning messages.
59 std::ostream& stapwarn(void);
60
61 // Return a stream for error messages.
62 std::ostream& staperror(void);
63
64 // Whether to color error and warning messages
65 extern bool color_errors;
66
67 // Adds coloring to strings
68 std::string colorize(std::string str, std::string type);
69
70 // Parse SYSTEMTAP_COLORS
71 std::string parse_stap_color(std::string type);
72
73 #endif // DYNUTIL_H
74
75 /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */