diff options
author | Eugene Syromyatnikov <evgsyr@gmail.com> | 2022-08-22 18:00:37 +0200 |
---|---|---|
committer | Eugene Syromyatnikov <evgsyr@gmail.com> | 2022-09-02 17:55:13 +0200 |
commit | b18f9c4d5b2672a491c1ca688288356858a0dfa5 (patch) | |
tree | 3cb1797847019c69c0d300dada36af563e858e23 | |
parent | 429d9701b47746f0600dfff66f3466c531515fc0 (diff) | |
download | strace-b18f9c4d5b2672a491c1ca688288356858a0dfa5.tar.gz |
Add tprint[fs]_pre_comment and tprint_pre_comment_{begin,end} helpers
For the situations when a comment precedes the thing it comments upon.
* src/defs.h (tprintf_pre_comment, tprints_pre_comment): New
declarations.
* src/print_fields.h (tprint_pre_comment_begin, tprint_pre_comment_end):
New functions.
* src/strace.c (tprints_comment): Use tprint_comment_begin
and tprint_comment_end.
(tprints_pre_comment, tprintf_pre_comment): New functions.
-rw-r--r-- | src/defs.h | 2 | ||||
-rw-r--r-- | src/print_fields.h | 12 | ||||
-rw-r--r-- | src/strace.c | 31 |
3 files changed, 43 insertions, 2 deletions
diff --git a/src/defs.h b/src/defs.h index 3f64e5737..e8a8e6469 100644 --- a/src/defs.h +++ b/src/defs.h @@ -1689,6 +1689,8 @@ extern void tprintf(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2)); extern void tprints(const char *str); extern void tprintf_comment(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2)); extern void tprints_comment(const char *str); +extern void tprintf_pre_comment(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2)); +extern void tprints_pre_comment(const char *str); /* * Staging output for status qualifier. diff --git a/src/print_fields.h b/src/print_fields.h index 8a01d053d..3ae042eab 100644 --- a/src/print_fields.h +++ b/src/print_fields.h @@ -145,6 +145,18 @@ tprint_comment_end(void) } static inline void +tprint_pre_comment_begin(void) +{ + STRACE_PRINTS("/* "); +} + +static inline void +tprint_pre_comment_end(void) +{ + STRACE_PRINTS(" */ "); +} + +static inline void tprint_indirect_begin(void) { STRACE_PRINTS("["); diff --git a/src/strace.c b/src/strace.c index 3f5a00a0a..418d90c9a 100644 --- a/src/strace.c +++ b/src/strace.c @@ -741,8 +741,11 @@ tprints(const char *str) void tprints_comment(const char *const str) { - if (str && *str) - tprintf(" /* %s */", str); + if (str && *str) { + tprint_comment_begin(); + tprints(str); + tprint_comment_end(); + } } void @@ -759,6 +762,30 @@ tprintf_comment(const char *fmt, ...) va_end(args); } +void +tprints_pre_comment(const char *const str) +{ + if (str && *str) { + tprint_pre_comment_begin(); + tprints(str); + tprint_pre_comment_end(); + } +} + +void +tprintf_pre_comment(const char *fmt, ...) +{ + if (!fmt || !*fmt) + return; + + va_list args; + va_start(args, fmt); + tprint_pre_comment_begin(); + tvprintf(fmt, args); + tprint_pre_comment_end(); + va_end(args); +} + static void flush_tcp_output(const struct tcb *const tcp) { |