* Parse options. */
| 445 | * Parse options. |
| 446 | */ |
| 447 | void parseOptions(char * const argv[], bool api) |
| 448 | { |
| 449 | int argc; |
| 450 | for (argc = 0; argv[argc] != nullptr; argc++) |
| 451 | ; |
| 452 | const int req_arg = required_argument, opt_arg = optional_argument, |
| 453 | no_arg = no_argument; |
| 454 | static const struct option long_options[] = |
| 455 | { |
| 456 | {"Ocall", opt_arg, nullptr, OPTION_OCALL}, |
| 457 | {"OCFR", opt_arg, nullptr, OPTION_OCFR}, |
| 458 | {"OCFR-hacks", opt_arg, nullptr, OPTION_OCFR_HACKS}, |
| 459 | {"Oepilogue", req_arg, nullptr, OPTION_OEPILOGUE}, |
| 460 | {"Oepilogue-size", req_arg, nullptr, OPTION_OEPILOGUE_SIZE}, |
| 461 | {"Oorder", opt_arg, nullptr, OPTION_OORDER}, |
| 462 | {"Opeephole", opt_arg, nullptr, OPTION_OPEEPHOLE}, |
| 463 | {"Oprologue", req_arg, nullptr, OPTION_OPROLOGUE}, |
| 464 | {"Oprologue-size", req_arg, nullptr, OPTION_OPROLOGUE_SIZE}, |
| 465 | {"Oscratch-stack", opt_arg, nullptr, OPTION_OSCRATCH_STACK}, |
| 466 | {"batch", opt_arg, nullptr, OPTION_BATCH}, |
| 467 | {"debug", opt_arg, nullptr, OPTION_DEBUG}, |
| 468 | {"help", no_arg, nullptr, OPTION_HELP}, |
| 469 | {"input", req_arg, nullptr, OPTION_INPUT}, |
| 470 | {"loader-base", req_arg, nullptr, OPTION_LOADER_BASE}, |
| 471 | {"loader-phdr", req_arg, nullptr, OPTION_LOADER_PHDR}, |
| 472 | {"loader-static", opt_arg, nullptr, OPTION_LOADER_STATIC}, |
| 473 | {"log", opt_arg, nullptr, OPTION_LOG}, |
| 474 | {"mem-granularity", req_arg, nullptr, OPTION_MEM_GRANULARITY}, |
| 475 | {"mem-lb", req_arg, nullptr, OPTION_MEM_LB}, |
| 476 | {"mem-mapping-size", req_arg, nullptr, OPTION_MEM_MAPPING_SIZE}, |
| 477 | {"mem-multi-page", opt_arg, nullptr, OPTION_MEM_MULTI_PAGE}, |
| 478 | {"mem-rebase", req_arg, nullptr, OPTION_MEM_REBASE}, |
| 479 | {"mem-ub", req_arg, nullptr, OPTION_MEM_UB}, |
| 480 | {"output", req_arg, nullptr, OPTION_OUTPUT}, |
| 481 | {"tactic-B0", opt_arg, nullptr, OPTION_TACTIC_B0}, |
| 482 | {"tactic-B1", opt_arg, nullptr, OPTION_TACTIC_B1}, |
| 483 | {"tactic-B2", opt_arg, nullptr, OPTION_TACTIC_B2}, |
| 484 | {"tactic-T0", opt_arg, nullptr, OPTION_TACTIC_T0}, |
| 485 | {"tactic-T1", opt_arg, nullptr, OPTION_TACTIC_T1}, |
| 486 | {"tactic-T2", opt_arg, nullptr, OPTION_TACTIC_T2}, |
| 487 | {"tactic-T3", opt_arg, nullptr, OPTION_TACTIC_T3}, |
| 488 | {"tactic-backward-T3", opt_arg, nullptr, OPTION_TACTIC_BACKWARD_T3}, |
| 489 | {"trap", req_arg, nullptr, OPTION_TRAP}, |
| 490 | {"trap-all", opt_arg, nullptr, OPTION_TRAP_ALL}, |
| 491 | {"trap-entry", opt_arg, nullptr, OPTION_TRAP_ENTRY}, |
| 492 | {"version", no_arg, nullptr, OPTION_VERSION}, |
| 493 | {nullptr, no_arg, nullptr, 0} |
| 494 | }; |
| 495 | |
| 496 | optind = 1; |
| 497 | while (true) |
| 498 | { |
| 499 | int idx; |
| 500 | int opt = getopt_long_only(argc, argv, "H::hi:o:", long_options, &idx); |
| 501 | if (opt < 0) |
| 502 | break; |
| 503 | switch (opt) |
| 504 | { |
no test coverage detected