Path: blob/main/contrib/llvm-project/lldb/source/Commands/CommandObjectApropos.cpp
39587 views
//===-- CommandObjectApropos.cpp ------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "CommandObjectApropos.h"9#include "lldb/Interpreter/CommandInterpreter.h"10#include "lldb/Interpreter/CommandReturnObject.h"11#include "lldb/Interpreter/Property.h"12#include "lldb/Utility/Args.h"1314using namespace lldb;15using namespace lldb_private;1617// CommandObjectApropos1819CommandObjectApropos::CommandObjectApropos(CommandInterpreter &interpreter)20: CommandObjectParsed(21interpreter, "apropos",22"List debugger commands related to a word or subject.", nullptr) {23AddSimpleArgumentList(eArgTypeSearchWord);24}2526CommandObjectApropos::~CommandObjectApropos() = default;2728void CommandObjectApropos::DoExecute(Args &args, CommandReturnObject &result) {29const size_t argc = args.GetArgumentCount();3031if (argc == 1) {32auto search_word = args[0].ref();33if (!search_word.empty()) {34// The bulk of the work must be done inside the Command Interpreter,35// since the command dictionary is private.36StringList commands_found;37StringList commands_help;3839m_interpreter.FindCommandsForApropos(40search_word, commands_found, commands_help, true, true, true, true);4142if (commands_found.GetSize() == 0) {43result.AppendMessageWithFormat("No commands found pertaining to '%s'. "44"Try 'help' to see a complete list of "45"debugger commands.\n",46args[0].c_str());47} else {48if (commands_found.GetSize() > 0) {49result.AppendMessageWithFormat(50"The following commands may relate to '%s':\n", args[0].c_str());51const size_t max_len = commands_found.GetMaxStringLength();5253for (size_t i = 0; i < commands_found.GetSize(); ++i)54m_interpreter.OutputFormattedHelpText(55result.GetOutputStream(), commands_found.GetStringAtIndex(i),56"--", commands_help.GetStringAtIndex(i), max_len);57}58}5960std::vector<const Property *> properties;61const size_t num_properties =62GetDebugger().Apropos(search_word, properties);63if (num_properties) {64const bool dump_qualified_name = true;65result.AppendMessageWithFormatv(66"\nThe following settings variables may relate to '{0}': \n\n",67args[0].ref());68for (size_t i = 0; i < num_properties; ++i)69properties[i]->DumpDescription(70m_interpreter, result.GetOutputStream(), 0, dump_qualified_name);71}7273result.SetStatus(eReturnStatusSuccessFinishNoResult);74} else {75result.AppendError("'' is not a valid search word.\n");76}77} else {78result.AppendError("'apropos' must be called with exactly one argument.\n");79}80}818283