From: Dmitry V. Levin Date: Tue, 11 Jul 2017 00:20:54 +0000 (+0000) Subject: Introduce PRINT_FIELD_CSTRING X-Git-Tag: v4.19~280 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=837a76f4ee8661d7b32672ac4cd21a14e33f5a84;p=strace Introduce PRINT_FIELD_CSTRING * print_fields.h (PRINT_FIELD_CSTRING): New macro. * block.c (print_blkpg_req, block_ioctl): Use PRINT_FIELD_CSTRING instead of print_quoted_string. * btrfs.c (btrfs_ioctl): Likewise. * dm.c (dm_decode_device, dm_decode_dm_target_spec): Likewise. * loop.c (decode_loop_info, decode_loop_info64): Likewise. * v4l2.c (print_v4l2_capability, print_v4l2_fmtdesc, print_v4l2_standard, print_v4l2_input, print_v4l2_tuner, print_v4l2_queryctrl): Likewise. * netlink_sock_diag.c (decode_smc_diag_lgrinfo): Use PRINT_FIELD_CSTRING instead of PRINT_FIELD_STRING. * uname.c (PRINT_UTS_MEMBER): Remove. (SYS_FUNC(uname)): Use PRINT_FIELD_CSTRING instead of PRINT_UTS_MEMBER. --- diff --git a/block.c b/block.c index c77b92ac..afd70980 100644 --- a/block.c +++ b/block.c @@ -66,6 +66,8 @@ typedef struct blk_user_trace_setup { #include MPERS_DEFS +#include "print_fields.h" + #ifndef BLKPG # define BLKPG _IO(0x12, 105) #endif @@ -131,13 +133,10 @@ print_blkpg_req(struct tcb *tcp, const struct_blkpg_ioctl_arg *blkpg) if (!umove_or_printaddr(tcp, ptr_to_kulong(blkpg->data), &p)) { tprintf("{start=%" PRId64 ", length=%" PRId64 - ", pno=%d, devname=", + ", pno=%d", p.start, p.length, p.pno); - print_quoted_string(p.devname, sizeof(p.devname), - QUOTE_0_TERMINATED); - tprints(", volname="); - print_quoted_string(p.volname, sizeof(p.volname), - QUOTE_0_TERMINATED); + PRINT_FIELD_CSTRING(", ", p, devname); + PRINT_FIELD_CSTRING(", ", p, volname); tprints("}"); } tprints("}"); @@ -250,11 +249,8 @@ MPERS_PRINTER_DECL(int, block_ioctl, struct tcb *const tcp, } else { struct_blk_user_trace_setup buts; - if (!syserror(tcp) && !umove(tcp, arg, &buts)) { - tprints(", name="); - print_quoted_string(buts.name, sizeof(buts.name), - QUOTE_0_TERMINATED); - } + if (!syserror(tcp) && !umove(tcp, arg, &buts)) + PRINT_FIELD_CSTRING(", ", buts, name); tprints("}"); break; } diff --git a/btrfs.c b/btrfs.c index e730c7aa..8bffba8b 100644 --- a/btrfs.c +++ b/btrfs.c @@ -52,6 +52,7 @@ typedef struct btrfs_ioctl_vol_args_v2 #ifdef HAVE_LINUX_BTRFS_H +#include "print_fields.h" #include /* @@ -646,10 +647,9 @@ MPERS_PRINTER_DECL(int, btrfs_ioctl, if (valid) tprintf("uuid=%s, ", uuid); tprintf("bytes_used=%" PRI__u64 - ", total_bytes=%" PRI__u64 ", path=", + ", total_bytes=%" PRI__u64, args.bytes_used, args.total_bytes); - print_quoted_string((const char *)args.path, sizeof(args.path), - QUOTE_0_TERMINATED); + PRINT_FIELD_CSTRING(", ", args, path); tprints("}"); break; } @@ -901,9 +901,7 @@ MPERS_PRINTER_DECL(int, btrfs_ioctl, tprints(", "); } - tprints("name="); - print_quoted_string(args.name, sizeof(args.name), - QUOTE_0_TERMINATED); + PRINT_FIELD_CSTRING("", args, name); tprints("}"); break; } @@ -1279,9 +1277,7 @@ MPERS_PRINTER_DECL(int, btrfs_ioctl, tprints("{fd="); printfd(tcp, args.fd); - tprints(", name="); - print_quoted_string(args.name, sizeof(args.name), - QUOTE_0_TERMINATED); + PRINT_FIELD_CSTRING(", ", args, name); tprints("}"); break; } @@ -1313,9 +1309,7 @@ MPERS_PRINTER_DECL(int, btrfs_ioctl, btrfs_print_qgroup_inherit(tcp, ptr_to_kulong(args.qgroup_inherit)); } - tprints(", name="); - print_quoted_string(args.name, sizeof(args.name), - QUOTE_0_TERMINATED); + PRINT_FIELD_CSTRING(", ", args, name); tprints("}"); return 0; } diff --git a/dm.c b/dm.c index a84b59d1..41de9018 100644 --- a/dm.c +++ b/dm.c @@ -32,10 +32,10 @@ */ #include "defs.h" -#include "print_fields.h" #ifdef HAVE_LINUX_DM_IOCTL_H +# include "print_fields.h" # include # include @@ -63,19 +63,15 @@ dm_decode_device(const unsigned int code, const struct dm_ioctl *ioc) case DM_LIST_VERSIONS: break; default: - if (ioc->dev) { + if (ioc->dev) PRINT_FIELD_DEV(", ", *ioc, dev); - } - if (ioc->name[0]) { - tprints(", name="); - print_quoted_string(ioc->name, DM_NAME_LEN, - QUOTE_0_TERMINATED); - } - if (ioc->uuid[0]) { - tprints(", uuid="); - print_quoted_string(ioc->uuid, DM_UUID_LEN, - QUOTE_0_TERMINATED); - } + + if (ioc->name[0]) + PRINT_FIELD_CSTRING(", ", *ioc, name); + + if (ioc->uuid[0]) + PRINT_FIELD_CSTRING(", ", *ioc, uuid); + break; } } @@ -177,9 +173,7 @@ dm_decode_dm_target_spec(struct tcb *const tcp, const kernel_ulong_t addr, if (exiting(tcp)) tprintf(", status=%" PRId32, s.status); - tprints(", target_type="); - print_quoted_string(s.target_type, DM_MAX_TYPE_NAME, - QUOTE_0_TERMINATED); + PRINT_FIELD_CSTRING(", ", s, target_type); tprints(", string="); printstr_ex(tcp, addr + offset_end, ioc->data_size - offset_end, diff --git a/loop.c b/loop.c index 27f1ddd2..e30b7ce5 100644 --- a/loop.c +++ b/loop.c @@ -75,15 +75,13 @@ decode_loop_info(struct tcb *const tcp, const kernel_ulong_t addr) tprints(", lo_flags="); printflags(loop_flags_options, info.lo_flags, "LO_FLAGS_???"); - tprints(", lo_name="); - print_quoted_string(info.lo_name, LO_NAME_SIZE, - QUOTE_0_TERMINATED); + PRINT_FIELD_CSTRING(", ", info, lo_name); if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) { - tprints(", lo_encrypt_key="); - print_quoted_string((void *) info.lo_encrypt_key, - MIN((uint32_t) info.lo_encrypt_key_size, - LO_KEY_SIZE), 0); + const unsigned int lo_encrypt_key_size = + MIN((unsigned) info.lo_encrypt_key_size, LO_KEY_SIZE); + PRINT_FIELD_STRING(", ", info, lo_encrypt_key, + lo_encrypt_key_size, 0); } if (!abbrev(tcp)) @@ -132,18 +130,14 @@ decode_loop_info64(struct tcb *const tcp, const kernel_ulong_t addr) tprints(", lo_flags="); printflags(loop_flags_options, info64.lo_flags, "LO_FLAGS_???"); - tprints(", lo_file_name="); - print_quoted_string((void *) info64.lo_file_name, - LO_NAME_SIZE, QUOTE_0_TERMINATED); + PRINT_FIELD_CSTRING(", ", info64, lo_file_name); if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) { - tprints(", lo_crypt_name="); - print_quoted_string((void *) info64.lo_crypt_name, - LO_NAME_SIZE, QUOTE_0_TERMINATED); - tprints(", lo_encrypt_key="); - print_quoted_string((void *) info64.lo_encrypt_key, - MIN(info64.lo_encrypt_key_size, - LO_KEY_SIZE), 0); + PRINT_FIELD_CSTRING(", ", info64, lo_crypt_name); + const unsigned int lo_encrypt_key_size = + MIN((unsigned) info64.lo_encrypt_key_size, LO_KEY_SIZE); + PRINT_FIELD_STRING(", ", info64, lo_encrypt_key, + lo_encrypt_key_size, 0); } if (!abbrev(tcp)) diff --git a/netlink_sock_diag.c b/netlink_sock_diag.c index 43c595df..cc80ed0d 100644 --- a/netlink_sock_diag.c +++ b/netlink_sock_diag.c @@ -964,16 +964,10 @@ decode_smc_diag_lgrinfo(struct tcb *const tcp, tprints("{lnk[0]={"); PRINT_FIELD_U("", linfo.lnk[0], link_id); - PRINT_FIELD_STRING(", ", linfo.lnk[0], ibname, - sizeof(linfo.lnk[0].ibname), - QUOTE_0_TERMINATED); + PRINT_FIELD_CSTRING(", ", linfo.lnk[0], ibname); PRINT_FIELD_U(", ", linfo.lnk[0], ibport); - PRINT_FIELD_STRING(", ", linfo.lnk[0], gid, - sizeof(linfo.lnk[0].gid), - QUOTE_0_TERMINATED); - PRINT_FIELD_STRING(", ", linfo.lnk[0], peer_gid, - sizeof(linfo.lnk[0].peer_gid), - QUOTE_0_TERMINATED); + PRINT_FIELD_CSTRING(", ", linfo.lnk[0], gid); + PRINT_FIELD_CSTRING(", ", linfo.lnk[0], peer_gid); PRINT_FIELD_XVAL("}, ", linfo, role, smc_link_group_roles, "SMC_???"); tprints("}"); diff --git a/print_fields.h b/print_fields.h index 4d486d35..2441defb 100644 --- a/print_fields.h +++ b/print_fields.h @@ -79,10 +79,19 @@ zero_extend_signed_to_ull((where_).field_)); \ } while (0) -#define PRINT_FIELD_STRING(prefix_, where_, field_, len_, style_) \ - do { \ - STRACE_PRINTF("%s%s=", (prefix_), #field_); \ - print_quoted_string((const char *)(where_).field_, len_, style_); \ +#define PRINT_FIELD_STRING(prefix_, where_, field_, len_, style_) \ + do { \ + STRACE_PRINTF("%s%s=", (prefix_), #field_); \ + print_quoted_string((const char *)(where_).field_, \ + (len_), (style_)); \ + } while (0) + +#define PRINT_FIELD_CSTRING(prefix_, where_, field_) \ + do { \ + STRACE_PRINTF("%s%s=", (prefix_), #field_); \ + print_quoted_string((const char *)(where_).field_, \ + sizeof((where_).field_), \ + QUOTE_0_TERMINATED); \ } while (0) #define PRINT_FIELD_INET_ADDR(prefix_, where_, field_, af_) \ diff --git a/uname.c b/uname.c index a63295e1..447b5d96 100644 --- a/uname.c +++ b/uname.c @@ -30,7 +30,7 @@ */ #include "defs.h" - +#include "print_fields.h" #include SYS_FUNC(uname) @@ -41,24 +41,17 @@ SYS_FUNC(uname) return 0; if (!umove_or_printaddr(tcp, tcp->u_arg[0], &uname)) { -#define PRINT_UTS_MEMBER(prefix, member) \ - do { \ - tprints(prefix #member "="); \ - print_quoted_string(uname.member, sizeof(uname.member), \ - QUOTE_0_TERMINATED); \ - } while (0) - - PRINT_UTS_MEMBER("{", sysname); - PRINT_UTS_MEMBER(", ", nodename); + PRINT_FIELD_CSTRING("{", uname, sysname); + PRINT_FIELD_CSTRING(", ", uname, nodename); if (abbrev(tcp)) { tprints(", ...}"); return 0; } - PRINT_UTS_MEMBER(", ", release); - PRINT_UTS_MEMBER(", ", version); - PRINT_UTS_MEMBER(", ", machine); + PRINT_FIELD_CSTRING(", ", uname, release); + PRINT_FIELD_CSTRING(", ", uname, version); + PRINT_FIELD_CSTRING(", ", uname, machine); #ifdef HAVE_STRUCT_UTSNAME_DOMAINNAME - PRINT_UTS_MEMBER(", ", domainname); + PRINT_FIELD_CSTRING(", ", uname, domainname); #endif tprints("}"); } diff --git a/v4l2.c b/v4l2.c index 12750a66..43d6c6e6 100644 --- a/v4l2.c +++ b/v4l2.c @@ -57,6 +57,8 @@ typedef struct v4l2_standard struct_v4l2_standard; #include MPERS_DEFS +#include "print_fields.h" + /* some historical constants */ #ifndef V4L2_CID_HCENTER #define V4L2_CID_HCENTER (V4L2_CID_BASE+22) @@ -145,15 +147,9 @@ print_v4l2_capability(struct tcb *const tcp, const kernel_ulong_t arg) tprints(", "); if (umove_or_printaddr(tcp, arg, &caps)) return 1; - tprints("{driver="); - print_quoted_string((const char *) caps.driver, - sizeof(caps.driver), QUOTE_0_TERMINATED); - tprints(", card="); - print_quoted_string((const char *) caps.card, - sizeof(caps.card), QUOTE_0_TERMINATED); - tprints(", bus_info="); - print_quoted_string((const char *) caps.bus_info, - sizeof(caps.bus_info), QUOTE_0_TERMINATED); + PRINT_FIELD_CSTRING("{", caps, driver); + PRINT_FIELD_CSTRING(", ", caps, card); + PRINT_FIELD_CSTRING(", ", caps, bus_info); tprintf(", version=%u.%u.%u, capabilities=", (caps.version >> 16) & 0xFF, (caps.version >> 8) & 0xFF, @@ -190,10 +186,7 @@ print_v4l2_fmtdesc(struct tcb *const tcp, const kernel_ulong_t arg) tprints(", flags="); printflags(v4l2_format_description_flags, f.flags, "V4L2_FMT_FLAG_???"); - tprints(", description="); - print_quoted_string((const char *) f.description, - sizeof(f.description), - QUOTE_0_TERMINATED); + PRINT_FIELD_CSTRING(", ", f, description); tprints(", pixelformat="); print_pixelformat(f.pixelformat); } @@ -562,10 +555,7 @@ print_v4l2_standard(struct tcb *const tcp, const kernel_ulong_t arg) tprintf("{index=%u", s.index); } else { if (!syserror(tcp) && !umove(tcp, arg, &s)) { - tprints(", name="); - print_quoted_string((const char *) s.name, - sizeof(s.name), - QUOTE_0_TERMINATED); + PRINT_FIELD_CSTRING(", ", s, name); tprintf(", frameperiod=" FMT_FRACT, ARGS_FRACT(s.frameperiod)); tprintf(", framelines=%d", s.framelines); @@ -589,10 +579,7 @@ print_v4l2_input(struct tcb *const tcp, const kernel_ulong_t arg) tprintf("{index=%u", i.index); } else { if (!syserror(tcp) && !umove(tcp, arg, &i)) { - tprints(", name="); - print_quoted_string((const char *) i.name, - sizeof(i.name), - QUOTE_0_TERMINATED); + PRINT_FIELD_CSTRING(", ", i, name); tprints(", type="); printxval(v4l2_input_types, i.type, "V4L2_INPUT_TYPE_???"); @@ -656,9 +643,7 @@ print_v4l2_tuner(struct tcb *const tcp, const kernel_ulong_t arg, tprints(is_get ? ", " : " => "); } - tprints("name="); - print_quoted_string((const char *) c.name, sizeof(c.name), - QUOTE_0_TERMINATED); + PRINT_FIELD_CSTRING("", c, name); tprints(", type="); printxval(v4l2_tuner_types, c.type, "V4L2_TUNER_TYPE_???"); tprints(", capability="); @@ -715,10 +700,7 @@ print_v4l2_queryctrl(struct tcb *const tcp, const kernel_ulong_t arg) if (exiting(tcp)) { tprints(", type="); printxval(v4l2_control_types, c.type, "V4L2_CTRL_TYPE_???"); - tprints(", name="); - print_quoted_string((const char *) c.name, - sizeof(c.name), - QUOTE_0_TERMINATED); + PRINT_FIELD_CSTRING(", ", c, name); tprintf(", minimum=%d, maximum=%d, step=%d" ", default_value=%d, flags=", c.minimum, c.maximum, c.step, c.default_value);