LLDB  mainline
CommandObjectApropos.cpp
Go to the documentation of this file.
1 //===-- CommandObjectApropos.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 "CommandObjectApropos.h"
13 #include "lldb/Utility/Args.h"
14 
15 using namespace lldb;
16 using namespace lldb_private;
17 
18 // CommandObjectApropos
19 
20 CommandObjectApropos::CommandObjectApropos(CommandInterpreter &interpreter)
22  interpreter, "apropos",
23  "List debugger commands related to a word or subject.", nullptr) {
25  CommandArgumentData search_word_arg;
26 
27  // Define the first (and only) variant of this arg.
28  search_word_arg.arg_type = eArgTypeSearchWord;
29  search_word_arg.arg_repetition = eArgRepeatPlain;
30 
31  // There is only one variant this argument could be; put it into the argument
32  // entry.
33  arg.push_back(search_word_arg);
34 
35  // Push the data for the first argument into the m_arguments vector.
36  m_arguments.push_back(arg);
37 }
38 
40 
42  const size_t argc = args.GetArgumentCount();
43 
44  if (argc == 1) {
45  auto search_word = args[0].ref();
46  if (!search_word.empty()) {
47  // The bulk of the work must be done inside the Command Interpreter,
48  // since the command dictionary is private.
49  StringList commands_found;
50  StringList commands_help;
51 
52  m_interpreter.FindCommandsForApropos(search_word, commands_found,
53  commands_help, true, true, true);
54 
55  if (commands_found.GetSize() == 0) {
56  result.AppendMessageWithFormat("No commands found pertaining to '%s'. "
57  "Try 'help' to see a complete list of "
58  "debugger commands.\n",
59  args[0].c_str());
60  } else {
61  if (commands_found.GetSize() > 0) {
63  "The following commands may relate to '%s':\n", args[0].c_str());
64  const size_t max_len = commands_found.GetMaxStringLength();
65 
66  for (size_t i = 0; i < commands_found.GetSize(); ++i)
68  result.GetOutputStream(), commands_found.GetStringAtIndex(i),
69  "--", commands_help.GetStringAtIndex(i), max_len);
70  }
71  }
72 
73  std::vector<const Property *> properties;
74  const size_t num_properties =
75  GetDebugger().Apropos(search_word, properties);
76  if (num_properties) {
77  const bool dump_qualified_name = true;
79  "\nThe following settings variables may relate to '{0}': \n\n",
80  args[0].ref());
81  for (size_t i = 0; i < num_properties; ++i)
82  properties[i]->DumpDescription(
83  m_interpreter, result.GetOutputStream(), 0, dump_qualified_name);
84  }
85 
87  } else {
88  result.AppendError("'' is not a valid search word.\n");
89  }
90  } else {
91  result.AppendError("'apropos' must be called with exactly one argument.\n");
92  }
93 
94  return result.Succeeded();
95 }
lldb_private::CommandObjectParsed
Definition: CommandObject.h:378
lldb_private::eArgRepeatPlain
@ eArgRepeatPlain
Definition: lldb-private-enumerations.h:95
lldb_private::CommandObject::CommandArgumentData
Definition: CommandObject.h:89
lldb_private::CommandObject::CommandArgumentData::arg_repetition
ArgumentRepetitionType arg_repetition
Definition: CommandObject.h:92
lldb_private::Args
Definition: Args.h:33
CommandReturnObject.h
lldb_private::StringList::GetSize
size_t GetSize() const
Definition: StringList.cpp:68
lldb::eReturnStatusSuccessFinishNoResult
@ eReturnStatusSuccessFinishNoResult
Definition: lldb-enumerations.h:260
lldb_private::CommandObject::m_arguments
std::vector< CommandArgumentEntry > m_arguments
Definition: CommandObject.h:366
lldb_private::StringList::GetStringAtIndex
const char * GetStringAtIndex(size_t idx) const
Definition: StringList.cpp:80
Args.h
lldb_private::StringList::GetMaxStringLength
size_t GetMaxStringLength() const
Definition: StringList.cpp:70
lldb_private::CommandReturnObject::SetStatus
void SetStatus(lldb::ReturnStatus status)
Definition: CommandReturnObject.cpp:121
lldb_private::CommandReturnObject::GetOutputStream
Stream & GetOutputStream()
Definition: CommandReturnObject.h:45
lldb_private::CommandInterpreter::FindCommandsForApropos
void FindCommandsForApropos(llvm::StringRef word, StringList &commands_found, StringList &commands_help, bool search_builtin_commands, bool search_user_commands, bool search_alias_commands)
Property.h
lldb_private::StringList
Definition: StringList.h:25
lldb_private::CommandObjectApropos::~CommandObjectApropos
~CommandObjectApropos() override
lldb_private::Properties::Apropos
size_t Apropos(llvm::StringRef keyword, std::vector< const Property * > &matching_properties) const
Definition: UserSettingsController.cpp:86
lldb_private::CommandInterpreter
Definition: CommandInterpreter.h:214
lldb_private::CommandObject::m_interpreter
CommandInterpreter & m_interpreter
Definition: CommandObject.h:358
lldb_private::CommandObject::CommandArgumentData::arg_type
lldb::CommandArgumentType arg_type
Definition: CommandObject.h:91
lldb_private::CommandObjectApropos::DoExecute
bool DoExecute(Args &command, CommandReturnObject &result) override
Definition: CommandObjectApropos.cpp:41
lldb_private::CommandReturnObject
Definition: CommandReturnObject.h:25
CommandObjectApropos.h
lldb_private::CommandReturnObject::AppendMessageWithFormat
void AppendMessageWithFormat(const char *format,...) __attribute__((format(printf
Definition: CommandReturnObject.cpp:64
lldb::eArgTypeSearchWord
@ eArgTypeSearchWord
Definition: lldb-enumerations.h:574
lldb_private::CommandReturnObject::Succeeded
bool Succeeded()
Definition: CommandReturnObject.cpp:125
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
CommandInterpreter.h
lldb_private::CommandObject::CommandArgumentEntry
std::vector< CommandArgumentData > CommandArgumentEntry
Definition: CommandObject.h:105
lldb_private::CommandInterpreter::OutputFormattedHelpText
void OutputFormattedHelpText(Stream &strm, llvm::StringRef prefix, llvm::StringRef help_text)
lldb_private::CommandReturnObject::AppendError
void void AppendError(llvm::StringRef in_string)
Definition: CommandReturnObject.cpp:100
lldb_private::Args::GetArgumentCount
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
Definition: Args.h:118
lldb
Definition: SBAddress.h:15
lldb_private::CommandReturnObject::AppendMessageWithFormatv
void void AppendMessageWithFormatv(const char *format, Args &&... args)
Definition: CommandReturnObject.h:119
lldb_private::CommandObject::GetDebugger
Debugger & GetDebugger()
Definition: CommandObject.cpp:51