Skip to content

Commit af861de

Browse files
bozutafvivier
authored andcommitted
linux-user: Add strace support for printing arguments of lseek()
This patch implements strace argument printing functionality for syscall: *lseek - reposition read/write file offset off_t lseek(int fd, off_t offset, int whence) man page: https://www.man7.org/linux/man-pages/man2/lseek.2.html Implementation notes: The syscall's third argument "whence" has predefined values: "SEEK_SET","SEEK_CUR","SEEK_END","SEEK_DATA","SEEK_HOLE" and thus a separate printing function "print_lseek" was stated in file "strace.list". This function is defined in "strace.c" by using an existing function "print_raw_param()" to print the first and second argument and a switch(case) statement for the predefined values of the third argument. Values "SEEK_DATA" and "SEEK_HOLE" are defined in kernel version 3.1. That is the reason why case statements for these values are enwrapped in #ifdef directive. Signed-off-by: Filip Bozuta <[email protected]> Reviewed-by: Laurent Vivier <[email protected]> Message-Id: <[email protected]> Signed-off-by: Laurent Vivier <[email protected]>
1 parent 4fc3cdd commit af861de

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

linux-user/strace.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,37 @@ print__llseek(const struct syscallname *name,
18331833
}
18341834
#endif
18351835

1836+
#ifdef TARGET_NR_lseek
1837+
static void
1838+
print_lseek(const struct syscallname *name,
1839+
abi_long arg0, abi_long arg1, abi_long arg2,
1840+
abi_long arg3, abi_long arg4, abi_long arg5)
1841+
{
1842+
print_syscall_prologue(name);
1843+
print_raw_param("%d", arg0, 0);
1844+
print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
1845+
switch (arg2) {
1846+
case SEEK_SET:
1847+
qemu_log("SEEK_SET"); break;
1848+
case SEEK_CUR:
1849+
qemu_log("SEEK_CUR"); break;
1850+
case SEEK_END:
1851+
qemu_log("SEEK_END"); break;
1852+
#ifdef SEEK_DATA
1853+
case SEEK_DATA:
1854+
qemu_log("SEEK_DATA"); break;
1855+
#endif
1856+
#ifdef SEEK_HOLE
1857+
case SEEK_HOLE:
1858+
qemu_log("SEEK_HOLE"); break;
1859+
#endif
1860+
default:
1861+
print_raw_param("%#x", arg2, 1);
1862+
}
1863+
print_syscall_epilogue(name);
1864+
}
1865+
#endif
1866+
18361867
#if defined(TARGET_NR_socket)
18371868
static void
18381869
print_socket(const struct syscallname *name,

linux-user/strace.list

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@
516516
{ TARGET_NR_lremovexattr, "lremovexattr" , NULL, print_lremovexattr, NULL },
517517
#endif
518518
#ifdef TARGET_NR_lseek
519-
{ TARGET_NR_lseek, "lseek" , NULL, NULL, NULL },
519+
{ TARGET_NR_lseek, "lseek" , NULL, print_lseek, NULL },
520520
#endif
521521
#ifdef TARGET_NR_lsetxattr
522522
{ TARGET_NR_lsetxattr, "lsetxattr" , NULL, NULL, NULL },

0 commit comments

Comments
 (0)