9#include "llvm/ADT/SmallString.h"
10#include "llvm/ADT/StringSet.h"
33#include "llvm/Support/FileSystem.h"
34#include "llvm/Support/Path.h"
92 for (
int i = 0;; i++) {
95 else if ((common_completions[i].type & completion_mask) ==
96 common_completions[i].type &&
97 common_completions[i].callback !=
nullptr) {
99 common_completions[i].
callback(interpreter, request, searcher);
111 : m_interpreter(interpreter), m_request(request) {}
113 ~Completer()
override =
default;
127 Completer(
const Completer &) =
delete;
128 const Completer &operator=(
const Completer &) =
delete;
134class SourceFileCompleter :
public Completer {
138 : Completer(interpreter, request) {
139 FileSpec partial_spec(m_request.GetCursorArgumentPrefix());
140 m_file_name = partial_spec.GetFilename().GetCString();
141 m_dir_name = partial_spec.GetDirectory().GetCString();
150 const char *cur_file_name =
152 const char *cur_dir_name =
156 if (m_file_name && cur_file_name &&
157 strstr(cur_file_name, m_file_name) == cur_file_name)
160 if (match && m_dir_name && cur_dir_name &&
161 strstr(cur_dir_name, m_dir_name) != cur_dir_name)
174 for (
size_t i = 0; i < m_matching_files.GetSize(); i++) {
175 m_request.AddCompletion(
176 m_matching_files.GetFileSpecAtIndex(i).GetFilename().GetCString());
182 const char *m_file_name;
183 const char *m_dir_name;
185 SourceFileCompleter(
const SourceFileCompleter &) =
delete;
186 const SourceFileCompleter &operator=(
const SourceFileCompleter &) =
delete;
191 return llvm::StringRef(
"[](){}+.*|^$\\?").contains(comp);
195class SymbolCompleter :
public Completer {
199 : Completer(interpreter, request) {
200 std::string regex_str;
201 if (!m_request.GetCursorArgumentPrefix().empty()) {
202 regex_str.append(
"^");
203 regex_str.append(std::string(m_request.GetCursorArgumentPrefix()));
206 regex_str.append(
".");
208 std::string::iterator pos =
209 find_if(regex_str.begin() + 1, regex_str.end(),
regex_chars);
210 while (pos < regex_str.end()) {
211 pos = regex_str.insert(pos,
'\\');
212 pos = find_if(pos + 2, regex_str.end(),
regex_chars);
227 context.
module_sp->FindFunctions(m_regex, function_options, sc_list);
237 m_match_set.insert(func_name);
245 collection::iterator pos = m_match_set.begin(), end = m_match_set.end();
246 for (pos = m_match_set.begin(); pos != end; pos++)
247 m_request.AddCompletion((*pos).GetCString());
252 typedef std::set<ConstString> collection;
253 collection m_match_set;
255 SymbolCompleter(
const SymbolCompleter &) =
delete;
256 const SymbolCompleter &operator=(
const SymbolCompleter &) =
delete;
261class ModuleCompleter :
public Completer {
264 : Completer(interpreter, request) {
265 FileSpec partial_spec(m_request.GetCursorArgumentPrefix());
266 m_file_name = partial_spec.GetFilename().GetCString();
267 m_dir_name = partial_spec.GetDirectory().GetCString();
276 const char *cur_file_name =
277 context.
module_sp->GetFileSpec().GetFilename().GetCString();
278 const char *cur_dir_name =
279 context.
module_sp->GetFileSpec().GetDirectory().GetCString();
282 if (m_file_name && cur_file_name &&
283 strstr(cur_file_name, m_file_name) == cur_file_name)
286 if (match && m_dir_name && cur_dir_name &&
287 strstr(cur_dir_name, m_dir_name) != cur_dir_name)
291 m_request.AddCompletion(cur_file_name);
300 const char *m_file_name;
301 const char *m_dir_name;
303 ModuleCompleter(
const ModuleCompleter &) =
delete;
304 const ModuleCompleter &operator=(
const ModuleCompleter &) =
delete;
311 SourceFileCompleter completer(interpreter, request);
313 if (searcher ==
nullptr) {
316 completer.DoCompletion(&null_searcher);
318 completer.DoCompletion(searcher);
323 bool only_directories,
326 llvm::SmallString<256> CompletionBuffer;
327 llvm::SmallString<256> Storage;
328 partial_name.toVector(CompletionBuffer);
330 if (CompletionBuffer.size() >=
PATH_MAX)
333 namespace path = llvm::sys::path;
335 llvm::StringRef SearchDir;
336 llvm::StringRef PartialItem;
338 if (CompletionBuffer.starts_with(
"~")) {
339 llvm::StringRef Buffer = CompletionBuffer;
341 Buffer.find_if([](
char c) {
return path::is_separator(c); });
343 llvm::StringRef Username = Buffer.take_front(FirstSep);
344 llvm::StringRef Remainder;
345 if (FirstSep != llvm::StringRef::npos)
346 Remainder = Buffer.drop_front(FirstSep + 1);
348 llvm::SmallString<256> Resolved;
353 if (FirstSep == llvm::StringRef::npos) {
354 llvm::StringSet<> MatchSet;
356 for (
const auto &S : MatchSet) {
357 Resolved = S.getKey();
358 path::append(Resolved, path::get_separator());
368 if (FirstSep == llvm::StringRef::npos) {
370 path::append(CompletionBuffer, path::get_separator());
379 llvm::StringRef RemainderDir = path::parent_path(Remainder);
380 if (!RemainderDir.empty()) {
382 Storage.append(path::get_separator());
383 Storage.append(RemainderDir);
386 }
else if (CompletionBuffer == path::root_directory(CompletionBuffer)) {
387 SearchDir = CompletionBuffer;
389 SearchDir = path::parent_path(CompletionBuffer);
392 size_t FullPrefixLen = CompletionBuffer.size();
394 PartialItem = path::filename(CompletionBuffer);
400 if ((PartialItem ==
"." || PartialItem == path::get_separator()) &&
401 path::is_separator(CompletionBuffer.back()))
402 PartialItem = llvm::StringRef();
404 if (SearchDir.empty()) {
405 llvm::sys::fs::current_path(Storage);
408 assert(!PartialItem.contains(path::get_separator()));
415 llvm::vfs::directory_iterator Iter = fs.
DirBegin(SearchDir, EC);
416 llvm::vfs::directory_iterator End;
417 for (; Iter != End && !EC; Iter.increment(EC)) {
424 auto Name = path::filename(
Entry.path());
427 if (Name ==
"." || Name ==
".." || !Name.starts_with(PartialItem))
430 bool is_dir =
Status->isDirectory();
434 if (
Status->isSymlink()) {
442 if (only_directories && !is_dir)
448 CompletionBuffer.resize(FullPrefixLen);
449 Name = Name.drop_front(PartialItem.size());
450 CompletionBuffer.append(Name);
453 path::append(CompletionBuffer, path::get_separator());
466 std::string partial_name_str = partial_name.str();
473 bool only_directories) {
509 platform_sp->AutoCompleteDiskFileOrDirectory(request,
false);
518 platform_sp->AutoCompleteDiskFileOrDirectory(request,
true);
524 ModuleCompleter completer(interpreter, request);
526 if (searcher ==
nullptr) {
529 completer.DoCompletion(&null_searcher);
531 completer.DoCompletion(searcher);
556 SymbolCompleter completer(interpreter, request);
558 if (searcher ==
nullptr) {
561 completer.DoCompletion(&null_searcher);
563 completer.DoCompletion(searcher);
572 if (g_property_names.
GetSize() == 0) {
579 const std::string &str = std::string(strm.
GetString());
584 for (
const std::string &s : g_property_names)
610 std::string reg_prefix;
620 for (
size_t reg_idx = 0; reg_idx < reg_num; ++reg_idx) {
636 std::unique_lock<std::recursive_mutex> lock;
639 size_t num_breakpoints = breakpoints.
GetSize();
640 if (num_breakpoints == 0)
643 for (
size_t i = 0; i < num_breakpoints; ++i) {
650 const size_t colon_pos = bp_info.find_first_of(
':');
651 if (colon_pos != llvm::StringRef::npos)
652 bp_info = bp_info.drop_front(colon_pos + 2);
665 std::vector<std::string> name_list;
666 target->GetBreakpointNames(name_list);
668 for (
const std::string &name : name_list)
683 static const char *flavors[] = {
"default",
"att",
"intel"};
684 for (
const char *flavor : flavors) {
697 platform_sp->FindProcesses(match_info, process_infos);
700 info.GetNameAsStringRef());
711 platform_sp->FindProcesses(match_info, process_infos);
735 const uint32_t frame_num = thread_sp->GetStackFrameCount();
736 for (uint32_t i = 0; i < frame_num; ++i) {
742 frame_sp->Dump(&strm,
false,
true);
755 const size_t num = target_sp->GetNumStopHooks();
756 for (
size_t idx = 0; idx < num; ++idx) {
777 for (uint32_t idx = 0; (thread_sp = threads.
GetThreadAtIndex(idx)); ++idx) {
779 thread_sp->GetStatus(strm, 0, 1, 1,
true);
807 category_sp->GetDescription());
821 for (uint32_t idx = 0; (thread_sp = threads.
GetThreadAtIndex(idx)); ++idx) {
823 thread_sp->GetStatus(strm, 0, 1, 1,
true);
836 std::vector<size_t> to_delete;
837 for (
auto &elem : opt_element_vector) {
838 to_delete.push_back(elem.opt_pos);
839 if (elem.opt_arg_pos != 0)
840 to_delete.push_back(elem.opt_arg_pos);
842 sort(to_delete.begin(), to_delete.end(), std::greater<size_t>());
843 for (
size_t idx : to_delete)
877 assert(mwc !=
nullptr);
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 INTERRUPT_REQUESTED(debugger,...)
This handy define will keep you from having to generate a report for the interruption by hand.
A section + offset based address class.
static void AutoComplete(CompletionRequest &request)
A command line argument class.
void DeleteArgumentAtIndex(size_t idx)
Deletes the argument value at index if idx is a valid argument index.
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
const char * GetArgumentAtIndex(size_t idx) const
Gets the NULL terminated C string argument pointer for the argument at index idx.
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 ThreadIDs(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 spec associated with this compile unit.
"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.
bool IsEmpty() const
Test for empty string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
const char * GetCString() const
Get the string value as a C string.
static void ForEach(TypeCategoryMap::ForEachCallback callback)
A class to manage flag bits.
lldb::TargetSP GetSelectedTarget()
PlatformList & GetPlatformList()
"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
const ConstString & GetFilename() const
Filename string const get accessor.
const ConstString & GetDirectory() const
Directory string const get accessor.
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()
static const char * GetNameForLanguageType(lldb::LanguageType language)
void ForEach(std::function< bool(const lldb::ModuleSP &module_sp)> const &callback) const
Applies 'callback' to each module in this ModuleList.
static void AutoCompletePlatformName(llvm::StringRef partial_name, CompletionRequest &request)
static void AutoCompleteProcessName(llvm::StringRef partial_name, CompletionRequest &request)
ThreadList & GetThreadList()
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.
General Outline: Provides the callback and search depth for the SearchFilter search.
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.
@ eCallbackReturnContinue
llvm::StringRef GetString() const
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
void SetIndentLevel(unsigned level)
Set the current indentation level.
size_t SplitIntoLines(const std::string &lines)
Defines a list of symbol context objects.
Defines a symbol context baton that can be handed other debug core functions.
lldb::ModuleSP module_sp
The Module for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
std::shared_ptr< StopHook > StopHookSP
const ModuleList & GetImages() const
Get accessor for the images for this process.
WatchpointList & GetWatchpointList()
lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update=true)
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)
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.
std::vector< OptionArgElement > OptionElementVector
@ Partial
The current token has been partially completed.
@ Normal
The current token has been completed.
std::vector< ProcessInstanceInfo > ProcessInstanceInfoList
@ eRemoteDiskDirectoryCompletion
@ eDisassemblyFlavorCompletion
@ eVariablePathCompletion
@ eDiskDirectoryCompletion
@ eTypeCategoryNameCompletion
@ ePlatformPluginCompletion
@ eSettingsNameCompletion
@ eTypeLanguageCompletion
@ eWatchpointIDCompletion
@ eBreakpointNameCompletion
@ eProcessPluginCompletion
@ eRemoteDiskFileCompletion
@ eArchitectureCompletion
std::shared_ptr< lldb_private::OptionValueProperties > OptionValuePropertiesSP
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
@ eDescriptionLevelInitial
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::Platform > PlatformSP
LanguageType
Programming language type.
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
std::shared_ptr< lldb_private::Watchpoint > WatchpointSP
std::shared_ptr< lldb_private::TypeCategoryImpl > TypeCategoryImplSP
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP
CompletionCallback callback
Options used by Module::FindFunctions.
bool include_inlines
Include inlined functions.
bool include_symbols
Include the symbol table.
Every register is described in detail including its name, alternate name (optional),...
const char * alt_name
Alternate name of this register, can be NULL.
const char * name
Name of this register, can't be NULL.