Fix typos [ci skip]
[ruby-80x24.org.git] / vm_debug.h
blob230f0f7b16ed8e715b8e7b9af532712ceb3e9ea2
1 #ifndef RUBY_DEBUG_H
2 #define RUBY_DEBUG_H
3 /**********************************************************************
5 vm_debug.h - YARV Debug function interface
7 $Author$
8 created at: 04/08/25 02:33:49 JST
10 Copyright (C) 2004-2007 Koichi Sasada
12 **********************************************************************/
14 #include "ruby/ruby.h"
16 RUBY_SYMBOL_EXPORT_BEGIN
18 #define dpv(h,v) ruby_debug_print_value(-1, 0, (h), (v))
19 #define dp(v) ruby_debug_print_value(-1, 0, "", (v))
20 #define dpi(i) ruby_debug_print_id(-1, 0, "", (i))
21 #define dpn(n) ruby_debug_print_node(-1, 0, "", (n))
23 struct RNode;
25 VALUE ruby_debug_print_value(int level, int debug_level, const char *header, VALUE v);
26 ID ruby_debug_print_id(int level, int debug_level, const char *header, ID id);
27 struct RNode *ruby_debug_print_node(int level, int debug_level, const char *header, const struct RNode *node);
28 int ruby_debug_print_indent(int level, int debug_level, int indent_level);
29 void ruby_debug_gc_check_func(void);
30 void ruby_set_debug_option(const char *str);
32 RUBY_SYMBOL_EXPORT_END
34 #if RUBY_DEVEL
35 #ifndef USE_RUBY_DEBUG_LOG
36 #define USE_RUBY_DEBUG_LOG 0
37 #endif
38 #else
39 // disable on !RUBY_DEVEL
40 #ifdef USE_RUBY_DEBUG_LOG
41 #undef USE_RUBY_DEBUG_LOG
42 #endif
43 #endif
45 /* RUBY_DEBUG_LOG: Logging debug information mechanism
47 * This feature provides a mechanism to store logging information
48 * to a file, stderr or memory space with simple macros.
50 * The following information will be stored.
51 * * (1) __FILE__, __LINE__ in C
52 * * (2) __FILE__, __LINE__ in Ruby
53 * * (3) __func__ in C (message title)
54 * * (4) given string with sprintf format
55 * * (5) Thread number (if multiple threads are running)
57 * This feature is enabled only USE_RUBY_DEBUG_LOG is enabled.
58 * Release version should not enable it.
60 * Running with the `RUBY_DEBUG_LOG` environment variable enables
61 * this feature.
63 * # logging into a file
64 * RUBY_DEBUG_LOG=/path/to/file STDERR
66 * # logging into STDERR
67 * RUBY_DEBUG_LOG=stderr
69 * # logging into memory space (check with a debugger)
70 * # It will help if the timing is important.
71 * RUBY_DEBUG_LOG=mem
73 * RUBY_DEBUG_LOG_FILTER environment variable can specify the filter string.
74 * If "(3) __func__ in C (message title)" contains the specified string, the
75 * information will be stored (example: RUBY_DEBUG_LOG_FILTER=str will enable
76 * only on str related information).
78 * In a MRI source code, you can use the following macros:
79 * * RUBY_DEBUG_LOG(fmt, ...): Above (1) to (4) will be logged.
80 * * RUBY_DEBUG_LOG2(file, line, fmt, ...):
81 * Same as RUBY_DEBUG_LOG(), but (1) will be replaced with given file, line.
84 extern enum ruby_debug_log_mode {
85 ruby_debug_log_disabled = 0x00,
86 ruby_debug_log_memory = 0x01,
87 ruby_debug_log_stderr = 0x02,
88 ruby_debug_log_file = 0x04,
89 } ruby_debug_log_mode;
91 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 4, 5)
92 void ruby_debug_log(const char *file, int line, const char *func_name, const char *fmt, ...);
93 void ruby_debug_log_print(unsigned int n);
94 bool ruby_debug_log_filter(const char *func_name);
96 // convenient macro to log even if the USE_RUBY_DEBUG_LOG macro is not specified.
97 // You can use this macro for temporary usage (you should not commit it).
98 #define _RUBY_DEBUG_LOG(...) ruby_debug_log(__FILE__, __LINE__, RUBY_FUNCTION_NAME_STRING, "" __VA_ARGS__)
100 #if USE_RUBY_DEBUG_LOG
101 # define RUBY_DEBUG_LOG_ENABLED(func_name) \
102 (ruby_debug_log_mode && ruby_debug_log_filter(func_name))
104 #define RUBY_DEBUG_LOG(...) do { \
105 if (RUBY_DEBUG_LOG_ENABLED(RUBY_FUNCTION_NAME_STRING)) \
106 ruby_debug_log(__FILE__, __LINE__, RUBY_FUNCTION_NAME_STRING, "" __VA_ARGS__); \
107 } while (0)
109 #define RUBY_DEBUG_LOG2(file, line, ...) do { \
110 if (RUBY_DEBUG_LOG_ENABLED(RUBY_FUNCTION_NAME_STRING)) \
111 ruby_debug_log(file, line, RUBY_FUNCTION_NAME_STRING, "" __VA_ARGS__); \
112 } while (0)
114 #else
115 // do nothing
116 #define RUBY_DEBUG_LOG(...)
117 #define RUBY_DEBUG_LOG2(file, line, ...)
118 #endif // USE_RUBY_DEBUG_LOG
120 #endif /* RUBY_DEBUG_H */