1*fcaf7f86SDimitry Andric //===-- CommandOptionArgumentTable.cpp ------------------------------------===//
2*fcaf7f86SDimitry Andric //
3*fcaf7f86SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*fcaf7f86SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*fcaf7f86SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*fcaf7f86SDimitry Andric //
7*fcaf7f86SDimitry Andric //===----------------------------------------------------------------------===//
8*fcaf7f86SDimitry Andric
9*fcaf7f86SDimitry Andric #include "lldb/Interpreter/CommandOptionArgumentTable.h"
10*fcaf7f86SDimitry Andric #include "lldb/DataFormatters/FormatManager.h"
11*fcaf7f86SDimitry Andric #include "lldb/Target/Language.h"
12*fcaf7f86SDimitry Andric #include "lldb/Utility/StreamString.h"
13*fcaf7f86SDimitry Andric
14*fcaf7f86SDimitry Andric using namespace lldb;
15*fcaf7f86SDimitry Andric using namespace lldb_private;
16*fcaf7f86SDimitry Andric
17*fcaf7f86SDimitry Andric namespace lldb_private {
RegisterNameHelpTextCallback()18*fcaf7f86SDimitry Andric llvm::StringRef RegisterNameHelpTextCallback() {
19*fcaf7f86SDimitry Andric return "Register names can be specified using the architecture specific "
20*fcaf7f86SDimitry Andric "names. "
21*fcaf7f86SDimitry Andric "They can also be specified using generic names. Not all generic "
22*fcaf7f86SDimitry Andric "entities have "
23*fcaf7f86SDimitry Andric "registers backing them on all architectures. When they don't the "
24*fcaf7f86SDimitry Andric "generic name "
25*fcaf7f86SDimitry Andric "will return an error.\n"
26*fcaf7f86SDimitry Andric "The generic names defined in lldb are:\n"
27*fcaf7f86SDimitry Andric "\n"
28*fcaf7f86SDimitry Andric "pc - program counter register\n"
29*fcaf7f86SDimitry Andric "ra - return address register\n"
30*fcaf7f86SDimitry Andric "fp - frame pointer register\n"
31*fcaf7f86SDimitry Andric "sp - stack pointer register\n"
32*fcaf7f86SDimitry Andric "flags - the flags register\n"
33*fcaf7f86SDimitry Andric "arg{1-6} - integer argument passing registers.\n";
34*fcaf7f86SDimitry Andric }
35*fcaf7f86SDimitry Andric
BreakpointIDHelpTextCallback()36*fcaf7f86SDimitry Andric llvm::StringRef BreakpointIDHelpTextCallback() {
37*fcaf7f86SDimitry Andric return "Breakpoints are identified using major and minor numbers; the major "
38*fcaf7f86SDimitry Andric "number corresponds to the single entity that was created with a "
39*fcaf7f86SDimitry Andric "'breakpoint "
40*fcaf7f86SDimitry Andric "set' command; the minor numbers correspond to all the locations that "
41*fcaf7f86SDimitry Andric "were "
42*fcaf7f86SDimitry Andric "actually found/set based on the major breakpoint. A full breakpoint "
43*fcaf7f86SDimitry Andric "ID might "
44*fcaf7f86SDimitry Andric "look like 3.14, meaning the 14th location set for the 3rd "
45*fcaf7f86SDimitry Andric "breakpoint. You "
46*fcaf7f86SDimitry Andric "can specify all the locations of a breakpoint by just indicating the "
47*fcaf7f86SDimitry Andric "major "
48*fcaf7f86SDimitry Andric "breakpoint number. A valid breakpoint ID consists either of just the "
49*fcaf7f86SDimitry Andric "major "
50*fcaf7f86SDimitry Andric "number, or the major number followed by a dot and the location "
51*fcaf7f86SDimitry Andric "number (e.g. "
52*fcaf7f86SDimitry Andric "3 or 3.2 could both be valid breakpoint IDs.)";
53*fcaf7f86SDimitry Andric }
54*fcaf7f86SDimitry Andric
BreakpointIDRangeHelpTextCallback()55*fcaf7f86SDimitry Andric llvm::StringRef BreakpointIDRangeHelpTextCallback() {
56*fcaf7f86SDimitry Andric return "A 'breakpoint ID list' is a manner of specifying multiple "
57*fcaf7f86SDimitry Andric "breakpoints. "
58*fcaf7f86SDimitry Andric "This can be done through several mechanisms. The easiest way is to "
59*fcaf7f86SDimitry Andric "just "
60*fcaf7f86SDimitry Andric "enter a space-separated list of breakpoint IDs. To specify all the "
61*fcaf7f86SDimitry Andric "breakpoint locations under a major breakpoint, you can use the major "
62*fcaf7f86SDimitry Andric "breakpoint number followed by '.*', eg. '5.*' means all the "
63*fcaf7f86SDimitry Andric "locations under "
64*fcaf7f86SDimitry Andric "breakpoint 5. You can also indicate a range of breakpoints by using "
65*fcaf7f86SDimitry Andric "<start-bp-id> - <end-bp-id>. The start-bp-id and end-bp-id for a "
66*fcaf7f86SDimitry Andric "range can "
67*fcaf7f86SDimitry Andric "be any valid breakpoint IDs. It is not legal, however, to specify a "
68*fcaf7f86SDimitry Andric "range "
69*fcaf7f86SDimitry Andric "using specific locations that cross major breakpoint numbers. I.e. "
70*fcaf7f86SDimitry Andric "3.2 - 3.7"
71*fcaf7f86SDimitry Andric " is legal; 2 - 5 is legal; but 3.2 - 4.4 is not legal.";
72*fcaf7f86SDimitry Andric }
73*fcaf7f86SDimitry Andric
BreakpointNameHelpTextCallback()74*fcaf7f86SDimitry Andric llvm::StringRef BreakpointNameHelpTextCallback() {
75*fcaf7f86SDimitry Andric return "A name that can be added to a breakpoint when it is created, or "
76*fcaf7f86SDimitry Andric "later "
77*fcaf7f86SDimitry Andric "on with the \"breakpoint name add\" command. "
78*fcaf7f86SDimitry Andric "Breakpoint names can be used to specify breakpoints in all the "
79*fcaf7f86SDimitry Andric "places breakpoint IDs "
80*fcaf7f86SDimitry Andric "and breakpoint ID ranges can be used. As such they provide a "
81*fcaf7f86SDimitry Andric "convenient way to group breakpoints, "
82*fcaf7f86SDimitry Andric "and to operate on breakpoints you create without having to track the "
83*fcaf7f86SDimitry Andric "breakpoint number. "
84*fcaf7f86SDimitry Andric "Note, the attributes you set when using a breakpoint name in a "
85*fcaf7f86SDimitry Andric "breakpoint command don't "
86*fcaf7f86SDimitry Andric "adhere to the name, but instead are set individually on all the "
87*fcaf7f86SDimitry Andric "breakpoints currently tagged with that "
88*fcaf7f86SDimitry Andric "name. Future breakpoints "
89*fcaf7f86SDimitry Andric "tagged with that name will not pick up the attributes previously "
90*fcaf7f86SDimitry Andric "given using that name. "
91*fcaf7f86SDimitry Andric "In order to distinguish breakpoint names from breakpoint IDs and "
92*fcaf7f86SDimitry Andric "ranges, "
93*fcaf7f86SDimitry Andric "names must start with a letter from a-z or A-Z and cannot contain "
94*fcaf7f86SDimitry Andric "spaces, \".\" or \"-\". "
95*fcaf7f86SDimitry Andric "Also, breakpoint names can only be applied to breakpoints, not to "
96*fcaf7f86SDimitry Andric "breakpoint locations.";
97*fcaf7f86SDimitry Andric }
98*fcaf7f86SDimitry Andric
GDBFormatHelpTextCallback()99*fcaf7f86SDimitry Andric llvm::StringRef GDBFormatHelpTextCallback() {
100*fcaf7f86SDimitry Andric return "A GDB format consists of a repeat count, a format letter and a size "
101*fcaf7f86SDimitry Andric "letter. "
102*fcaf7f86SDimitry Andric "The repeat count is optional and defaults to 1. The format letter is "
103*fcaf7f86SDimitry Andric "optional "
104*fcaf7f86SDimitry Andric "and defaults to the previous format that was used. The size letter "
105*fcaf7f86SDimitry Andric "is optional "
106*fcaf7f86SDimitry Andric "and defaults to the previous size that was used.\n"
107*fcaf7f86SDimitry Andric "\n"
108*fcaf7f86SDimitry Andric "Format letters include:\n"
109*fcaf7f86SDimitry Andric "o - octal\n"
110*fcaf7f86SDimitry Andric "x - hexadecimal\n"
111*fcaf7f86SDimitry Andric "d - decimal\n"
112*fcaf7f86SDimitry Andric "u - unsigned decimal\n"
113*fcaf7f86SDimitry Andric "t - binary\n"
114*fcaf7f86SDimitry Andric "f - float\n"
115*fcaf7f86SDimitry Andric "a - address\n"
116*fcaf7f86SDimitry Andric "i - instruction\n"
117*fcaf7f86SDimitry Andric "c - char\n"
118*fcaf7f86SDimitry Andric "s - string\n"
119*fcaf7f86SDimitry Andric "T - OSType\n"
120*fcaf7f86SDimitry Andric "A - float as hex\n"
121*fcaf7f86SDimitry Andric "\n"
122*fcaf7f86SDimitry Andric "Size letters include:\n"
123*fcaf7f86SDimitry Andric "b - 1 byte (byte)\n"
124*fcaf7f86SDimitry Andric "h - 2 bytes (halfword)\n"
125*fcaf7f86SDimitry Andric "w - 4 bytes (word)\n"
126*fcaf7f86SDimitry Andric "g - 8 bytes (giant)\n"
127*fcaf7f86SDimitry Andric "\n"
128*fcaf7f86SDimitry Andric "Example formats:\n"
129*fcaf7f86SDimitry Andric "32xb - show 32 1 byte hexadecimal integer values\n"
130*fcaf7f86SDimitry Andric "16xh - show 16 2 byte hexadecimal integer values\n"
131*fcaf7f86SDimitry Andric "64 - show 64 2 byte hexadecimal integer values (format and size "
132*fcaf7f86SDimitry Andric "from the last format)\n"
133*fcaf7f86SDimitry Andric "dw - show 1 4 byte decimal integer value\n";
134*fcaf7f86SDimitry Andric }
135*fcaf7f86SDimitry Andric
FormatHelpTextCallback()136*fcaf7f86SDimitry Andric llvm::StringRef FormatHelpTextCallback() {
137*fcaf7f86SDimitry Andric static std::string help_text;
138*fcaf7f86SDimitry Andric
139*fcaf7f86SDimitry Andric if (!help_text.empty())
140*fcaf7f86SDimitry Andric return help_text;
141*fcaf7f86SDimitry Andric
142*fcaf7f86SDimitry Andric StreamString sstr;
143*fcaf7f86SDimitry Andric sstr << "One of the format names (or one-character names) that can be used "
144*fcaf7f86SDimitry Andric "to show a variable's value:\n";
145*fcaf7f86SDimitry Andric for (Format f = eFormatDefault; f < kNumFormats; f = Format(f + 1)) {
146*fcaf7f86SDimitry Andric if (f != eFormatDefault)
147*fcaf7f86SDimitry Andric sstr.PutChar('\n');
148*fcaf7f86SDimitry Andric
149*fcaf7f86SDimitry Andric char format_char = FormatManager::GetFormatAsFormatChar(f);
150*fcaf7f86SDimitry Andric if (format_char)
151*fcaf7f86SDimitry Andric sstr.Printf("'%c' or ", format_char);
152*fcaf7f86SDimitry Andric
153*fcaf7f86SDimitry Andric sstr.Printf("\"%s\"", FormatManager::GetFormatAsCString(f));
154*fcaf7f86SDimitry Andric }
155*fcaf7f86SDimitry Andric
156*fcaf7f86SDimitry Andric sstr.Flush();
157*fcaf7f86SDimitry Andric
158*fcaf7f86SDimitry Andric help_text = std::string(sstr.GetString());
159*fcaf7f86SDimitry Andric
160*fcaf7f86SDimitry Andric return help_text;
161*fcaf7f86SDimitry Andric }
162*fcaf7f86SDimitry Andric
LanguageTypeHelpTextCallback()163*fcaf7f86SDimitry Andric llvm::StringRef LanguageTypeHelpTextCallback() {
164*fcaf7f86SDimitry Andric static std::string help_text;
165*fcaf7f86SDimitry Andric
166*fcaf7f86SDimitry Andric if (!help_text.empty())
167*fcaf7f86SDimitry Andric return help_text;
168*fcaf7f86SDimitry Andric
169*fcaf7f86SDimitry Andric StreamString sstr;
170*fcaf7f86SDimitry Andric sstr << "One of the following languages:\n";
171*fcaf7f86SDimitry Andric
172*fcaf7f86SDimitry Andric Language::PrintAllLanguages(sstr, " ", "\n");
173*fcaf7f86SDimitry Andric
174*fcaf7f86SDimitry Andric sstr.Flush();
175*fcaf7f86SDimitry Andric
176*fcaf7f86SDimitry Andric help_text = std::string(sstr.GetString());
177*fcaf7f86SDimitry Andric
178*fcaf7f86SDimitry Andric return help_text;
179*fcaf7f86SDimitry Andric }
180*fcaf7f86SDimitry Andric
SummaryStringHelpTextCallback()181*fcaf7f86SDimitry Andric llvm::StringRef SummaryStringHelpTextCallback() {
182*fcaf7f86SDimitry Andric return "A summary string is a way to extract information from variables in "
183*fcaf7f86SDimitry Andric "order to present them using a summary.\n"
184*fcaf7f86SDimitry Andric "Summary strings contain static text, variables, scopes and control "
185*fcaf7f86SDimitry Andric "sequences:\n"
186*fcaf7f86SDimitry Andric " - Static text can be any sequence of non-special characters, i.e. "
187*fcaf7f86SDimitry Andric "anything but '{', '}', '$', or '\\'.\n"
188*fcaf7f86SDimitry Andric " - Variables are sequences of characters beginning with ${, ending "
189*fcaf7f86SDimitry Andric "with } and that contain symbols in the format described below.\n"
190*fcaf7f86SDimitry Andric " - Scopes are any sequence of text between { and }. Anything "
191*fcaf7f86SDimitry Andric "included in a scope will only appear in the output summary if there "
192*fcaf7f86SDimitry Andric "were no errors.\n"
193*fcaf7f86SDimitry Andric " - Control sequences are the usual C/C++ '\\a', '\\n', ..., plus "
194*fcaf7f86SDimitry Andric "'\\$', '\\{' and '\\}'.\n"
195*fcaf7f86SDimitry Andric "A summary string works by copying static text verbatim, turning "
196*fcaf7f86SDimitry Andric "control sequences into their character counterpart, expanding "
197*fcaf7f86SDimitry Andric "variables and trying to expand scopes.\n"
198*fcaf7f86SDimitry Andric "A variable is expanded by giving it a value other than its textual "
199*fcaf7f86SDimitry Andric "representation, and the way this is done depends on what comes after "
200*fcaf7f86SDimitry Andric "the ${ marker.\n"
201*fcaf7f86SDimitry Andric "The most common sequence if ${var followed by an expression path, "
202*fcaf7f86SDimitry Andric "which is the text one would type to access a member of an aggregate "
203*fcaf7f86SDimitry Andric "types, given a variable of that type"
204*fcaf7f86SDimitry Andric " (e.g. if type T has a member named x, which has a member named y, "
205*fcaf7f86SDimitry Andric "and if t is of type T, the expression path would be .x.y and the way "
206*fcaf7f86SDimitry Andric "to fit that into a summary string would be"
207*fcaf7f86SDimitry Andric " ${var.x.y}). You can also use ${*var followed by an expression path "
208*fcaf7f86SDimitry Andric "and in that case the object referred by the path will be "
209*fcaf7f86SDimitry Andric "dereferenced before being displayed."
210*fcaf7f86SDimitry Andric " If the object is not a pointer, doing so will cause an error. For "
211*fcaf7f86SDimitry Andric "additional details on expression paths, you can type 'help "
212*fcaf7f86SDimitry Andric "expr-path'. \n"
213*fcaf7f86SDimitry Andric "By default, summary strings attempt to display the summary for any "
214*fcaf7f86SDimitry Andric "variable they reference, and if that fails the value. If neither can "
215*fcaf7f86SDimitry Andric "be shown, nothing is displayed."
216*fcaf7f86SDimitry Andric "In a summary string, you can also use an array index [n], or a "
217*fcaf7f86SDimitry Andric "slice-like range [n-m]. This can have two different meanings "
218*fcaf7f86SDimitry Andric "depending on what kind of object the expression"
219*fcaf7f86SDimitry Andric " path refers to:\n"
220*fcaf7f86SDimitry Andric " - if it is a scalar type (any basic type like int, float, ...) the "
221*fcaf7f86SDimitry Andric "expression is a bitfield, i.e. the bits indicated by the indexing "
222*fcaf7f86SDimitry Andric "operator are extracted out of the number"
223*fcaf7f86SDimitry Andric " and displayed as an individual variable\n"
224*fcaf7f86SDimitry Andric " - if it is an array or pointer the array items indicated by the "
225*fcaf7f86SDimitry Andric "indexing operator are shown as the result of the variable. if the "
226*fcaf7f86SDimitry Andric "expression is an array, real array items are"
227*fcaf7f86SDimitry Andric " printed; if it is a pointer, the pointer-as-array syntax is used to "
228*fcaf7f86SDimitry Andric "obtain the values (this means, the latter case can have no range "
229*fcaf7f86SDimitry Andric "checking)\n"
230*fcaf7f86SDimitry Andric "If you are trying to display an array for which the size is known, "
231*fcaf7f86SDimitry Andric "you can also use [] instead of giving an exact range. This has the "
232*fcaf7f86SDimitry Andric "effect of showing items 0 thru size - 1.\n"
233*fcaf7f86SDimitry Andric "Additionally, a variable can contain an (optional) format code, as "
234*fcaf7f86SDimitry Andric "in ${var.x.y%code}, where code can be any of the valid formats "
235*fcaf7f86SDimitry Andric "described in 'help format', or one of the"
236*fcaf7f86SDimitry Andric " special symbols only allowed as part of a variable:\n"
237*fcaf7f86SDimitry Andric " %V: show the value of the object by default\n"
238*fcaf7f86SDimitry Andric " %S: show the summary of the object by default\n"
239*fcaf7f86SDimitry Andric " %@: show the runtime-provided object description (for "
240*fcaf7f86SDimitry Andric "Objective-C, it calls NSPrintForDebugger; for C/C++ it does "
241*fcaf7f86SDimitry Andric "nothing)\n"
242*fcaf7f86SDimitry Andric " %L: show the location of the object (memory address or a "
243*fcaf7f86SDimitry Andric "register name)\n"
244*fcaf7f86SDimitry Andric " %#: show the number of children of the object\n"
245*fcaf7f86SDimitry Andric " %T: show the type of the object\n"
246*fcaf7f86SDimitry Andric "Another variable that you can use in summary strings is ${svar . "
247*fcaf7f86SDimitry Andric "This sequence works exactly like ${var, including the fact that "
248*fcaf7f86SDimitry Andric "${*svar is an allowed sequence, but uses"
249*fcaf7f86SDimitry Andric " the object's synthetic children provider instead of the actual "
250*fcaf7f86SDimitry Andric "objects. For instance, if you are using STL synthetic children "
251*fcaf7f86SDimitry Andric "providers, the following summary string would"
252*fcaf7f86SDimitry Andric " count the number of actual elements stored in an std::list:\n"
253*fcaf7f86SDimitry Andric "type summary add -s \"${svar%#}\" -x \"std::list<\"";
254*fcaf7f86SDimitry Andric }
255*fcaf7f86SDimitry Andric
ExprPathHelpTextCallback()256*fcaf7f86SDimitry Andric llvm::StringRef ExprPathHelpTextCallback() {
257*fcaf7f86SDimitry Andric return "An expression path is the sequence of symbols that is used in C/C++ "
258*fcaf7f86SDimitry Andric "to access a member variable of an aggregate object (class).\n"
259*fcaf7f86SDimitry Andric "For instance, given a class:\n"
260*fcaf7f86SDimitry Andric " class foo {\n"
261*fcaf7f86SDimitry Andric " int a;\n"
262*fcaf7f86SDimitry Andric " int b; .\n"
263*fcaf7f86SDimitry Andric " foo* next;\n"
264*fcaf7f86SDimitry Andric " };\n"
265*fcaf7f86SDimitry Andric "the expression to read item b in the item pointed to by next for foo "
266*fcaf7f86SDimitry Andric "aFoo would be aFoo.next->b.\n"
267*fcaf7f86SDimitry Andric "Given that aFoo could just be any object of type foo, the string "
268*fcaf7f86SDimitry Andric "'.next->b' is the expression path, because it can be attached to any "
269*fcaf7f86SDimitry Andric "foo instance to achieve the effect.\n"
270*fcaf7f86SDimitry Andric "Expression paths in LLDB include dot (.) and arrow (->) operators, "
271*fcaf7f86SDimitry Andric "and most commands using expression paths have ways to also accept "
272*fcaf7f86SDimitry Andric "the star (*) operator.\n"
273*fcaf7f86SDimitry Andric "The meaning of these operators is the same as the usual one given to "
274*fcaf7f86SDimitry Andric "them by the C/C++ standards.\n"
275*fcaf7f86SDimitry Andric "LLDB also has support for indexing ([ ]) in expression paths, and "
276*fcaf7f86SDimitry Andric "extends the traditional meaning of the square brackets operator to "
277*fcaf7f86SDimitry Andric "allow bitfield extraction:\n"
278*fcaf7f86SDimitry Andric "for objects of native types (int, float, char, ...) saying '[n-m]' "
279*fcaf7f86SDimitry Andric "as an expression path (where n and m are any positive integers, e.g. "
280*fcaf7f86SDimitry Andric "[3-5]) causes LLDB to extract"
281*fcaf7f86SDimitry Andric " bits n thru m from the value of the variable. If n == m, [n] is "
282*fcaf7f86SDimitry Andric "also allowed as a shortcut syntax. For arrays and pointers, "
283*fcaf7f86SDimitry Andric "expression paths can only contain one index"
284*fcaf7f86SDimitry Andric " and the meaning of the operation is the same as the one defined by "
285*fcaf7f86SDimitry Andric "C/C++ (item extraction). Some commands extend bitfield-like syntax "
286*fcaf7f86SDimitry Andric "for arrays and pointers with the"
287*fcaf7f86SDimitry Andric " meaning of array slicing (taking elements n thru m inside the array "
288*fcaf7f86SDimitry Andric "or pointed-to memory).";
289*fcaf7f86SDimitry Andric }
290*fcaf7f86SDimitry Andric
arch_helper()291*fcaf7f86SDimitry Andric llvm::StringRef arch_helper() {
292*fcaf7f86SDimitry Andric static StreamString g_archs_help;
293*fcaf7f86SDimitry Andric if (g_archs_help.Empty()) {
294*fcaf7f86SDimitry Andric StringList archs;
295*fcaf7f86SDimitry Andric
296*fcaf7f86SDimitry Andric ArchSpec::ListSupportedArchNames(archs);
297*fcaf7f86SDimitry Andric g_archs_help.Printf("These are the supported architecture names:\n");
298*fcaf7f86SDimitry Andric archs.Join("\n", g_archs_help);
299*fcaf7f86SDimitry Andric }
300*fcaf7f86SDimitry Andric return g_archs_help.GetString();
301*fcaf7f86SDimitry Andric }
302*fcaf7f86SDimitry Andric
303*fcaf7f86SDimitry Andric template <int I> struct TableValidator : TableValidator<I + 1> {
304*fcaf7f86SDimitry Andric static_assert(
305*fcaf7f86SDimitry Andric g_argument_table[I].arg_type == I,
306*fcaf7f86SDimitry Andric "g_argument_table order doesn't match CommandArgumentType enumeration");
307*fcaf7f86SDimitry Andric };
308*fcaf7f86SDimitry Andric
309*fcaf7f86SDimitry Andric template <> struct TableValidator<eArgTypeLastArg> {};
310*fcaf7f86SDimitry Andric
311*fcaf7f86SDimitry Andric TableValidator<0> validator;
312*fcaf7f86SDimitry Andric
313*fcaf7f86SDimitry Andric } // namespace lldb_private
314