Skip to content

Commit

Permalink
misc: Add -h/--help options and end marker to demangler_options
Browse files Browse the repository at this point in the history
This commit adds support for the -h and --help options to display
usage of misc/demangler like follows.

  $ misc/demangler -h
  demangler v0.11-683-g804a

   OPTION:
        --simple           Use internal simple demangler (default)
        --full             Use libstdc++ demangler
        --no               Do not use demangler
    -v, --verbose          Be verbose
    -h, --help             Display this help and exit

An end marker has also been added to the demangler_options array for
proper termination and prevent potential undefined behavior.

Fixed: #1939

Signed-off-by: Kang Minchul <[email protected]>
  • Loading branch information
kangtegong authored and honggyukim committed Aug 14, 2024
1 parent 354c270 commit c54660b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions misc/demangler.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ enum options {
};

static struct option demangler_options[] = {
{ "simple", no_argument, 0, OPT_simple },
{ "full", no_argument, 0, OPT_full },
{ "no", no_argument, 0, OPT_no },
{ "verbose", no_argument, 0, 'v' },
{ "simple", no_argument, 0, OPT_simple }, { "full", no_argument, 0, OPT_full },
{ "no", no_argument, 0, OPT_no }, { "verbose", no_argument, 0, 'v' },
{ "help", no_argument, 0, 'h' }, { 0 }
};

static const char demangler_usage[] =
Expand All @@ -32,6 +31,7 @@ static const char demangler_usage[] =
" --full Use libstdc++ demangler\n"
" --no Do not use demangler\n"
" -v, --verbose Be verbose\n"
" -h, --help Display this help and exit\n"
"\n";

struct demangler_opts {
Expand All @@ -46,7 +46,7 @@ static void parse_option(int argc, char **argv, struct demangler_opts *opts)
while (!done) {
int key, tmp;

key = getopt_long(argc, argv, "v", demangler_options, &tmp);
key = getopt_long(argc, argv, "vh", demangler_options, &tmp);
switch (key) {
case OPT_simple:
opts->mode = DEMANGLE_SIMPLE;
Expand All @@ -65,6 +65,10 @@ static void parse_option(int argc, char **argv, struct demangler_opts *opts)
dbg_domain[DBG_DEMANGLE]++;
break;

case 'h':
printf("%s", demangler_usage);
exit(0);

case -1:
done = true;
break;
Expand Down

0 comments on commit c54660b

Please sign in to comment.