Changeset 53646 in vbox for trunk/src/VBox/ExtPacks/VBoxDTrace/onnv
- Timestamp:
- Jan 2, 2015 12:17:12 PM (10 years ago)
- Location:
- trunk/src/VBox/ExtPacks/VBoxDTrace/onnv
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/dtrace.c
r53634 r53646 25 25 */ 26 26 27 #ifndef VBOX 27 28 #pragma ident "%Z%%M% %I% %E% SMI" 29 #endif 28 30 29 31 #include <sys/types.h> 30 32 #include <sys/stat.h> 31 #include <sys/wait.h> 33 #ifndef _MSC_VER 34 # include <sys/wait.h> 35 #endif 32 36 33 37 #include <dtrace.h> … … 35 39 #include <stdarg.h> 36 40 #include <stdio.h> 37 #include <strings.h> 38 #include <unistd.h> 41 #ifndef VBOX 42 # include <strings.h> 43 #endif 44 #ifndef _MSC_VER 45 # include <unistd.h> 46 #else 47 # include <direct.h> 48 # include <io.h> 49 #endif 39 50 #include <limits.h> 40 51 #include <fcntl.h> 41 52 #include <errno.h> 42 53 #include <signal.h> 54 #ifndef VBOX 43 55 #include <alloca.h> 44 56 #include <libgen.h> 45 57 #include <libproc.h> 58 #endif 59 60 #ifdef VBOX 61 # include <stdio.h> 62 63 # include <iprt/alloca.h> 64 # include <iprt/getopt.h> 65 # include <iprt/initterm.h> 66 # include <iprt/path.h> 67 # include <iprt/message.h> 68 # include <iprt/process.h> 69 # include <iprt/string.h> 70 71 # undef PATH_MAX 72 # define PATH_MAX RTPATH_MAX 73 74 # define getpid RTProcSelf 75 # define strlcpy(a_pszDst, a_pszSrc, a_cbDst) RTStrCopy(a_pszDst, a_cbDst, a_pszSrc) 76 # define basename(a_pszPath) RTPathFilename(a_pszPath) 77 78 # ifdef _MSC_VER 79 # pragma warning(disable:4267) /* size_t conversion warnings */ 80 # pragma warning(disable:4018) /* signed/unsigned mismatch */ 81 # endif 82 #endif 46 83 47 84 typedef struct dtrace_cmd { … … 66 103 #define E_USAGE 2 67 104 105 #ifndef VBOX 68 106 static const char DTRACE_OPTSTR[] = 69 107 "3:6:aAb:Bc:CD:ef:FGhHi:I:lL:m:n:o:p:P:qs:SU:vVwx:X:Z"; 108 #else 109 static const RTGETOPTDEF g_aOptions[] = 110 { 111 { "-32", 10064, RTGETOPT_REQ_NOTHING }, 112 { "-64", 10032, RTGETOPT_REQ_NOTHING }, 113 { NULL, 'a', RTGETOPT_REQ_NOTHING }, 114 { NULL, 'A', RTGETOPT_REQ_NOTHING }, 115 { NULL, 'b', RTGETOPT_REQ_STRING }, 116 { NULL, 'B', RTGETOPT_REQ_NOTHING }, 117 { NULL, 'c', RTGETOPT_REQ_STRING }, 118 { NULL, 'C', RTGETOPT_REQ_NOTHING }, 119 { NULL, 'D', RTGETOPT_REQ_STRING }, 120 { NULL, 'e', RTGETOPT_REQ_NOTHING }, 121 { NULL, 'f', RTGETOPT_REQ_STRING }, 122 { NULL, 'F', RTGETOPT_REQ_NOTHING }, 123 { NULL, 'G', RTGETOPT_REQ_NOTHING }, 124 { NULL, 'h', RTGETOPT_REQ_NOTHING }, 125 { NULL, 'H', RTGETOPT_REQ_NOTHING }, 126 { NULL, 'i', RTGETOPT_REQ_STRING }, 127 { NULL, 'I', RTGETOPT_REQ_STRING }, 128 { NULL, 'l', RTGETOPT_REQ_NOTHING }, 129 { NULL, 'L', RTGETOPT_REQ_STRING }, 130 { NULL, 'M', RTGETOPT_REQ_STRING }, 131 { NULL, 'n', RTGETOPT_REQ_STRING }, 132 { NULL, 'o', RTGETOPT_REQ_STRING }, 133 { NULL, 'p', RTGETOPT_REQ_STRING }, 134 { NULL, 'P', RTGETOPT_REQ_STRING }, 135 { NULL, 'q', RTGETOPT_REQ_NOTHING }, 136 { NULL, 's', RTGETOPT_REQ_STRING }, 137 { NULL, 'S', RTGETOPT_REQ_NOTHING }, 138 { NULL, 'U', RTGETOPT_REQ_STRING }, 139 { NULL, 'v', RTGETOPT_REQ_NOTHING }, 140 { NULL, 'V', RTGETOPT_REQ_NOTHING }, 141 { NULL, 'w', RTGETOPT_REQ_NOTHING }, 142 { NULL, 'x', RTGETOPT_REQ_STRING }, 143 { NULL, 'X', RTGETOPT_REQ_STRING }, 144 { NULL, 'Z', RTGETOPT_REQ_NOTHING }, 145 }; 146 #endif /* VBOX */ 147 70 148 71 149 static char **g_argv; … … 93 171 static int g_grabanon = 0; 94 172 static const char *g_ofile = NULL; 173 #ifndef _MSC_VER /* stdout isn't a constant usable in C code. */ 95 174 static FILE *g_ofp = stdout; 175 #else 176 static FILE *g_ofp = NULL; 177 #endif 96 178 static dtrace_hdl_t *g_dtp; 97 179 static char *g_etcfile = "/etc/system"; … … 437 519 (void) close(fd); 438 520 521 #ifndef _MSC_VER 439 522 if (chown(tmpname, sbuf.st_uid, sbuf.st_gid) != 0) { 440 523 (void) unlink(tmpname); … … 442 525 (int)sbuf.st_uid, (int)sbuf.st_gid); 443 526 } 527 #endif 444 528 445 529 if (rename(tmpname, fname) == -1) … … 511 595 512 596 for (i = 0; i < p->dtp_argc; i++) { 597 #ifndef VBOX /* no ctf for now */ 513 598 if (ctf_type_name(p->dtp_argv[i].dtt_ctfp, 514 599 p->dtp_argv[i].dtt_type, buf, sizeof (buf)) == NULL) 600 #endif 515 601 (void) strlcpy(buf, "(unknown)", sizeof (buf)); 516 602 oprintf("\t\targs[%d]: %s\n", i, buf); … … 742 828 prochandler(struct ps_prochandle *P, const char *msg, void *arg) 743 829 { 830 #ifndef VBOX 744 831 const psinfo_t *prp = Ppsinfo(P); 745 832 int pid = Pstatus(P)->pr_pid; … … 779 866 break; 780 867 } 868 #endif /* !VBOX */ 781 869 } 782 870 … … 1155 1243 { 1156 1244 dtrace_bufdesc_t buf; 1245 #ifndef _MSC_VER 1157 1246 struct sigaction act, oact; 1247 #endif 1158 1248 dtrace_status_t status[2]; 1159 1249 dtrace_optval_t opt; … … 1165 1255 struct ps_prochandle *P; 1166 1256 pid_t pid; 1167 1257 #ifdef VBOX 1258 RTGETOPTUNION ValueUnion; 1259 RTGETOPTSTATE GetState; 1260 1261 err = RTR3InitExe(argc, &argv, RTR3INIT_FLAGS_SUPLIB); 1262 if (RT_FAILURE(err)) 1263 return RTMsgInitFailure(err); 1264 #endif 1265 #ifdef _MSC_VER 1266 g_ofp = stdout; 1267 #endif 1168 1268 g_pname = basename(argv[0]); 1169 1269 … … 1188 1288 * options into g_argv[], and abort if any invalid options are found. 1189 1289 */ 1290 #ifndef VBOX 1190 1291 for (optind = 1; optind < argc; optind++) { 1191 1292 while ((c = getopt(argc, argv, DTRACE_OPTSTR)) != EOF) { 1293 #else 1294 RTGetOptInit(&GetState, argc, argv, g_aOptions, RT_ELEMENTS(g_aOptions), 1, 0); 1295 while ((c = RTGetOpt(&GetState, &ValueUnion))) { 1296 { 1297 const char *optarg = ValueUnion.psz; 1298 #endif 1192 1299 switch (c) { 1300 #ifndef VBOX 1193 1301 case '3': 1194 1302 if (strcmp(optarg, "2") != 0) { … … 1198 1306 return (usage(stderr)); 1199 1307 } 1308 #else 1309 case 10032: 1310 #endif 1200 1311 g_oflags &= ~DTRACE_O_LP64; 1201 1312 g_oflags |= DTRACE_O_ILP32; 1202 1313 break; 1203 1314 1315 #ifndef VBOX 1204 1316 case '6': 1205 1317 if (strcmp(optarg, "4") != 0) { … … 1209 1321 return (usage(stderr)); 1210 1322 } 1323 #else 1324 case 10064: 1325 #endif 1211 1326 g_oflags &= ~DTRACE_O_ILP32; 1212 1327 g_oflags |= DTRACE_O_LP64; … … 1255 1370 break; 1256 1371 1372 #ifndef VBOX 1257 1373 default: 1258 1374 if (strchr(DTRACE_OPTSTR, c) == NULL) 1259 1375 return (usage(stderr)); 1376 #else 1377 case VINF_GETOPT_NOT_OPTION: 1378 g_argv[g_argc++] = (char *)ValueUnion.psz; 1379 break; 1380 1381 default: 1382 if (c < 0) { /* Note: Not all options are handled. */ 1383 RTGetOptPrintError(c, &ValueUnion); 1384 return (usage(stderr)); 1385 } 1386 #endif 1260 1387 } 1261 1388 } 1262 1389 1390 #ifndef VBOX 1263 1391 if (optind < argc) 1264 1392 g_argv[g_argc++] = argv[optind]; 1393 #endif 1265 1394 } 1266 1395 … … 1274 1403 return (printf("%s: %s\n", g_pname, _dtrace_version) <= 0); 1275 1404 1405 #ifndef VBOX 1276 1406 /* 1277 1407 * If we're in linker mode and the data model hasn't been specified, … … 1323 1453 } 1324 1454 } 1455 #endif /* !VBOX */ 1325 1456 1326 1457 /* … … 1371 1502 * this time; these will compiled as part of the fourth processing pass. 1372 1503 */ 1504 #ifndef VBOX 1373 1505 for (optind = 1; optind < argc; optind++) { 1374 1506 while ((c = getopt(argc, argv, DTRACE_OPTSTR)) != EOF) { 1507 #else 1508 RTGetOptInit(&GetState, argc, argv, g_aOptions, RT_ELEMENTS(g_aOptions), 1, 0); 1509 while ((c = RTGetOpt(&GetState, &ValueUnion))) { 1510 { 1511 char *optarg = (char *)ValueUnion.psz; 1512 #endif 1513 1375 1514 switch (c) { 1376 1515 case 'a': … … 1504 1643 break; 1505 1644 1645 #ifndef VBOX 1506 1646 default: 1507 1647 if (strchr(DTRACE_OPTSTR, c) == NULL) 1508 1648 return (usage(stderr)); 1649 #else 1650 default: 1651 if (c < 0) { /* Note: Not all options are handled. */ 1652 RTGetOptPrintError(c, &ValueUnion); 1653 return (usage(stderr)); 1654 } 1655 #endif 1509 1656 } 1510 1657 } … … 1528 1675 * may been affected by any library options set by the second pass. 1529 1676 */ 1677 #ifndef VBOX 1530 1678 for (optind = 1; optind < argc; optind++) { 1531 1679 while ((c = getopt(argc, argv, DTRACE_OPTSTR)) != EOF) { 1680 #else 1681 RTGetOptInit(&GetState, argc, argv, g_aOptions, RT_ELEMENTS(g_aOptions), 1, 0); 1682 while ((c = RTGetOpt(&GetState, &ValueUnion))) { 1683 { 1684 char *optarg = (char *)ValueUnion.psz; 1685 #endif 1532 1686 switch (c) { 1533 1687 case 'c': … … 1771 1925 notice("allowing destructive actions\n"); 1772 1926 1927 #ifndef _MSC_VER 1773 1928 (void) sigemptyset(&act.sa_mask); 1774 1929 act.sa_flags = 0; … … 1780 1935 if (sigaction(SIGTERM, NULL, &oact) == 0 && oact.sa_handler != SIG_IGN) 1781 1936 (void) sigaction(SIGTERM, &act, NULL); 1937 #else 1938 signal(SIGINT, intr); 1939 signal(SIGTERM, intr); 1940 #endif 1782 1941 1783 1942 /* -
trunk/src/VBox/ExtPacks/VBoxDTrace/onnv/lib/libdtrace/common/dtrace.h
r53634 r53646 28 28 #define _DTRACE_H 29 29 30 #ifndef VBOX 30 31 #pragma ident "%Z%%M% %I% %E% SMI" 32 #endif 31 33 32 34 #include <sys/dtrace.h> 33 35 #include <stdarg.h> 34 36 #include <stdio.h> 37 #ifndef VBOX 35 38 #include <gelf.h> 39 #endif 36 40 37 41 #ifdef __cplusplus … … 431 435 * be flushed and not used subsequently by the client program. 432 436 */ 437 #ifndef VBOX 433 438 434 439 #define DTRACE_OBJ_EXEC ((const char *)0L) /* primary executable file */ … … 445 450 int dto_id; /* object file id (if any) */ 446 451 uint_t dto_flags; /* object flags (see below) */ 452 447 453 GElf_Addr dto_text_va; /* address of text section */ 448 454 GElf_Xword dto_text_size; /* size of text section */ … … 472 478 extern int dtrace_lookup_by_addr(dtrace_hdl_t *, GElf_Addr addr, 473 479 GElf_Sym *, dtrace_syminfo_t *); 480 #endif /* !VBOX */ 474 481 475 482 typedef struct dtrace_typeinfo { … … 482 489 dtrace_typeinfo_t *); 483 490 491 #ifndef VBOX 484 492 extern int dtrace_symbol_type(dtrace_hdl_t *, const GElf_Sym *, 485 493 const dtrace_syminfo_t *, dtrace_typeinfo_t *); 494 #endif 486 495 487 496 extern int dtrace_type_strcompile(dtrace_hdl_t *, … … 513 522 const dtrace_probedesc_t *, dtrace_probeinfo_t *); 514 523 524 #ifndef VBOX 515 525 /* 516 526 * DTrace Vector Interface … … 528 538 long (*dtv_sysconf)(void *, int); 529 539 }; 540 #endif /* !VBOX */ 530 541 531 542 /*
Note:
See TracChangeset
for help on using the changeset viewer.