kcmp: output fds using a separate function
This is a preparation for the future introduction of cross-NS PID derivation, which would enable us to print fd information for fds related to all processes, not just traced ones. Note the change in output type for idx1/idx2 in KCMP_FILE command from unsigned to int, it follows printfd output format. * kcmp.c (printpidfd): New function. (PRINT_FIELD_PIDFD): New macro. (SYS_FUNC(kcmp)) <case KCMP_FILE>: Use printpidfd for printing idx1/idx2, as they are fds, after all.
This commit is contained in:
parent
8cddc598da
commit
76cf3b2a98
23
kcmp.c
23
kcmp.c
@ -27,8 +27,25 @@
|
||||
*/
|
||||
|
||||
#include "defs.h"
|
||||
#include "print_fields.h"
|
||||
#include "xlat/kcmp_types.h"
|
||||
|
||||
static void
|
||||
printpidfd(struct tcb *tcp, pid_t pid, int fd)
|
||||
{
|
||||
/*
|
||||
* XXX We want to use printfd here, but we should figure out which
|
||||
* process in strace's PID NS is referred to first.
|
||||
*/
|
||||
tprintf("%d", fd);
|
||||
}
|
||||
|
||||
#define PRINT_FIELD_PIDFD(prefix_, where_, field_, tcp_, pid_) \
|
||||
do { \
|
||||
STRACE_PRINTF("%s%s=", (prefix_), #field_); \
|
||||
printpidfd((tcp_), (pid_), (where_).field_); \
|
||||
} while (0)
|
||||
|
||||
SYS_FUNC(kcmp)
|
||||
{
|
||||
pid_t pid1 = tcp->u_arg[0];
|
||||
@ -42,7 +59,11 @@ SYS_FUNC(kcmp)
|
||||
|
||||
switch (type) {
|
||||
case KCMP_FILE:
|
||||
tprintf(", %u, %u", (unsigned) idx1, (unsigned) idx2);
|
||||
tprints(", ");
|
||||
printpidfd(tcp, pid1, idx1);
|
||||
tprints(", ");
|
||||
printpidfd(tcp, pid1, idx2);
|
||||
|
||||
break;
|
||||
case KCMP_FILES:
|
||||
case KCMP_FS:
|
||||
|
14
tests/kcmp.c
14
tests/kcmp.c
@ -55,6 +55,12 @@
|
||||
# define KCMP_SYSVSEM 6
|
||||
# endif
|
||||
|
||||
static void
|
||||
printpidfd(const char *prefix, pid_t pid, unsigned fd)
|
||||
{
|
||||
printf("%s%d", prefix, fd);
|
||||
}
|
||||
|
||||
static void
|
||||
do_kcmp(kernel_ulong_t pid1, kernel_ulong_t pid2, kernel_ulong_t type,
|
||||
const char *type_str, kernel_ulong_t idx1, kernel_ulong_t idx2)
|
||||
@ -72,11 +78,13 @@ do_kcmp(kernel_ulong_t pid1, kernel_ulong_t pid2, kernel_ulong_t type,
|
||||
else
|
||||
printf("%#x /* KCMP_??? */", (int) type);
|
||||
|
||||
if (type == KCMP_FILE)
|
||||
printf(", %u, %u", (unsigned) idx1, (unsigned) idx2);
|
||||
else if (type > KCMP_SYSVSEM)
|
||||
if (type == KCMP_FILE) {
|
||||
printpidfd(", ", pid1, idx1);
|
||||
printpidfd(", ", pid2, idx2);
|
||||
} else if (type > KCMP_SYSVSEM) {
|
||||
printf(", %#llx, %#llx",
|
||||
(unsigned long long) idx1, (unsigned long long) idx2);
|
||||
}
|
||||
|
||||
printf(") = %s\n", errstr);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user