LLDB mainline
CommandCompletions.cpp
Go to the documentation of this file.
1//===-- CommandCompletions.cpp --------------------------------------------===//
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#include "llvm/ADT/SmallString.h"
10#include "llvm/ADT/StringSet.h"
11
13#include "lldb/Core/Module.h"
25#include "lldb/Target/Process.h"
27#include "lldb/Target/Thread.h"
32
33#include "llvm/Support/FileSystem.h"
34#include "llvm/Support/Path.h"
35
36using namespace lldb_private;
37
38// This is the command completion callback that is used to complete the
39// argument of the option it is bound to (in the OptionDefinition table
40// below).
41typedef void (*CompletionCallback)(CommandInterpreter &interpreter,
42 CompletionRequest &request,
43 // A search filter to limit the search...
45
49};
50
52 CommandInterpreter &interpreter, uint32_t completion_mask,
53 CompletionRequest &request, SearchFilter *searcher) {
54 bool handled = false;
55
56 const CommonCompletionElement common_completions[] = {
87 nullptr} // This one has to be last in the list.
88 };
89
90 for (int i = 0;; i++) {
91 if (common_completions[i].type == lldb::eNoCompletion)
92 break;
93 else if ((common_completions[i].type & completion_mask) ==
94 common_completions[i].type &&
95 common_completions[i].callback != nullptr) {
96 handled = true;
97 common_completions[i].callback(interpreter, request, searcher);
98 }
99 }
100 return handled;
101}
102
103namespace {
104// The Completer class is a convenient base class for building searchers that
105// go along with the SearchFilter passed to the standard Completer functions.
106class Completer : public Searcher {
107public:
108 Completer(CommandInterpreter &interpreter, CompletionRequest &request)
109 : m_interpreter(interpreter), m_request(request) {}
110
111 ~Completer() override = default;
112
113 CallbackReturn SearchCallback(SearchFilter &filter, SymbolContext &context,
114 Address *addr) override = 0;
115
116 lldb::SearchDepth GetDepth() override = 0;
117
118 virtual void DoCompletion(SearchFilter *filter) = 0;
119
120protected:
121 CommandInterpreter &m_interpreter;
122 CompletionRequest &m_request;
123
124private:
125 Completer(const Completer &) = delete;
126 const Completer &operator=(const Completer &) = delete;
127};
128} // namespace
129
130// SourceFileCompleter implements the source file completer
131namespace {
132class SourceFileCompleter : public Completer {
133public:
134 SourceFileCompleter(CommandInterpreter &interpreter,
135 CompletionRequest &request)
136 : Completer(interpreter, request) {
137 FileSpec partial_spec(m_request.GetCursorArgumentPrefix());
138 m_file_name = partial_spec.GetFilename().GetCString();
139 m_dir_name = partial_spec.GetDirectory().GetCString();
140 }
141
142 lldb::SearchDepth GetDepth() override { return lldb::eSearchDepthCompUnit; }
143
144 Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
145 SymbolContext &context,
146 Address *addr) override {
147 if (context.comp_unit != nullptr) {
148 const char *cur_file_name =
150 const char *cur_dir_name =
152
153 bool match = false;
154 if (m_file_name && cur_file_name &&
155 strstr(cur_file_name, m_file_name) == cur_file_name)
156 match = true;
157
158 if (match && m_dir_name && cur_dir_name &&
159 strstr(cur_dir_name, m_dir_name) != cur_dir_name)
160 match = false;
161
162 if (match) {
163 m_matching_files.AppendIfUnique(context.comp_unit->GetPrimaryFile());
164 }
165 }
167 }
168
169 void DoCompletion(SearchFilter *filter) override {
170 filter->Search(*this);
171 // Now convert the filelist to completions:
172 for (size_t i = 0; i < m_matching_files.GetSize(); i++) {
173 m_request.AddCompletion(
174 m_matching_files.GetFileSpecAtIndex(i).GetFilename().GetCString());
175 }
176 }
177
178private:
179 FileSpecList m_matching_files;
180 const char *m_file_name;
181 const char *m_dir_name;
182
183 SourceFileCompleter(const SourceFileCompleter &) = delete;
184 const SourceFileCompleter &operator=(const SourceFileCompleter &) = delete;
185};
186} // namespace
187
188static bool regex_chars(const char comp) {
189 return llvm::StringRef("[](){}+.*|^$\\?").contains(comp);
190}
191
192namespace {
193class SymbolCompleter : public Completer {
194
195public:
196 SymbolCompleter(CommandInterpreter &interpreter, CompletionRequest &request)
197 : Completer(interpreter, request) {
198 std::string regex_str;
199 if (!m_request.GetCursorArgumentPrefix().empty()) {
200 regex_str.append("^");
201 regex_str.append(std::string(m_request.GetCursorArgumentPrefix()));
202 } else {
203 // Match anything since the completion string is empty
204 regex_str.append(".");
205 }
206 std::string::iterator pos =
207 find_if(regex_str.begin() + 1, regex_str.end(), regex_chars);
208 while (pos < regex_str.end()) {
209 pos = regex_str.insert(pos, '\\');
210 pos = find_if(pos + 2, regex_str.end(), regex_chars);
211 }
212 m_regex = RegularExpression(regex_str);
213 }
214
215 lldb::SearchDepth GetDepth() override { return lldb::eSearchDepthModule; }
216
217 Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
218 SymbolContext &context,
219 Address *addr) override {
220 if (context.module_sp) {
221 SymbolContextList sc_list;
222 ModuleFunctionSearchOptions function_options;
223 function_options.include_symbols = true;
224 function_options.include_inlines = true;
225 context.module_sp->FindFunctions(m_regex, function_options, sc_list);
226
227 // Now add the functions & symbols to the list - only add if unique:
228 for (const SymbolContext &sc : sc_list) {
229 ConstString func_name = sc.GetFunctionName(Mangled::ePreferDemangled);
230 // Ensure that the function name matches the regex. This is more than
231 // a sanity check. It is possible that the demangled function name
232 // does not start with the prefix, for example when it's in an
233 // anonymous namespace.
234 if (!func_name.IsEmpty() && m_regex.Execute(func_name.GetStringRef()))
235 m_match_set.insert(func_name);
236 }
237 }
239 }
240
241 void DoCompletion(SearchFilter *filter) override {
242 filter->Search(*this);
243 collection::iterator pos = m_match_set.begin(), end = m_match_set.end();
244 for (pos = m_match_set.begin(); pos != end; pos++)
245 m_request.AddCompletion((*pos).GetCString());
246 }
247
248private:
249 RegularExpression m_regex;
250 typedef std::set<ConstString> collection;
251 collection m_match_set;
252
253 SymbolCompleter(const SymbolCompleter &) = delete;
254 const SymbolCompleter &operator=(const SymbolCompleter &) = delete;
255};
256} // namespace
257
258namespace {
259class ModuleCompleter : public Completer {
260public:
261 ModuleCompleter(CommandInterpreter &interpreter, CompletionRequest &request)
262 : Completer(interpreter, request) {
263 FileSpec partial_spec(m_request.GetCursorArgumentPrefix());
264 m_file_name = partial_spec.GetFilename().GetCString();
265 m_dir_name = partial_spec.GetDirectory().GetCString();
266 }
267
268 lldb::SearchDepth GetDepth() override { return lldb::eSearchDepthModule; }
269
270 Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
271 SymbolContext &context,
272 Address *addr) override {
273 if (context.module_sp) {
274 const char *cur_file_name =
275 context.module_sp->GetFileSpec().GetFilename().GetCString();
276 const char *cur_dir_name =
277 context.module_sp->GetFileSpec().GetDirectory().GetCString();
278
279 bool match = false;
280 if (m_file_name && cur_file_name &&
281 strstr(cur_file_name, m_file_name) == cur_file_name)
282 match = true;
283
284 if (match && m_dir_name && cur_dir_name &&
285 strstr(cur_dir_name, m_dir_name) != cur_dir_name)
286 match = false;
287
288 if (match) {
289 m_request.AddCompletion(cur_file_name);
290 }
291 }
293 }
294
295 void DoCompletion(SearchFilter *filter) override { filter->Search(*this); }
296
297private:
298 const char *m_file_name;
299 const char *m_dir_name;
300
301 ModuleCompleter(const ModuleCompleter &) = delete;
302 const ModuleCompleter &operator=(const ModuleCompleter &) = delete;
303};
304} // namespace
305
307 CompletionRequest &request,
308 SearchFilter *searcher) {
309 SourceFileCompleter completer(interpreter, request);
310
311 if (searcher == nullptr) {
312 lldb::TargetSP target_sp = interpreter.GetDebugger().GetSelectedTarget();
313 SearchFilterForUnconstrainedSearches null_searcher(target_sp);
314 completer.DoCompletion(&null_searcher);
315 } else {
316 completer.DoCompletion(searcher);
317 }
318}
319
320static void DiskFilesOrDirectories(const llvm::Twine &partial_name,
321 bool only_directories,
322 CompletionRequest &request,
323 TildeExpressionResolver &Resolver) {
324 llvm::SmallString<256> CompletionBuffer;
325 llvm::SmallString<256> Storage;
326 partial_name.toVector(CompletionBuffer);
327
328 if (CompletionBuffer.size() >= PATH_MAX)
329 return;
330
331 namespace path = llvm::sys::path;
332
333 llvm::StringRef SearchDir;
334 llvm::StringRef PartialItem;
335
336 if (CompletionBuffer.startswith("~")) {
337 llvm::StringRef Buffer = CompletionBuffer;
338 size_t FirstSep =
339 Buffer.find_if([](char c) { return path::is_separator(c); });
340
341 llvm::StringRef Username = Buffer.take_front(FirstSep);
342 llvm::StringRef Remainder;
343 if (FirstSep != llvm::StringRef::npos)
344 Remainder = Buffer.drop_front(FirstSep + 1);
345
346 llvm::SmallString<256> Resolved;
347 if (!Resolver.ResolveExact(Username, Resolved)) {
348 // We couldn't resolve it as a full username. If there were no slashes
349 // then this might be a partial username. We try to resolve it as such
350 // but after that, we're done regardless of any matches.
351 if (FirstSep == llvm::StringRef::npos) {
352 llvm::StringSet<> MatchSet;
353 Resolver.ResolvePartial(Username, MatchSet);
354 for (const auto &S : MatchSet) {
355 Resolved = S.getKey();
356 path::append(Resolved, path::get_separator());
357 request.AddCompletion(Resolved, "", CompletionMode::Partial);
358 }
359 }
360 return;
361 }
362
363 // If there was no trailing slash, then we're done as soon as we resolve
364 // the expression to the correct directory. Otherwise we need to continue
365 // looking for matches within that directory.
366 if (FirstSep == llvm::StringRef::npos) {
367 // Make sure it ends with a separator.
368 path::append(CompletionBuffer, path::get_separator());
369 request.AddCompletion(CompletionBuffer, "", CompletionMode::Partial);
370 return;
371 }
372
373 // We want to keep the form the user typed, so we special case this to
374 // search in the fully resolved directory, but CompletionBuffer keeps the
375 // unmodified form that the user typed.
376 Storage = Resolved;
377 llvm::StringRef RemainderDir = path::parent_path(Remainder);
378 if (!RemainderDir.empty()) {
379 // Append the remaining path to the resolved directory.
380 Storage.append(path::get_separator());
381 Storage.append(RemainderDir);
382 }
383 SearchDir = Storage;
384 } else if (CompletionBuffer == path::root_directory(CompletionBuffer)) {
385 SearchDir = CompletionBuffer;
386 } else {
387 SearchDir = path::parent_path(CompletionBuffer);
388 }
389
390 size_t FullPrefixLen = CompletionBuffer.size();
391
392 PartialItem = path::filename(CompletionBuffer);
393
394 // path::filename() will return "." when the passed path ends with a
395 // directory separator or the separator when passed the disk root directory.
396 // We have to filter those out, but only when the "." doesn't come from the
397 // completion request itself.
398 if ((PartialItem == "." || PartialItem == path::get_separator()) &&
399 path::is_separator(CompletionBuffer.back()))
400 PartialItem = llvm::StringRef();
401
402 if (SearchDir.empty()) {
403 llvm::sys::fs::current_path(Storage);
404 SearchDir = Storage;
405 }
406 assert(!PartialItem.contains(path::get_separator()));
407
408 // SearchDir now contains the directory to search in, and Prefix contains the
409 // text we want to match against items in that directory.
410
412 std::error_code EC;
413 llvm::vfs::directory_iterator Iter = fs.DirBegin(SearchDir, EC);
414 llvm::vfs::directory_iterator End;
415 for (; Iter != End && !EC; Iter.increment(EC)) {
416 auto &Entry = *Iter;
417 llvm::ErrorOr<llvm::vfs::Status> Status = fs.GetStatus(Entry.path());
418
419 if (!Status)
420 continue;
421
422 auto Name = path::filename(Entry.path());
423
424 // Omit ".", ".."
425 if (Name == "." || Name == ".." || !Name.startswith(PartialItem))
426 continue;
427
428 bool is_dir = Status->isDirectory();
429
430 // If it's a symlink, then we treat it as a directory as long as the target
431 // is a directory.
432 if (Status->isSymlink()) {
433 FileSpec symlink_filespec(Entry.path());
434 FileSpec resolved_filespec;
435 auto error = fs.ResolveSymbolicLink(symlink_filespec, resolved_filespec);
436 if (error.Success())
437 is_dir = fs.IsDirectory(symlink_filespec);
438 }
439
440 if (only_directories && !is_dir)
441 continue;
442
443 // Shrink it back down so that it just has the original prefix the user
444 // typed and remove the part of the name which is common to the located
445 // item and what the user typed.
446 CompletionBuffer.resize(FullPrefixLen);
447 Name = Name.drop_front(PartialItem.size());
448 CompletionBuffer.append(Name);
449
450 if (is_dir) {
451 path::append(CompletionBuffer, path::get_separator());
452 }
453
454 CompletionMode mode =
456 request.AddCompletion(CompletionBuffer, "", mode);
457 }
458}
459
460static void DiskFilesOrDirectories(const llvm::Twine &partial_name,
461 bool only_directories, StringList &matches,
462 TildeExpressionResolver &Resolver) {
463 CompletionResult result;
464 std::string partial_name_str = partial_name.str();
465 CompletionRequest request(partial_name_str, partial_name_str.size(), result);
466 DiskFilesOrDirectories(partial_name, only_directories, request, Resolver);
467 result.GetMatches(matches);
468}
469
471 bool only_directories) {
473 DiskFilesOrDirectories(request.GetCursorArgumentPrefix(), only_directories,
474 request, resolver);
475}
476
478 CompletionRequest &request,
479 SearchFilter *searcher) {
480 DiskFilesOrDirectories(request, /*only_dirs*/ false);
481}
482
483void CommandCompletions::DiskFiles(const llvm::Twine &partial_file_name,
484 StringList &matches,
485 TildeExpressionResolver &Resolver) {
486 DiskFilesOrDirectories(partial_file_name, false, matches, Resolver);
487}
488
490 CompletionRequest &request,
491 SearchFilter *searcher) {
492 DiskFilesOrDirectories(request, /*only_dirs*/ true);
493}
494
495void CommandCompletions::DiskDirectories(const llvm::Twine &partial_file_name,
496 StringList &matches,
497 TildeExpressionResolver &Resolver) {
498 DiskFilesOrDirectories(partial_file_name, true, matches, Resolver);
499}
500
502 CompletionRequest &request,
503 SearchFilter *searcher) {
504 lldb::PlatformSP platform_sp =
506 if (platform_sp)
507 platform_sp->AutoCompleteDiskFileOrDirectory(request, false);
508}
509
511 CompletionRequest &request,
512 SearchFilter *searcher) {
513 lldb::PlatformSP platform_sp =
515 if (platform_sp)
516 platform_sp->AutoCompleteDiskFileOrDirectory(request, true);
517}
518
520 CompletionRequest &request,
521 SearchFilter *searcher) {
522 ModuleCompleter completer(interpreter, request);
523
524 if (searcher == nullptr) {
525 lldb::TargetSP target_sp = interpreter.GetDebugger().GetSelectedTarget();
526 SearchFilterForUnconstrainedSearches null_searcher(target_sp);
527 completer.DoCompletion(&null_searcher);
528 } else {
529 completer.DoCompletion(searcher);
530 }
531}
532
534 CompletionRequest &request,
535 SearchFilter *searcher) {
536 const ExecutionContext &exe_ctx = interpreter.GetExecutionContext();
537 if (!exe_ctx.HasTargetScope())
538 return;
539
540 exe_ctx.GetTargetPtr()->GetImages().ForEach(
541 [&request](const lldb::ModuleSP &module) {
542 StreamString strm;
543 module->GetDescription(strm.AsRawOstream(),
545 request.TryCompleteCurrentArg(module->GetUUID().GetAsString(),
546 strm.GetString());
547 return true;
548 });
549}
550
552 CompletionRequest &request,
553 SearchFilter *searcher) {
554 SymbolCompleter completer(interpreter, request);
555
556 if (searcher == nullptr) {
557 lldb::TargetSP target_sp = interpreter.GetDebugger().GetSelectedTarget();
558 SearchFilterForUnconstrainedSearches null_searcher(target_sp);
559 completer.DoCompletion(&null_searcher);
560 } else {
561 completer.DoCompletion(searcher);
562 }
563}
564
566 CompletionRequest &request,
567 SearchFilter *searcher) {
568 // Cache the full setting name list
569 static StringList g_property_names;
570 if (g_property_names.GetSize() == 0) {
571 // Generate the full setting name list on demand
572 lldb::OptionValuePropertiesSP properties_sp(
573 interpreter.GetDebugger().GetValueProperties());
574 if (properties_sp) {
575 StreamString strm;
576 properties_sp->DumpValue(nullptr, strm, OptionValue::eDumpOptionName);
577 const std::string &str = std::string(strm.GetString());
578 g_property_names.SplitIntoLines(str.c_str(), str.size());
579 }
580 }
581
582 for (const std::string &s : g_property_names)
583 request.TryCompleteCurrentArg(s);
584}
585
587 CompletionRequest &request,
588 SearchFilter *searcher) {
590 request);
591}
592
594 CompletionRequest &request,
595 SearchFilter *searcher) {
596 ArchSpec::AutoComplete(request);
597}
598
600 CompletionRequest &request,
601 SearchFilter *searcher) {
602 Variable::AutoComplete(interpreter.GetExecutionContext(), request);
603}
604
606 CompletionRequest &request,
607 SearchFilter *searcher) {
608 std::string reg_prefix;
609 if (request.GetCursorArgumentPrefix().startswith("$"))
610 reg_prefix = "$";
611
612 RegisterContext *reg_ctx =
614 const size_t reg_num = reg_ctx->GetRegisterCount();
615 for (size_t reg_idx = 0; reg_idx < reg_num; ++reg_idx) {
616 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_idx);
617 request.TryCompleteCurrentArg(reg_prefix + reg_info->name,
618 reg_info->alt_name);
619 }
620}
621
623 CompletionRequest &request,
624 SearchFilter *searcher) {
625 lldb::TargetSP target = interpreter.GetDebugger().GetSelectedTarget();
626 if (!target)
627 return;
628
629 const BreakpointList &breakpoints = target->GetBreakpointList();
630
631 std::unique_lock<std::recursive_mutex> lock;
632 target->GetBreakpointList().GetListMutex(lock);
633
634 size_t num_breakpoints = breakpoints.GetSize();
635 if (num_breakpoints == 0)
636 return;
637
638 for (size_t i = 0; i < num_breakpoints; ++i) {
639 lldb::BreakpointSP bp = breakpoints.GetBreakpointAtIndex(i);
640
641 StreamString s;
642 bp->GetDescription(&s, lldb::eDescriptionLevelBrief);
643 llvm::StringRef bp_info = s.GetString();
644
645 const size_t colon_pos = bp_info.find_first_of(':');
646 if (colon_pos != llvm::StringRef::npos)
647 bp_info = bp_info.drop_front(colon_pos + 2);
648
649 request.TryCompleteCurrentArg(std::to_string(bp->GetID()), bp_info);
650 }
651}
652
654 CompletionRequest &request,
655 SearchFilter *searcher) {
656 lldb::TargetSP target = interpreter.GetDebugger().GetSelectedTarget();
657 if (!target)
658 return;
659
660 std::vector<std::string> name_list;
661 target->GetBreakpointNames(name_list);
662
663 for (const std::string &name : name_list)
664 request.TryCompleteCurrentArg(name);
665}
666
668 CompletionRequest &request,
669 SearchFilter *searcher) {
671 request);
672}
674 CompletionRequest &request,
675 SearchFilter *searcher) {
676 // Currently the only valid options for disassemble -F are default, and for
677 // Intel architectures, att and intel.
678 static const char *flavors[] = {"default", "att", "intel"};
679 for (const char *flavor : flavors) {
680 request.TryCompleteCurrentArg(flavor);
681 }
682}
683
685 CompletionRequest &request,
686 SearchFilter *searcher) {
687 lldb::PlatformSP platform_sp(interpreter.GetPlatform(true));
688 if (!platform_sp)
689 return;
690 ProcessInstanceInfoList process_infos;
691 ProcessInstanceInfoMatch match_info;
692 platform_sp->FindProcesses(match_info, process_infos);
693 for (const ProcessInstanceInfo &info : process_infos)
694 request.TryCompleteCurrentArg(std::to_string(info.GetProcessID()),
695 info.GetNameAsStringRef());
696}
697
699 CompletionRequest &request,
700 SearchFilter *searcher) {
701 lldb::PlatformSP platform_sp(interpreter.GetPlatform(true));
702 if (!platform_sp)
703 return;
704 ProcessInstanceInfoList process_infos;
705 ProcessInstanceInfoMatch match_info;
706 platform_sp->FindProcesses(match_info, process_infos);
707 for (const ProcessInstanceInfo &info : process_infos)
708 request.TryCompleteCurrentArg(info.GetNameAsStringRef());
709}
710
712 CompletionRequest &request,
713 SearchFilter *searcher) {
714 for (int bit :
715 Language::GetLanguagesSupportingTypeSystems().bitvector.set_bits()) {
716 request.TryCompleteCurrentArg(
718 }
719}
720
722 CompletionRequest &request,
723 SearchFilter *searcher) {
724 const ExecutionContext &exe_ctx = interpreter.GetExecutionContext();
725 if (!exe_ctx.HasProcessScope())
726 return;
727
728 lldb::ThreadSP thread_sp = exe_ctx.GetThreadSP();
729 Debugger &dbg = interpreter.GetDebugger();
730 const uint32_t frame_num = thread_sp->GetStackFrameCount();
731 for (uint32_t i = 0; i < frame_num; ++i) {
732 lldb::StackFrameSP frame_sp = thread_sp->GetStackFrameAtIndex(i);
733 StreamString strm;
734 // Dumping frames can be slow, allow interruption.
735 if (dbg.InterruptRequested())
736 break;
737 frame_sp->Dump(&strm, false, true);
738 request.TryCompleteCurrentArg(std::to_string(i), strm.GetString());
739 }
740}
741
743 CompletionRequest &request,
744 SearchFilter *searcher) {
745 const lldb::TargetSP target_sp =
746 interpreter.GetExecutionContext().GetTargetSP();
747 if (!target_sp)
748 return;
749
750 const size_t num = target_sp->GetNumStopHooks();
751 for (size_t idx = 0; idx < num; ++idx) {
752 StreamString strm;
753 // The value 11 is an offset to make the completion description looks
754 // neater.
755 strm.SetIndentLevel(11);
756 const Target::StopHookSP stophook_sp = target_sp->GetStopHookAtIndex(idx);
757 stophook_sp->GetDescription(&strm, lldb::eDescriptionLevelInitial);
758 request.TryCompleteCurrentArg(std::to_string(stophook_sp->GetID()),
759 strm.GetString());
760 }
761}
762
764 CompletionRequest &request,
765 SearchFilter *searcher) {
766 const ExecutionContext &exe_ctx = interpreter.GetExecutionContext();
767 if (!exe_ctx.HasProcessScope())
768 return;
769
770 ThreadList &threads = exe_ctx.GetProcessPtr()->GetThreadList();
771 lldb::ThreadSP thread_sp;
772 for (uint32_t idx = 0; (thread_sp = threads.GetThreadAtIndex(idx)); ++idx) {
773 StreamString strm;
774 thread_sp->GetStatus(strm, 0, 1, 1, true);
775 request.TryCompleteCurrentArg(std::to_string(thread_sp->GetIndexID()),
776 strm.GetString());
777 }
778}
779
781 CompletionRequest &request,
782 SearchFilter *searcher) {
783 const ExecutionContext &exe_ctx = interpreter.GetExecutionContext();
784 if (!exe_ctx.HasTargetScope())
785 return;
786
787 const WatchpointList &wp_list = exe_ctx.GetTargetPtr()->GetWatchpointList();
788 for (lldb::WatchpointSP wp_sp : wp_list.Watchpoints()) {
789 StreamString strm;
790 wp_sp->Dump(&strm);
791 request.TryCompleteCurrentArg(std::to_string(wp_sp->GetID()),
792 strm.GetString());
793 }
794}
795
797 CompletionRequest &request,
798 SearchFilter *searcher) {
800 [&request](const lldb::TypeCategoryImplSP &category_sp) {
801 request.TryCompleteCurrentArg(category_sp->GetName(),
802 category_sp->GetDescription());
803 return true;
804 });
805}
806
808 CommandInterpreter &interpreter, CompletionRequest &request,
809 OptionElementVector &opt_element_vector) {
810 // The only arguments constitute a command path, however, there might be
811 // options interspersed among the arguments, and we need to skip those. Do that
812 // by copying the args vector, and just dropping all the option bits:
813 Args args = request.GetParsedLine();
814 std::vector<size_t> to_delete;
815 for (auto &elem : opt_element_vector) {
816 to_delete.push_back(elem.opt_pos);
817 if (elem.opt_arg_pos != 0)
818 to_delete.push_back(elem.opt_arg_pos);
819 }
820 sort(to_delete.begin(), to_delete.end(), std::greater<size_t>());
821 for (size_t idx : to_delete)
822 args.DeleteArgumentAtIndex(idx);
823
824 // At this point, we should only have args, so now lookup the command up to
825 // the cursor element.
826
827 // There's nothing here but options. It doesn't seem very useful here to
828 // dump all the commands, so just return.
829 size_t num_args = args.GetArgumentCount();
830 if (num_args == 0)
831 return;
832
833 // There's just one argument, so we should complete its name:
834 StringList matches;
835 if (num_args == 1) {
836 interpreter.GetUserCommandObject(args.GetArgumentAtIndex(0), &matches,
837 nullptr);
838 request.AddCompletions(matches);
839 return;
840 }
841
842 // There was more than one path element, lets find the containing command:
845 interpreter.VerifyUserMultiwordCmdPath(args, true, error);
846
847 // Something was wrong somewhere along the path, but I don't think there's
848 // a good way to go back and fill in the missing elements:
849 if (error.Fail())
850 return;
851
852 // This should never happen. We already handled the case of one argument
853 // above, and we can only get Success & nullptr back if there's a one-word
854 // leaf.
855 assert(mwc != nullptr);
856
857 mwc->GetSubcommandObject(args.GetArgumentAtIndex(num_args - 1), &matches);
858 if (matches.GetSize() == 0)
859 return;
860
861 request.AddCompletions(matches);
862}
static void DiskFilesOrDirectories(const llvm::Twine &partial_name, bool only_directories, CompletionRequest &request, TildeExpressionResolver &Resolver)
static bool regex_chars(const char comp)
void(* CompletionCallback)(CommandInterpreter &interpreter, CompletionRequest &request, lldb_private::SearchFilter *searcher)
static llvm::raw_ostream & error(Stream &strm)
#define bit
A section + offset based address class.
Definition: Address.h:59
static void AutoComplete(CompletionRequest &request)
Definition: ArchSpec.cpp:272
A command line argument class.
Definition: Args.h:33
void DeleteArgumentAtIndex(size_t idx)
Deletes the argument value at index if idx is a valid argument index.
Definition: Args.cpp:349
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
Definition: Args.h:116
const char * GetArgumentAtIndex(size_t idx) const
Gets the NULL terminated C string argument pointer for the argument at index idx.
Definition: Args.cpp:263
General Outline: Allows adding and removing breakpoints and find by ID and index.
void GetListMutex(std::unique_lock< std::recursive_mutex > &lock)
Sets the passed in Locker to hold the Breakpoint List mutex.
size_t GetSize() const
Returns the number of elements in this breakpoint list.
lldb::BreakpointSP GetBreakpointAtIndex(size_t i) const
Returns a shared pointer to the breakpoint with index i.
static void DisassemblyFlavors(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static bool InvokeCommonCompletionCallbacks(CommandInterpreter &interpreter, uint32_t completion_mask, lldb_private::CompletionRequest &request, SearchFilter *searcher)
static void ArchitectureNames(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void DiskDirectories(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void RemoteDiskDirectories(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void SourceFiles(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void Registers(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void TypeLanguages(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void DiskFiles(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void ProcessPluginNames(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void PlatformPluginNames(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void Breakpoints(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void ProcessIDs(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void Symbols(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void StopHookIDs(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void ModuleUUIDs(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void ThreadIndexes(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void SettingsNames(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void CompleteModifiableCmdPathArgs(CommandInterpreter &interpreter, CompletionRequest &request, OptionElementVector &opt_element_vector)
This completer works for commands whose only arguments are a command path.
static void FrameIndexes(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void TypeCategoryNames(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void WatchPointIDs(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void Modules(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void RemoteDiskFiles(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void ProcessNames(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void VariablePath(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void BreakpointNames(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
ExecutionContext GetExecutionContext() const
CommandObject * GetUserCommandObject(llvm::StringRef cmd, StringList *matches=nullptr, StringList *descriptions=nullptr) const
CommandObjectMultiword * VerifyUserMultiwordCmdPath(Args &path, bool leaf_is_command, Status &result)
Look up the command pointed to by path encoded in the arguments of the incoming command object.
lldb::PlatformSP GetPlatform(bool prefer_target_platform)
CommandObject * GetSubcommandObject(llvm::StringRef sub_cmd, StringList *matches=nullptr) override
const FileSpec & GetPrimaryFile() const
Return the primary source file associated with this compile unit.
Definition: CompileUnit.h:227
"lldb/Utility/ArgCompletionRequest.h"
void AddCompletion(llvm::StringRef completion, llvm::StringRef description="", CompletionMode mode=CompletionMode::Normal)
Adds a possible completion string.
void AddCompletions(const StringList &completions)
Adds multiple possible completion strings.
const Args & GetParsedLine() const
llvm::StringRef GetCursorArgumentPrefix() const
void TryCompleteCurrentArg(llvm::StringRef completion, llvm::StringRef description="")
Adds a possible completion string if the completion would complete the current argument.
void GetMatches(StringList &matches) const
Adds all collected completion matches to the given list.
A uniqued constant string class.
Definition: ConstString.h:40
bool IsEmpty() const
Test for empty string.
Definition: ConstString.h:309
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:207
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:221
static void ForEach(TypeCategoryMap::ForEachCallback callback)
A class to manage flag bits.
Definition: Debugger.h:78
lldb::TargetSP GetSelectedTarget()
Definition: Debugger.h:188
bool InterruptRequested()
This is the correct way to query the state of Interruption.
Definition: Debugger.cpp:1265
PlatformList & GetPlatformList()
Definition: Debugger.h:203
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
bool HasProcessScope() const
Returns true the ExecutionContext object contains a valid target and process.
const lldb::TargetSP & GetTargetSP() const
Get accessor to get the target shared pointer.
Target * GetTargetPtr() const
Returns a pointer to the target object.
const lldb::ThreadSP & GetThreadSP() const
Get accessor to get the thread shared pointer.
bool HasTargetScope() const
Returns true the ExecutionContext object contains a valid target.
Process * GetProcessPtr() const
Returns a pointer to the process object.
RegisterContext * GetRegisterContext() const
A file collection class.
Definition: FileSpecList.h:24
A file utility class.
Definition: FileSpec.h:56
const ConstString & GetFilename() const
Filename string const get accessor.
Definition: FileSpec.h:240
const ConstString & GetDirectory() const
Directory string const get accessor.
Definition: FileSpec.h:223
Status ResolveSymbolicLink(const FileSpec &src, FileSpec &dst)
llvm::vfs::directory_iterator DirBegin(const FileSpec &file_spec, std::error_code &ec)
Get a directory iterator.
llvm::ErrorOr< llvm::vfs::Status > GetStatus(const FileSpec &file_spec) const
Returns the Status object for the given file.
bool IsDirectory(const FileSpec &file_spec) const
Returns whether the given path is a directory.
static FileSystem & Instance()
static LanguageSet GetLanguagesSupportingTypeSystems()
Definition: Language.cpp:389
static const char * GetNameForLanguageType(lldb::LanguageType language)
Definition: Language.cpp:232
void ForEach(std::function< bool(const lldb::ModuleSP &module_sp)> const &callback) const
Applies 'callback' to each module in this ModuleList.
lldb::PlatformSP GetSelectedPlatform()
Select the active platform.
Definition: Platform.h:1009
static void AutoCompletePlatformName(llvm::StringRef partial_name, CompletionRequest &request)
static void AutoCompleteProcessName(llvm::StringRef partial_name, CompletionRequest &request)
ThreadList & GetThreadList()
Definition: Process.h:2126
virtual lldb::OptionValuePropertiesSP GetValueProperties() const
virtual const RegisterInfo * GetRegisterInfoAtIndex(size_t reg)=0
virtual size_t GetRegisterCount()=0
"lldb/Core/SearchFilter.h" This is a SearchFilter that searches through all modules.
Definition: SearchFilter.h:289
General Outline: Provides the callback and search depth for the SearchFilter search.
Definition: SearchFilter.h:83
virtual void Search(Searcher &searcher)
Call this method to do the search using the Searcher.
General Outline: Provides the callback and search depth for the SearchFilter search.
Definition: SearchFilter.h:42
An error handling class.
Definition: Status.h:44
llvm::StringRef GetString() const
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition: Stream.h:357
void SetIndentLevel(unsigned level)
Set the current indentation level.
Definition: Stream.cpp:163
size_t SplitIntoLines(const std::string &lines)
Definition: StringList.cpp:152
size_t GetSize() const
Definition: StringList.cpp:74
Defines a list of symbol context objects.
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:33
lldb::ModuleSP module_sp
The Module for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
std::shared_ptr< StopHook > StopHookSP
Definition: Target.h:1378
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition: Target.h:965
WatchpointList & GetWatchpointList()
Definition: Target.h:759
lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update=true)
Definition: ThreadList.cpp:91
virtual bool ResolveExact(llvm::StringRef Expr, llvm::SmallVectorImpl< char > &Output)=0
Resolve a Tilde Expression contained according to bash rules.
virtual bool ResolvePartial(llvm::StringRef Expr, llvm::StringSet<> &Output)=0
Auto-complete a tilde expression with all matching values.
static void AutoComplete(const ExecutionContext &exe_ctx, CompletionRequest &request)
Definition: Variable.cpp:715
This class is used by Watchpoint to manage a list of watchpoints,.
WatchpointIterable Watchpoints() const
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
std::vector< OptionArgElement > OptionElementVector
Definition: Options.h:43
@ Partial
The current token has been partially completed.
@ Normal
The current token has been completed.
std::vector< ProcessInstanceInfo > ProcessInstanceInfoList
Definition: Host.h:32
@ eRemoteDiskDirectoryCompletion
@ eFrameIndexCompletion
@ eModuleUUIDCompletion
@ eDisassemblyFlavorCompletion
@ eVariablePathCompletion
@ eDiskDirectoryCompletion
@ eTypeCategoryNameCompletion
@ ePlatformPluginCompletion
@ eSettingsNameCompletion
@ eDiskFileCompletion
@ eSourceFileCompletion
@ eTypeLanguageCompletion
@ eStopHookIDCompletion
@ eWatchpointIDCompletion
@ eBreakpointNameCompletion
@ eRegisterCompletion
@ eProcessPluginCompletion
@ eRemoteDiskFileCompletion
@ eBreakpointCompletion
@ eThreadIndexCompletion
@ eArchitectureCompletion
@ eProcessIDCompletion
@ eProcessNameCompletion
@ eDescriptionLevelBrief
@ eDescriptionLevelInitial
LanguageType
Programming language type.
@ eSearchDepthModule
@ eSearchDepthCompUnit
CompletionCallback callback
Options used by Module::FindFunctions.
Definition: Module.h:65
bool include_inlines
Include inlined functions.
Definition: Module.h:69
bool include_symbols
Include the symbol table.
Definition: Module.h:67
#define PATH_MAX