blob: a8f53f608031ee6d27cf307b87dbf48692e95f4a [file] [log] [blame]
Dmitry V. Levin7be23182014-12-11 19:25:02 +00001#include "defs.h"
2
3static void
4printargv(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;
Dmitry V. Levinad181322015-07-20 15:17:24 +000013 const unsigned wordsize = current_wordsize;
Dmitry V. Levin7be23182014-12-11 19:25:02 +000014
15 cp.p64 = 1;
16 for (sep = ""; !abbrev(tcp) || n < max_strlen / 2; sep = ", ", ++n) {
Dmitry V. Levinad181322015-07-20 15:17:24 +000017 if (umoven_or_printaddr(tcp, addr, wordsize, cp.data))
Dmitry V. Levin7be23182014-12-11 19:25:02 +000018 return;
Dmitry V. Levin7be23182014-12-11 19:25:02 +000019 if (wordsize == 4)
20 cp.p64 = cp.p32;
21 if (cp.p64 == 0)
22 break;
23 tprints(sep);
24 printstr(tcp, cp.p64, -1);
25 addr += wordsize;
26 }
27 if (cp.p64)
28 tprintf("%s...", sep);
29}
30
31static void
32printargc(const char *fmt, struct tcb *tcp, long addr)
33{
34 int count;
Dmitry V. Levin4ff687b2015-07-27 10:02:33 +000035 char *cp = NULL;
Dmitry V. Levin7be23182014-12-11 19:25:02 +000036
Dmitry V. Levin4ff687b2015-07-27 10:02:33 +000037 for (count = 0; !umoven(tcp, addr, current_wordsize, &cp) && cp; count++) {
38 addr += current_wordsize;
Dmitry V. Levin7be23182014-12-11 19:25:02 +000039 }
40 tprintf(fmt, count, count == 1 ? "" : "s");
41}
42
Dmitry V. Levin7c221012015-07-26 11:06:53 +000043static void
44decode_execve(struct tcb *tcp, const unsigned int index)
45{
46 printpath(tcp, tcp->u_arg[index + 0]);
47 tprints(", ");
48
49 if (!tcp->u_arg[index + 1] || !verbose(tcp))
50 printaddr(tcp->u_arg[index + 1]);
51 else {
52 tprints("[");
53 printargv(tcp, tcp->u_arg[index + 1]);
54 tprints("]");
55 }
56 tprints(", ");
57
58 if (!tcp->u_arg[index + 2] || !verbose(tcp))
59 printaddr(tcp->u_arg[index + 2]);
60 else if (abbrev(tcp))
61 printargc("[/* %d var%s */]", tcp, tcp->u_arg[index + 2]);
62 else {
63 tprints("[");
64 printargv(tcp, tcp->u_arg[index + 2]);
65 tprints("]");
66 }
67}
68
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000069SYS_FUNC(execve)
Dmitry V. Levin7be23182014-12-11 19:25:02 +000070{
Dmitry V. Levin7c221012015-07-26 11:06:53 +000071 decode_execve(tcp, 0);
Dmitry V. Levinad181322015-07-20 15:17:24 +000072
Dmitry V. Levin7c221012015-07-26 11:06:53 +000073 return RVAL_DECODED;
74}
Dmitry V. Levin7e56b4e2015-07-20 15:20:46 +000075
Dmitry V. Levin7c221012015-07-26 11:06:53 +000076SYS_FUNC(execveat)
77{
78 print_dirfd(tcp, tcp->u_arg[0]);
79 decode_execve(tcp, 1);
80 tprints(", ");
81 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin7e56b4e2015-07-20 15:20:46 +000082
83 return RVAL_DECODED;
Dmitry V. Levin7be23182014-12-11 19:25:02 +000084}
85
86#if defined(SPARC) || defined(SPARC64)
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000087SYS_FUNC(execv)
Dmitry V. Levin7be23182014-12-11 19:25:02 +000088{
Dmitry V. Levin7e56b4e2015-07-20 15:20:46 +000089 printpath(tcp, tcp->u_arg[0]);
90 tprints(", ");
91 if (!tcp->u_arg[1] || !verbose(tcp))
92 printaddr(tcp->u_arg[1]);
93 else {
94 tprints("[");
95 printargv(tcp, tcp->u_arg[1]);
96 tprints("]");
Dmitry V. Levin7be23182014-12-11 19:25:02 +000097 }
Dmitry V. Levin7e56b4e2015-07-20 15:20:46 +000098
99 return RVAL_DECODED;
Dmitry V. Levin7be23182014-12-11 19:25:02 +0000100}
101#endif /* SPARC || SPARC64 */