Dmitry V. Levin | 7be2318 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 1 | #include "defs.h" |
| 2 | |
| 3 | static void |
| 4 | printargv(struct tcb *tcp, long addr) |
| 5 | { |
| 6 | union { |
| 7 | unsigned int p32; |
| 8 | unsigned long p64; |
| 9 | char data[sizeof(long)]; |
| 10 | } cp; |
| 11 | const char *sep; |
| 12 | unsigned int n = 0; |
| 13 | unsigned wordsize = current_wordsize; |
| 14 | |
| 15 | cp.p64 = 1; |
| 16 | for (sep = ""; !abbrev(tcp) || n < max_strlen / 2; sep = ", ", ++n) { |
| 17 | if (umoven(tcp, addr, wordsize, cp.data) < 0) { |
| 18 | tprintf("%#lx", addr); |
| 19 | return; |
| 20 | } |
| 21 | if (wordsize == 4) |
| 22 | cp.p64 = cp.p32; |
| 23 | if (cp.p64 == 0) |
| 24 | break; |
| 25 | tprints(sep); |
| 26 | printstr(tcp, cp.p64, -1); |
| 27 | addr += wordsize; |
| 28 | } |
| 29 | if (cp.p64) |
| 30 | tprintf("%s...", sep); |
| 31 | } |
| 32 | |
| 33 | static void |
| 34 | printargc(const char *fmt, struct tcb *tcp, long addr) |
| 35 | { |
| 36 | int count; |
| 37 | char *cp; |
| 38 | |
| 39 | for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) { |
| 40 | addr += sizeof(char *); |
| 41 | } |
| 42 | tprintf(fmt, count, count == 1 ? "" : "s"); |
| 43 | } |
| 44 | |
| 45 | int |
| 46 | sys_execve(struct tcb *tcp) |
| 47 | { |
| 48 | if (entering(tcp)) { |
| 49 | printpath(tcp, tcp->u_arg[0]); |
| 50 | if (!verbose(tcp)) |
| 51 | tprintf(", %#lx", tcp->u_arg[1]); |
| 52 | else { |
| 53 | tprints(", ["); |
| 54 | printargv(tcp, tcp->u_arg[1]); |
| 55 | tprints("]"); |
| 56 | } |
| 57 | if (!verbose(tcp)) |
| 58 | tprintf(", %#lx", tcp->u_arg[2]); |
| 59 | else if (abbrev(tcp)) |
| 60 | printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]); |
| 61 | else { |
| 62 | tprints(", ["); |
| 63 | printargv(tcp, tcp->u_arg[2]); |
| 64 | tprints("]"); |
| 65 | } |
| 66 | } |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | #if defined(SPARC) || defined(SPARC64) |
| 71 | int |
| 72 | sys_execv(struct tcb *tcp) |
| 73 | { |
| 74 | if (entering(tcp)) { |
| 75 | printpath(tcp, tcp->u_arg[0]); |
| 76 | if (!verbose(tcp)) |
| 77 | tprintf(", %#lx", tcp->u_arg[1]); |
| 78 | else { |
| 79 | tprints(", ["); |
| 80 | printargv(tcp, tcp->u_arg[1]); |
| 81 | tprints("]"); |
| 82 | } |
| 83 | } |
| 84 | return 0; |
| 85 | } |
| 86 | #endif /* SPARC || SPARC64 */ |