Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- CommandObjectApropos.cpp ---------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 10 | // C Includes |
| 11 | // C++ Includes |
| 12 | // Other libraries and framework includes |
| 13 | // Project includes |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 14 | #include "CommandObjectApropos.h" |
Jim Ingham | 40af72e | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 15 | #include "lldb/Interpreter/Args.h" |
| 16 | #include "lldb/Interpreter/Options.h" |
Zachary Turner | 633a29c | 2015-03-04 01:58:01 +0000 | [diff] [blame] | 17 | #include "lldb/Interpreter/Property.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 19 | #include "lldb/Interpreter/CommandReturnObject.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace lldb; |
| 22 | using namespace lldb_private; |
| 23 | |
| 24 | //------------------------------------------------------------------------- |
| 25 | // CommandObjectApropos |
| 26 | //------------------------------------------------------------------------- |
| 27 | |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame^] | 28 | CommandObjectApropos::CommandObjectApropos(CommandInterpreter &interpreter) |
| 29 | : CommandObjectParsed(interpreter, "apropos", "List debugger commands related to a word or subject.", nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 31 | CommandArgumentEntry arg; |
| 32 | CommandArgumentData search_word_arg; |
| 33 | |
| 34 | // Define the first (and only) variant of this arg. |
| 35 | search_word_arg.arg_type = eArgTypeSearchWord; |
| 36 | search_word_arg.arg_repetition = eArgRepeatPlain; |
| 37 | |
| 38 | // There is only one variant this argument could be; put it into the argument entry. |
| 39 | arg.push_back (search_word_arg); |
| 40 | |
| 41 | // Push the data for the first argument into the m_arguments vector. |
| 42 | m_arguments.push_back (arg); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 45 | CommandObjectApropos::~CommandObjectApropos() = default; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 46 | |
| 47 | bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 48 | CommandObjectApropos::DoExecute (Args& args, CommandReturnObject &result) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 50 | const size_t argc = args.GetArgumentCount (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | |
| 52 | if (argc == 1) |
| 53 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 54 | const char *search_word = args.GetArgumentAtIndex(0); |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 55 | if ((search_word != nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 56 | && (strlen (search_word) > 0)) |
| 57 | { |
| 58 | // The bulk of the work must be done inside the Command Interpreter, since the command dictionary |
| 59 | // is private. |
| 60 | StringList commands_found; |
| 61 | StringList commands_help; |
Jim Ingham | af3753e | 2013-05-17 01:30:37 +0000 | [diff] [blame] | 62 | |
Enrico Granata | d033e1c | 2016-03-23 01:21:55 +0000 | [diff] [blame] | 63 | m_interpreter.FindCommandsForApropos (search_word, commands_found, commands_help, true, true, true); |
Jim Ingham | af3753e | 2013-05-17 01:30:37 +0000 | [diff] [blame] | 64 | |
Enrico Granata | d033e1c | 2016-03-23 01:21:55 +0000 | [diff] [blame] | 65 | if (commands_found.GetSize() == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 66 | { |
Greg Clayton | 3bcbf84 | 2010-11-02 18:23:13 +0000 | [diff] [blame] | 67 | result.AppendMessageWithFormat ("No commands found pertaining to '%s'. Try 'help' to see a complete list of debugger commands.\n", search_word); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 68 | } |
| 69 | else |
| 70 | { |
Jim Ingham | af3753e | 2013-05-17 01:30:37 +0000 | [diff] [blame] | 71 | if (commands_found.GetSize() > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | { |
Enrico Granata | d033e1c | 2016-03-23 01:21:55 +0000 | [diff] [blame] | 73 | result.AppendMessageWithFormat ("The following commands may relate to '%s':\n", search_word); |
Jim Ingham | af3753e | 2013-05-17 01:30:37 +0000 | [diff] [blame] | 74 | size_t max_len = 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 75 | |
Jim Ingham | af3753e | 2013-05-17 01:30:37 +0000 | [diff] [blame] | 76 | for (size_t i = 0; i < commands_found.GetSize(); ++i) |
| 77 | { |
| 78 | size_t len = strlen (commands_found.GetStringAtIndex (i)); |
| 79 | if (len > max_len) |
| 80 | max_len = len; |
| 81 | } |
| 82 | |
| 83 | for (size_t i = 0; i < commands_found.GetSize(); ++i) |
| 84 | m_interpreter.OutputFormattedHelpText (result.GetOutputStream(), |
| 85 | commands_found.GetStringAtIndex(i), |
| 86 | "--", |
| 87 | commands_help.GetStringAtIndex(i), |
| 88 | max_len); |
Jim Ingham | af3753e | 2013-05-17 01:30:37 +0000 | [diff] [blame] | 89 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 90 | } |
Caroline Tice | 73fd272 | 2011-02-04 00:16:49 +0000 | [diff] [blame] | 91 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 92 | std::vector<const Property *> properties; |
| 93 | const size_t num_properties = m_interpreter.GetDebugger().Apropos(search_word, properties); |
| 94 | if (num_properties) |
Caroline Tice | 73fd272 | 2011-02-04 00:16:49 +0000 | [diff] [blame] | 95 | { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 96 | const bool dump_qualified_name = true; |
Caroline Tice | 73fd272 | 2011-02-04 00:16:49 +0000 | [diff] [blame] | 97 | result.AppendMessageWithFormat ("\nThe following settings variables may relate to '%s': \n\n", search_word); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 98 | for (size_t i=0; i<num_properties; ++i) |
| 99 | properties[i]->DumpDescription (m_interpreter, result.GetOutputStream(), 0, dump_qualified_name); |
| 100 | |
Caroline Tice | 73fd272 | 2011-02-04 00:16:49 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 103 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 104 | } |
| 105 | else |
| 106 | { |
| 107 | result.AppendError ("'' is not a valid search word.\n"); |
| 108 | result.SetStatus (eReturnStatusFailed); |
| 109 | } |
| 110 | } |
| 111 | else |
| 112 | { |
| 113 | result.AppendError ("'apropos' must be called with exactly one argument.\n"); |
| 114 | result.SetStatus (eReturnStatusFailed); |
| 115 | } |
| 116 | |
| 117 | return result.Succeeded(); |
| 118 | } |