Skip to content

Commit 9c23c18

Browse files
committed
MINOR: debug: show return values of all functions in the debug output
If the program is configured using the --enable-debug option, then log messages are printed to stdout during operation (or to a file specified at program startup). In the log one can then find (among other things) the order in which the function is called and the value that the function returns (if it is not a void type). Prior to applying this patch, no value returned by a function was logged. Log output example: [ 1][ 0.000661] worker_thread(0x558c674ba200) { [ 1][ 0.000672] Worker started, thread id: 104866 [ 1][ 0.000716] ev_backend_type(0x7f7858000b60) { [ 1][ 0.000721] ev_backend_name(4) { [ 1][ 0.000722] } = 0x558c6554b05c [ 1][ 0.000722] } = 0x558c6554b05c [ 1][ 0.000723] libev: using backend 'epoll' .. [ 1][ 5.210447] worker_thread_exit(0x558c674ba200) { [ 1][ 5.210458] Worker is stopped [ 1][ 5.210459] } = (nil) Version of the program changed to v1.2.14.
1 parent 92d85c3 commit 9c23c18

File tree

21 files changed

+329
-224
lines changed

21 files changed

+329
-224
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.13
1+
1.2.14

include/common/debug.h

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ enum DBG_LEVEL_enum {
4040
};
4141

4242
# define IFDEF_DBG(a, b) a
43+
# define DBG_INDENT_STEP 2
4344
# define DBG_PARM(a, ...) a, ##__VA_ARGS__
4445
# define C_DBG(l,C,f, ...) \
4546
do { \
@@ -56,18 +57,42 @@ enum DBG_LEVEL_enum {
5657
if (cfg.debug_level & (1 << DBG_LEVEL_##l)) \
5758
w_log((W), f, ##__VA_ARGS__); \
5859
} while (0)
59-
# define DBG_FUNC(W,f, ...) \
60-
do { \
61-
if (cfg.debug_level & (1 << DBG_LEVEL_ENABLED)) \
62-
W_DBG(FUNC, (W), "%s(" f ")", __func__, ##__VA_ARGS__); \
60+
# define DBG_FUNC(W,f, ...) \
61+
do { \
62+
if (cfg.debug_level & (1 << DBG_LEVEL_ENABLED)) \
63+
W_DBG(FUNC, (W), "%s(" f ") {", __func__, ##__VA_ARGS__); \
64+
dbg_w_ptr = (W); \
65+
dbg_indent += DBG_INDENT_STEP; \
6366
} while (0)
67+
# define DBG_FUNC_END(f, ...) \
68+
do { \
69+
dbg_indent -= DBG_INDENT_STEP; \
70+
if (cfg.debug_level & (1 << DBG_LEVEL_ENABLED)) \
71+
W_DBG(FUNC, dbg_w_ptr, f, ##__VA_ARGS__); \
72+
} while (0)
73+
# define DBG_RETURN() do { DBG_FUNC_END("}"); return; } while (0)
74+
# define DBG_RETURN_EX(a,t,f) do { t _r = (a); DBG_FUNC_END("} = " f, _r); return _r; } while (0)
75+
# define DBG_RETURN_INT(a) DBG_RETURN_EX((a), int, "%d")
76+
# define DBG_RETURN_U64(a) DBG_RETURN_EX((a), uint64_t, "%lu")
77+
# define DBG_RETURN_SIZE(a) DBG_RETURN_EX((a), size_t, "%ld")
78+
# define DBG_RETURN_SSIZE(a) DBG_RETURN_EX((a), ssize_t, "%lu")
79+
# define DBG_RETURN_PTR(a) DBG_RETURN_EX((a), void *, "%p")
80+
# define DBG_RETURN_CPTR(a) DBG_RETURN_EX((a), const void *, "%p")
6481
#else
6582
# define IFDEF_DBG(a, b) b
6683
# define DBG_PARM(...)
6784
# define C_DBG(...) while (0)
6885
# define F_DBG(...) while (0)
6986
# define W_DBG(...) while (0)
7087
# define DBG_FUNC(...) while (0)
88+
# define DBG_RETURN() return
89+
# define DBG_RETURN_EX(a,t,f) return a
90+
# define DBG_RETURN_INT(a) return a
91+
# define DBG_RETURN_U64(a) return a
92+
# define DBG_RETURN_SIZE(a) return a
93+
# define DBG_RETURN_SSIZE(a) return a
94+
# define DBG_RETURN_PTR(a) return a
95+
# define DBG_RETURN_CPTR(a) return a
7196
#endif /* DEBUG */
7297

7398
#endif /* _COMMON_DEBUG_H */

include/types/curl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#define CURL_STR "cURL: "
2424
#define CURL_ERR_EASY(a,b) w_log(NULL, _E(CURL_STR a ": %s (%u)"), curl_easy_strerror(b), (b))
2525
#define CURL_ERR_MULTI(a,b) w_log(NULL, _E(CURL_STR a ": %s (%d)"), curl_multi_strerror(b), (b))
26-
#define CURL_DBG(a, ...) W_DBG(CURL, NULL, " " CURL_STR a, ##__VA_ARGS__)
26+
#define CURL_DBG(a, ...) W_DBG(CURL, NULL, CURL_STR a, ##__VA_ARGS__)
2727

2828
/* Time-out connect operations after this amount of milliseconds. */
2929
#define CURL_CON_TMOUT 20000

include/types/main.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ struct program_data {
9292
extern struct config_data cfg;
9393
extern struct program_data prg;
9494

95+
#ifdef DEBUG
96+
extern __THR const void *dbg_w_ptr;
97+
extern __THR int dbg_indent;
98+
#endif
99+
95100
#endif /* _TYPES_MAIN_H */
96101

97102
/*

include/types/util.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
# define LOG_RUNTIME(a,b) ((b) / 1000000.0)
3232
#endif
3333

34+
#ifdef DEBUG
35+
# define LOG_FMT_INDENT "%.*s"
36+
# define LOG_INDENT dbg_indent, " >>>",
37+
#else
38+
# define LOG_FMT_INDENT
39+
# define LOG_INDENT
40+
#endif
41+
3442
#define _F(s) "(F) " s
3543
#define _E(s) "(E) " s
3644
#define _W(s) "(W) " s

src/.build-counter

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2439
1+
2491

0 commit comments

Comments
 (0)