Skip to content

Commit c349527

Browse files
committed
Introduce tprintf_comment and tprints_comment functions
* defs.h (tprintf_comment, tprints_comment): New prototypes. * strace.c (tvprintf): New function. (tprintf): Use it. (tprintf_comment, tprints_comment): New functions. * aio.c (tprint_lio_opcode): Use tprints_comment. * dm.c (dm_decode_dm_target_spec, dm_decode_dm_target_deps, dm_decode_dm_name_list, dm_decode_dm_target_versions, dm_decode_dm_target_msg, dm_decode_string, dm_known_ioctl): Likewise. * futex.c (SYS_FUNC(futex)): Likewise. * perf.c (print_perf_event_attr): Likewise. * seccomp.c (decode_bpf_code): Likewise. * util.c (printxvals, printxval_searchn, printflags64): Likewise. * btrfs.c (print_u64, btrfs_print_key_type, btrfs_print_objectid, print_key_value_internal): Likewise. (btrfs_ioctl): Use tprints_comment and tprintf_comment. * dirent.c (SYS_FUNC(getdents)): Likewise. * dirent64.c (SYS_FUNC(getdents64)): Likewise. * execve.c (printargc): Use tprintf_comment. * tests/btrfs.c (btrfs_test_get_dev_stats_ioctl, btrfs_test_features_ioctls): Update expected output.
1 parent 37fc8e6 commit c349527

File tree

13 files changed

+137
-107
lines changed

13 files changed

+137
-107
lines changed

aio.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ tprint_lio_opcode(unsigned cmd)
7373
tprints(cmds[cmd].name);
7474
return cmds[cmd].sub;
7575
}
76-
tprintf("%u /* SUB_??? */", cmd);
76+
tprintf("%u", cmd);
77+
tprints_comment("SUB_???");
7778
return SUB_NONE;
7879
}
7980

btrfs.c

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ print_u64(const char *name, uint64_t value)
180180
{
181181
tprintf(", %s=%" PRIu64, name, value);
182182
if (value == UINT64_MAX)
183-
tprints(" /* UINT64_MAX */");
183+
tprints_comment("UINT64_MAX");
184184
}
185185

186186
#define print_member_u64(obj, name) print_u64(#name, obj->name)
@@ -261,19 +261,15 @@ btrfs_print_qgroup_limit(const struct btrfs_qgroup_limit *lim)
261261
static void
262262
btrfs_print_key_type(uint32_t type)
263263
{
264-
const char *str = xlookup(btrfs_key_types, type);
265264
tprintf("%u", type);
266-
if (str)
267-
tprintf(" /* %s */", str);
265+
tprints_comment(xlookup(btrfs_key_types, type));
268266
}
269267

270268
static void
271269
btrfs_print_objectid(uint64_t objectid)
272270
{
273-
const char *str = xlookup(btrfs_tree_objectids, objectid);
274271
tprintf("%" PRIu64, objectid);
275-
if (str)
276-
tprintf(" /* %s */", str);
272+
tprints_comment(xlookup(btrfs_tree_objectids, objectid));
277273
}
278274

