summaryrefslogtreecommitdiff
path: root/linux-user/strace.c
diff options
context:
space:
mode:
authorFilip Bozuta <Filip.Bozuta@syrmia.com>2020-06-19 14:47:27 +0200
committerLaurent Vivier <laurent@vivier.eu>2020-07-04 18:08:51 +0200
commit79482e5987c824086d8824ebcf95a0c8c9c16cd7 (patch)
tree38db55f8feb76e9dea3bf4d01526bd842131c623 /linux-user/strace.c
parenta20a7c26406b14aed56815e2bb9f150facca2cc0 (diff)
downloadqemu-79482e5987c824086d8824ebcf95a0c8c9c16cd7.zip
linux-user: Add strace support for printing arguments of ioctl()
This patch implements functionality for strace argument printing for ioctls. When running ioctls through qemu with "-strace", they get printed in format: "ioctl(fd_num,0x*,0x*) = ret_value" where the request code an the ioctl's third argument get printed in a hexadicemal format. This patch changes that by enabling strace to print both the request code name and the contents of the third argument. For example, when running ioctl RTC_SET_TIME with "-strace", with changes from this patch, it gets printed in this way: "ioctl(3,RTC_SET_TIME,{12,13,15,20,10,119,0,0,0}) = 0" In case of IOC_R type ioctls, the contents of the third argument get printed after the return value, and the argument inside the ioctl call gets printed as pointer in hexadecimal format. For example, when running RTC_RD_TIME with "-strace", with changes from this patch, it gets printed in this way: "ioctl(3,RTC_RD_TIME,0x40800374) = 0 ({22,9,13,11,5,120,0,0,0})" In case of IOC_RW type ioctls, the contents of the third argument get printed both inside the ioctl call and after the return value. Implementation notes: Functions "print_ioctl()" and "print_syscall_ret_ioctl()", that are defined in "strace.c", are listed in file "strace.list" as "call" and "result" value for ioctl. Structure definition "IOCTLEntry" as well as predefined values for IOC_R, IOC_W and IOC_RW were cut and pasted from file "syscall.c" to file "qemu.h" so that they can be used by these functions to print the contents of the third ioctl argument. Also, the "static" identifier for array "ioctl_entries[]" was removed and this array was declared as "extern" in "qemu.h" so that it can also be used by these functions. To decode the structure type of the ioctl third argument, function "thunk_print()" was defined in file "thunk.c" and its definition is somewhat simillar to that of function "thunk_convert()". Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20200619124727.18080-3-filip.bozuta@syrmia.com> [lv: fix close-bracket] Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Diffstat (limited to 'linux-user/strace.c')
-rw-r--r--linux-user/strace.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 32e5e987ac..5235b2260c 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -860,6 +860,44 @@ print_syscall_ret_listxattr(const struct syscallname *name, abi_long ret,
#define print_syscall_ret_flistxattr print_syscall_ret_listxattr
#endif
+#ifdef TARGET_NR_ioctl
+static void
+print_syscall_ret_ioctl(const struct syscallname *name, abi_long ret,
+ abi_long arg0, abi_long arg1, abi_long arg2,
+ abi_long arg3, abi_long arg4, abi_long arg5)
+{
+ print_syscall_err(ret);
+
+ if (ret >= 0) {
+ qemu_log(TARGET_ABI_FMT_ld, ret);
+
+ const IOCTLEntry *ie;
+ const argtype *arg_type;
+ void *argptr;
+ int target_size;
+
+ for (ie = ioctl_entries; ie->target_cmd != 0; ie++) {
+ if (ie->target_cmd == arg1) {
+ break;
+ }
+ }
+
+ if (ie->target_cmd == arg1 &&
+ (ie->access == IOC_R || ie->access == IOC_RW)) {
+ arg_type = ie->arg_type;
+ qemu_log(" (");
+ arg_type++;
+ target_size = thunk_type_size(arg_type, 0);
+ argptr = lock_user(VERIFY_READ, arg2, target_size, 1);
+ thunk_print(argptr, arg_type);
+ unlock_user(argptr, arg2, target_size);
+ qemu_log(")");
+ }
+ }
+ qemu_log("\n");
+}
+#endif
+
UNUSED static struct flags access_flags[] = {
FLAG_GENERIC(F_OK),
FLAG_GENERIC(R_OK),
@@ -3026,6 +3064,75 @@ print_statx(const struct syscallname *name,
}
#endif
+#ifdef TARGET_NR_ioctl
+static void
+print_ioctl(const struct syscallname *name,
+ abi_long arg0, abi_long arg1, abi_long arg2,
+ abi_long arg3, abi_long arg4, abi_long arg5)
+{
+ print_syscall_prologue(name);
+ print_raw_param("%d", arg0, 0);
+
+ const IOCTLEntry *ie;
+ const argtype *arg_type;
+ void *argptr;
+ int target_size;
+
+ for (ie = ioctl_entries; ie->target_cmd != 0; ie++) {
+ if (ie->target_cmd == arg1) {
+ break;
+ }
+ }
+
+ if (ie->target_cmd == 0) {
+ print_raw_param("%#x", arg1, 0);
+ print_raw_param("%#x", arg2, 1);
+ } else {
+ qemu_log("%s", ie->name);
+ arg_type = ie->arg_type;
+
+ if (arg_type[0] != TYPE_NULL) {
+ qemu_log(",");
+
+ switch (arg_type[0]) {
+ case TYPE_PTRVOID:
+ print_pointer(arg2, 1);
+ break;
+ case TYPE_CHAR:
+ case TYPE_SHORT:
+ case TYPE_INT:
+ print_raw_param("%d", arg2, 1);
+ break;
+ case TYPE_LONG:
+ print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
+ break;
+ case TYPE_ULONG:
+ print_raw_param(TARGET_ABI_FMT_lu, arg2, 1);
+ break;
+ case TYPE_PTR:
+ switch (ie->access) {
+ case IOC_R:
+ print_pointer(arg2, 1);
+ break;
+ case IOC_W:
+ case IOC_RW:
+ arg_type++;
+ target_size = thunk_type_size(arg_type, 0);
+ argptr = lock_user(VERIFY_READ, arg2, target_size, 1);
+ thunk_print(argptr, arg_type);
+ unlock_user(argptr, arg2, target_size);
+ break;
+ }
+ break;
+ default:
+ g_assert_not_reached();
+ }
+ }
+ }
+ print_syscall_epilogue(name);
+}
+#endif
+
/*
* An array of all of the syscalls we know about
*/