forked from bminor/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli-decode.c
2947 lines (2494 loc) · 87.1 KB
/
cli-decode.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Handle lists of commands, their decoding and documentation, for GDB.
Copyright (C) 1986-2024 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "symtab.h"
#include <ctype.h>
#include "gdbsupport/gdb_regex.h"
#include "completer.h"
#include "ui-out.h"
#include "cli/cli-cmds.h"
#include "cli/cli-decode.h"
#include "cli/cli-style.h"
#include "cli/cli-utils.h"
#include <optional>
/* Prototypes for local functions. */
static void undef_cmd_error (const char *, const char *);
static cmd_list_element::aliases_list_type delete_cmd
(const char *name, cmd_list_element **list, cmd_list_element **prehook,
cmd_list_element **prehookee, cmd_list_element **posthook,
cmd_list_element **posthookee);
static struct cmd_list_element *find_cmd (const char *command,
int len,
struct cmd_list_element *clist,
int ignore_help_classes,
int *nfound);
static void help_cmd_list (struct cmd_list_element *list,
enum command_class theclass,
bool recurse,
struct ui_file *stream);
static void help_all (struct ui_file *stream);
static int lookup_cmd_composition_1 (const char *text,
struct cmd_list_element **alias,
struct cmd_list_element **prefix_cmd,
struct cmd_list_element **cmd,
struct cmd_list_element *cur_list);
/* Look up a command whose 'subcommands' field is SUBCOMMANDS. Return the
command if found, otherwise return NULL. */
static struct cmd_list_element *
lookup_cmd_with_subcommands (cmd_list_element **subcommands,
cmd_list_element *list)
{
struct cmd_list_element *p = NULL;
for (p = list; p != NULL; p = p->next)
{
struct cmd_list_element *q;
if (!p->is_prefix ())
continue;
else if (p->subcommands == subcommands)
{
/* If we found an alias, we must return the aliased
command. */
return p->is_alias () ? p->alias_target : p;
}
q = lookup_cmd_with_subcommands (subcommands, *(p->subcommands));
if (q != NULL)
return q;
}
return NULL;
}
static void
print_help_for_command (const cmd_list_element &c,
bool recurse, struct ui_file *stream);
static void
do_simple_func (const char *args, int from_tty, cmd_list_element *c)
{
c->function.simple_func (args, from_tty);
}
static void
set_cmd_simple_func (struct cmd_list_element *cmd, cmd_simple_func_ftype *simple_func)
{
if (simple_func == NULL)
cmd->func = NULL;
else
cmd->func = do_simple_func;
cmd->function.simple_func = simple_func;
}
int
cmd_simple_func_eq (struct cmd_list_element *cmd, cmd_simple_func_ftype *simple_func)
{
return (cmd->func == do_simple_func
&& cmd->function.simple_func == simple_func);
}
void
set_cmd_completer (struct cmd_list_element *cmd, completer_ftype *completer)
{
cmd->completer = completer; /* Ok. */
}
/* See definition in commands.h. */
void
set_cmd_completer_handle_brkchars (struct cmd_list_element *cmd,
completer_handle_brkchars_ftype *func)
{
cmd->completer_handle_brkchars = func;
}
/* See cli-decode.h. */
std::string
cmd_list_element::prefixname_no_space () const
{
if (!this->is_prefix ())
/* Not a prefix command. */
return "";
std::string prefixname;
if (this->prefix != nullptr)
{
prefixname = this->prefix->prefixname_no_space ();
prefixname += " ";
}
prefixname += this->name;
return prefixname;
}
/* See cli-decode.h. */
std::string
cmd_list_element::prefixname () const
{
std::string result = prefixname_no_space ();
if (!result.empty ())
result += " ";
return result;
}
/* See cli/cli-decode.h. */
std::vector<std::string>
cmd_list_element::command_components () const
{
std::vector<std::string> result;
if (this->prefix != nullptr)
result = this->prefix->command_components ();
result.emplace_back (this->name);
return result;
}
/* Add element named NAME.
Space for NAME and DOC must be allocated by the caller.
THECLASS is the top level category into which commands are broken down
for "help" purposes.
FUN should be the function to execute the command;
it will get a character string as argument, with leading
and trailing blanks already eliminated.
DOC is a documentation string for the command.
Its first line should be a complete sentence.
It should start with ? for a command that is an abbreviation
or with * for a command that most users don't need to know about.
Add this command to command list *LIST.
Returns a pointer to the added command (not necessarily the head
of *LIST). */
static struct cmd_list_element *
do_add_cmd (const char *name, enum command_class theclass,
const char *doc, struct cmd_list_element **list)
{
struct cmd_list_element *c = new struct cmd_list_element (name, theclass,
doc);
/* Turn each alias of the old command into an alias of the new
command. */
c->aliases = delete_cmd (name, list, &c->hook_pre, &c->hookee_pre,
&c->hook_post, &c->hookee_post);
for (cmd_list_element &alias : c->aliases)
alias.alias_target = c;
if (c->hook_pre)
c->hook_pre->hookee_pre = c;
if (c->hookee_pre)
c->hookee_pre->hook_pre = c;
if (c->hook_post)
c->hook_post->hookee_post = c;
if (c->hookee_post)
c->hookee_post->hook_post = c;
if (*list == NULL || strcmp ((*list)->name, name) >= 0)
{
c->next = *list;
*list = c;
}
else
{
cmd_list_element *p = *list;
while (p->next && strcmp (p->next->name, name) <= 0)
{
p = p->next;
}
c->next = p->next;
p->next = c;
}
/* Search the prefix cmd of C, and assigns it to C->prefix.
See also add_prefix_cmd and update_prefix_field_of_prefixed_commands. */
cmd_list_element *prefixcmd = lookup_cmd_with_subcommands (list, cmdlist);
c->prefix = prefixcmd;
return c;
}
struct cmd_list_element *
add_cmd (const char *name, enum command_class theclass,
const char *doc, struct cmd_list_element **list)
{
cmd_list_element *result = do_add_cmd (name, theclass, doc, list);
result->func = NULL;
result->function.simple_func = NULL;
return result;
}
struct cmd_list_element *
add_cmd (const char *name, enum command_class theclass,
cmd_simple_func_ftype *fun,
const char *doc, struct cmd_list_element **list)
{
cmd_list_element *result = do_add_cmd (name, theclass, doc, list);
set_cmd_simple_func (result, fun);
return result;
}
/* Add an element with a suppress notification to the LIST of commands. */
struct cmd_list_element *
add_cmd_suppress_notification (const char *name, enum command_class theclass,
cmd_simple_func_ftype *fun, const char *doc,
struct cmd_list_element **list,
bool *suppress_notification)
{
struct cmd_list_element *element;
element = add_cmd (name, theclass, fun, doc, list);
element->suppress_notification = suppress_notification;
return element;
}
/* Deprecates a command CMD.
REPLACEMENT is the name of the command which should be used in
place of this command, or NULL if no such command exists.
This function does not check to see if command REPLACEMENT exists
since gdb may not have gotten around to adding REPLACEMENT when
this function is called.
Returns a pointer to the deprecated command. */
struct cmd_list_element *
deprecate_cmd (struct cmd_list_element *cmd, const char *replacement)
{
cmd->cmd_deprecated = 1;
cmd->deprecated_warn_user = 1;
if (replacement != NULL)
cmd->replacement = replacement;
else
cmd->replacement = NULL;
return cmd;
}
struct cmd_list_element *
add_alias_cmd (const char *name, cmd_list_element *target,
enum command_class theclass, int abbrev_flag,
struct cmd_list_element **list)
{
gdb_assert (target != nullptr);
struct cmd_list_element *c = add_cmd (name, theclass, target->doc, list);
/* If TARGET->DOC can be freed, we should make another copy. */
if (target->doc_allocated)
{
c->doc = xstrdup (target->doc);
c->doc_allocated = 1;
}
/* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
c->func = target->func;
c->function = target->function;
c->subcommands = target->subcommands;
c->allow_unknown = target->allow_unknown;
c->abbrev_flag = abbrev_flag;
c->alias_target = target;
target->aliases.push_front (*c);
return c;
}
/* Update the prefix field of all sub-commands of the prefix command C.
We must do this when a prefix command is defined as the GDB init sequence
does not guarantee that a prefix command is created before its sub-commands.
For example, break-catch-sig.c initialization runs before breakpoint.c
initialization, but it is breakpoint.c that creates the "catch" command used
by the "catch signal" command created by break-catch-sig.c. */
static void
update_prefix_field_of_prefixed_commands (struct cmd_list_element *c)
{
for (cmd_list_element *p = *c->subcommands; p != NULL; p = p->next)
{
p->prefix = c;
/* We must recursively update the prefix field to cover
e.g. 'info auto-load libthread-db' where the creation
order was:
libthread-db
auto-load
info
In such a case, when 'auto-load' was created by do_add_cmd,
the 'libthread-db' prefix field could not be updated, as the
'auto-load' command was not yet reachable by
lookup_cmd_for_subcommands (list, cmdlist)
that searches from the top level 'cmdlist'. */
if (p->is_prefix ())
update_prefix_field_of_prefixed_commands (p);
}
}
/* Like add_cmd but adds an element for a command prefix: a name that
should be followed by a subcommand to be looked up in another
command list. SUBCOMMANDS should be the address of the variable
containing that list. */
struct cmd_list_element *
add_prefix_cmd (const char *name, enum command_class theclass,
cmd_simple_func_ftype *fun,
const char *doc, struct cmd_list_element **subcommands,
int allow_unknown, struct cmd_list_element **list)
{
struct cmd_list_element *c = add_cmd (name, theclass, fun, doc, list);
c->subcommands = subcommands;
c->allow_unknown = allow_unknown;
/* Now that prefix command C is defined, we need to set the prefix field
of all prefixed commands that were defined before C itself was defined. */
update_prefix_field_of_prefixed_commands (c);
return c;
}
/* A helper function for add_basic_prefix_cmd. This is a command
function that just forwards to help_list. */
static void
do_prefix_cmd (const char *args, int from_tty, struct cmd_list_element *c)
{
/* Look past all aliases. */
while (c->is_alias ())
c = c->alias_target;
help_list (*c->subcommands, c->prefixname_no_space ().c_str (),
all_commands, gdb_stdout);
}
/* See command.h. */
struct cmd_list_element *
add_basic_prefix_cmd (const char *name, enum command_class theclass,
const char *doc, struct cmd_list_element **subcommands,
int allow_unknown, struct cmd_list_element **list)
{
struct cmd_list_element *cmd = add_prefix_cmd (name, theclass, nullptr,
doc, subcommands,
allow_unknown, list);
cmd->func = do_prefix_cmd;
return cmd;
}
/* A helper function for add_show_prefix_cmd. This is a command
function that just forwards to cmd_show_list. */
static void
do_show_prefix_cmd (const char *args, int from_tty, struct cmd_list_element *c)
{
cmd_show_list (*c->subcommands, from_tty);
}
/* See command.h. */
struct cmd_list_element *
add_show_prefix_cmd (const char *name, enum command_class theclass,
const char *doc, struct cmd_list_element **subcommands,
int allow_unknown, struct cmd_list_element **list)
{
struct cmd_list_element *cmd = add_prefix_cmd (name, theclass, nullptr,
doc, subcommands,
allow_unknown, list);
cmd->func = do_show_prefix_cmd;
return cmd;
}
/* See command.h. */
set_show_commands
add_setshow_prefix_cmd (const char *name, command_class theclass,
const char *set_doc, const char *show_doc,
cmd_list_element **set_subcommands_list,
cmd_list_element **show_subcommands_list,
cmd_list_element **set_list,
cmd_list_element **show_list)
{
set_show_commands cmds;
cmds.set = add_basic_prefix_cmd (name, theclass, set_doc,
set_subcommands_list, 0,
set_list);
cmds.show = add_show_prefix_cmd (name, theclass, show_doc,
show_subcommands_list, 0,
show_list);
return cmds;
}
/* Like ADD_PREFIX_CMD but sets the suppress_notification pointer on the
new command list element. */
struct cmd_list_element *
add_prefix_cmd_suppress_notification
(const char *name, enum command_class theclass,
cmd_simple_func_ftype *fun,
const char *doc, struct cmd_list_element **subcommands,
int allow_unknown, struct cmd_list_element **list,
bool *suppress_notification)
{
struct cmd_list_element *element
= add_prefix_cmd (name, theclass, fun, doc, subcommands,
allow_unknown, list);
element->suppress_notification = suppress_notification;
return element;
}
/* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
struct cmd_list_element *
add_abbrev_prefix_cmd (const char *name, enum command_class theclass,
cmd_simple_func_ftype *fun, const char *doc,
struct cmd_list_element **subcommands,
int allow_unknown, struct cmd_list_element **list)
{
struct cmd_list_element *c = add_cmd (name, theclass, fun, doc, list);
c->subcommands = subcommands;
c->allow_unknown = allow_unknown;
c->abbrev_flag = 1;
return c;
}
/* This is an empty "simple func". */
void
not_just_help_class_command (const char *args, int from_tty)
{
}
/* This is an empty cmd func. */
static void
empty_func (const char *args, int from_tty, cmd_list_element *c)
{
}
/* Add element named NAME to command list LIST (the list for set/show
or some sublist thereof).
TYPE is set_cmd or show_cmd.
THECLASS is as in add_cmd.
VAR_TYPE is the kind of thing we are setting.
EXTRA_LITERALS if non-NULL define extra literals to be accepted in lieu of
a number for integer variables.
ARGS is a pre-validated type-erased reference to the variable being
controlled by this command.
DOC is the documentation string. */
static struct cmd_list_element *
add_set_or_show_cmd (const char *name,
enum cmd_types type,
enum command_class theclass,
var_types var_type,
const literal_def *extra_literals,
const setting::erased_args &arg,
const char *doc,
struct cmd_list_element **list)
{
struct cmd_list_element *c = add_cmd (name, theclass, doc, list);
gdb_assert (type == set_cmd || type == show_cmd);
c->type = type;
c->var.emplace (var_type, extra_literals, arg);
/* This needs to be something besides NULL so that this isn't
treated as a help class. */
c->func = empty_func;
return c;
}
/* Add element named NAME to both command lists SET_LIST and SHOW_LIST.
THECLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
setting. EXTRA_LITERALS if non-NULL define extra literals to be
accepted in lieu of a number for integer variables. ARGS is a
pre-validated type-erased reference to the variable being controlled
by this command. SET_FUNC and SHOW_FUNC are the callback functions
(if non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation
strings.
Return the newly created set and show commands. */
static set_show_commands
add_setshow_cmd_full_erased (const char *name,
enum command_class theclass,
var_types var_type,
const literal_def *extra_literals,
const setting::erased_args &args,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_func_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
struct cmd_list_element *set;
struct cmd_list_element *show;
gdb::unique_xmalloc_ptr<char> full_set_doc;
gdb::unique_xmalloc_ptr<char> full_show_doc;
if (help_doc != NULL)
{
full_set_doc = xstrprintf ("%s\n%s", set_doc, help_doc);
full_show_doc = xstrprintf ("%s\n%s", show_doc, help_doc);
}
else
{
full_set_doc = make_unique_xstrdup (set_doc);
full_show_doc = make_unique_xstrdup (show_doc);
}
set = add_set_or_show_cmd (name, set_cmd, theclass, var_type,
extra_literals, args,
full_set_doc.release (), set_list);
set->doc_allocated = 1;
if (set_func != NULL)
set->func = set_func;
show = add_set_or_show_cmd (name, show_cmd, theclass, var_type,
extra_literals, args,
full_show_doc.release (), show_list);
show->doc_allocated = 1;
show->show_value_func = show_func;
/* Disable the default symbol completer. Doesn't make much sense
for the "show" command to complete on anything. */
set_cmd_completer (show, nullptr);
return {set, show};
}
/* Completes on integer commands that support extra literals. */
static void
integer_literals_completer (struct cmd_list_element *c,
completion_tracker &tracker,
const char *text, const char *word)
{
const literal_def *extra_literals = c->var->extra_literals ();
if (*text == '\0')
{
tracker.add_completion (make_unique_xstrdup ("NUMBER"));
for (const literal_def *l = extra_literals;
l->literal != nullptr;
l++)
tracker.add_completion (make_unique_xstrdup (l->literal));
}
else
for (const literal_def *l = extra_literals;
l->literal != nullptr;
l++)
if (startswith (l->literal, text))
tracker.add_completion (make_unique_xstrdup (l->literal));
}
/* Add element named NAME to both command lists SET_LIST and SHOW_LIST.
THECLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
setting. VAR is address of the variable being controlled by this
command. EXTRA_LITERALS if non-NULL define extra literals to be
accepted in lieu of a number for integer variables. If nullptr is
given as VAR, then both SET_SETTING_FUNC and GET_SETTING_FUNC must
be provided. SET_SETTING_FUNC and GET_SETTING_FUNC are callbacks
used to access and modify the underlying property, whatever its
storage is. SET_FUNC and SHOW_FUNC are the callback functions
(if non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the
documentation strings.
Return the newly created set and show commands. */
template<typename T>
static set_show_commands
add_setshow_cmd_full (const char *name,
enum command_class theclass,
var_types var_type, T *var,
const literal_def *extra_literals,
const char *set_doc, const char *show_doc,
const char *help_doc,
typename setting_func_types<T>::set set_setting_func,
typename setting_func_types<T>::get get_setting_func,
cmd_func_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
auto erased_args
= setting::erase_args (var_type, var,
set_setting_func, get_setting_func);
auto cmds = add_setshow_cmd_full_erased (name,
theclass,
var_type, extra_literals,
erased_args,
set_doc, show_doc,
help_doc,
set_func,
show_func,
set_list,
show_list);
if (extra_literals != nullptr)
set_cmd_completer (cmds.set, integer_literals_completer);
return cmds;
}
/* Same as above but omitting EXTRA_LITERALS. */
template<typename T>
static set_show_commands
add_setshow_cmd_full (const char *name,
enum command_class theclass,
var_types var_type, T *var,
const char *set_doc, const char *show_doc,
const char *help_doc,
typename setting_func_types<T>::set set_setting_func,
typename setting_func_types<T>::get get_setting_func,
cmd_func_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
return add_setshow_cmd_full (name, theclass, var_type, var, nullptr,
set_doc, show_doc, help_doc,
set_setting_func, get_setting_func,
set_func, show_func, set_list, show_list);
}
/* Add element named NAME to command list LIST (the list for set or
some sublist thereof). THECLASS is as in add_cmd. ENUMLIST is a list
of strings which may follow NAME. VAR is address of the variable
which will contain the matching string (from ENUMLIST). */
set_show_commands
add_setshow_enum_cmd (const char *name,
enum command_class theclass,
const char *const *enumlist,
const char **var,
const char *set_doc,
const char *show_doc,
const char *help_doc,
cmd_func_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
/* We require *VAR to be initialized before this call, and
furthermore it must be == to one of the values in ENUMLIST. */
gdb_assert (var != nullptr && *var != nullptr);
for (int i = 0; ; ++i)
{
gdb_assert (enumlist[i] != nullptr);
if (*var == enumlist[i])
break;
}
set_show_commands commands
= add_setshow_cmd_full<const char *> (name, theclass, var_enum, var,
set_doc, show_doc, help_doc,
nullptr, nullptr, set_func,
show_func, set_list, show_list);
commands.set->enums = enumlist;
return commands;
}
/* Same as above but using a getter and a setter function instead of a pointer
to a global storage buffer. */
set_show_commands
add_setshow_enum_cmd (const char *name, command_class theclass,
const char *const *enumlist, const char *set_doc,
const char *show_doc, const char *help_doc,
setting_func_types<const char *>::set set_func,
setting_func_types<const char *>::get get_func,
show_value_ftype *show_func,
cmd_list_element **set_list,
cmd_list_element **show_list)
{
auto cmds = add_setshow_cmd_full<const char *> (name, theclass, var_enum,
nullptr, set_doc, show_doc,
help_doc, set_func, get_func,
nullptr, show_func, set_list,
show_list);
cmds.set->enums = enumlist;
return cmds;
}
/* See cli-decode.h. */
void
complete_on_color (completion_tracker &tracker,
const char *text, const char *word)
{
complete_on_enum (tracker, ui_file_style::basic_color_enums.data (),
text, word);
if (*text == '\0')
{
/* Convenience to let the user know what the option
can accept. Note there's no common prefix between
the strings on purpose, so that complete_on_enum doesn't do
a partial match. */
tracker.add_completion (make_unique_xstrdup ("NUMBER"));
tracker.add_completion (make_unique_xstrdup ("#RRGGBB"));
}
}
/* Completer used in color commands. */
static void
color_completer (struct cmd_list_element *ignore,
completion_tracker &tracker,
const char *text, const char *word)
{
complete_on_color (tracker, text, word);
}
/* Add element named NAME to command list LIST (the list for set or
some sublist thereof). CLASS is as in add_cmd. VAR is address
of the variable which will contain the color. */
set_show_commands
add_setshow_color_cmd (const char *name,
enum command_class theclass,
ui_file_style::color *var,
const char *set_doc,
const char *show_doc,
const char *help_doc,
cmd_func_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
set_show_commands commands = add_setshow_cmd_full<ui_file_style::color>
(name, theclass, var_color, var,
set_doc, show_doc, help_doc,
nullptr, nullptr, set_func, show_func,
set_list, show_list);
set_cmd_completer (commands.set, color_completer);
return commands;
}
/* Same as above but using a getter and a setter function instead of a pointer
to a global storage buffer. */
set_show_commands
add_setshow_color_cmd (const char *name, command_class theclass,
const char *set_doc, const char *show_doc,
const char *help_doc,
setting_func_types<ui_file_style::color>::set set_func,
setting_func_types<ui_file_style::color>::get get_func,
show_value_ftype *show_func,
cmd_list_element **set_list,
cmd_list_element **show_list)
{
auto cmds = add_setshow_cmd_full<ui_file_style::color>
(name, theclass, var_color, nullptr,
set_doc, show_doc, help_doc,
set_func, get_func, nullptr, show_func,
set_list, show_list);
set_cmd_completer (cmds.set, color_completer);
return cmds;
}
/* See cli-decode.h. */
const char * const auto_boolean_enums[] = { "on", "off", "auto", NULL };
/* Add an auto-boolean command named NAME to both the set and show
command list lists. THECLASS is as in add_cmd. VAR is address of the
variable which will contain the value. DOC is the documentation
string. FUNC is the corresponding callback. */
set_show_commands
add_setshow_auto_boolean_cmd (const char *name,
enum command_class theclass,
enum auto_boolean *var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_func_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
set_show_commands commands
= add_setshow_cmd_full<enum auto_boolean> (name, theclass, var_auto_boolean,
var, set_doc, show_doc, help_doc,
nullptr, nullptr, set_func,
show_func, set_list, show_list);
commands.set->enums = auto_boolean_enums;
return commands;
}
/* Same as above but using a getter and a setter function instead of a pointer
to a global storage buffer. */
set_show_commands
add_setshow_auto_boolean_cmd (const char *name, command_class theclass,
const char *set_doc, const char *show_doc,
const char *help_doc,
setting_func_types<enum auto_boolean>::set set_func,
setting_func_types<enum auto_boolean>::get get_func,
show_value_ftype *show_func,
cmd_list_element **set_list,
cmd_list_element **show_list)
{
auto cmds = add_setshow_cmd_full<enum auto_boolean> (name, theclass,
var_auto_boolean,
nullptr, set_doc,
show_doc, help_doc,
set_func, get_func,
nullptr, show_func,
set_list, show_list);
cmds.set->enums = auto_boolean_enums;
return cmds;
}
/* See cli-decode.h. */
const char * const boolean_enums[] = { "on", "off", NULL };
/* Add element named NAME to both the set and show command LISTs (the
list for set/show or some sublist thereof). THECLASS is as in
add_cmd. VAR is address of the variable which will contain the
value. SET_DOC and SHOW_DOC are the documentation strings.
Returns the new command element. */
set_show_commands
add_setshow_boolean_cmd (const char *name, enum command_class theclass, bool *var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_func_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
set_show_commands commands
= add_setshow_cmd_full<bool> (name, theclass, var_boolean, var,
set_doc, show_doc, help_doc,
nullptr, nullptr, set_func, show_func,
set_list, show_list);
commands.set->enums = boolean_enums;
return commands;
}
/* Same as above but using a getter and a setter function instead of a pointer
to a global storage buffer. */
set_show_commands
add_setshow_boolean_cmd (const char *name, command_class theclass,
const char *set_doc, const char *show_doc,
const char *help_doc,
setting_func_types<bool>::set set_func,
setting_func_types<bool>::get get_func,
show_value_ftype *show_func,
cmd_list_element **set_list,
cmd_list_element **show_list)
{
auto cmds = add_setshow_cmd_full<bool> (name, theclass, var_boolean, nullptr,
set_doc, show_doc, help_doc,
set_func, get_func, nullptr,
show_func, set_list, show_list);
cmds.set->enums = boolean_enums;
return cmds;
}
/* Add element named NAME to both the set and show command LISTs (the
list for set/show or some sublist thereof). */
set_show_commands
add_setshow_filename_cmd (const char *name, enum command_class theclass,
std::string *var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_func_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
set_show_commands commands
= add_setshow_cmd_full<std::string> (name, theclass, var_filename, var,
set_doc, show_doc, help_doc,
nullptr, nullptr, set_func,
show_func, set_list, show_list);
set_cmd_completer (commands.set, deprecated_filename_completer);
return commands;
}
/* Same as above but using a getter and a setter function instead of a pointer
to a global storage buffer. */
set_show_commands
add_setshow_filename_cmd (const char *name, command_class theclass,
const char *set_doc, const char *show_doc,
const char *help_doc,
setting_func_types<std::string>::set set_func,
setting_func_types<std::string>::get get_func,
show_value_ftype *show_func,
cmd_list_element **set_list,
cmd_list_element **show_list)
{
auto cmds = add_setshow_cmd_full<std::string> (name, theclass, var_filename,
nullptr, set_doc, show_doc,
help_doc, set_func, get_func,
nullptr, show_func, set_list,
show_list);
set_cmd_completer (cmds.set, deprecated_filename_completer);
return cmds;
}
/* Add element named NAME to both the set and show command LISTs (the
list for set/show or some sublist thereof). */
set_show_commands
add_setshow_string_cmd (const char *name, enum command_class theclass,
std::string *var,