diff options
author | Kenny Root <kroot@google.com> | 2014-05-14 15:07:08 -0700 |
---|---|---|
committer | Kenny Root <kroot@google.com> | 2014-05-14 16:11:37 -0700 |
commit | 8f197e65790265b362fc01c5f730365dc7dc1809 (patch) | |
tree | 2d2a35e3341fac9217818a8be502b34081b01f28 | |
parent | f03397fad4430742d85579fc7a80224ed6e6fb2a (diff) | |
download | system_core-8f197e65790265b362fc01c5f730365dc7dc1809.zip system_core-8f197e65790265b362fc01c5f730365dc7dc1809.tar.gz system_core-8f197e65790265b362fc01c5f730365dc7dc1809.tar.bz2 |
ps: add flag to show ABI
Allow us to easily identify the 32/64 bitness of the process. Yes, I
know this is not technically an ABI, but it seemed close enough!
Change-Id: Ia03a17fd74d61e7619911cb26b3dd7d82b62930c
-rw-r--r-- | toolbox/ps.c | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/toolbox/ps.c b/toolbox/ps.c index 7c35ccb..e9fba0b 100644 --- a/toolbox/ps.c +++ b/toolbox/ps.c @@ -28,9 +28,12 @@ static char *nexttok(char **strp) #define SHOW_POLICY 4 #define SHOW_CPU 8 #define SHOW_MACLABEL 16 +#define SHOW_ABI 32 static int display_flags = 0; +static void print_exe_abi(int pid); + static int ps_line(int pid, int tid, char *namefilter) { char statline[1024]; @@ -170,7 +173,11 @@ static int ps_line(int pid, int tid, char *namefilter) else printf(" %.2s ", get_sched_policy_name(p)); } - printf(" %08x %08x %s %s", wchan, eip, state, cmdline[0] ? cmdline : name); + printf(" %08x %08x %s ", wchan, eip, state); + if (display_flags & SHOW_ABI) { + print_exe_abi(pid); + } + printf("%s", cmdline[0] ? cmdline : name); if(display_flags&SHOW_TIME) printf(" (u:%d, s:%d)", utime, stime); @@ -179,6 +186,39 @@ static int ps_line(int pid, int tid, char *namefilter) return 0; } +static void print_exe_abi(int pid) +{ + int fd, r; + char exeline[1024]; + + sprintf(exeline, "/proc/%d/exe", pid); + fd = open(exeline, O_RDONLY); + if(fd == 0) { + printf(" "); + return; + } + r = read(fd, exeline, 5 /* 4 byte ELFMAG + 1 byte EI_CLASS */); + close(fd); + if(r < 0) { + printf(" "); + return; + } + if (memcmp("\177ELF", exeline, 4) != 0) { + printf("?? "); + return; + } + switch (exeline[4]) { + case 1: + printf("32 "); + return; + case 2: + printf("64 "); + return; + default: + printf("?? "); + return; + } +} void ps_threads(int pid, char *namefilter) { @@ -224,7 +264,9 @@ int ps_main(int argc, char **argv) display_flags |= SHOW_PRIO; } else if(!strcmp(argv[1],"-c")) { display_flags |= SHOW_CPU; - } else if(isdigit(argv[1][0])){ + } else if(!strcmp(argv[1],"--abi")) { + display_flags |= SHOW_ABI; + } else if(isdigit(argv[1][0])){ pidfilter = atoi(argv[1]); } else { namefilter = argv[1]; @@ -236,10 +278,11 @@ int ps_main(int argc, char **argv) if (display_flags & SHOW_MACLABEL) { printf("LABEL USER PID PPID NAME\n"); } else { - printf("USER PID PPID VSIZE RSS %s%s %s WCHAN PC NAME\n", + printf("USER PID PPID VSIZE RSS %s%s %s WCHAN PC %sNAME\n", (display_flags&SHOW_CPU)?"CPU ":"", (display_flags&SHOW_PRIO)?"PRIO NICE RTPRI SCHED ":"", - (display_flags&SHOW_POLICY)?"PCY " : ""); + (display_flags&SHOW_POLICY)?"PCY " : "", + (display_flags&SHOW_ABI)?"ABI " : ""); } while((de = readdir(d)) != 0){ if(isdigit(de->d_name[0])){ |