Skip to content

Commit 202adae

Browse files
committed
[lldb/Commands] Add support to auto-completion for user commands
This patch should allow the user to set specific auto-completion type for their custom commands. To do so, we had to hoist the `CompletionType` enum so the user can access it and add a new completion type flag to the CommandScriptAdd Command Object. So now, the user can specify which completion type will be used with their custom command, when they register it. This also makes the `crashlog` custom commands use disk-file completion type, to browse through the user file system and load the report. Differential Revision: https://reviews.llvm.org/D152011 Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent e2b11c2 commit 202adae

38 files changed

+497
-401
lines changed

lldb/docs/python_api_enums.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@ CommandArgumentType
875875
.. py:data:: eArgTypeColumnNum
876876
.. py:data:: eArgTypeModuleUUID
877877
.. py:data:: eArgTypeLastArg
878+
.. py:data:: eArgTypeCompletionType
878879
879880
.. _SymbolType:
880881

lldb/examples/python/crashlog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,10 +1494,10 @@ def should_run_in_interactive_mode(options, ci):
14941494

14951495
def __lldb_init_module(debugger, internal_dict):
14961496
debugger.HandleCommand(
1497-
"command script add -o -c lldb.macosx.crashlog.Symbolicate crashlog"
1497+
"command script add -o -c lldb.macosx.crashlog.Symbolicate -C disk-file crashlog"
14981498
)
14991499
debugger.HandleCommand(
1500-
"command script add -o -f lldb.macosx.crashlog.save_crashlog save_crashlog"
1500+
"command script add -o -f lldb.macosx.crashlog.save_crashlog -C disk-file save_crashlog"
15011501
)
15021502
print(
15031503
'"crashlog" and "save_crashlog" commands have been installed, use '

lldb/include/lldb/Interpreter/CommandCompletions.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,6 @@ namespace lldb_private {
2424
class TildeExpressionResolver;
2525
class CommandCompletions {
2626
public:
27-
enum CommonCompletionTypes {
28-
eNoCompletion = 0u,
29-
eSourceFileCompletion = (1u << 0),
30-
eDiskFileCompletion = (1u << 1),
31-
eDiskDirectoryCompletion = (1u << 2),
32-
eSymbolCompletion = (1u << 3),
33-
eModuleCompletion = (1u << 4),
34-
eSettingsNameCompletion = (1u << 5),
35-
ePlatformPluginCompletion = (1u << 6),
36-
eArchitectureCompletion = (1u << 7),
37-
eVariablePathCompletion = (1u << 8),
38-
eRegisterCompletion = (1u << 9),
39-
eBreakpointCompletion = (1u << 10),
40-
eProcessPluginCompletion = (1u << 11),
41-
eDisassemblyFlavorCompletion = (1u << 12),
42-
eTypeLanguageCompletion = (1u << 13),
43-
eFrameIndexCompletion = (1u << 14),
44-
eModuleUUIDCompletion = (1u << 15),
45-
eStopHookIDCompletion = (1u << 16),
46-
eThreadIndexCompletion = (1u << 17),
47-
eWatchPointIDCompletion = (1u << 18),
48-
eBreakpointNameCompletion = (1u << 19),
49-
eProcessIDCompletion = (1u << 20),
50-
eProcessNameCompletion = (1u << 21),
51-
eRemoteDiskFileCompletion = (1u << 22),
52-
eRemoteDiskDirectoryCompletion = (1u << 23),
53-
eTypeCategoryNameCompletion = (1u << 24),
54-
// This item serves two purposes. It is the last element in the enum, so
55-
// you can add custom enums starting from here in your Option class. Also
56-
// if you & in this bit the base code will not process the option.
57-
eCustomCompletion = (1u << 24)
58-
};
59-
6027
static bool InvokeCommonCompletionCallbacks(
6128
CommandInterpreter &interpreter, uint32_t completion_mask,
6229
lldb_private::CompletionRequest &request, SearchFilter *searcher);

lldb/include/lldb/Interpreter/CommandObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class CommandObject : public std::enable_shared_from_this<CommandObject> {
8282
struct ArgumentTableEntry {
8383
lldb::CommandArgumentType arg_type;
8484
const char *arg_name;
85-
CommandCompletions::CommonCompletionTypes completion_type;
85+
lldb::CompletionType completion_type;
8686
OptionEnumValues enum_values;
8787
ArgumentHelpCallback help_function;
8888
const char *help_text;

lldb/include/lldb/Interpreter/CommandOptionArgumentTable.h

Lines changed: 142 additions & 97 deletions
Large diffs are not rendered by default.

lldb/include/lldb/Interpreter/OptionValueFileColonLine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class OptionValueFileColonLine :
5252
FileSpec m_file_spec;
5353
uint32_t m_line_number = LLDB_INVALID_LINE_NUMBER;
5454
uint32_t m_column_number = LLDB_INVALID_COLUMN_NUMBER;
55-
uint32_t m_completion_mask = CommandCompletions::eSourceFileCompletion;
55+
uint32_t m_completion_mask = lldb::eSourceFileCompletion;
5656
};
5757

5858
} // namespace lldb_private

lldb/include/lldb/Interpreter/OptionValueFileSpec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class OptionValueFileSpec : public Cloneable<OptionValueFileSpec, OptionValue> {
7979
FileSpec m_default_value;
8080
lldb::DataBufferSP m_data_sp;
8181
llvm::sys::TimePoint<> m_data_mod_time;
82-
uint32_t m_completion_mask = CommandCompletions::eDiskFileCompletion;
82+
uint32_t m_completion_mask = lldb::eDiskFileCompletion;
8383
bool m_resolve;
8484
};
8585

lldb/include/lldb/Utility/OptionDefinition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct OptionDefinition {
3838
/// If not empty, an array of enum values.
3939
OptionEnumValues enum_values;
4040
/// The kind of completion for this option.
41-
/// Contains values of the CommandCompletions::CommonCompletionTypes enum.
41+
/// Contains values of the lldb::CompletionType enum.
4242
uint32_t completion_type;
4343
/// Type of argument this option takes.
4444
lldb::CommandArgumentType argument_type;

lldb/include/lldb/lldb-enumerations.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ enum CommandArgumentType {
637637
// BEGIN SWIFT
638638
eArgTypeBindGenTypeParamValue,
639639
// END SWIFT
640+
eArgTypeCompletionType,
640641
eArgTypeLastArg // Always keep this entry as the last entry in this
641642
// enumeration!!
642643
};
@@ -1267,6 +1268,39 @@ enum WatchpointValueKind {
12671268
eWatchPointValueKindExpression = 2,
12681269
};
12691270

1271+
enum CompletionType {
1272+
eNoCompletion = 0u,
1273+
eSourceFileCompletion = (1u << 0),
1274+
eDiskFileCompletion = (1u << 1),
1275+
eDiskDirectoryCompletion = (1u << 2),
1276+
eSymbolCompletion = (1u << 3),
1277+
eModuleCompletion = (1u << 4),
1278+
eSettingsNameCompletion = (1u << 5),
1279+
ePlatformPluginCompletion = (1u << 6),
1280+
eArchitectureCompletion = (1u << 7),
1281+
eVariablePathCompletion = (1u << 8),
1282+
eRegisterCompletion = (1u << 9),
1283+
eBreakpointCompletion = (1u << 10),
1284+
eProcessPluginCompletion = (1u << 11),
1285+
eDisassemblyFlavorCompletion = (1u << 12),
1286+
eTypeLanguageCompletion = (1u << 13),
1287+
eFrameIndexCompletion = (1u << 14),
1288+
eModuleUUIDCompletion = (1u << 15),
1289+
eStopHookIDCompletion = (1u << 16),
1290+
eThreadIndexCompletion = (1u << 17),
1291+
eWatchpointIDCompletion = (1u << 18),
1292+
eBreakpointNameCompletion = (1u << 19),
1293+
eProcessIDCompletion = (1u << 20),
1294+
eProcessNameCompletion = (1u << 21),
1295+
eRemoteDiskFileCompletion = (1u << 22),
1296+
eRemoteDiskDirectoryCompletion = (1u << 23),
1297+
eTypeCategoryNameCompletion = (1u << 24),
1298+
// This item serves two purposes. It is the last element in the enum, so
1299+
// you can add custom enums starting from here in your Option class. Also
1300+
// if you & in this bit the base code will not process the option.
1301+
eCustomCompletion = (1u << 25)
1302+
};
1303+
12701304
} // namespace lldb
12711305

12721306
#endif // LLDB_LLDB_ENUMERATIONS_H

lldb/source/Commands/CommandCompletions.cpp

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,37 +54,41 @@ bool CommandCompletions::InvokeCommonCompletionCallbacks(
5454
bool handled = false;
5555

5656
const CommonCompletionElement common_completions[] = {
57-
{eSourceFileCompletion, CommandCompletions::SourceFiles},
58-
{eDiskFileCompletion, CommandCompletions::DiskFiles},
59-
{eDiskDirectoryCompletion, CommandCompletions::DiskDirectories},
60-
{eSymbolCompletion, CommandCompletions::Symbols},
61-
{eModuleCompletion, CommandCompletions::Modules},
62-
{eModuleUUIDCompletion, CommandCompletions::ModuleUUIDs},
63-
{eSettingsNameCompletion, CommandCompletions::SettingsNames},
64-
{ePlatformPluginCompletion, CommandCompletions::PlatformPluginNames},
65-
{eArchitectureCompletion, CommandCompletions::ArchitectureNames},
66-
{eVariablePathCompletion, CommandCompletions::VariablePath},
67-
{eRegisterCompletion, CommandCompletions::Registers},
68-
{eBreakpointCompletion, CommandCompletions::Breakpoints},
69-
{eProcessPluginCompletion, CommandCompletions::ProcessPluginNames},
70-
{eDisassemblyFlavorCompletion, CommandCompletions::DisassemblyFlavors},
71-
{eTypeLanguageCompletion, CommandCompletions::TypeLanguages},
72-
{eFrameIndexCompletion, CommandCompletions::FrameIndexes},
73-
{eStopHookIDCompletion, CommandCompletions::StopHookIDs},
74-
{eThreadIndexCompletion, CommandCompletions::ThreadIndexes},
75-
{eWatchPointIDCompletion, CommandCompletions::WatchPointIDs},
76-
{eBreakpointNameCompletion, CommandCompletions::BreakpointNames},
77-
{eProcessIDCompletion, CommandCompletions::ProcessIDs},
78-
{eProcessNameCompletion, CommandCompletions::ProcessNames},
79-
{eRemoteDiskFileCompletion, CommandCompletions::RemoteDiskFiles},
80-
{eRemoteDiskDirectoryCompletion,
57+
{lldb::eSourceFileCompletion, CommandCompletions::SourceFiles},
58+
{lldb::eDiskFileCompletion, CommandCompletions::DiskFiles},
59+
{lldb::eDiskDirectoryCompletion, CommandCompletions::DiskDirectories},
60+
{lldb::eSymbolCompletion, CommandCompletions::Symbols},
61+
{lldb::eModuleCompletion, CommandCompletions::Modules},
62+
{lldb::eModuleUUIDCompletion, CommandCompletions::ModuleUUIDs},
63+
{lldb::eSettingsNameCompletion, CommandCompletions::SettingsNames},
64+
{lldb::ePlatformPluginCompletion,
65+
CommandCompletions::PlatformPluginNames},
66+
{lldb::eArchitectureCompletion, CommandCompletions::ArchitectureNames},
67+
{lldb::eVariablePathCompletion, CommandCompletions::VariablePath},
68+
{lldb::eRegisterCompletion, CommandCompletions::Registers},
69+
{lldb::eBreakpointCompletion, CommandCompletions::Breakpoints},
70+
{lldb::eProcessPluginCompletion, CommandCompletions::ProcessPluginNames},
71+
{lldb::eDisassemblyFlavorCompletion,
72+
CommandCompletions::DisassemblyFlavors},
73+
{lldb::eTypeLanguageCompletion, CommandCompletions::TypeLanguages},
74+
{lldb::eFrameIndexCompletion, CommandCompletions::FrameIndexes},
75+
{lldb::eStopHookIDCompletion, CommandCompletions::StopHookIDs},
76+
{lldb::eThreadIndexCompletion, CommandCompletions::ThreadIndexes},
77+
{lldb::eWatchpointIDCompletion, CommandCompletions::WatchPointIDs},
78+
{lldb::eBreakpointNameCompletion, CommandCompletions::BreakpointNames},
79+
{lldb::eProcessIDCompletion, CommandCompletions::ProcessIDs},
80+
{lldb::eProcessNameCompletion, CommandCompletions::ProcessNames},
81+
{lldb::eRemoteDiskFileCompletion, CommandCompletions::RemoteDiskFiles},
82+
{lldb::eRemoteDiskDirectoryCompletion,
8183
CommandCompletions::RemoteDiskDirectories},
82-
{eTypeCategoryNameCompletion, CommandCompletions::TypeCategoryNames},
83-
{eNoCompletion, nullptr} // This one has to be last in the list.
84+
{lldb::eTypeCategoryNameCompletion,
85+
CommandCompletions::TypeCategoryNames},
86+
{lldb::CompletionType::eNoCompletion,
87+
nullptr} // This one has to be last in the list.
8488
};
8589

8690
for (int i = 0;; i++) {
87-
if (common_completions[i].type == eNoCompletion)
91+
if (common_completions[i].type == lldb::eNoCompletion)
8892
break;
8993
else if ((common_completions[i].type & completion_mask) ==
9094
common_completions[i].type &&

lldb/source/Commands/CommandObjectBreakpoint.cpp

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -832,9 +832,8 @@ class CommandObjectBreakpointModify : public CommandObjectParsed {
832832
void
833833
HandleArgumentCompletion(CompletionRequest &request,
834834
OptionElementVector &opt_element_vector) override {
835-
CommandCompletions::InvokeCommonCompletionCallbacks(
836-
GetCommandInterpreter(), CommandCompletions::eBreakpointCompletion,
837-
request, nullptr);
835+
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
836+
GetCommandInterpreter(), lldb::eBreakpointCompletion, request, nullptr);
838837
}
839838

840839
Options *GetOptions() override { return &m_options; }
@@ -906,9 +905,8 @@ class CommandObjectBreakpointEnable : public CommandObjectParsed {
906905
void
907906
HandleArgumentCompletion(CompletionRequest &request,
908907
OptionElementVector &opt_element_vector) override {
909-
CommandCompletions::InvokeCommonCompletionCallbacks(
910-
GetCommandInterpreter(), CommandCompletions::eBreakpointCompletion,
911-
request, nullptr);
908+
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
909+
GetCommandInterpreter(), lldb::eBreakpointCompletion, request, nullptr);
912910
}
913911

914912
protected:
@@ -1021,9 +1019,8 @@ the second re-enables the first location.");
10211019
void
10221020
HandleArgumentCompletion(CompletionRequest &request,
10231021
OptionElementVector &opt_element_vector) override {
1024-
CommandCompletions::InvokeCommonCompletionCallbacks(
1025-
GetCommandInterpreter(), CommandCompletions::eBreakpointCompletion,
1026-
request, nullptr);
1022+
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
1023+
GetCommandInterpreter(), lldb::eBreakpointCompletion, request, nullptr);
10271024
}
10281025

10291026
protected:
@@ -1398,9 +1395,8 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {
13981395
void
13991396
HandleArgumentCompletion(CompletionRequest &request,
14001397
OptionElementVector &opt_element_vector) override {
1401-
CommandCompletions::InvokeCommonCompletionCallbacks(
1402-
GetCommandInterpreter(), CommandCompletions::eBreakpointCompletion,
1403-
request, nullptr);
1398+
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
1399+
GetCommandInterpreter(), lldb::eBreakpointCompletion, request, nullptr);
14041400
}
14051401

14061402
Options *GetOptions() override { return &m_options; }
@@ -1803,9 +1799,8 @@ class CommandObjectBreakpointNameAdd : public CommandObjectParsed {
18031799
void
18041800
HandleArgumentCompletion(CompletionRequest &request,
18051801
OptionElementVector &opt_element_vector) override {
1806-
CommandCompletions::InvokeCommonCompletionCallbacks(
1807-
GetCommandInterpreter(), CommandCompletions::eBreakpointCompletion,
1808-
request, nullptr);
1802+
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
1803+
GetCommandInterpreter(), lldb::eBreakpointCompletion, request, nullptr);
18091804
}
18101805

18111806
Options *GetOptions() override { return &m_option_group; }
@@ -1887,9 +1882,8 @@ class CommandObjectBreakpointNameDelete : public CommandObjectParsed {
18871882
void
18881883
HandleArgumentCompletion(CompletionRequest &request,
18891884
OptionElementVector &opt_element_vector) override {
1890-
CommandCompletions::InvokeCommonCompletionCallbacks(
1891-
GetCommandInterpreter(), CommandCompletions::eBreakpointCompletion,
1892-
request, nullptr);
1885+
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
1886+
GetCommandInterpreter(), lldb::eBreakpointCompletion, request, nullptr);
18931887
}
18941888

18951889
Options *GetOptions() override { return &m_option_group; }
@@ -2203,9 +2197,8 @@ class CommandObjectBreakpointRead : public CommandObjectParsed {
22032197

22042198
switch (GetDefinitions()[opt_defs_index].short_option) {
22052199
case 'f':
2206-
CommandCompletions::InvokeCommonCompletionCallbacks(
2207-
interpreter, CommandCompletions::eDiskFileCompletion, request,
2208-
nullptr);
2200+
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
2201+
interpreter, lldb::eDiskFileCompletion, request, nullptr);
22092202
break;
22102203

22112204
case 'N':
@@ -2343,9 +2336,8 @@ class CommandObjectBreakpointWrite : public CommandObjectParsed {
23432336
void
23442337
HandleArgumentCompletion(CompletionRequest &request,
23452338
OptionElementVector &opt_element_vector) override {
2346-
CommandCompletions::InvokeCommonCompletionCallbacks(
2347-
GetCommandInterpreter(), CommandCompletions::eBreakpointCompletion,
2348-
request, nullptr);
2339+
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
2340+
GetCommandInterpreter(), lldb::eBreakpointCompletion, request, nullptr);
23492341
}
23502342

23512343
Options *GetOptions() override { return &m_options; }

0 commit comments

Comments
 (0)