]> granicus.if.org Git - strace/commitdiff
Introduce PRINT_FIELD_CSTRING
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 11 Jul 2017 00:20:54 +0000 (00:20 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 11 Jul 2017 00:20:54 +0000 (00:20 +0000)
* 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.

block.c
btrfs.c
dm.c
loop.c
netlink_sock_diag.c
print_fields.h
uname.c
v4l2.c

diff --git a/block.c b/block.c
index c77b92ac66321e5660f60e6b6364933eba7e852c..afd7098010c458930be41e661c79fbb61b621798 100644 (file)
--- 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 e730c7aac7a1e435de481419539524690304b7db..8bffba8b6604072dcb4b79a0a9e3249607d5465d 100644 (file)
--- 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 <linux/fs.h>
 
 /*
@@ -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 a84b59d14aaef9f5ffd66802e59e9a49fe1d92b9..41de90180c495d7f0360959366a2b01903183dcb 100644 (file)
--- a/dm.c
+++ b/dm.c
  */
 
 #include "defs.h"
-#include "print_fields.h"
 
 #ifdef HAVE_LINUX_DM_IOCTL_H
 
+# include "print_fields.h"
 # include <linux/dm-ioctl.h>
 # include <linux/ioctl.h>
 
@@ -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 27f1ddd24a8a616065c62ad767d29fe48a445ec8..e30b7ce59b4a6a36b867f56f41dacd62a8d4d3f3 100644 (file)
--- 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))
index 43c595dfa0c61be9b5fa9f8594b2c4d40a44e307..cc80ed0d9da5e97bff15f51d0a1931854ff4f9cc 100644 (file)
@@ -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("}");
 
index 4d486d3535a5f6e418a9799024e532cc86a25a50..2441defb81e99a7116e21ef6c9f06364bdf29136 100644 (file)
                                      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 a63295e1231c561c0ef5cba0eb15a8ee265a4093..447b5d9634d68b6f170b2ba9cb712d5e8a57b870 100644 (file)
--- a/uname.c
+++ b/uname.c
@@ -30,7 +30,7 @@
  */
 
 #include "defs.h"
-
+#include "print_fields.h"
 #include <sys/utsname.h>
 
 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 12750a66b031f1f180d68dde825dde96fbb93982..43d6c6e6fc5862bd144496779772c92d85d5b06b 100644 (file)
--- 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);