linux-user: some strace improvements
cover linux-user: some strace improvements
These patches for linux-user strace are living for years in my tree.
Laurent Vivier (5):
linux-user: add socketcall() strace
linux-user: correct setsockopt() strace.
linux-user: add socket() strace
linux-user: fix clone() strace
linux-user: update get_thread_area/set_thread_area strace
include/exec/user/abitypes.h | 23 ++ linux-user/strace.c | 601 ++++++++++++++++++++++++++++++++++++++++++- linux-user/strace.list | 8 +- linux-user/syscall_defs.h | 22 +- 4 files changed, 635 insertions(+), 19 deletions(-)
Signature · 1 line
2.5.5
PATCH 1/5 linux-user: add socketcall() strace
From: Laurent Vivier <[email protected]>
--- include/exec/user/abitypes.h | 23 ++ linux-user/strace.c | 550 +++++++++++++++++++++++++++++++++++++++++++ linux-user/strace.list | 2 +- linux-user/syscall_defs.h | 22 +- 4 files changed, 592 insertions(+), 5 deletions(-)
include/exec/user/abitypes.h +23 -0
@@ -46,6 +46,15 @@ static inline abi_ulong tswapal(abi_ulong v) return tswap32(v); } +static inline abi_ulong abi_ntohl (abi_ulong v) +{ +#if defined(HOST_BIG_ENDIAN ) +return v; +#else +return bswap_32 (v); +#endif +} +#else typedef target_ulong abi_ulong __attribute__((aligned (ABI_LONG_ALIGNMENT )));typedef target_long abi_long __attribute__((aligned (ABI_LONG_ALIGNMENT )));
@@ -62,5 +71,19 @@ static inline abi_ulong tswapal(abi_ulong v)return tswapl (v); } +static inline abi_ulong abi_ntohl (abi_ulong v) +{ +#if defined(HOST_BIG_ENDIAN ) +return v; +#else +#if TARGET_LONG_SIZE ==4 +return bswap_32 (v); +#else +return bswap_64 (v); +#endif +#endif +} + +#endif #endif
linux-user/strace.c +550 -0
590 lines not on this page · raw message
linux-user/strace.list +1 -1
@@ -1294,7 +1294,7 @@ { TARGET_NR_socket, "socket" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_socketcall -{ TARGET_NR_socketcall, "socketcall" , NULL, NULL, NULL }, +{ TARGET_NR_socketcall, "socketcall" , NULL, print_socketcall, NULL }, #endif #ifdef TARGET_NR_socketpair { TARGET_NR_socketpair, "socketpair" , NULL, NULL, NULL },
linux-user/syscall_defs.h +18 -4
@@ -135,6 +135,24 @@ struct target_sockaddr_ll {uint8_t sll_addr[8 ];/* Physical layer address */ }; +struct target_sockaddr_un { +uint16_t su_family; +uint8_t sun_path[108 ]; +}; + +struct target_in_addr { +uint32_t s_addr;/* big endian */ +}; + +struct target_sockaddr_in { +uint16_t sin_family; +int16_t sin_port;/* big endian */ +struct target_in_addr sin_addr; +uint8_t __pad[sizeof (struct target_sockaddr ) - +sizeof (uint16_t ) -sizeof (int16_t ) - +sizeof (struct target_in_addr )]; +}; +struct target_sock_filter {abi_ushort code;uint8_t jt;
@@ -147,10 +165,6 @@ struct target_sock_fprog {abi_ulong filter; }; -struct target_in_addr { -uint32_t s_addr;/* big endian */ -}; -struct target_ip_mreq {struct target_in_addr imr_multiaddr;struct target_in_addr imr_address;
Signature · 1 line
2.5.5
Re: [Qemu-devel] [PATCH 1/5] linux-user: add socketcall() strace
Quoted 9 lines · Laurent Vivier
From: Laurent Vivier <[email protected]>
Signed-off-by Laurent Vivier <[email protected]>--- include/exec/user/abitypes.h | 23 ++ linux-user/strace.c | 550 +++++++++++++++++++++++++++++++++++++++++++ linux-user/strace.list | 2 +- linux-user/syscall_defs.h | 22 +- 4 files changed, 592 insertions(+), 5 deletions(-)
I have a few comments, but this mostly looks good.
Quoted 30 lines
include/exec/user/abitypes.h +15
-0@@ -46,6 +46,15 @@ static inline abi_ulong tswapal(abi_ulong v) return tswap32(v); } +static inline abi_ulong abi_ntohl (abi_ulong v) +{ +#if defined(HOST_BIG_ENDIAN ) +return v; +#else +return bswap_32 (v); +#endif +} +#else typedef target_ulong abi_ulong __attribute__((aligned (ABI_LONG_ALIGNMENT )));typedef target_long abi_long __attribute__((aligned (ABI_LONG_ALIGNMENT )));@@ -62,5 +71,19 @@ static inline abi_ulong tswapal(abi_ulong v)return tswapl (v); } +static inline abi_ulong abi_ntohl (abi_ulong v) +{ +#if defined(HOST_BIG_ENDIAN ) +return v; +#else +#if TARGET_LONG_SIZE ==4
include/exec/user/abitypes.h static inline abi_ulong tswapal(abi_ulong v) · line 89
Quoted 10 lines
include/exec/user/abitypes.h +8
-0+return bswap_32 (v); +#else +return bswap_64 (v); +#endif +#endif +} + +#endif #endif
I suspect we don't actually need an abi_ntohl() -- see below.
include/exec/user/abitypes.h print__llseek(const struct syscallname *name, · line 1230
Quoted 11 lines
include/exec/user/abitypes.h +7
-0@@ -1004,6 +1221,339 @@ print__llseek(const struct syscallname *name, }#endif +#if defined(TARGET_NR_socketcall) +static void +print_socketcall (const struct syscallname *name, +abi_long arg0,abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4,abi_long arg5) +{ +const int n =sizeof (abi_ulong);
This is a kind of confusing variable name for this.
(Should we use the same code that do_socketcall in syscall.c does to read the right number of arguments into an array of abi_ulongs ?)
Quoted 8 lines
include/exec/user/abitypes.h +8
-0+const char *socketcallname; + +switch (arg0) { +case SOCKOP_bind: { +abi_ulong sockfd, addr, addrlen; + + socketcallname ="bind" ; +
include/exec/user/abitypes.h print__llseek(const struct syscallname *name, · line 1248
Quoted 10 lines
include/exec/user/abitypes.h +10
-0+print_sockaddr: +get_user_ual (sockfd, arg1); +get_user_ual (addr, arg1 + n); +get_user_ual (addrlen, arg1 +2 * n); + +gemu_log ("%s(" , socketcallname); +print_raw_param (TARGET_ABI_FMT_ld, sockfd,0 ); +print_sockaddr (addr, addrlen); +gemu_log (")" ); +break ;
I think a helper function so you just say do_print_sockaddr("bind", arg1);
would be nicer than these gotos. Similarly with the other code like this below.
Quoted 18 lines
include/exec/user/abitypes.h +18
-0+ } +case SOCKOP_connect: + socketcallname ="connect" ; + goto print_sockaddr; +case SOCKOP_accept: + socketcallname ="accept" ; + goto print_sockaddr; +case SOCKOP_getsockname: + socketcallname ="getsockname" ; + goto print_sockaddr; +case SOCKOP_getpeername: + socketcallname ="getpeername" ; + goto print_sockaddr; +case SOCKOP_socket: { +abi_ulong domain, type, protocol; + +get_user_ual (domain, arg1); +get_user_ual (type, arg1 + n);
include/exec/user/abitypes.h print__llseek(const struct syscallname *name, · line 1276
Quoted 10 lines
include/exec/user/abitypes.h +10
-0+get_user_ual (protocol, arg1 +2 * n); +gemu_log ("socket(" ); +print_socket_domain (domain); +gemu_log ("," ); +print_socket_type (type); +gemu_log ("," ); +if (domain ==AF_PACKET || + type ==TARGET_SOCK_PACKET ) { + protocol =tswapal (protocol);/* restore network endian long */ + protocol =abi_ntohl (protocol);/* a host endian long */
This doesn't seem to match the kind of byteswapping we do in the syscall.c code, which just does a tswap16().
include/exec/user/abitypes.h print__llseek(const struct syscallname *name, · line 1281
Quoted 5 lines
include/exec/user/abitypes.h +5
-0+ } +print_socket_protocol (domain, type, protocol); +gemu_log (")" ); +break ; + }
thanks
-- PMM
PATCH 2/5 linux-user: correct setsockopt() strace.
In reply to Laurent VivierFrom: Laurent Vivier <[email protected]>
Parameter of SO_RCVTIMEO and SO_SNDTIMEO is timeval, not int.
To test this, you can use :
QEMU_STRACE= ping localhost 2>&1 |grep TIMEO 568 setsockopt(3,SOL_SOCKET,SO_SNDTIMEO,{1,0},8) = 0 568 setsockopt(3,SOL_SOCKET,SO_RCVTIMEO,{1,0},8) = 0
--- linux-user/strace.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
linux-user/strace.c +4 -2
@@ -1486,10 +1486,12 @@ print_optint: goto print_optint;case TARGET_SO_RCVTIMEO :gemu_log ("SO_RCVTIMEO," ); - goto print_optint; +print_timeval (optval,0 ); +break ;case TARGET_SO_SNDTIMEO :gemu_log ("SO_SNDTIMEO," ); - goto print_optint; +print_timeval (optval,0 ); +break ;case TARGET_SO_ATTACH_FILTER : {struct target_sock_fprog *fprog;
Signature · 1 line
2.5.5
Re: [Qemu-devel] [PATCH 2/5] linux-user: correct setsockopt() strace.
Quoted 23 lines · Laurent Vivier
From: Laurent Vivier <[email protected]>
Parameter of
SO_RCVTIMEOandSO_SNDTIMEOis timeval, not int.To test this, you can use :
QEMU_STRACE= ping localhost 2>&1 |grep TIMEO 568
setsockopt(3,SOL_SOCKET,SO_SNDTIMEO,{1,0},8)= 0 568setsockopt(3,SOL_SOCKET,SO_RCVTIMEO,{1,0},8)= 0Signed-off-by Laurent Vivier <[email protected]>--- linux-user/strace.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)linux-user/strace.c +0
-0@@ -1486,10 +1486,12 @@ print_optint: goto print_optint;case TARGET_SO_RCVTIMEO :gemu_log ("SO_RCVTIMEO," );
linux-user/strace.c print_optint: · line 1496
Quoted 10 lines
linux-user/strace.c +4
-2- goto print_optint; +print_timeval (optval,0 ); +break ;case TARGET_SO_SNDTIMEO :gemu_log ("SO_SNDTIMEO," ); - goto print_optint; +print_timeval (optval,0 ); +break ;case TARGET_SO_ATTACH_FILTER : {struct target_sock_fprog *fprog;
You should just squash this into patch 1.
thanks
-- PMM
PATCH 3/5 linux-user: add socket() strace
In reply to Laurent Vivier--- linux-user/strace.c | 24 ++++++++++++++++++++++++ linux-user/strace.list | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-)
linux-user/strace.c +24 -0
@@ -1221,6 +1221,30 @@ print__llseek(const struct syscallname *name, }#endif +#if defined(TARGET_NR_socket) +static void +print_socket (const struct syscallname *name, +abi_long arg0,abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4,abi_long arg5) +{ +abi_ulong domain = arg0, type = arg1, protocol = arg2; + +print_syscall_prologue (name); +print_socket_domain (domain); +gemu_log ("," ); +print_socket_type (type); +gemu_log ("," ); +if (domain ==AF_PACKET || + type ==TARGET_SOCK_PACKET ) { + protocol =tswapal (protocol);/* restore network endian long */ + protocol =abi_ntohl (protocol);/* a host endian long */ + } +print_socket_protocol (domain, type, protocol); +print_syscall_epilogue (name); +} + +#endif +#if defined(TARGET_NR_socketcall) static void print_socketcall(const struct syscallname *name,
linux-user/strace.list +1 -1
@@ -1291,7 +1291,7 @@ { TARGET_NR_sigsuspend, "sigsuspend" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_socket -{ TARGET_NR_socket, "socket" , NULL, NULL, NULL }, +{ TARGET_NR_socket, "socket" , NULL, print_socket, NULL }, #endif #ifdef TARGET_NR_socketcall { TARGET_NR_socketcall, "socketcall" , NULL, print_socketcall, NULL },
Signature · 1 line
2.5.5
Re: [Qemu-devel] [PATCH 3/5] linux-user: add socket() strace
Quoted 21 lines · Laurent Vivier
Signed-off-by Laurent Vivier <[email protected]>--- linux-user/strace.c | 24 ++++++++++++++++++++++++ linux-user/strace.list | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-)linux-user/strace.c +7
-0@@ -1221,6 +1221,30 @@ print__llseek(const struct syscallname *name, }#endif +#if defined(TARGET_NR_socket) +static void +print_socket (const struct syscallname *name, +abi_long arg0,abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4,abi_long arg5) +{ +abi_ulong domain = arg0, type = arg1, protocol = arg2;
linux-user/strace.c print__llseek(const struct syscallname *name, · line 1240
Quoted 10 lines
linux-user/strace.c +10
-0+ +print_syscall_prologue (name); +print_socket_domain (domain); +gemu_log ("," ); +print_socket_type (type); +gemu_log ("," ); +if (domain ==AF_PACKET || + type ==TARGET_SOCK_PACKET ) { + protocol =tswapal (protocol);/* restore network endian long */ + protocol =abi_ntohl (protocol);/* a host endian long */
Same remarks apply about this not being the same swapping we do in syscall.c for do_socket().
Quoted 24 lines
linux-user/strace.c +7
-0+ } +print_socket_protocol (domain, type, protocol); +print_syscall_epilogue (name); +} + +#endif +#if defined(TARGET_NR_socketcall) static void print_socketcall(const struct syscallname *name,linux-user/strace.list +1
-2@@ -1291,7 +1291,7 @@ { TARGET_NR_sigsuspend, "sigsuspend" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_socket -{ TARGET_NR_socket, "socket" , NULL, NULL, NULL }, +{ TARGET_NR_socket, "socket" , NULL, print_socket, NULL }, #endif #ifdef TARGET_NR_socketcall { TARGET_NR_socketcall, "socketcall" , NULL, print_socketcall, NULL }, --
Quoted 3 lines
2.5.5
thanks
-- PMM
PATCH 4/5 linux-user: fix clone() strace
In reply to Laurent Vivier--- linux-user/strace.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
linux-user/strace.c +14 -11
@@ -964,27 +964,30 @@ print_clone(const struct syscallname *name, abi_long arg3, abi_long arg4, abi_long arg5) {print_syscall_prologue (name ); -#if defined(TARGET_M68K ) +#if defined(TARGET_MICROBLAZE )print_flags (clone_flags, arg0,0 ); -print_raw_param ("newsp=0x" TARGET_ABI_FMT_lx, arg1,1 ); -#elif defined(TARGET_SH4 ) || defined(TARGET_ALPHA ) +print_raw_param ("child_stack=0x" TARGET_ABI_FMT_lx, arg1,0 ); +print_raw_param ("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg3,0 ); +print_raw_param ("tls=0x" TARGET_ABI_FMT_lx, arg5,0 ); +print_raw_param ("child_tidptr=0x" TARGET_ABI_FMT_lx, arg4,1 ); +#elif defined(TARGET_CLONE_BACKWARDS )print_flags (clone_flags, arg0,0 );print_raw_param ("child_stack=0x" TARGET_ABI_FMT_lx, arg1,0 );print_raw_param ("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2,0 ); -print_raw_param ("child_tidptr=0x" TARGET_ABI_FMT_lx, arg3,0 ); -print_raw_param ("tls=0x" TARGET_ABI_FMT_lx, arg4,1 ); -#elif defined(TARGET_CRIS ) -print_raw_param ("child_stack=0x" TARGET_ABI_FMT_lx, arg0,0 ); +print_raw_param ("tls=0x" TARGET_ABI_FMT_lx, arg3,0 ); +print_raw_param ("child_tidptr=0x" TARGET_ABI_FMT_lx, arg4,1 ); +#elif defined(TARGET_CLONE_BACKWARDS2 )print_flags (clone_flags, arg1,0 ); +print_raw_param ("child_stack=0x" TARGET_ABI_FMT_lx, arg0,0 );print_raw_param ("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2,0 ); -print_raw_param ("tls=0x" TARGET_ABI_FMT_lx, arg3,0 ); -print_raw_param ("child_tidptr=0x" TARGET_ABI_FMT_lx, arg4,1 ); +print_raw_param ("tls=0x" TARGET_ABI_FMT_lx, arg4,0 ); +print_raw_param ("child_tidptr=0x" TARGET_ABI_FMT_lx, arg3,1 );#else print_flags (clone_flags, arg0,0 );print_raw_param ("child_stack=0x" TARGET_ABI_FMT_lx, arg1,0 );print_raw_param ("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2,0 ); -print_raw_param ("tls=0x" TARGET_ABI_FMT_lx, arg3,0 ); -print_raw_param ("child_tidptr=0x" TARGET_ABI_FMT_lx, arg4,1 ); +print_raw_param ("tls=0x" TARGET_ABI_FMT_lx, arg4,0 ); +print_raw_param ("child_tidptr=0x" TARGET_ABI_FMT_lx, arg3,1 );#endif print_syscall_epilogue (name); }
Signature · 1 line
2.5.5
Re: [Qemu-devel] [PATCH 4/5] linux-user: fix clone() strace
Quoted 4 lines · Laurent Vivier
Signed-off-by Laurent Vivier <[email protected]>--- linux-user/strace.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
I think this change is correct, but it would be clearer to read if we defined a do_print_clone() that did the actual printing and took arguments in the same order as the do_fork() function in syscall.c. Then it would be easy to compare the syscall.c and this code to check they pass the arguments in the same order to the function that does the work.
(Also, naming the arguments here arg1..arg6 rather than arg0..arg5 would make them match syscall.c.)
thanks
-- PMM
PATCH 5/5 linux-user: update get_thread_area/set_thread_area strace
In reply to Laurent Vivier int get_thread_area(struct user_desc *u_info);
int set_thread_area(struct user_desc *u_info);--- linux-user/strace.list | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/strace.list +2 -2
@@ -337,7 +337,7 @@ { TARGET_NR_getsockopt, "getsockopt" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_get_thread_area -{ TARGET_NR_get_thread_area, "get_thread_area" , NULL, NULL, NULL }, +{ TARGET_NR_get_thread_area, "get_thread_area", "%s(%p)", NULL, NULL }, #endif #ifdef TARGET_NR_gettid { TARGET_NR_gettid, "gettid" , NULL, NULL, NULL },
@@ -1234,7 +1234,7 @@ { TARGET_NR_setsockopt, "setsockopt" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_set_thread_area -{ TARGET_NR_set_thread_area, "set_thread_area" , NULL, NULL, NULL }, +{ TARGET_NR_set_thread_area, "set_thread_area", "%s(%p)", NULL, NULL }, #endif #ifdef TARGET_NR_set_tid_address { TARGET_NR_set_tid_address, "set_tid_address" , NULL, NULL, NULL },
Signature · 1 line
2.5.5
Re: [Qemu-devel] [PATCH 5/5] linux-user: update get_thread_area/set_thread_area strace
Quoted 22 lines · Laurent Vivier
int get_thread_area(struct user_desc *u_info); int set_thread_area(struct user_desc *u_info);Signed-off-by Laurent Vivier <[email protected]>--- linux-user/strace.list | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)linux-user/strace.list +1
-1@@ -337,7 +337,7 @@ { TARGET_NR_getsockopt, "getsockopt" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_get_thread_area -{ TARGET_NR_get_thread_area, "get_thread_area" , NULL, NULL, NULL }, +{ TARGET_NR_get_thread_area, "get_thread_area", "%s(%p)", NULL, NULL }, #endif #ifdef TARGET_NR_gettid { TARGET_NR_gettid, "gettid" , NULL, NULL, NULL },
linux-user/strace.list line 1240
Quoted 8 lines
linux-user/strace.list +1
-1@@ -1234,7 +1234,7 @@ { TARGET_NR_setsockopt, "setsockopt" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_set_thread_area -{ TARGET_NR_set_thread_area, "set_thread_area" , NULL, NULL, NULL }, +{ TARGET_NR_set_thread_area, "set_thread_area", "%s(%p)", NULL, NULL }, #endif #ifdef TARGET_NR_set_tid_address { TARGET_NR_set_tid_address, "set_tid_address" , NULL, NULL, NULL },
The problem with this is that %p is a format string for a host pointer, but the argument we pass to gemu_log() in print_syscall() is an abi_long. If host pointers are 64 bit but abi_long is 32 bit this is going to do the wrong thing.
This is a bug present in some of our current format strings, but we should probably not add to it. I think TARGET_ABI_FMT_lx should do what you want?
thanks
-- PMM