56 #include <langinfo.h>
57 #include <unistd.h>
58 #include <ctype.h>
59 #include <fcntl.h>
60 #include <string.h>
61 #include <strings.h>
62 #include <limits.h>
63 #include <pwd.h>
64 #include <grp.h>
65 #include <errno.h>
66 #include <setjmp.h>
67 #include <sys/types.h>
68 #include <sys/auxv.h>
69 #include <sys/archsystm.h>
70 #include <sys/proc.h>
71 #include <sys/elf.h>
72 #include <libproc.h>
73 #include <wctype.h>
74 #include <widec.h>
75 #include <elfcap.h>
76 #include <libgen.h>
77
78 typedef enum pargs_cmd {
79 PARGS_ARGV,
80 PARGS_ENV,
81 PARGS_AUXV
82 } pargs_cmd_t;
83
84 typedef struct pargs_data {
85 struct ps_prochandle *pd_proc; /* target proc handle */
86 psinfo_t *pd_psinfo; /* target psinfo */
87 char *pd_locale; /* target process locale */
88 int pd_conv_flags; /* flags governing string conversion */
89 iconv_t pd_iconv; /* iconv conversion descriptor */
90 size_t pd_argc;
91 uintptr_t *pd_argv;
92 char **pd_argv_strs;
93 size_t pd_envc;
94 size_t pd_envc_curr;
95 uintptr_t *pd_envp;
96 char **pd_envp_strs;
97 size_t pd_auxc;
98 auxv_t *pd_auxv;
99 char **pd_auxv_strs;
100 char *pd_execname;
101 } pargs_data_t;
102
103 #define CONV_USE_ICONV 0x01
1273 aux->aux_decode(v, datap->pd_auxv_strs[i],
1274 sizeof (decode), decode);
1275 } else {
1276 (void) snprintf(type, sizeof (type), "%d", pa->a_type);
1277 decode[0] = '\0';
1278 }
1279
1280 (void) printf("%-*s 0x%0*lx %s\n", MAX_AT_NAME_LEN, type,
1281 (dmodel == PR_MODEL_LP64)? 16 : 8, v, decode);
1282 }
1283 }
1284
1285 int
1286 main(int argc, char *argv[])
1287 {
1288 int aflag = 0, cflag = 0, eflag = 0, xflag = 0, lflag = 0;
1289 int errflg = 0, retc = 0;
1290 int opt;
1291 int error = 1;
1292 core_content_t content = 0;
1293 pargs_cmd_t cmd = PARGS_ARGV;
1294
1295 (void) setlocale(LC_ALL, "");
1296
1297 command = basename(argv[0]);
1298
1299 if (strcmp(command, "penv") == 0)
1300 cmd = PARGS_ENV;
1301 else if (strcmp(command, "pauxv") == 0)
1302 cmd = PARGS_AUXV;
1303
1304 while ((opt = getopt(argc, argv, "acelxF")) != EOF) {
1305 switch (opt) {
1306 case 'a': /* show process arguments */
1307 content |= CC_CONTENT_STACK;
1308 aflag++;
1309 if (cmd != PARGS_ARGV)
1310 errflg++;
1311 break;
1312 case 'c': /* force 7-bit ascii */
1313 cflag++;
1314 break;
1315 case 'e': /* show environment variables */
1316 content |= CC_CONTENT_STACK;
1317 eflag++;
1318 if (cmd != PARGS_ARGV)
1319 errflg++;
1320 break;
1321 case 'l':
1322 lflag++;
1323 aflag++; /* -l implies -a */
1324 if (cmd != PARGS_ARGV)
1325 errflg++;
1326 break;
1327 case 'x': /* show aux vector entries */
1328 xflag++;
1329 if (cmd != PARGS_ARGV)
1330 errflg++;
1331 break;
1332 case 'F':
1333 /*
1334 * Since we open the process read-only, there is no need
1335 * for the -F flag. It's a documented flag, so we
1336 * consume it silently.
1337 */
1338 break;
1339 default:
1340 errflg++;
1341 break;
1342 }
1343 }
1344
1345 /* -a is the default if no options are specified */
1346 if ((aflag + eflag + xflag + lflag) == 0) {
1347 switch (cmd) {
1348 case PARGS_ARGV:
1349 aflag++;
1350 content |= CC_CONTENT_STACK;
1351 break;
1352 case PARGS_ENV:
1353 content |= CC_CONTENT_STACK;
1354 eflag++;
1355 break;
1356 case PARGS_AUXV:
1357 xflag++;
1358 break;
1359 }
1360 }
1361
1362 /* -l cannot be used with the -x or -e flags */
1363 if (lflag && (xflag || eflag)) {
1364 (void) fprintf(stderr, "-l is incompatible with -x and -e\n");
1365 errflg++;
1366 }
1367
1368 argc -= optind;
1369 argv += optind;
1370
1371 if (errflg || argc <= 0) {
1372 (void) fprintf(stderr,
1373 "usage: %s [-aceFlx] { pid | core } ...\n"
1374 " (show process arguments and environment)\n"
1375 " -a: show process arguments (default)\n"
1376 " -c: interpret characters as 7-bit ascii regardless of "
1377 "locale\n"
1378 " -e: show environment variables\n"
1379 " -F: force grabbing of the target process\n"
1380 " -l: display arguments as command line\n"
|
56 #include <langinfo.h>
57 #include <unistd.h>
58 #include <ctype.h>
59 #include <fcntl.h>
60 #include <string.h>
61 #include <strings.h>
62 #include <limits.h>
63 #include <pwd.h>
64 #include <grp.h>
65 #include <errno.h>
66 #include <setjmp.h>
67 #include <sys/types.h>
68 #include <sys/auxv.h>
69 #include <sys/archsystm.h>
70 #include <sys/proc.h>
71 #include <sys/elf.h>
72 #include <libproc.h>
73 #include <wctype.h>
74 #include <widec.h>
75 #include <elfcap.h>
76
77 typedef struct pargs_data {
78 struct ps_prochandle *pd_proc; /* target proc handle */
79 psinfo_t *pd_psinfo; /* target psinfo */
80 char *pd_locale; /* target process locale */
81 int pd_conv_flags; /* flags governing string conversion */
82 iconv_t pd_iconv; /* iconv conversion descriptor */
83 size_t pd_argc;
84 uintptr_t *pd_argv;
85 char **pd_argv_strs;
86 size_t pd_envc;
87 size_t pd_envc_curr;
88 uintptr_t *pd_envp;
89 char **pd_envp_strs;
90 size_t pd_auxc;
91 auxv_t *pd_auxv;
92 char **pd_auxv_strs;
93 char *pd_execname;
94 } pargs_data_t;
95
96 #define CONV_USE_ICONV 0x01
1266 aux->aux_decode(v, datap->pd_auxv_strs[i],
1267 sizeof (decode), decode);
1268 } else {
1269 (void) snprintf(type, sizeof (type), "%d", pa->a_type);
1270 decode[0] = '\0';
1271 }
1272
1273 (void) printf("%-*s 0x%0*lx %s\n", MAX_AT_NAME_LEN, type,
1274 (dmodel == PR_MODEL_LP64)? 16 : 8, v, decode);
1275 }
1276 }
1277
1278 int
1279 main(int argc, char *argv[])
1280 {
1281 int aflag = 0, cflag = 0, eflag = 0, xflag = 0, lflag = 0;
1282 int errflg = 0, retc = 0;
1283 int opt;
1284 int error = 1;
1285 core_content_t content = 0;
1286
1287 (void) setlocale(LC_ALL, "");
1288
1289 if ((command = strrchr(argv[0], '/')) != NULL)
1290 command++;
1291 else
1292 command = argv[0];
1293
1294 while ((opt = getopt(argc, argv, "acelxF")) != EOF) {
1295 switch (opt) {
1296 case 'a': /* show process arguments */
1297 content |= CC_CONTENT_STACK;
1298 aflag++;
1299 break;
1300 case 'c': /* force 7-bit ascii */
1301 cflag++;
1302 break;
1303 case 'e': /* show environment variables */
1304 content |= CC_CONTENT_STACK;
1305 eflag++;
1306 break;
1307 case 'l':
1308 lflag++;
1309 aflag++; /* -l implies -a */
1310 break;
1311 case 'x': /* show aux vector entries */
1312 xflag++;
1313 break;
1314 case 'F':
1315 /*
1316 * Since we open the process read-only, there is no need
1317 * for the -F flag. It's a documented flag, so we
1318 * consume it silently.
1319 */
1320 break;
1321 default:
1322 errflg++;
1323 break;
1324 }
1325 }
1326
1327 /* -a is the default if no options are specified */
1328 if ((aflag + eflag + xflag + lflag) == 0) {
1329 aflag++;
1330 content |= CC_CONTENT_STACK;
1331 }
1332
1333 /* -l cannot be used with the -x or -e flags */
1334 if (lflag && (xflag || eflag)) {
1335 (void) fprintf(stderr, "-l is incompatible with -x and -e\n");
1336 errflg++;
1337 }
1338
1339 argc -= optind;
1340 argv += optind;
1341
1342 if (errflg || argc <= 0) {
1343 (void) fprintf(stderr,
1344 "usage: %s [-aceFlx] { pid | core } ...\n"
1345 " (show process arguments and environment)\n"
1346 " -a: show process arguments (default)\n"
1347 " -c: interpret characters as 7-bit ascii regardless of "
1348 "locale\n"
1349 " -e: show environment variables\n"
1350 " -F: force grabbing of the target process\n"
1351 " -l: display arguments as command line\n"
|