279275
static void
@@ -412,7 +408,7 @@ print_key_value_internal(struct tcb *tcp, const char *name, uint64_t value)
412408
if (value) {
413409
tprintf(", %s=%" PRIu64, name, value);
414410
if (value == UINT64_MAX)
415-
tprints(" /* UINT64_MAX */");
411+
tprints_comment("UINT64_MAX");
416412
}
417413
}
418414
#define print_key_value(tcp, key, name) \
@@ -610,7 +606,7 @@ MPERS_PRINTER_DECL(int, btrfs_ioctl,
610606

611607
tprintf("%" PRIu64, (uint64_t) args.len);
612608
if (args.len == UINT64_MAX)
613-
tprints(" /* UINT64_MAX */");
609+
tprints_comment("UINT64_MAX");
614610

615611
tprints(", flags=");
616612
printflags64(btrfs_defrag_flags, args.flags,
@@ -702,35 +698,27 @@ MPERS_PRINTER_DECL(int, btrfs_ioctl,
702698
printxval64(btrfs_dev_replace_results, args.result,
703699
"BTRFS_IOCTL_DEV_REPLACE_RESULT_???");
704700
if (args.cmd == BTRFS_IOCTL_DEV_REPLACE_CMD_STATUS) {
705-
char buf[sizeof("HH:MM:SS") + 1];
706-
time_t time;
707701
tprints(", ");
708702
printxval64(btrfs_dev_replace_state,
709703
args.status.replace_state,
710704
"BTRFS_IOCTL_DEV_REPLACE_STATE_???");
711-
tprintf(", progress_1000=%" PRIu64 " /* ",
705+
tprintf(", progress_1000=%" PRIu64,
712706
(uint64_t) args.status.progress_1000);
707+
713708
if (args.status.progress_1000 <= 1000)
714-
tprintf("%" PRIu64 ".%.2" PRIu64 "%%",
715-
(uint64_t) args.status.progress_1000 / 10,
716-
(uint64_t) args.status.progress_1000 % 10);
717-
else
718-
tprints("???");
719-
tprints(" */ ,");
720-
721-
time = args.status.time_started;
722-
strftime(buf, sizeof(buf), "%T",
723-
localtime(&time));
724-
tprintf("time_started=%" PRIu64" /* %s */, ",
725-
(uint64_t) args.status.time_started, buf);
726-
727-
time = args.status.time_stopped;
728-
strftime(buf, sizeof(buf), "%T",
729-
localtime(&time));
730-
tprintf("time_stopped=%" PRIu64" /* %s */, ",
731-
(uint64_t) args.status.time_stopped, buf);
732-
733-
tprintf("num_write_errors=%" PRIu64
709+
tprintf_comment("%u.%u%%",
710+
(unsigned) args.status.progress_1000 / 10,
711+
(unsigned) args.status.progress_1000 % 10);
712+
713+
tprintf(", time_started=%" PRIu64,
714+
(uint64_t) args.status.time_started);
715+
tprints_comment(sprinttime(args.status.time_started));
716+
717+
tprintf(", time_stopped=%" PRIu64,
718+
(uint64_t) args.status.time_stopped);
719+
tprints_comment(sprinttime(args.status.time_stopped));
720+
721+
tprintf(", num_write_errors=%" PRIu64
734722
", num_uncorrectable_read_errors=%" PRIu64,
735723
(uint64_t) args.status.num_write_errors,
736724
(uint64_t) args.status.num_uncorrectable_read_errors);
@@ -779,14 +767,17 @@ MPERS_PRINTER_DECL(int, btrfs_ioctl,
779767
if (umove_or_printaddr(tcp, arg, &flarg))
780768
break;
781769

782-
tprints("[ /* supported */ ");
770+
tprints("[");
783771
btrfs_print_features(&flarg[0]);
772+
tprints_comment("supported");
784773

785-
tprints(", /* safe to set */ ");
774+
tprints(", ");
786775
btrfs_print_features(&flarg[1]);
776+
tprints_comment("safe to set");
787777

788-
tprints(", /* safe to clear */ ");
778+
tprints(", ");
789779
btrfs_print_features(&flarg[2]);
780+
tprints_comment("safe to clear");
790781
tprints("]");
791782

792783
break;
@@ -869,10 +860,8 @@ MPERS_PRINTER_DECL(int, btrfs_ioctl,
869860
tprints("...");
870861
break;
871862
}
872-
const char *name = xlookup(btrfs_dev_stats_values, i);
873-
if (name)
874-
tprintf("/* %s */ ", name);
875863
tprintf("%" PRI__u64, args.values[i]);
864+
tprints_comment(xlookup(btrfs_dev_stats_values, i));
876865
}
877866
tprints("]}");
878867
break;
@@ -1108,7 +1097,7 @@ MPERS_PRINTER_DECL(int, btrfs_ioctl,
11081097
args.start);
11091098
tprintf("%" PRI__u64, args.end);
11101099
if (args.end == UINT64_MAX)
1111-
tprints(" /* UINT64_MAX */");
1100+
tprints_comment("UINT64_MAX");
11121101
tprints(", flags=");
11131102
printflags64(btrfs_scrub_flags, args.flags,
11141103
"BTRFS_SCRUB_???");

defs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,8 @@ extern void line_ended(void);
747747
extern void tabto(void);
748748
extern void tprintf(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2));
749749
extern void tprints(const char *str);
750+
extern void tprintf_comment(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2));
751+
extern void tprints_comment(const char *str);
750752

751753
#if SUPPORTED_PERSONALITIES > 1
752754
extern void set_personality(int personality);

dirent.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ SYS_FUNC(getdents)
7878

7979
if (entering(tcp)) {
8080
printfd(tcp, tcp->u_arg[0]);
81-
tprints(", ");
8281
return 0;
8382
}
8483

8584
const unsigned int count = tcp->u_arg[2];
8685

8786
if (syserror(tcp) || !verbose(tcp)) {
87+
tprints(", ");
8888
printaddr(tcp->u_arg[1]);
8989
tprintf(", %u", count);
9090
return 0;
@@ -101,6 +101,7 @@ SYS_FUNC(getdents)
101101
if (len) {
102102
buf = malloc(len);
103103
if (!buf || umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
104+
tprints(", ");
104105
printaddr(tcp->u_arg[1]);
105106
tprintf(", %u", count);
106107
free(buf);
@@ -110,8 +111,9 @@ SYS_FUNC(getdents)
110111
buf = NULL;
111112
}
112113

114+
tprints(",");
113115
if (!abbrev(tcp))
114-
tprints("[");
116+
tprints(" [");
115117
for (i = 0; len && i <= len - sizeof(kernel_dirent); ) {
116118
kernel_dirent *d = (kernel_dirent *) &buf[i];
117119

@@ -143,15 +145,15 @@ SYS_FUNC(getdents)
143145
}
144146
dents++;
145147
if (d->d_reclen < sizeof(kernel_dirent)) {
146-
tprints("/* d_reclen < sizeof(struct dirent) */");
148+
tprints_comment("d_reclen < sizeof(struct dirent)");
147149
break;
148150
}
149151
i += d->d_reclen;
150152
}
151153
if (!abbrev(tcp))
152154
tprints("]");
153155
else
154-
tprintf("/* %u entries */", dents);
156+
tprintf_comment("%u entries", dents);
155157
tprintf(", %u", count);
156158
free(buf);
157159
return 0;

dirent64.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ SYS_FUNC(getdents64)
4646

4747
if (entering(tcp)) {
4848
printfd(tcp, tcp->u_arg[0]);
49-
tprints(", ");
5049
return 0;
5150
}
5251

5352
const unsigned int count = tcp->u_arg[2];
5453

5554
if (syserror(tcp) || !verbose(tcp)) {
55+
tprints(", ");
5656
printaddr(tcp->u_arg[1]);
5757
tprintf(", %u", count);
5858
return 0;
@@ -69,6 +69,7 @@ SYS_FUNC(getdents64)
6969
if (len) {
7070
buf = malloc(len);
7171
if (!buf || umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
72+
tprints(", ");
7273
printaddr(tcp->u_arg[1]);
7374
tprintf(", %u", count);
7475
free(buf);
@@ -78,8 +79,9 @@ SYS_FUNC(getdents64)
7879
buf = NULL;
7980
}
8081

82+
tprints(",");
8183
if (!abbrev(tcp))
82-
tprints("[");
84+
tprints(" [");
8385
for (i = 0; len && i <= len - d_name_offset; ) {
8486
struct dirent64 *d = (struct dirent64 *) &buf[i];
8587
if (!abbrev(tcp)) {
@@ -110,7 +112,7 @@ SYS_FUNC(getdents64)
110112
tprints("}");
111113
}
112114
if (d->d_reclen < d_name_offset) {
113-
tprints("/* d_reclen < offsetof(struct dirent64, d_name) */");
115+
tprints_comment("d_reclen < offsetof(struct dirent64, d_name)");
114116
break;
115117
}
116118
i += d->d_reclen;
@@ -119,7 +121,7 @@ SYS_FUNC(getdents64)
119121
if (!abbrev(tcp))
120122
tprints("]");
121123
else
122-
tprintf("/* %u entries */", dents);
124+
tprintf_comment("%u entries", dents);
123125
tprintf(", %u", count);
124126
free(buf);
125127
return 0;

dm.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ dm_decode_dm_target_spec(struct tcb *const tcp, const kernel_ulong_t addr,
195195

196196
misplaced:
197197
tprints("???");
198-
tprints(" /* misplaced struct dm_target_spec */");
198+
tprints_comment("misplaced struct dm_target_spec");
199199
}
200200

201201
bool
@@ -252,7 +252,7 @@ dm_decode_dm_target_deps(struct tcb *const tcp, const kernel_ulong_t addr,
252252

253253
misplaced:
254254
tprints("???");
255-
tprints(" /* misplaced struct dm_target_deps */");
255+
tprints_comment("misplaced struct dm_target_deps");
256256
}
257257

258258
static void
@@ -311,7 +311,7 @@ dm_decode_dm_name_list(struct tcb *const tcp, const kernel_ulong_t addr,
311311

312312
misplaced:
313313
tprints("???");
314-
tprints(" /* misplaced struct dm_name_list */");
314+
tprints_comment("misplaced struct dm_name_list");
315315
}
316316

317317
static void
@@ -368,7 +368,7 @@ dm_decode_dm_target_versions(struct tcb *const tcp, const kernel_ulong_t addr,
368368

369369
misplaced:
370370
tprints("???");
371-
tprints(" /* misplaced struct dm_target_versions */");
371+
tprints_comment("misplaced struct dm_target_versions");
372372
}
373373

374374
static void
@@ -402,7 +402,7 @@ dm_decode_dm_target_msg(struct tcb *const tcp, const kernel_ulong_t addr,
402402
tprints("}");
403403
} else {
404404
tprints("???");
405-
tprints(" /* misplaced struct dm_target_msg */");
405+
tprints_comment("misplaced struct dm_target_msg");
406406
}
407407
}
408408

@@ -425,7 +425,7 @@ dm_decode_string(struct tcb *const tcp, const kernel_ulong_t addr,
425425
QUOTE_0_TERMINATED);
426426
} else {
427427
tprints("???");
428-
tprints(" /* misplaced string */");
428+
tprints_comment("misplaced string");
429429
}
430430
}
431431

@@ -503,14 +503,14 @@ dm_known_ioctl(struct tcb *const tcp, const unsigned int code,
503503
* ioctl fields
504504
*/
505505
if (ioc->version[0] != DM_VERSION_MAJOR) {
506-
tprints(" /* unsupported device mapper ABI version */");
506+
tprints_comment("unsupported device mapper ABI version");
507507
goto skip;
508508
}
509509

510510
tprintf(", data_size=%u", ioc->data_size);
511511

512512
if (ioc->data_size < offsetof(struct dm_ioctl, data)) {
513-
tprints(" /* data_size too small */");
513+
tprints_comment("data_size too small");
514514
goto skip;
515515
}
516516

execve.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ printargc(struct tcb *const tcp, kernel_ulong_t addr)
9898
if (!cp)
9999
break;
100100
}
101-
tprintf(" /* %u var%s%s */",
101+
tprintf_comment("%u var%s%s",
102102
count, count == 1 ? "" : "s",
103103
unterminated ? ", unterminated" : "");
104104
}

futex.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ SYS_FUNC(futex)
5151
const unsigned int val = tcp->u_arg[2];
5252
const unsigned int val2 = tcp->u_arg[3];
5353
const unsigned int val3 = tcp->u_arg[5];
54+
const char *comment;
5455

5556
printaddr(uaddr);
5657
tprints(", ");
@@ -94,15 +95,15 @@ SYS_FUNC(futex)
9495
tprints(", ");
9596
if ((val3 >> 28) & 8)
9697
tprints("FUTEX_OP_OPARG_SHIFT<<28|");
97-
if (printxval(futexwakeops, (val3 >> 28) & 0x7, NULL))
98-
tprints("<<28");
99-
else
100-
tprints("<<28 /* FUTEX_OP_??? */");
98+
comment = printxval(futexwakeops, (val3 >> 28) & 0x7, NULL)
99+
? NULL : "FUTEX_OP_???";
100+
tprints("<<28");
101+
tprints_comment(comment);
101102
tprintf("|%#x<<12|", (val3 >> 12) & 0xfff);
102-
if (printxval(futexwakecmps, (val3 >> 24) & 0xf, NULL))
103-
tprints("<<24");
104-
else
105-
tprints("<<24 /* FUTEX_OP_CMP_??? */");
103+
comment = printxval(futexwakecmps, (val3 >> 24) & 0xf, NULL)
104+
? NULL : "FUTEX_OP_CMP_???";
105+
tprints("<<24");
106+
tprints_comment(comment);
106107
tprintf("|%#x", val3 & 0xfff);
107108
break;
108109
case FUTEX_WAIT_REQUEUE_PI:

0 commit comments

Comments
 (0)