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
13#include "lldb/Utility/Args.h"
15
16using namespace lldb;
17using namespace lldb_private;
18
19// CommandObjectApropos
20
23 interpreter, "apropos",
24 "List debugger commands related to a word or subject.", nullptr) {
26}
27
29
31 const size_t argc = args.GetArgumentCount();
32
33 if (argc == 1) {
34 auto search_word = args[0].ref();
35 if (!search_word.empty()) {
37
38 // Find all commands matching the search word.
39 StringList commands_found;
40 StringList commands_help;
41 m_interpreter.FindCommandsForApropos(
42 search_word, commands_found, commands_help, true, true, true, true);
43
44 if (commands_found.GetSize() == 0) {
45 result.AppendMessageWithFormat("No commands found pertaining to '%s'. "
46 "Try 'help' to see a complete list of "
47 "debugger commands.\n",
48 args[0].c_str());
49 } else {
51 "The following commands may relate to '%s':\n", args[0].c_str());
52 const size_t commands_max_len = commands_found.GetMaxStringLength();
53 for (size_t i = 0; i < commands_found.GetSize(); ++i)
54 m_interpreter.OutputFormattedHelpText(
55 result.GetOutputStream(), commands_found.GetStringAtIndex(i),
56 "--", commands_help.GetStringAtIndex(i), commands_max_len);
58 }
59
60 // Find all the properties matching the search word.
61 size_t properties_max_len = 0;
62 std::vector<const Property *> properties;
63 const size_t num_properties =
64 GetDebugger().Apropos(search_word, properties);
65 for (const Property *prop : properties) {
66 StreamString qualified_name;
67 prop->DumpQualifiedName(qualified_name);
68 properties_max_len =
69 std::max(properties_max_len, qualified_name.GetString().size());
70 }
71
72 if (num_properties == 0) {
74 "No settings found pertaining to '%s'. "
75 "Try 'settings show' to see a complete list of "
76 "debugger settings.\n",
77 args[0].c_str());
78
79 } else {
81 "\nThe following settings variables may relate to '{0}': \n\n",
82 search_word);
83
84 const bool dump_qualified_name = true;
85 for (size_t i = 0; i < num_properties; ++i)
86 properties[i]->DumpDescription(
87 m_interpreter, result.GetOutputStream(), properties_max_len,
88 dump_qualified_name);
90 }
91
92 result.SetStatus(return_status);
93 } else {
94 result.AppendError("'' is not a valid search word.\n");
95 }
96 } else {
97 result.AppendError("'apropos' must be called with exactly one argument.\n");
98 }
99}
A command line argument class.
Definition Args.h:33
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
Definition Args.h:120
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectApropos(CommandInterpreter &interpreter)
CommandObjectParsed(CommandInterpreter &interpreter, const char *name, const char *help=nullptr, const char *syntax=nullptr, uint32_t flags=0)
void AddSimpleArgumentList(lldb::CommandArgumentType arg_type, ArgumentRepetitionType repetition_type=eArgRepeatPlain)
CommandInterpreter & m_interpreter
void void AppendError(llvm::StringRef in_string)
void SetStatus(lldb::ReturnStatus status)
void AppendMessageWithFormat(const char *format,...) __attribute__((format(printf
void void AppendMessageWithFormatv(const char *format, Args &&...args)
size_t Apropos(llvm::StringRef keyword, std::vector< const Property * > &matching_properties) const
llvm::StringRef GetString() const
size_t GetMaxStringLength() const
const char * GetStringAtIndex(size_t idx) const
A class that represents a running process on the host machine.
ReturnStatus
Command Return Status Types.
@ eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishNoResult