9#include "llvm/ADT/STLExtras.h"
10#include "llvm/ADT/SmallString.h"
11#include "llvm/ADT/StringRef.h"
12#include "llvm/ADT/StringSet.h"
36#include "llvm/Support/FileSystem.h"
37#include "llvm/Support/Path.h"
101 else if ((common_completions[i].type & completion_mask) ==
102 common_completions[i].type &&
103 common_completions[i].callback !=
nullptr) {
105 common_completions[i].
callback(interpreter, request, searcher);
117 : m_interpreter(interpreter), m_request(request) {}
119 ~Completer()
override =
default;
133 Completer(
const Completer &) =
delete;
134 const Completer &operator=(
const Completer &) =
delete;
140class SourceFileCompleter :
public Completer {
142 SourceFileCompleter(CommandInterpreter &interpreter,
143 CompletionRequest &request)
144 : Completer(interpreter, request),
145 m_partial_spec(m_request.GetCursorArgumentPrefix()) {}
150 SymbolContext &context,
151 Address *addr)
override {
152 llvm::StringRef spec_file_name = m_partial_spec.GetFilename();
153 llvm::StringRef spec_dir_name = m_partial_spec.GetDirectory();
155 llvm::StringRef cur_file_name =
157 llvm::StringRef cur_dir_name =
161 if (!spec_file_name.empty() && cur_file_name.starts_with(spec_file_name))
164 if (match && !spec_dir_name.empty() &&
165 !cur_dir_name.starts_with(spec_dir_name))
172 return m_matching_files.GetSize() >=
173 m_request.GetMaxNumberOfCompletionsToAdd()
178 void DoCompletion(SearchFilter *filter)
override {
181 for (
size_t i = 0; i < m_matching_files.GetSize(); i++) {
182 m_request.AddCompletion(
183 m_matching_files.GetFileSpecAtIndex(i).GetFilename());
188 FileSpec m_partial_spec;
189 FileSpecList m_matching_files;
191 SourceFileCompleter(
const SourceFileCompleter &) =
delete;
192 const SourceFileCompleter &operator=(
const SourceFileCompleter &) =
delete;
197 return llvm::StringRef(
"[](){}+.*|^$\\?").contains(comp);
201class SymbolCompleter :
public Completer {
204 SymbolCompleter(CommandInterpreter &interpreter, CompletionRequest &request)
205 : Completer(interpreter, request) {
206 std::string regex_str;
207 if (!m_request.GetCursorArgumentPrefix().empty()) {
208 regex_str.append(
"^");
209 regex_str.append(std::string(m_request.GetCursorArgumentPrefix()));
212 regex_str.append(
".");
214 std::string::iterator pos =
215 find_if(regex_str.begin() + 1, regex_str.end(),
regex_chars);
216 while (pos < regex_str.end()) {
217 pos = regex_str.insert(pos,
'\\');
218 pos = find_if(pos + 2, regex_str.end(), regex_chars);
226 SymbolContext &context,
227 Address *addr)
override {
229 SymbolContextList sc_list;
230 ModuleFunctionSearchOptions function_options;
233 context.
module_sp->FindFunctions(m_regex, function_options, sc_list);
236 for (
const SymbolContext &sc : sc_list) {
237 if (m_match_set.size() >= m_request.GetMaxNumberOfCompletionsToAdd())
246 m_match_set.insert(func_name);
249 return m_match_set.size() >= m_request.GetMaxNumberOfCompletionsToAdd()
254 void DoCompletion(SearchFilter *filter)
override {
256 collection::iterator pos = m_match_set.begin(), end = m_match_set.end();
257 for (pos = m_match_set.begin(); pos != end; pos++)
258 m_request.AddCompletion((*pos).GetCString());
263 typedef std::set<ConstString> collection;
264 collection m_match_set;
266 SymbolCompleter(
const SymbolCompleter &) =
delete;
267 const SymbolCompleter &operator=(
const SymbolCompleter &) =
delete;
272class ModuleCompleter :
public Completer {
274 ModuleCompleter(CommandInterpreter &interpreter, CompletionRequest &request)
275 : Completer(interpreter, request) {
276 llvm::StringRef request_str = m_request.GetCursorArgumentPrefix();
283 m_spelled_path = request_str;
284 m_canonical_path = FileSpec(m_spelled_path).GetPath();
285 if (!m_spelled_path.empty() &&
286 llvm::sys::path::is_separator(m_spelled_path.back()) &&
287 !llvm::StringRef(m_canonical_path).ends_with(m_spelled_path.back())) {
288 m_canonical_path += m_spelled_path.back();
291 if (llvm::find_if(request_str, [](
char c) {
292 return llvm::sys::path::is_separator(c);
293 }) == request_str.end())
294 m_file_name = request_str;
300 SymbolContext &context,
301 Address *addr)
override {
304 std::string cur_path = context.
module_sp->GetFileSpec().GetPath();
305 llvm::StringRef cur_path_view = cur_path;
306 if (cur_path_view.consume_front(m_canonical_path))
307 m_request.AddCompletion((m_spelled_path + cur_path_view).str());
311 llvm::StringRef cur_file_name =
312 context.
module_sp->GetFileSpec().GetFilename();
313 if (cur_file_name.starts_with(*m_file_name))
314 m_request.AddCompletion(cur_file_name);
321 void DoCompletion(SearchFilter *filter)
override { filter->
Search(*
this); }
324 std::optional<llvm::StringRef> m_file_name;
325 llvm::StringRef m_spelled_path;
326 std::string m_canonical_path;
328 ModuleCompleter(
const ModuleCompleter &) =
delete;
329 const ModuleCompleter &operator=(
const ModuleCompleter &) =
delete;
336 SourceFileCompleter completer(interpreter, request);
338 if (searcher ==
nullptr) {
341 completer.DoCompletion(&null_searcher);
343 completer.DoCompletion(searcher);
348 bool only_directories,
351 llvm::SmallString<256> CompletionBuffer;
352 llvm::SmallString<256> Storage;
353 partial_name.toVector(CompletionBuffer);
355 if (CompletionBuffer.size() >=
PATH_MAX)
358 namespace path = llvm::sys::path;
360 llvm::StringRef SearchDir;
361 llvm::StringRef PartialItem;
363 if (CompletionBuffer.starts_with(
"~")) {
364 llvm::StringRef Buffer = CompletionBuffer;
366 Buffer.find_if([](
char c) {
return path::is_separator(c); });
368 llvm::StringRef Username = Buffer.take_front(FirstSep);
369 llvm::StringRef Remainder;
370 if (FirstSep != llvm::StringRef::npos)
371 Remainder = Buffer.drop_front(FirstSep + 1);
373 llvm::SmallString<256> Resolved;
378 if (FirstSep == llvm::StringRef::npos) {
379 llvm::StringSet<> MatchSet;
381 for (
const auto &S : MatchSet) {
382 Resolved = S.getKey();
383 path::append(Resolved, path::get_separator());
393 if (FirstSep == llvm::StringRef::npos) {
395 path::append(CompletionBuffer, path::get_separator());
404 llvm::StringRef RemainderDir = path::parent_path(Remainder);
405 if (!RemainderDir.empty()) {
407 Storage.append(path::get_separator());
408 Storage.append(RemainderDir);
411 }
else if (CompletionBuffer == path::root_directory(CompletionBuffer)) {
412 SearchDir = CompletionBuffer;
414 SearchDir = path::parent_path(CompletionBuffer);
417 size_t FullPrefixLen = CompletionBuffer.size();
419 PartialItem = path::filename(CompletionBuffer);
425 if ((PartialItem ==
"." || PartialItem == path::get_separator()) &&
426 path::is_separator(CompletionBuffer.back()))
427 PartialItem = llvm::StringRef();
429 if (SearchDir.empty()) {
430 llvm::sys::fs::current_path(Storage);
433 assert(!PartialItem.contains(path::get_separator()));
440 llvm::vfs::directory_iterator Iter = fs.
DirBegin(SearchDir, EC);
441 llvm::vfs::directory_iterator End;
443 Iter.increment(EC)) {
450 auto Name = path::filename(
Entry.path());
453 if (Name ==
"." || Name ==
".." || !Name.starts_with(PartialItem))
456 bool is_dir =
Status->isDirectory();
460 if (
Status->isSymlink()) {
468 if (only_directories && !is_dir)
474 CompletionBuffer.resize(FullPrefixLen);
475 Name = Name.drop_front(PartialItem.size());
476 CompletionBuffer.append(Name);
479 path::append(CompletionBuffer, path::get_separator());
492 std::string partial_name_str = partial_name.str();
499 bool only_directories) {
535 platform_sp->AutoCompleteDiskFileOrDirectory(request,
false);
544 platform_sp->AutoCompleteDiskFileOrDirectory(request,
true);
550 ModuleCompleter completer(interpreter, request);
552 if (searcher ==
nullptr) {
555 completer.DoCompletion(&null_searcher);
557 completer.DoCompletion(searcher);
571 module->GetDescription(strm.AsRawOstream(),
572 lldb::eDescriptionLevelInitial);
582 SymbolCompleter completer(interpreter, request);
584 if (searcher ==
nullptr) {
587 completer.DoCompletion(&null_searcher);
589 completer.DoCompletion(searcher);
599 if (g_property_names.
GetSize() == 0) {
606 const std::string &str = std::string(strm.
GetString());
611 for (
const std::string &name : g_property_names) {
612 std::string description;
614 properties_sp->GetPropertyAtPath(
nullptr, name))
615 description =
property->GetDescription().str();
621 assert(g_property_names.
GetSize() == g_property_descriptions.
GetSize() &&
622 "Not all properties got descriptions?");
623 for (
size_t i = 0; i < g_property_names.
GetSize(); ++i)
625 g_property_descriptions[i]);
650 std::string reg_prefix;
660 for (
size_t reg_idx = 0; reg_idx < reg_num; ++reg_idx) {
676 std::unique_lock<std::recursive_mutex> lock;
677 target->GetBreakpointList().GetListMutex(lock);
679 size_t num_breakpoints = breakpoints.
GetSize();
680 if (num_breakpoints == 0)
683 for (
size_t i = 0; i < num_breakpoints; ++i) {
690 const size_t colon_pos = bp_info.find_first_of(
':');
691 if (colon_pos != llvm::StringRef::npos)
692 bp_info = bp_info.drop_front(colon_pos + 2);
705 std::vector<std::string> name_list;
706 target->GetBreakpointNames(name_list);
708 for (
const std::string &name : name_list)
723 static const char *flavors[] = {
"default",
"att",
"intel"};
724 for (
const char *flavor : flavors) {
737 platform_sp->FindProcesses(match_info, process_infos);
751 platform_sp->FindProcesses(match_info, process_infos);
775 const uint32_t frame_num = thread_sp->GetStackFrameCount();
776 for (uint32_t i = 0; i < frame_num; ++i) {
782 frame_sp->Dump(&strm,
false,
true);
795 for (
auto &stophook_sp : target_sp->GetStopHooks()) {
815 for (uint32_t idx = 0; (thread_sp = threads.
GetThreadAtIndex(idx)); ++idx) {
817 thread_sp->GetStatus(strm, 0, 1, 1,
true,
true);
845 category_sp->GetDescription());
859 for (uint32_t idx = 0; (thread_sp = threads.
GetThreadAtIndex(idx)); ++idx) {
861 thread_sp->GetStatus(strm, 0, 1, 1,
true,
true);
888 std::vector<size_t> to_delete;
889 for (
auto &elem : opt_element_vector) {
890 to_delete.push_back(elem.opt_pos);
891 if (elem.opt_arg_pos != 0)
892 to_delete.push_back(elem.opt_arg_pos);
894 sort(to_delete.begin(), to_delete.end(), std::greater<size_t>());
895 for (
size_t idx : to_delete)
929 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.
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 ManagedPlugins(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)
static void ScriptedExtensions(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
lldb::TargetSP GetSelectedTarget()
Get the target selected by the user at the command line.
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)
ExecutionContext GetExecutionContext(bool adopt_dummy_target=true) const
Returns the execution context the interpreter should run a command in.
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
bool ShouldAddCompletions() const
Returns true if the maximum number of completions has not been reached yet, hence we should keep addi...
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.
bool IsEmpty() const
Test for empty string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
static void ForEach(TypeCategoryMap::ForEachCallback callback)
A class to manage flag bits.
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
llvm::StringRef GetFilename() const
Filename string const get accessor.
llvm::StringRef 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)
Returns the internal LLDB name for the specified language.
void ForEach(std::function< IterationAction(const lldb::ModuleSP &module_sp)> const &callback) const
Applies 'callback' to each module in this ModuleList.
static void AutoCompleteScriptedExtension(llvm::StringRef partial_name, CompletionRequest &request, lldb::ScriptLanguage language=lldb::eScriptLanguageUnknown)
static void AutoCompletePlatformName(llvm::StringRef partial_name, CompletionRequest &request)
static void AutoCompleteProcessName(llvm::StringRef partial_name, CompletionRequest &request)
static void AutoCompletePluginName(llvm::StringRef partial_name, CompletionRequest &request)
ThreadList & GetThreadList()
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
void SetIndentLevel(unsigned level)
Set the current indentation level.
size_t SplitIntoLines(const std::string &lines)
void AppendString(const std::string &s)
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.
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.
static uint32_t bit(const uint32_t val, const uint32_t msbit)
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
@ eScriptedExtensionCompletion
@ eManagedPluginCompletion
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
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.