<div dir="ltr"><div class="gmail_default" style="color:#000000">Hi,</div><div class="gmail_default" style="color:#000000"><br></div><div class="gmail_default" style="color:#000000">>setrlimit.c:49:24: error: format '%lx' expects argument of type 'long unsigned int', but argument 2 has type '<br>
uint64_t' {aka 'const long long unsigned int'} [-Werror=format=]</div><div class="gmail_default" style="color:#000000"><span class="gmail-im"><br></span></div><div class="gmail_default" style="color:#000000"><span class="gmail-im">My compiler (gcc 9.0) says uint64_t is const long unsigned int and complains when I use %llx. I am not too sure what the right thing to do here is my apologies.</span></div><div class="gmail_default" style="color:#000000"><span class="gmail-im"><br></span></div><div class="gmail_default" style="color:#000000"><span class="gmail-im">Regards,</span></div><div class="gmail_default" style="color:#000000"><span class="gmail-im">Shankara<br></span></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Feb 17, 2019 at 3:23 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:12:14PM -0800, shankarapailoor wrote:<br>
> Subject: [PATCH v3] 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 | 22 ++++++++++++++<br>
> tests/xgetrlimit.c | 42 ++++++++++++++++++++++++---<br>
> 9 files changed, 120 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>
> diff --git a/resource.c b/resource.c<br>
> index 724223ef..0ebf25a8 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>
<br>
Trailing whitespace here.<br>
<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>
> 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>
<br>
Trailing whitespace here.<br>
<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>
> 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>
> 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..084e7beb 100644<br>
> --- a/tests/setrlimit.c<br>
> +++ b/tests/setrlimit.c<br>
> @@ -23,7 +23,14 @@ 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(%#lx, NULL) = %s\n", xlat->val, sprintrc(rc));<br>
<br>
In file included from setrlimit-Xraw.c:2:<br>
setrlimit.c: In function 'main':<br>
setrlimit.c:27:24: error: format '%lx' expects argument of type 'long unsigned int', but argument 2 has type 'uint64_t' {aka 'const long long unsigned int'} [-Werror=format=]<br>
printf("setrlimit(%#lx, NULL) = %s\n", xlat->val, sprintrc(rc));<br>
~~~^ ~~~~~~~~~<br>
%#llx<br>
<br>
> +#elif XLAT_VERBOSE<br>
> + printf("setrlimit(%#lx /* %s */, NULL) = %s\n", xlat->val,<br>
> + xlat->str, sprintrc(rc));<br>
<br>
In file included from setrlimit-Xverbose.c:2:<br>
setrlimit.c: In function 'main':<br>
setrlimit.c:29:24: error: format '%lx' expects argument of type 'long unsigned int', but argument 2 has type '<br>
uint64_t' {aka 'const long long unsigned int'} [-Werror=format=]<br>
printf("setrlimit(%#lx /* %s */, NULL) = %s\n", xlat->val,<br>
~~~^ ~~~~~~~~~<br>
%#llx<br>
<br>
> +#else<br>
> printf("setrlimit(%s, NULL) = %s\n", xlat->str, sprintrc(rc));<br>
> +#endif<br>
> <br>
> struct rlimit libc_rlim = {};<br>
> if (getrlimit((int) res, &libc_rlim))<br>
> @@ -33,10 +40,25 @@ main(void)<br>
> <br>
> rc = syscall(__NR_setrlimit, res, rlimit);<br>
> const char *errstr = sprintrc(rc);<br>
> +#if XLAT_RAW<br>
> + printf("setrlimit(%#lx, {rlim_cur=%s, rlim_max=%s}) = %s\n",<br>
> + xlat->val,<br>
> + sprint_rlim(rlimit[0]), sprint_rlim(rlimit[1]),<br>
> + errstr);<br>
<br>
setrlimit.c:44:24: error: format '%lx' expects argument of type 'long unsigned int', but argument 2 has type 'uint64_t' {aka 'const long long unsigned int'} [-Werror=format=]<br>
printf("setrlimit(%#lx, {rlim_cur=%s, rlim_max=%s}) = %s\n",<br>
~~~^<br>
%#llx<br>
xlat->val,<br>
~~~~~~~~~ <br>
<br>
> +#elif XLAT_VERBOSE<br>
> + printf("setrlimit(%#lx /* %s */,"<br>
> + " {rlim_cur=%s, rlim_max=%s}) = %s\n",<br>
> + xlat->val,<br>
> + xlat->str,<br>
> + sprint_rlim(rlimit[0]), sprint_rlim(rlimit[1]),<br>
> + errstr);<br>
<br>
setrlimit.c:49:24: error: format '%lx' expects argument of type 'long unsigned int', but argument 2 has type '<br>
uint64_t' {aka 'const long long unsigned int'} [-Werror=format=]<br>
printf("setrlimit(%#lx /* %s */,"<br>
~~~^<br>
%#llx<br>
../../tests/setrlimit.c:51:10:<br>
xlat->val,<br>
~~~~~~~~~ <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"><br>-- <br><div dir="ltr" class="gmail_signature">Regards,<div>Shankara Pailoor</div></div>