libcsdbg  1.28
C++ exception (and generic) stack trace debug library
util.hpp
Go to the documentation of this file.
1 #ifndef _CSDBG_UTIL
2 #define _CSDBG_UTIL 1
3 
10 #include "./string.hpp"
11 #if !defined CSDBG_WITH_PLUGIN && !defined CSDBG_WITH_HIGHLIGHT
12 #include "./chain.hpp"
13 #endif
14 
15 namespace csdbg {
16 
20 class util: virtual public object
21 {
22 protected:
23 
24  /* Protected static variables */
25 
26  static pthread_mutex_t m_lock;
31  /* Protected static methods */
32 
33  static void on_lib_load() __attribute((constructor));
34 
35  static void on_lib_unload() __attribute((destructor));
36 
37 public:
38 
39  /* Generic methods */
40 
41  /* Library compile time and runtime configuration handling methods */
42 
43  static void version(u16*, u16*);
44 
45  static const i8* prefix();
46 
47  static const i8* exec_path();
48 
49  static chain<string>* getenv(const i8*);
50 
51  static void init(i32&, i8**);
52 
53  static u32 argc();
54 
55  static const string* argv(u32);
56 
57  static const i8* type_name(const std::type_info&);
58 
59 
60  /* Various methods (with portability issues) */
61 
62  static u32 min(u32, u32, u32);
63 
64  static void* memset(void*, u8, u32);
65 
66  static void* memcpy(void*, const void*, u32);
67 
68  static void* memswap(void*, u32);
69 
70  static void lock();
71 
72  static void unlock();
73 
74  static bool is_regular(const fileinfo_t&);
75 
76  static bool is_chardev(const fileinfo_t&);
77 
78  static bool is_readable(const fileinfo_t&);
79 
80  static bool is_writable(const fileinfo_t&);
81 
82 
83  /* Output and debug methods */
84 
85  static i32 va_size(const i8*, va_list);
86 
87  static i8* va_format(const i8*, va_list);
88 
89  static i8* va_format(i8*, const i8*, va_list);
90 
91  static void header(std::ostream&, const i8*);
92 
93  static void dbg(const i8*, const i8*, va_list);
94 
95  static void dbg_info(const i8*, ...);
96 
97  static void dbg_warn(const i8*, ...);
98 
99  static void dbg_error(const i8*, ...);
100 };
101 
102 }
103 
104 #endif
105 
static pthread_mutex_t m_lock
Global access mutex.
Definition: util.hpp:26
This abstract class serves as the root of the class hierarchy tree.
Definition: object.hpp:17
static const i8 * exec_path()
Get the absolute path of the executable.
Definition: util.cpp:87
static bool is_writable(const fileinfo_t &)
Check if the process has write access to a file.
Definition: util.cpp:464
static void * memset(void *, u8, u32)
Fill a memory block with a constant byte.
Definition: util.cpp:320
char i8
8-bit signed integer
Definition: config.hpp:72
struct stat fileinfo_t
File metadata.
Definition: config.hpp:112
static void version(u16 *, u16 *)
Get the library version numbers.
Definition: util.cpp:58
static void on_lib_load() __attribute((constructor))
Library constructor.
Definition: util.cpp:24
static u32 argc()
Get the number of CLI arguments.
Definition: util.cpp:242
static const i8 * type_name(const std::type_info &)
Get the demangled name of a type.
Definition: util.cpp:276
Class csdbg::chain definition and method implementation.
unsigned short u16
16-bit unsigned integer
Definition: config.hpp:97
static void on_lib_unload() __attribute((destructor))
Library destructor.
Definition: util.cpp:42
static void dbg_warn(const i8 *,...)
Print a warning debug message on the standard error stream.
Definition: util.cpp:703
static const i8 * prefix()
Get the library installation prefix.
Definition: util.cpp:73
unsigned char u8
8-bit unsigned integer
Definition: config.hpp:92
static void lock()
Lock the global access mutex.
Definition: util.cpp:397
static void unlock()
Unlock the global access mutex.
Definition: util.cpp:406
static bool is_readable(const fileinfo_t &)
Check if the process has read access to a file.
Definition: util.cpp:445
static void dbg_error(const i8 *,...)
Print an error debug message on the standard error stream.
Definition: util.cpp:726
static bool is_chardev(const fileinfo_t &)
Check if a file is a character device node.
Definition: util.cpp:432
static chain< string > * m_config
Runtime configuration.
Definition: util.hpp:28
Class csdbg::string definition.
static void dbg(const i8 *, const i8 *, va_list)
Print a tagged debug message on the standard error stream.
Definition: util.cpp:641
static u32 min(u32, u32, u32)
Get the minimum of three numbers.
Definition: util.cpp:298
static i8 * va_format(const i8 *, va_list)
Format a buffer with a printf-style string expanded with the values of a variable argument list...
Definition: util.cpp:519
static void * memswap(void *, u32)
Reverse the byte order of a memory block.
Definition: util.cpp:374
unsigned int u32
32-bit unsigned integer
Definition: config.hpp:102
int i32
32-bit signed integer
Definition: config.hpp:82
static chain< string > * getenv(const i8 *)
Parse a shell (environment) variable to its components.
Definition: util.cpp:128
static bool is_regular(const fileinfo_t &)
Check if a file is a regular one.
Definition: util.cpp:419
static void header(std::ostream &, const i8 *)
Print a tagged message header on an output stream.
Definition: util.cpp:594
This class provides various low level utility and portability methods.
Definition: util.hpp:20
static i32 va_size(const i8 *, va_list)
Compute the size of a printf-style format string expanded with the values of a variable argument list...
Definition: util.cpp:489
static void * memcpy(void *, const void *, u32)
Copy a memory block.
Definition: util.cpp:347
static void dbg_info(const i8 *,...)
Print an informational debug message on the standard error stream.
Definition: util.cpp:680
static const string * argv(u32)
Get a CLI argument, given its offset in util::m_config.
Definition: util.cpp:259
static void init(i32 &, i8 **)
Initialize the library runtime configuration. Seek command line arguments that are related with libcs...
Definition: util.cpp:188