From: Alexandra Hájková Date: Wed, 16 Oct 2024 11:25:40 +0000 (+0200) Subject: gdbreplay: Use getopt_long to parse command line arguments X-Git-Tag: gdb-16-branchpoint~620 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=32ffcd0737a703398646f7e0b62bd5de348319e1;p=thirdparty%2Fbinutils-gdb.git gdbreplay: Use getopt_long to parse command line arguments Approved-By: Tom Tromey --- diff --git a/gdbserver/gdbreplay.cc b/gdbserver/gdbreplay.cc index c2359e4ab43..7ef52b82d0b 100644 --- a/gdbserver/gdbreplay.cc +++ b/gdbserver/gdbreplay.cc @@ -57,6 +57,8 @@ #include "gdbsupport/netstuff.h" #include "gdbsupport/rsp-low.h" +#include "getopt.h" + #ifndef HAVE_SOCKLEN_T typedef int socklen_t; #endif @@ -425,30 +427,39 @@ gdbreplay_usage (FILE *stream) captured_main (int argc, char *argv[]) { FILE *fp; - int ch; - - if (argc >= 2 && strcmp (argv[1], "--version") == 0) + int ch, optc; + enum opts { OPT_VERSION = 1, OPT_HELP }; + static struct option longopts[] = { - gdbreplay_version (); - exit (0); - } - if (argc >= 2 && strcmp (argv[1], "--help") == 0) + {"version", no_argument, nullptr, OPT_VERSION}, + {"help", no_argument, nullptr, OPT_HELP}, + {nullptr, no_argument, nullptr, 0} + }; + + while ((optc = getopt_long (argc, argv, "", longopts, nullptr)) != -1) { - gdbreplay_usage (stdout); - exit (0); + switch (optc) + { + case OPT_VERSION: + gdbreplay_version (); + exit (0); + case OPT_HELP: + gdbreplay_usage (stdout); + exit (0); + } } - if (argc < 3) + if (optind + 2 != argc) { gdbreplay_usage (stderr); exit (1); } - fp = fopen (argv[1], "r"); + fp = fopen (argv[optind], "r"); if (fp == NULL) { - perror_with_name (argv[1]); + perror_with_name (argv[optind]); } - remote_open (argv[2]); + remote_open (argv[optind + 1]); while ((ch = logchar (fp)) != EOF) { switch (ch)