LLDB  mainline
CommandCompletions.h
Go to the documentation of this file.
1 //===-- CommandCompletions.h ------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef lldb_CommandCompletions_h_
10 #define lldb_CommandCompletions_h_
11 
12 #include <set>
13 
14 #include "lldb/Core/FileSpecList.h"
15 #include "lldb/Core/SearchFilter.h"
18 #include "lldb/lldb-private.h"
19 
20 #include "llvm/ADT/Twine.h"
21 
22 namespace lldb_private {
23 class TildeExpressionResolver;
25 public:
26  // This is the command completion callback that is used to complete the
27  // argument of the option it is bound to (in the OptionDefinition table
28  // below). Return the total number of matches.
29  typedef int (*CompletionCallback)(CommandInterpreter &interpreter,
30  CompletionRequest &request,
31  // A search filter to limit the search...
32  lldb_private::SearchFilter *searcher);
33  typedef enum {
35  eSourceFileCompletion = (1u << 0),
36  eDiskFileCompletion = (1u << 1),
38  eSymbolCompletion = (1u << 3),
39  eModuleCompletion = (1u << 4),
44  // This item serves two purposes. It is the last element in the enum, so
45  // you can add custom enums starting from here in your Option class. Also
46  // if you & in this bit the base code will not process the option.
47  eCustomCompletion = (1u << 9)
49 
53  };
54 
56  CommandInterpreter &interpreter, uint32_t completion_mask,
57  lldb_private::CompletionRequest &request, SearchFilter *searcher);
58 
59  // These are the generic completer functions:
60  static int DiskFiles(CommandInterpreter &interpreter,
61  CompletionRequest &request, SearchFilter *searcher);
62 
63  static int DiskFiles(const llvm::Twine &partial_file_name,
64  StringList &matches, TildeExpressionResolver &Resolver);
65 
66  static int DiskDirectories(CommandInterpreter &interpreter,
67  CompletionRequest &request,
68  SearchFilter *searcher);
69 
70  static int DiskDirectories(const llvm::Twine &partial_file_name,
71  StringList &matches,
72  TildeExpressionResolver &Resolver);
73 
74  static int SourceFiles(CommandInterpreter &interpreter,
75  CompletionRequest &request, SearchFilter *searcher);
76 
77  static int Modules(CommandInterpreter &interpreter,
78  CompletionRequest &request, SearchFilter *searcher);
79 
80  static int Symbols(CommandInterpreter &interpreter,
81  CompletionRequest &request, SearchFilter *searcher);
82 
83  static int SettingsNames(CommandInterpreter &interpreter,
84  CompletionRequest &request, SearchFilter *searcher);
85 
86  static int PlatformPluginNames(CommandInterpreter &interpreter,
87  CompletionRequest &request,
88  SearchFilter *searcher);
89 
90  static int ArchitectureNames(CommandInterpreter &interpreter,
91  CompletionRequest &request,
92  SearchFilter *searcher);
93 
94  static int VariablePath(CommandInterpreter &interpreter,
95  CompletionRequest &request, SearchFilter *searcher);
96 
97  // The Completer class is a convenient base class for building searchers that
98  // go along with the SearchFilter passed to the standard Completer functions.
99  class Completer : public Searcher {
100  public:
101  Completer(CommandInterpreter &interpreter, CompletionRequest &request);
102 
103  ~Completer() override;
104 
105  CallbackReturn SearchCallback(SearchFilter &filter, SymbolContext &context,
106  Address *addr, bool complete) override = 0;
107 
108  lldb::SearchDepth GetDepth() override = 0;
109 
110  virtual size_t DoCompletion(SearchFilter *filter) = 0;
111 
112  protected:
115 
116  private:
117  DISALLOW_COPY_AND_ASSIGN(Completer);
118  };
119 
120  // SourceFileCompleter implements the source file completer
122  public:
124  bool include_support_files, CompletionRequest &request);
125 
126  lldb::SearchDepth GetDepth() override;
127 
128  Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
129  SymbolContext &context,
130  Address *addr,
131  bool complete) override;
132 
133  size_t DoCompletion(SearchFilter *filter) override;
134 
135  private:
136  bool m_include_support_files;
137  FileSpecList m_matching_files;
138  const char *m_file_name;
139  const char *m_dir_name;
140 
141  DISALLOW_COPY_AND_ASSIGN(SourceFileCompleter);
142  };
143 
144  // ModuleCompleter implements the module completer
145  class ModuleCompleter : public Completer {
146  public:
147  ModuleCompleter(CommandInterpreter &interpreter,
148  CompletionRequest &request);
149 
150  lldb::SearchDepth GetDepth() override;
151 
152  Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
153  SymbolContext &context,
154  Address *addr,
155  bool complete) override;
156 
157  size_t DoCompletion(SearchFilter *filter) override;
158 
159  private:
160  const char *m_file_name;
161  const char *m_dir_name;
162 
163  DISALLOW_COPY_AND_ASSIGN(ModuleCompleter);
164  };
165 
166  // SymbolCompleter implements the symbol completer
167  class SymbolCompleter : public Completer {
168  public:
169  SymbolCompleter(CommandInterpreter &interpreter,
170  CompletionRequest &request);
171 
172  lldb::SearchDepth GetDepth() override;
173 
174  Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
175  SymbolContext &context,
176  Address *addr,
177  bool complete) override;
178 
179  size_t DoCompletion(SearchFilter *filter) override;
180 
181  private:
182  // struct NameCmp {
183  // bool operator() (const ConstString& lhs, const ConstString&
184  // rhs) const
185  // {
186  // return lhs < rhs;
187  // }
188  // };
189 
190  RegularExpression m_regex;
191  typedef std::set<ConstString> collection;
192  collection m_match_set;
193 
194  DISALLOW_COPY_AND_ASSIGN(SymbolCompleter);
195  };
196 
197 private:
198  static CommonCompletionElement g_common_completions[];
199 };
200 
201 } // namespace lldb_private
202 
203 #endif // lldb_CommandCompletions_h_
static bool InvokeCommonCompletionCallbacks(CommandInterpreter &interpreter, uint32_t completion_mask, lldb_private::CompletionRequest &request, SearchFilter *searcher)
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
static int VariablePath(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:33
static int Symbols(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
"lldb/Utility/RegularExpression.h" A C++ wrapper class for regex.
static int ArchitectureNames(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static int DiskFiles(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
"lldb/Utility/ArgCompletionRequest.h"
General Outline: Provides the callback and search depth for the SearchFilter search.
Definition: SearchFilter.h:101
General Outline: Provides the callback and search depth for the SearchFilter search.
Definition: SearchFilter.h:60
static int PlatformPluginNames(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
A section + offset based address class.
Definition: Address.h:80
static int SettingsNames(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static int SourceFiles(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static int DiskDirectories(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static int Modules(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
int(* CompletionCallback)(CommandInterpreter &interpreter, CompletionRequest &request, lldb_private::SearchFilter *searcher)