<div dir="ltr"><div class="gmail_default" style="color:#000000">Thanks Dmitry! Appreciate it.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Feb 17, 2019 at 7:30 PM Dmitry V. Levin <<a href="mailto:ldv@altlinux.org">ldv@altlinux.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Sun, Feb 17, 2019 at 03:59:51PM -0800, shankarapailoor wrote:<br>
> Subject: [PATCH v4] handle xlat_styles when printing rlim_cur, rlim_max<br>
> <br>
> * resource.c (sprint_rlimit{32, 64}, print_rlimfield{32,64},<br>
> print_rlimit{32, 64}): handle xlat styles.<br>
> * tests/setrlimit.c: Add XLAT_{ABBREV, RAW, VERBOSE} macros.<br>
> * tests/xgetrlimit.c (sprint_rlim): Likewise.<br>
> * tests/setrlimit-Xabbrev.c: Add new test for rlimit xlat_style.<br>
> * tests/setrlimit-Xraw.c: Likewise.<br>
> * tests/setrlimit-Xverbose.c: Likewise.<br>
> * tests/pure_executables.list: Add setrlimit-X{abbrev, raw,<br>
> verbose} tests.<br>
> * tests/<a href="http://gen_tests.in" rel="noreferrer" target="_blank">gen_tests.in</a>: Likewise.<br>
> ---<br>
>  resource.c                  | 58 +++++++++++++++++++++++++++++--------<br>
>  tests/.gitignore            |  3 ++<br>
>  tests/<a href="http://gen_tests.in" rel="noreferrer" target="_blank">gen_tests.in</a>          |  3 ++<br>
>  tests/pure_executables.list |  3 ++<br>
>  tests/setrlimit-Xabbrev.c   |  1 +<br>
>  tests/setrlimit-Xraw.c      |  2 ++<br>
>  tests/setrlimit-Xverbose.c  |  2 ++<br>
>  tests/setrlimit.c           | 23 +++++++++++++++<br>
>  tests/xgetrlimit.c          | 42 ++++++++++++++++++++++++---<br>
>  9 files changed, 121 insertions(+), 16 deletions(-)<br>
>  create mode 100644 tests/setrlimit-Xabbrev.c<br>
>  create mode 100644 tests/setrlimit-Xraw.c<br>
>  create mode 100644 tests/setrlimit-Xverbose.c<br>
<br>
Merged with some adjustments, thanks.<br>
<br>
> diff --git a/resource.c b/resource.c<br>
> index 724223ef..b9853530 100644<br>
> --- a/resource.c<br>
> +++ b/resource.c<br>
> @@ -24,11 +24,25 @@ sprint_rlim64(uint64_t lim)<br>
>       if (lim == UINT64_MAX)<br>
>               return "RLIM64_INFINITY";<br>
>  <br>
> -     if (lim > 1024 && lim % 1024 == 0)<br>
> +     if (lim > 1024 && lim % 1024 == 0) {<br>
>               xsprintf(buf, "%" PRIu64 "*1024", lim / 1024);<br>
> -     else<br>
> -             xsprintf(buf, "%" PRIu64, lim);<br>
> -     return buf;<br>
> +             return buf;<br>
> +     }<br>
> +     return NULL;<br>
> +}<br>
> +<br>
> +static void<br>
> +print_rlimfield64(uint64_t rlim_field) {<br>
> +     const char *str = sprint_rlim64(rlim_field);<br>
> +<br>
> +     if (!str || xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)<br>
> +             tprintf("%" PRIu64, rlim_field);<br>
> +<br>
> +     if (!str || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)<br>
> +             return;<br>
> +<br>
> +     (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE<br>
> +                ? tprints_comment : tprints)(str);<br>
>  }<br>
<br>
I cannot say that the name of this new function is self-explanatory.<br>
Given that sprint_rlim64 is now used just once inside this function,<br>
I merged both into a new function called print_rlim64_t.<br>
<br>
>  static void<br>
> @@ -40,8 +54,11 @@ print_rlimit64(struct tcb *const tcp, const kernel_ulong_t addr)<br>
>       } rlim;<br>
>  <br>
>       if (!umove_or_printaddr(tcp, addr, &rlim)) {<br>
> -             tprintf("{rlim_cur=%s,", sprint_rlim64(rlim.rlim_cur));<br>
> -             tprintf(" rlim_max=%s}", sprint_rlim64(rlim.rlim_max));<br>
> +             tprints("{rlim_cur=");<br>
> +             print_rlimfield64(rlim.rlim_cur);<br>
> +             tprints(", rlim_max=");<br>
> +             print_rlimfield64(rlim.rlim_max);<br>
> +             tprints("}");<br>
>       }<br>
>  }<br>
>  <br>
> @@ -55,11 +72,25 @@ sprint_rlim32(uint32_t lim)<br>
>       if (lim == UINT32_MAX)<br>
>               return "RLIM_INFINITY";<br>
>  <br>
> -     if (lim > 1024 && lim % 1024 == 0)<br>
> +     if (lim > 1024 && lim % 1024 == 0) {<br>
>               xsprintf(buf, "%" PRIu32 "*1024", lim / 1024);<br>
> -     else<br>
> -             xsprintf(buf, "%" PRIu32, lim);<br>
> -     return buf;<br>
> +             return buf;<br>
> +     }<br>
> +     return NULL;<br>
> +}<br>
> +<br>
> +static void<br>
> +print_rlimfield32(uint32_t rlim_field) {<br>
> +     const char *str = sprint_rlim32(rlim_field);<br>
> +<br>
> +     if (!str || xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)<br>
> +             tprintf("%" PRIu32, rlim_field);<br>
> +<br>
> +     if (!str || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)<br>
> +             return;<br>
> +<br>
> +     (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE<br>
> +                ? tprints_comment : tprints)(str);<br>
>  }<br>
<br>
Likewise, I merged both into a new function called print_rlim32_t.<br>
<br>
>  static void<br>
> @@ -71,8 +102,11 @@ print_rlimit32(struct tcb *const tcp, const kernel_ulong_t addr)<br>
>       } rlim;<br>
>  <br>
>       if (!umove_or_printaddr(tcp, addr, &rlim)) {<br>
> -             tprintf("{rlim_cur=%s,", sprint_rlim32(rlim.rlim_cur));<br>
> -             tprintf(" rlim_max=%s}", sprint_rlim32(rlim.rlim_max));<br>
> +             tprints("{rlim_cur=");<br>
> +             print_rlimfield32(rlim.rlim_cur);<br>
> +             tprints(", rlim_max=");<br>
> +             print_rlimfield32(rlim.rlim_max);<br>
> +             tprints("}");<br>
>       }<br>
>  }<br>
>  <br>
> diff --git a/tests/.gitignore b/tests/.gitignore<br>
> index 24b17017..327a75cf 100644<br>
> --- a/tests/.gitignore<br>
> +++ b/tests/.gitignore<br>
> @@ -501,6 +501,9 @@ setresuid32<br>
>  setreuid<br>
>  setreuid32<br>
>  setrlimit<br>
> +setrlimit-Xabbrev<br>
> +setrlimit-Xraw<br>
> +setrlimit-Xverbose<br>
>  setuid<br>
>  setuid32<br>
>  shmxt<br>
> diff --git a/tests/<a href="http://gen_tests.in" rel="noreferrer" target="_blank">gen_tests.in</a> b/tests/<a href="http://gen_tests.in" rel="noreferrer" target="_blank">gen_tests.in</a><br>
> index e2e70a12..1c11d2da 100644<br>
> --- a/tests/<a href="http://gen_tests.in" rel="noreferrer" target="_blank">gen_tests.in</a><br>
> +++ b/tests/<a href="http://gen_tests.in" rel="noreferrer" target="_blank">gen_tests.in</a><br>
> @@ -414,6 +414,9 @@ setresuid32       -a21<br>
>  setreuid     -a15<br>
>  setreuid32   -a17<br>
>  setrlimit    -a27<br>
> +setrlimit-Xabbrev    -a1 -e trace=setrlimit -Xabbrev<br>
> +setrlimit-Xraw       -a1 -e trace=setrlimit -Xraw<br>
> +setrlimit-Xverbose   -a1 -e trace=setrlimit -Xverbose<br>
<br>
I changed -a1 to something else.<br>
<br>
>  setuid       -a10<br>
>  setuid32     -a12<br>
>  shmxt        -a11 -e trace='/(osf_)?shmat,shmdt'<br>
> diff --git a/tests/pure_executables.list b/tests/pure_executables.list<br>
> index 23aabb9e..616ee9ed 100755<br>
> --- a/tests/pure_executables.list<br>
> +++ b/tests/pure_executables.list<br>
> @@ -420,6 +420,9 @@ setresuid32<br>
>  setreuid<br>
>  setreuid32<br>
>  setrlimit<br>
> +setrlimit-Xabbrev<br>
> +setrlimit-Xraw<br>
> +setrlimit-Xverbose<br>
>  setuid<br>
>  setuid32<br>
>  shmxt<br>
> diff --git a/tests/setrlimit-Xabbrev.c b/tests/setrlimit-Xabbrev.c<br>
> new file mode 100644<br>
> index 00000000..d5cf2ad3<br>
> --- /dev/null<br>
> +++ b/tests/setrlimit-Xabbrev.c<br>
> @@ -0,0 +1 @@<br>
> +#include "setrlimit.c"<br>
> diff --git a/tests/setrlimit-Xraw.c b/tests/setrlimit-Xraw.c<br>
> new file mode 100644<br>
> index 00000000..1a5ead0b<br>
> --- /dev/null<br>
> +++ b/tests/setrlimit-Xraw.c<br>
> @@ -0,0 +1,2 @@<br>
> +#define XLAT_RAW 1<br>
> +#include "setrlimit.c"<br>
> diff --git a/tests/setrlimit-Xverbose.c b/tests/setrlimit-Xverbose.c<br>
> new file mode 100644<br>
> index 00000000..20cd135f<br>
> --- /dev/null<br>
> +++ b/tests/setrlimit-Xverbose.c<br>
> @@ -0,0 +1,2 @@<br>
> +#define XLAT_VERBOSE 1<br>
> +#include "setrlimit.c"<br>
> diff --git a/tests/setrlimit.c b/tests/setrlimit.c<br>
> index f199abe1..f1bb12d1 100644<br>
> --- a/tests/setrlimit.c<br>
> +++ b/tests/setrlimit.c<br>
> @@ -23,7 +23,15 @@ main(void)<br>
>       for (xlat = resources; xlat->str; ++xlat) {<br>
>               unsigned long res = 0xfacefeed00000000ULL | xlat->val;<br>
>               long rc = syscall(__NR_setrlimit, res, 0);<br>
> +#if XLAT_RAW<br>
> +             printf("setrlimit(%#x, NULL) = %s\n",<br>
> +                     (unsigned int) xlat->val, sprintrc(rc));<br>
> +#elif XLAT_VERBOSE<br>
> +             printf("setrlimit(%#x /* %s */, NULL) = %s\n",<br>
> +                     (unsigned int) xlat->val, xlat->str, sprintrc(rc));<br>
> +#else<br>
>               printf("setrlimit(%s, NULL) = %s\n", xlat->str, sprintrc(rc));<br>
> +#endif<br>
<br>
I changed indentation of preprocessor directives here<br>
<br>
>  <br>
>               struct rlimit libc_rlim = {};<br>
>               if (getrlimit((int) res, &libc_rlim))<br>
> @@ -33,10 +41,25 @@ main(void)<br>
>  <br>
>               rc = syscall(__NR_setrlimit, res, rlimit);<br>
>               const char *errstr = sprintrc(rc);<br>
> +#if XLAT_RAW<br>
> +             printf("setrlimit(%#x, {rlim_cur=%s, rlim_max=%s}) = %s\n",<br>
> +                    (unsigned int) xlat->val,<br>
> +                    sprint_rlim(rlimit[0]), sprint_rlim(rlimit[1]),<br>
> +                    errstr);<br>
> +#elif XLAT_VERBOSE<br>
> +             printf("setrlimit(%#x /* %s */,"<br>
> +                    " {rlim_cur=%s, rlim_max=%s}) = %s\n",<br>
> +                    (unsigned int) xlat->val,<br>
> +                    xlat->str,<br>
> +                    sprint_rlim(rlimit[0]), sprint_rlim(rlimit[1]),<br>
> +                    errstr);<br>
> +#else<br>
>               printf("setrlimit(%s, {rlim_cur=%s, rlim_max=%s}) = %s\n",<br>
>                      xlat->str,<br>
>                      sprint_rlim(rlimit[0]), sprint_rlim(rlimit[1]),<br>
>                      errstr);<br>
> +#endif<br>
> +<br>
<br>
... and here.<br>
<br>
>       }<br>
>  <br>
>       puts("+++ exited with 0 +++");<br>
> diff --git a/tests/xgetrlimit.c b/tests/xgetrlimit.c<br>
> index b807f290..448ca9c3 100644<br>
> --- a/tests/xgetrlimit.c<br>
> +++ b/tests/xgetrlimit.c<br>
> @@ -19,23 +19,57 @@<br>
>  const char *<br>
>  sprint_rlim(kernel_ulong_t lim)<br>
>  {<br>
> +     static char buf[2][ /* space for 2 llu strings */<br>
> +                             2*sizeof(lim)*3 +<br>
> +                         /* space for XLAT_STYLE_ABBREV decoding */<br>
> +                             sizeof("*1024") + sizeof("RLIM64_INFINITY") +<br>
> +                         /* space for C style comments */<br>
> +                             6];<br>
> +     static int i;<br>
> +<br>
> +#if XLAT_RAW<br>
> +     i &= 1;<br>
<br>
I moved this statement to the beginning of this function.<br>
<br>
> +     sprintf(buf[i], "%llu", (unsigned long long) lim);<br>
> +     return buf[i++];<br>
> +#else<br>
>       if (sizeof(lim) == sizeof(uint64_t)) {<br>
> -             if (lim == (kernel_ulong_t) -1ULL)<br>
> +             if (lim == (kernel_ulong_t) -1ULL) {<br>
> +#if XLAT_VERBOSE<br>
> +                     i &= 1;<br>
> +                     sprintf(buf[i], "%llu /* RLIM64_INFINITY */",<br>
> +                             (unsigned long long) lim);<br>
> +                     return buf[i++];<br>
> +#else /* XLAT_ABBREV */<br>
>                       return "RLIM64_INFINITY";<br>
> +#endif /* #if XLAT_VERBOSE */<br>
> +             }<br>
>       } else {<br>
> -             if (lim == (kernel_ulong_t) -1U)<br>
> +             if (lim == (kernel_ulong_t) -1U) {<br>
> +#if XLAT_VERBOSE<br>
> +                     i &= 1;<br>
> +                     sprintf(buf[i], "%llu /* RLIM_INFINITY */",<br>
> +                             (unsigned long long) lim);<br>
> +                     return buf[i++];<br>
> +#else /* XLAT_ABBREV */<br>
>                       return "RLIM_INFINITY";<br>
> +#endif /* #if XLAT_VERBOSE */<br>
> +             }<br>
>       }<br>
>  <br>
> -     static char buf[2][sizeof(lim)*3 + sizeof("*1024")];<br>
> -     static int i;<br>
>       i &= 1;<br>
>       if (lim > 1024 && lim % 1024 == 0)<br>
> +#if XLAT_VERBOSE<br>
> +             sprintf(buf[i], "%llu /* %llu*1024 */",<br>
> +                     (unsigned long long) lim,<br>
> +                     (unsigned long long) lim / 1024);<br>
> +#else<br>
>               sprintf(buf[i], "%llu*1024", (unsigned long long) lim / 1024);<br>
> +#endif<br>
>       else<br>
>               sprintf(buf[i], "%llu", (unsigned long long) lim);<br>
>  <br>
>       return buf[i++];<br>
> +#endif /* #if XLAT_RAW */<br>
<br>
I fixed indentation of preprocessor directives in this file.<br>
<br>
<br>
-- <br>
ldv<br>
-- <br>
Strace-devel mailing list<br>
<a href="mailto:Strace-devel@lists.strace.io" target="_blank">Strace-devel@lists.strace.io</a><br>
<a href="https://lists.strace.io/mailman/listinfo/strace-devel" rel="noreferrer" target="_blank">https://lists.strace.io/mailman/listinfo/strace-devel</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature">Regards,<div>Shankara Pailoor</div></div>