Re: svn commit: r227873 - head/usr.bin/procstat
On Thu, 24 Nov 2011 09:12:35 +0200 Mikolaj Golub wrote: MG On Wed, 23 Nov 2011 11:10:47 -0800 m...@freebsd.org wrote: printf( AT_IGNORE=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); m I didn't see this before, but this gives very misleading output. The m 0x prefix implies the output will be hex, but it's printed as decimal, m here and below. MG Oh. Thanks! Will fix. m I don't know if there's a style preference for 0x%lx versus %#lx, m though, or a preference for a different type for the print (uintmax_t, m for example). There is probably a preference for using u_long rather m than unsigned long, since it's shorter. MG It looks like both 0x%lx and %#lx are widely spread in our source, I like %#lx MG a little more. It looks for me that (u_long) will be ok for now, so the chage MG for the printf above would be: MG printf( AT_IGNORE=%#lx, (u_long)auxv[i].a_un.a_val); MG Anyway, printing all values in the same format was considered by me as a MG temporary solution. I am going to have format depending on a_type, so e.g. MG AT_PAGESZ will be 4096, not 0x1000. MG Also, now they are printed as one string for a process: MG PID COMM AUXV MG 2520 firefox-bin AT_PHDR=0x400040 AT_PHENT=0x38 AT_PHNUM=0x7 AT_PAGESZ=0x1000 ... MG I am considering changing this too, to something like below: MG PID COMM AUXVVALUE MG 2520 firefox-bin AT_PHDR 0x400040 MG 2520 firefox-bin AT_PHENT56 MG 2520 firefox-bin AT_PHNUM7 MG ... I am going to commit this patch if nobody has any other suggestions. The typical output: in138:~% procstat -x 2008 PID COMM AUXV VALUE 2008 nginxAT_PHDR 0x400040 2008 nginxAT_PHENT 56 2008 nginxAT_PHNUM 8 2008 nginxAT_PAGESZ4096 2008 nginxAT_FLAGS 0 2008 nginxAT_ENTRY 0x40de00 2008 nginxAT_BASE 0x800689000 2008 nginxAT_EXECPATH 0x7fffefca 2008 nginxAT_OSRELDATE 101 2008 nginxAT_CANARY0x7fffef8a 2008 nginxAT_CANARYLEN 64 2008 nginxAT_NCPUS 2 2008 nginxAT_PAGESIZES 0x7fffef72 2008 nginxAT_PAGESIZESLEN 24 2008 nginxAT_STACKPROT VM_PROT_ALL -- Mikolaj Golub Index: usr.bin/procstat/procstat_auxv.c === --- usr.bin/procstat/procstat_auxv.c (revision 227989) +++ usr.bin/procstat/procstat_auxv.c (working copy) @@ -27,9 +27,12 @@ */ #include sys/param.h +#include sys/elf.h #include sys/sysctl.h #include sys/user.h +#include vm/vm.h + #include err.h #include errno.h #include libprocstat.h @@ -38,12 +41,79 @@ #include stdlib.h #include string.h -#include machine/elf.h - #include procstat.h static Elf_Auxinfo auxv[256]; +static char prefix[256]; +#define PRINT(name, spec, val) \ + printf(%s %-16s #spec \n, prefix, #name, (val)) +#define PRINT_UNKNOWN(type, val) \ + printf(%s %16ld %#lx\n, prefix, (long)type, (u_long)(val)) + +static const char* +stack_protection(u_long protection) +{ + size_t size; + int n; + char *p; + const char *delimiter; + static char buf[256]; + + buf[0] = '\0'; + + if (protection == VM_PROT_NONE) { + snprintf(buf, sizeof(buf), %s, VM_PROT_NONE); + } else if (protection == VM_PROT_ALL) { + snprintf(buf, sizeof(buf), %s, VM_PROT_ALL); + } else if (protection == VM_PROT_RW) { + snprintf(buf, sizeof(buf), %s, VM_PROT_RW); + } else { + size = sizeof(buf); + p = buf; + delimiter = ; + + if (size 0 (protection VM_PROT_READ) != 0) { + n = snprintf(p, size, %s%s, delimiter, + VM_PROT_READ); + protection = ~VM_PROT_READ; + delimiter = | ; + p += n; + size -= n; + } + if (size 0 (protection VM_PROT_WRITE) != 0) { + n = snprintf(p, size, %s%s, delimiter, + VM_PROT_WRITE); + protection = ~VM_PROT_WRITE; + delimiter = | ; + p += n; + size -= n; + } + if (size 0 (protection VM_PROT_EXECUTE) != 0) { + n = snprintf(p, size, %s%s, delimiter, + VM_PROT_EXECUTE); + protection = ~VM_PROT_EXECUTE; + delimiter = | ; + p += n; + size -= n; + } + if (size 0 (protection VM_PROT_COPY) != 0) { + n = snprintf(p, size, %s%s, delimiter, + VM_PROT_COPY); + protection = ~VM_PROT_COPY; + delimiter = | ; + p += n; + size -= n; + } + if (size 0 protection != VM_PROT_NONE) { + n = snprintf(p, size, %s%#lx, delimiter, + protection); + } + } + + return buf; +} + void procstat_auxv(struct kinfo_proc *kipp) { @@ -51,7 +121,7 @@ size_t len, i; if (!hflag) - printf(%5s %-16s %-53s\n, PID, COMM, AUXV); + printf(%5s %-16s %-16s %-16s\n, PID, COMM, AUXV, VALUE); name[0] =
Re: svn commit: r227873 - head/usr.bin/procstat
On Sat, Nov 26, 2011 at 06:43:01PM +0200, Mikolaj Golub wrote: On Thu, 24 Nov 2011 09:12:35 +0200 Mikolaj Golub wrote: MG On Wed, 23 Nov 2011 11:10:47 -0800 m...@freebsd.org wrote: printf( AT_IGNORE=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); m I didn't see this before, but this gives very misleading output. The m 0x prefix implies the output will be hex, but it's printed as decimal, m here and below. MG Oh. Thanks! Will fix. m I don't know if there's a style preference for 0x%lx versus %#lx, m though, or a preference for a different type for the print (uintmax_t, m for example). There is probably a preference for using u_long rather m than unsigned long, since it's shorter. MG It looks like both 0x%lx and %#lx are widely spread in our source, I like %#lx MG a little more. It looks for me that (u_long) will be ok for now, so the chage MG for the printf above would be: MG printf( AT_IGNORE=%#lx, (u_long)auxv[i].a_un.a_val); MG Anyway, printing all values in the same format was considered by me as a MG temporary solution. I am going to have format depending on a_type, so e.g. MG AT_PAGESZ will be 4096, not 0x1000. MG Also, now they are printed as one string for a process: MG PID COMM AUXV MG 2520 firefox-bin AT_PHDR=0x400040 AT_PHENT=0x38 AT_PHNUM=0x7 AT_PAGESZ=0x1000 ... MG I am considering changing this too, to something like below: MG PID COMM AUXVVALUE MG 2520 firefox-bin AT_PHDR 0x400040 MG 2520 firefox-bin AT_PHENT56 MG 2520 firefox-bin AT_PHNUM7 MG ... I am going to commit this patch if nobody has any other suggestions. The typical output: in138:~% procstat -x 2008 PID COMM AUXV VALUE 2008 nginxAT_PHDR 0x400040 2008 nginxAT_PHENT 56 2008 nginxAT_PHNUM 8 2008 nginxAT_PAGESZ4096 2008 nginxAT_FLAGS 0 2008 nginxAT_ENTRY 0x40de00 2008 nginxAT_BASE 0x800689000 2008 nginxAT_EXECPATH 0x7fffefca 2008 nginxAT_OSRELDATE 101 2008 nginxAT_CANARY0x7fffef8a 2008 nginxAT_CANARYLEN 64 2008 nginxAT_NCPUS 2 2008 nginxAT_PAGESIZES 0x7fffef72 2008 nginxAT_PAGESIZESLEN 24 2008 nginxAT_STACKPROT VM_PROT_ALL I like this output much better. The only thing I am unsure of is the pretty-printing of AT_STACKPROT. Might be, change it to EXECUTABLE/NONEXECUTABLE printout. pgpd9Uh5m0Dwm.pgp Description: PGP signature
Re: svn commit: r227873 - head/usr.bin/procstat
On 26 Nov 2011, at 17:48, Kostik Belousov wrote: in138:~% procstat -x 2008 PID COMM AUXV VALUE 2008 nginxAT_PHDR 0x400040 2008 nginxAT_PHENT 56 2008 nginxAT_PHNUM 8 2008 nginxAT_PAGESZ4096 2008 nginxAT_FLAGS 0 2008 nginxAT_ENTRY 0x40de00 2008 nginxAT_BASE 0x800689000 2008 nginxAT_EXECPATH 0x7fffefca 2008 nginxAT_OSRELDATE 101 2008 nginxAT_CANARY0x7fffef8a 2008 nginxAT_CANARYLEN 64 2008 nginxAT_NCPUS 2 2008 nginxAT_PAGESIZES 0x7fffef72 2008 nginxAT_PAGESIZESLEN 24 2008 nginxAT_STACKPROT VM_PROT_ALL I like this output much better. The only thing I am unsure of is the pretty-printing of AT_STACKPROT. Might be, change it to EXECUTABLE/NONEXECUTABLE printout. On a related note, I wouldn't mind if we stripped AT_ and lower-cased the rest of the field name to make it slightly easier on the eyes. :-) Robert___ svn-src-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org
Re: svn commit: r227873 - head/usr.bin/procstat
On Sat, Nov 26, 2011 at 06:13:14PM +, Robert N. M. Watson wrote: On 26 Nov 2011, at 17:48, Kostik Belousov wrote: in138:~% procstat -x 2008 PID COMM AUXV VALUE 2008 nginxAT_PHDR 0x400040 2008 nginxAT_PHENT 56 2008 nginxAT_PHNUM 8 2008 nginxAT_PAGESZ4096 2008 nginxAT_FLAGS 0 2008 nginxAT_ENTRY 0x40de00 2008 nginxAT_BASE 0x800689000 2008 nginxAT_EXECPATH 0x7fffefca 2008 nginxAT_OSRELDATE 101 2008 nginxAT_CANARY0x7fffef8a 2008 nginxAT_CANARYLEN 64 2008 nginxAT_NCPUS 2 2008 nginxAT_PAGESIZES 0x7fffef72 2008 nginxAT_PAGESIZESLEN 24 2008 nginxAT_STACKPROT VM_PROT_ALL I like this output much better. The only thing I am unsure of is the pretty-printing of AT_STACKPROT. Might be, change it to EXECUTABLE/NONEXECUTABLE printout. On a related note, I wouldn't mind if we stripped AT_ and lower-cased the rest of the field name to make it slightly easier on the eyes. :-) It would then need some explanation what the names mean. For my, AT_SOMETHING has a unique meaning, while something does not. pgpa1GVaXFALN.pgp Description: PGP signature
Re: svn commit: r227873 - head/usr.bin/procstat
On Wed, Nov 23, 2011 at 11:10:47AM -0800, m...@freebsd.org wrote: I don't know if there's a style preference for 0x%lx versus %#lx, though, or a preference for a different type for the print (uintmax_t, for example). There is probably a preference for using u_long rather than unsigned long, since it's shorter. u_long is preferred in kernel, in userland unsigned long is better. -- Pawel Jakub Dawidek http://www.wheelsystems.com FreeBSD committer http://www.FreeBSD.org Am I Evil? Yes, I Am! http://yomoli.com pgp5WmgE5wvIW.pgp Description: PGP signature
Re: svn commit: r227873 - head/usr.bin/procstat
On Sat, 26 Nov 2011, Pawel Jakub Dawidek wrote: On Wed, Nov 23, 2011 at 11:10:47AM -0800, m...@freebsd.org wrote: I don't know if there's a style preference for 0x%lx versus %#lx, though, or a preference for a different type for the print (uintmax_t, for example). There is probably a preference for using u_long rather than unsigned long, since it's shorter. u_long is preferred in kernel, in userland unsigned long is better. u_long is preferred in FreeBSD code in both, but portable code cannot use it. Portable code is very rare. Bruce ___ svn-src-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org
Re: svn commit: r227873 - head/usr.bin/procstat
On Tue, Nov 22, 2011 at 11:34 PM, Mikolaj Golub troc...@freebsd.org wrote: Author: trociny Date: Wed Nov 23 07:34:09 2011 New Revision: 227873 URL: http://svn.freebsd.org/changeset/base/227873 Log: Fix build, hopefully. Reviewed by: kib Modified: head/usr.bin/procstat/procstat_auxv.c Modified: head/usr.bin/procstat/procstat_auxv.c == --- head/usr.bin/procstat/procstat_auxv.c Wed Nov 23 07:12:26 2011 (r227872) +++ head/usr.bin/procstat/procstat_auxv.c Wed Nov 23 07:34:09 2011 (r227873) @@ -42,14 +42,13 @@ #include procstat.h -static char auxv[sizeof(Elf_Auxinfo) * 256]; +static Elf_Auxinfo auxv[256]; void procstat_auxv(struct kinfo_proc *kipp) { - Elf_Auxinfo *aux; - int i, error, name[4]; - size_t len; + int error, name[4]; + size_t len, i; if (!hflag) printf(%5s %-16s %-53s\n, PID, COMM, AUXV); @@ -58,7 +57,7 @@ procstat_auxv(struct kinfo_proc *kipp) name[1] = KERN_PROC; name[2] = KERN_PROC_AUXV; name[3] = kipp-ki_pid; - len = sizeof(auxv); + len = sizeof(auxv) * sizeof(*auxv); error = sysctl(name, 4, auxv, len, NULL, 0); if (error 0 errno != ESRCH) { warn(sysctl: kern.proc.auxv: %d: %d, kipp-ki_pid, errno); @@ -72,106 +71,116 @@ procstat_auxv(struct kinfo_proc *kipp) printf( -\n); return; } - for (aux = (Elf_Auxinfo *)auxv, i = 0; i 256; i++, aux++) { - switch(aux-a_type) { + for (i = 0; i len; i++) { + switch(auxv[i].a_type) { case AT_NULL: - printf( (%d)\n, i + 1); + printf( (%zu)\n, i + 1); return; case AT_IGNORE: printf( AT_IGNORE=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); I didn't see this before, but this gives very misleading output. The 0x prefix implies the output will be hex, but it's printed as decimal, here and below. I don't know if there's a style preference for 0x%lx versus %#lx, though, or a preference for a different type for the print (uintmax_t, for example). There is probably a preference for using u_long rather than unsigned long, since it's shorter. Thanks, matthew break; case AT_EXECFD: printf( AT_EXECFD=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; case AT_PHDR: printf( AT_PHDR=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; case AT_PHENT: printf( AT_PHENT=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; case AT_PHNUM: printf( AT_PHNUM=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; case AT_PAGESZ: printf( AT_PAGESZ=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; case AT_BASE: printf( AT_BASE=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; case AT_FLAGS: printf( AT_FLAGS=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; case AT_ENTRY: printf( AT_ENTRY=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; +#ifdef AT_NOTELF case AT_NOTELF: printf( AT_NOTELF=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; +#endif +#ifdef AT_UID case AT_UID: printf( AT_UID=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; +#endif +#ifdef AT_EUID case AT_EUID:
Re: svn commit: r227873 - head/usr.bin/procstat
On Wed, 23 Nov 2011 11:10:47 -0800 m...@freebsd.org wrote: printf( AT_IGNORE=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); m I didn't see this before, but this gives very misleading output. The m 0x prefix implies the output will be hex, but it's printed as decimal, m here and below. Oh. Thanks! Will fix. m I don't know if there's a style preference for 0x%lx versus %#lx, m though, or a preference for a different type for the print (uintmax_t, m for example). There is probably a preference for using u_long rather m than unsigned long, since it's shorter. It looks like both 0x%lx and %#lx are widely spread in our source, I like %#lx a little more. It looks for me that (u_long) will be ok for now, so the chage for the printf above would be: printf( AT_IGNORE=%#lx, (u_long)auxv[i].a_un.a_val); Anyway, printing all values in the same format was considered by me as a temporary solution. I am going to have format depending on a_type, so e.g. AT_PAGESZ will be 4096, not 0x1000. Also, now they are printed as one string for a process: PID COMM AUXV 2520 firefox-bin AT_PHDR=0x400040 AT_PHENT=0x38 AT_PHNUM=0x7 AT_PAGESZ=0x1000 ... I am considering changing this too, to something like below: PID COMM AUXVVALUE 2520 firefox-bin AT_PHDR 0x400040 2520 firefox-bin AT_PHENT56 2520 firefox-bin AT_PHNUM7 ... -- Mikolaj Golub ___ svn-src-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org
svn commit: r227873 - head/usr.bin/procstat
Author: trociny Date: Wed Nov 23 07:34:09 2011 New Revision: 227873 URL: http://svn.freebsd.org/changeset/base/227873 Log: Fix build, hopefully. Reviewed by: kib Modified: head/usr.bin/procstat/procstat_auxv.c Modified: head/usr.bin/procstat/procstat_auxv.c == --- head/usr.bin/procstat/procstat_auxv.c Wed Nov 23 07:12:26 2011 (r227872) +++ head/usr.bin/procstat/procstat_auxv.c Wed Nov 23 07:34:09 2011 (r227873) @@ -42,14 +42,13 @@ #include procstat.h -static char auxv[sizeof(Elf_Auxinfo) * 256]; +static Elf_Auxinfo auxv[256]; void procstat_auxv(struct kinfo_proc *kipp) { - Elf_Auxinfo *aux; - int i, error, name[4]; - size_t len; + int error, name[4]; + size_t len, i; if (!hflag) printf(%5s %-16s %-53s\n, PID, COMM, AUXV); @@ -58,7 +57,7 @@ procstat_auxv(struct kinfo_proc *kipp) name[1] = KERN_PROC; name[2] = KERN_PROC_AUXV; name[3] = kipp-ki_pid; - len = sizeof(auxv); + len = sizeof(auxv) * sizeof(*auxv); error = sysctl(name, 4, auxv, len, NULL, 0); if (error 0 errno != ESRCH) { warn(sysctl: kern.proc.auxv: %d: %d, kipp-ki_pid, errno); @@ -72,106 +71,116 @@ procstat_auxv(struct kinfo_proc *kipp) printf( -\n); return; } - for (aux = (Elf_Auxinfo *)auxv, i = 0; i 256; i++, aux++) { - switch(aux-a_type) { + for (i = 0; i len; i++) { + switch(auxv[i].a_type) { case AT_NULL: - printf( (%d)\n, i + 1); + printf( (%zu)\n, i + 1); return; case AT_IGNORE: printf( AT_IGNORE=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; case AT_EXECFD: printf( AT_EXECFD=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; case AT_PHDR: printf( AT_PHDR=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; case AT_PHENT: printf( AT_PHENT=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; case AT_PHNUM: printf( AT_PHNUM=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; case AT_PAGESZ: printf( AT_PAGESZ=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; case AT_BASE: printf( AT_BASE=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; case AT_FLAGS: printf( AT_FLAGS=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; case AT_ENTRY: printf( AT_ENTRY=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; +#ifdef AT_NOTELF case AT_NOTELF: printf( AT_NOTELF=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; +#endif +#ifdef AT_UID case AT_UID: printf( AT_UID=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; +#endif +#ifdef AT_EUID case AT_EUID: printf( AT_EUID=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; +#endif +#ifdef AT_GID case AT_GID: printf( AT_GID=0x%lu, - (unsigned long)aux-a_un.a_val); + (unsigned long)auxv[i].a_un.a_val); break; +#endif +#ifdef AT_EGID case AT_EGID: printf( AT_EGID=0x%lu, -