Skip to content

Commit c54660b

Browse files
kangtegonghonggyukim
authored andcommitted
misc: Add -h/--help options and end marker to demangler_options
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]>
1 parent 354c270 commit c54660b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

misc/demangler.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ enum options {
1818
};
1919

2020
static struct option demangler_options[] = {
21-
{ "simple", no_argument, 0, OPT_simple },
22-
{ "full", no_argument, 0, OPT_full },
23-
{ "no", no_argument, 0, OPT_no },
24-
{ "verbose", no_argument, 0, 'v' },
21+
{ "simple", no_argument, 0, OPT_simple }, { "full", no_argument, 0, OPT_full },
22+
{ "no", no_argument, 0, OPT_no }, { "verbose", no_argument, 0, 'v' },
23+
{ "help", no_argument, 0, 'h' }, { 0 }
2524
};
2625

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

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

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

68+
case 'h':
69+
printf("%s", demangler_usage);
70+
exit(0);
71+
6872
case -1:
6973
done = true;
7074
break;

0 commit comments

Comments
 (0)