From 1740c1cca0039c3338cde8f9b42ed0711ddb00b3 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sat, 11 Apr 2020 18:09:11 +0000 Subject: Print the second argument of getdents/getdents64 syscalls in abbrev mode * dirent.c (SYS_FUNC(getdents)) [!abbrev(tcp)]: Print u_arg[1] along with the number of entries. * dirent64.c (SYS_FUNC(getdents64)) [!abbrev(tcp)]: Likewise. * tests/xgetdents.c (ls): Update expected output. --- dirent.c | 20 ++++++++++++-------- dirent64.c | 20 ++++++++++++-------- tests/xgetdents.c | 9 ++++----- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/dirent.c b/dirent.c index 35616f509..2d0d21532 100644 --- a/dirent.c +++ b/dirent.c @@ -63,10 +63,11 @@ SYS_FUNC(getdents) return 0; } + tprints(", "); + const unsigned int count = tcp->u_arg[2]; if (syserror(tcp) || !verbose(tcp)) { - tprints(", "); printaddr(tcp->u_arg[1]); tprintf(", %u", count); return 0; @@ -83,7 +84,6 @@ SYS_FUNC(getdents) if (len) { buf = malloc(len); if (!buf || umoven(tcp, tcp->u_arg[1], len, buf) < 0) { - tprints(", "); printaddr(tcp->u_arg[1]); tprintf(", %u", count); free(buf); @@ -93,9 +93,11 @@ SYS_FUNC(getdents) buf = NULL; } - tprints(","); - if (!abbrev(tcp)) - tprints(" ["); + if (abbrev(tcp)) + printaddr(tcp->u_arg[1]); + else + tprints("["); + for (i = 0; len && i <= len - sizeof(kernel_dirent_t); ) { kernel_dirent_t *d = (kernel_dirent_t *) &buf[i]; @@ -129,10 +131,12 @@ SYS_FUNC(getdents) } i += d->d_reclen; } - if (!abbrev(tcp)) - tprints("]"); - else + + if (abbrev(tcp)) tprintf_comment("%u entries", dents); + else + tprints("]"); + tprintf(", %u", count); free(buf); return 0; diff --git a/dirent64.c b/dirent64.c index f7d68daa4..cffa9a81a 100644 --- a/dirent64.c +++ b/dirent64.c @@ -30,10 +30,11 @@ SYS_FUNC(getdents64) return 0; } + tprints(", "); + const unsigned int count = tcp->u_arg[2]; if (syserror(tcp) || !verbose(tcp)) { - tprints(", "); printaddr(tcp->u_arg[1]); tprintf(", %u", count); return 0; @@ -50,7 +51,6 @@ SYS_FUNC(getdents64) if (len) { buf = malloc(len); if (!buf || umoven(tcp, tcp->u_arg[1], len, buf) < 0) { - tprints(", "); printaddr(tcp->u_arg[1]); tprintf(", %u", count); free(buf); @@ -60,9 +60,11 @@ SYS_FUNC(getdents64) buf = NULL; } - tprints(","); - if (!abbrev(tcp)) - tprints(" ["); + if (abbrev(tcp)) + printaddr(tcp->u_arg[1]); + else + tprints("["); + for (i = 0; len && i <= len - d_name_offset; ) { struct dirent64 *d = (struct dirent64 *) &buf[i]; if (!abbrev(tcp)) { @@ -96,10 +98,12 @@ SYS_FUNC(getdents64) i += d->d_reclen; dents++; } - if (!abbrev(tcp)) - tprints("]"); - else + + if (abbrev(tcp)) tprintf_comment("%u entries", dents); + else + tprints("]"); + tprintf(", %u", count); free(buf); return 0; diff --git a/tests/xgetdents.c b/tests/xgetdents.c index 772c0c333..c550625ef 100644 --- a/tests/xgetdents.c +++ b/tests/xgetdents.c @@ -77,17 +77,16 @@ ls(int fd, char *buf, unsigned int size) #if VERBOSE printf("]"); #else - printf("/* %lu entries */", entries); + printf("%p /* %lu entries */", buf, entries); #endif printf(", %u) = %ld\n", size, rc); } - printf("%s(%d, %s, %u) = 0\n", STR_getdents, fd, #if VERBOSE - "[]", + printf("%s(%d, [], %u) = 0\n", STR_getdents, fd, size); #else - "/* 0 entries */", + printf("%s(%d, %p /* 0 entries */, %u) = 0\n", + STR_getdents, fd, buf, size); #endif - size); } int -- cgit v1.2.1