Skip to content

Commit

Permalink
MINOR: debug: show return values of all functions in the debug output
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zaga00 committed Apr 12, 2022
1 parent 92d85c3 commit 9c23c18
Show file tree
Hide file tree
Showing 21 changed files with 329 additions and 224 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.13
1.2.14
33 changes: 29 additions & 4 deletions include/common/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ enum DBG_LEVEL_enum {
};

# define IFDEF_DBG(a, b) a
# define DBG_INDENT_STEP 2
# define DBG_PARM(a, ...) a, ##__VA_ARGS__
# define C_DBG(l,C,f, ...) \
do { \
Expand All @@ -56,18 +57,42 @@ enum DBG_LEVEL_enum {
if (cfg.debug_level & (1 << DBG_LEVEL_##l)) \
w_log((W), f, ##__VA_ARGS__); \
} while (0)
# define DBG_FUNC(W,f, ...) \
do { \
if (cfg.debug_level & (1 << DBG_LEVEL_ENABLED)) \
W_DBG(FUNC, (W), "%s(" f ")", __func__, ##__VA_ARGS__); \
# define DBG_FUNC(W,f, ...) \
do { \
if (cfg.debug_level & (1 << DBG_LEVEL_ENABLED)) \
W_DBG(FUNC, (W), "%s(" f ") {", __func__, ##__VA_ARGS__); \
dbg_w_ptr = (W); \
dbg_indent += DBG_INDENT_STEP; \
} while (0)
# define DBG_FUNC_END(f, ...) \
do { \
dbg_indent -= DBG_INDENT_STEP; \
if (cfg.debug_level & (1 << DBG_LEVEL_ENABLED)) \
W_DBG(FUNC, dbg_w_ptr, f, ##__VA_ARGS__); \
} while (0)
# define DBG_RETURN() do { DBG_FUNC_END("}"); return; } while (0)
# define DBG_RETURN_EX(a,t,f) do { t _r = (a); DBG_FUNC_END("} = " f, _r); return _r; } while (0)
# define DBG_RETURN_INT(a) DBG_RETURN_EX((a), int, "%d")
# define DBG_RETURN_U64(a) DBG_RETURN_EX((a), uint64_t, "%lu")
# define DBG_RETURN_SIZE(a) DBG_RETURN_EX((a), size_t, "%ld")
# define DBG_RETURN_SSIZE(a) DBG_RETURN_EX((a), ssize_t, "%lu")
# define DBG_RETURN_PTR(a) DBG_RETURN_EX((a), void *, "%p")
# define DBG_RETURN_CPTR(a) DBG_RETURN_EX((a), const void *, "%p")
#else
# define IFDEF_DBG(a, b) b
# define DBG_PARM(...)
# define C_DBG(...) while (0)
# define F_DBG(...) while (0)
# define W_DBG(...) while (0)
# define DBG_FUNC(...) while (0)
# define DBG_RETURN() return
# define DBG_RETURN_EX(a,t,f) return a
# define DBG_RETURN_INT(a) return a
# define DBG_RETURN_U64(a) return a
# define DBG_RETURN_SIZE(a) return a
# define DBG_RETURN_SSIZE(a) return a
# define DBG_RETURN_PTR(a) return a
# define DBG_RETURN_CPTR(a) return a
#endif /* DEBUG */

#endif /* _COMMON_DEBUG_H */
Expand Down
2 changes: 1 addition & 1 deletion include/types/curl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#define CURL_STR "cURL: "
#define CURL_ERR_EASY(a,b) w_log(NULL, _E(CURL_STR a ": %s (%u)"), curl_easy_strerror(b), (b))
#define CURL_ERR_MULTI(a,b) w_log(NULL, _E(CURL_STR a ": %s (%d)"), curl_multi_strerror(b), (b))
#define CURL_DBG(a, ...) W_DBG(CURL, NULL, " " CURL_STR a, ##__VA_ARGS__)
#define CURL_DBG(a, ...) W_DBG(CURL, NULL, CURL_STR a, ##__VA_ARGS__)

/* Time-out connect operations after this amount of milliseconds. */
#define CURL_CON_TMOUT 20000
Expand Down
5 changes: 5 additions & 0 deletions include/types/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ struct program_data {
extern struct config_data cfg;
extern struct program_data prg;

#ifdef DEBUG
extern __THR const void *dbg_w_ptr;
extern __THR int dbg_indent;
#endif

#endif /* _TYPES_MAIN_H */

/*
Expand Down
8 changes: 8 additions & 0 deletions include/types/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
# define LOG_RUNTIME(a,b) ((b) / 1000000.0)
#endif

#ifdef DEBUG
# define LOG_FMT_INDENT "%.*s"
# define LOG_INDENT dbg_indent, " >>>",
#else
# define LOG_FMT_INDENT
# define LOG_INDENT
#endif

#define _F(s) "(F) " s
#define _E(s) "(E) " s
#define _W(s) "(W) " s
Expand Down
2 changes: 1 addition & 1 deletion src/.build-counter
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2439
2491
Loading

0 comments on commit 9c23c18

Please sign in to comment.