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 | |
Daniel Malea | 93a6430 | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | #include "CommandObjectApropos.h" |
| 13 | |
| 14 | // C Includes |
| 15 | // C++ Includes |
| 16 | // Other libraries and framework includes |
| 17 | // Project includes |
Jim Ingham | 40af72e | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 18 | #include "lldb/Interpreter/Args.h" |
| 19 | #include "lldb/Interpreter/Options.h" |
Zachary Turner | 633a29c | 2015-03-04 01:58:01 +0000 | [diff] [blame^] | 20 | #include "lldb/Interpreter/Property.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | |
| 22 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 23 | #include "lldb/Interpreter/CommandReturnObject.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | |
| 25 | using namespace lldb; |
| 26 | using namespace lldb_private; |
| 27 | |
| 28 | //------------------------------------------------------------------------- |
| 29 | // CommandObjectApropos |
| 30 | //------------------------------------------------------------------------- |
| 31 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 32 | CommandObjectApropos::CommandObjectApropos (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 33 | CommandObjectParsed (interpreter, |
| 34 | "apropos", |
| 35 | "Find a list of debugger commands related to a particular word/subject.", |
| 36 | NULL) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 38 | CommandArgumentEntry arg; |
| 39 | CommandArgumentData search_word_arg; |
| 40 | |
| 41 | // Define the first (and only) variant of this arg. |
| 42 | search_word_arg.arg_type = eArgTypeSearchWord; |
| 43 | search_word_arg.arg_repetition = eArgRepeatPlain; |
| 44 | |
| 45 | // There is only one variant this argument could be; put it into the argument entry. |
| 46 | arg.push_back (search_word_arg); |
| 47 | |
| 48 | // Push the data for the first argument into the m_arguments vector. |
| 49 | m_arguments.push_back (arg); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | CommandObjectApropos::~CommandObjectApropos() |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | |
| 57 | bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 58 | CommandObjectApropos::DoExecute (Args& args, CommandReturnObject &result) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 59 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 60 | const size_t argc = args.GetArgumentCount (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | |
| 62 | if (argc == 1) |
| 63 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 64 | const char *search_word = args.GetArgumentAtIndex(0); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | if ((search_word != NULL) |
| 66 | && (strlen (search_word) > 0)) |
| 67 | { |
| 68 | // The bulk of the work must be done inside the Command Interpreter, since the command dictionary |
| 69 | // is private. |
| 70 | StringList commands_found; |
| 71 | StringList commands_help; |
Jim Ingham | af3753e | 2013-05-17 01:30:37 +0000 | [diff] [blame] | 72 | StringList user_commands_found; |
| 73 | StringList user_commands_help; |
| 74 | |
| 75 | m_interpreter.FindCommandsForApropos (search_word, commands_found, commands_help, true, false); |
| 76 | m_interpreter.FindCommandsForApropos (search_word, user_commands_found, user_commands_help, false, true); |
| 77 | |
| 78 | if (commands_found.GetSize() == 0 && user_commands_found.GetSize() == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 79 | { |
Greg Clayton | 3bcbf84 | 2010-11-02 18:23:13 +0000 | [diff] [blame] | 80 | 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] | 81 | } |
| 82 | else |
| 83 | { |
Jim Ingham | af3753e | 2013-05-17 01:30:37 +0000 | [diff] [blame] | 84 | if (commands_found.GetSize() > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 85 | { |
Jim Ingham | af3753e | 2013-05-17 01:30:37 +0000 | [diff] [blame] | 86 | result.AppendMessageWithFormat ("The following built-in commands may relate to '%s':\n", search_word); |
| 87 | size_t max_len = 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 88 | |
Jim Ingham | af3753e | 2013-05-17 01:30:37 +0000 | [diff] [blame] | 89 | for (size_t i = 0; i < commands_found.GetSize(); ++i) |
| 90 | { |
| 91 | size_t len = strlen (commands_found.GetStringAtIndex (i)); |
| 92 | if (len > max_len) |
| 93 | max_len = len; |
| 94 | } |
| 95 | |
| 96 | for (size_t i = 0; i < commands_found.GetSize(); ++i) |
| 97 | m_interpreter.OutputFormattedHelpText (result.GetOutputStream(), |
| 98 | commands_found.GetStringAtIndex(i), |
| 99 | "--", |
| 100 | commands_help.GetStringAtIndex(i), |
| 101 | max_len); |
| 102 | if (user_commands_found.GetSize() > 0) |
| 103 | result.AppendMessage(""); |
| 104 | } |
| 105 | |
| 106 | if (user_commands_found.GetSize() > 0) |
| 107 | { |
| 108 | result.AppendMessageWithFormat ("The following user commands may relate to '%s':\n", search_word); |
| 109 | size_t max_len = 0; |
| 110 | |
| 111 | for (size_t i = 0; i < user_commands_found.GetSize(); ++i) |
| 112 | { |
| 113 | size_t len = strlen (user_commands_found.GetStringAtIndex (i)); |
| 114 | if (len > max_len) |
| 115 | max_len = len; |
| 116 | } |
| 117 | |
| 118 | for (size_t i = 0; i < user_commands_found.GetSize(); ++i) |
| 119 | m_interpreter.OutputFormattedHelpText (result.GetOutputStream(), |
| 120 | user_commands_found.GetStringAtIndex(i), |
| 121 | "--", |
| 122 | user_commands_help.GetStringAtIndex(i), |
| 123 | max_len); |
| 124 | } |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 125 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 126 | } |
Caroline Tice | 73fd272 | 2011-02-04 00:16:49 +0000 | [diff] [blame] | 127 | |
| 128 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 129 | std::vector<const Property *> properties; |
| 130 | const size_t num_properties = m_interpreter.GetDebugger().Apropos(search_word, properties); |
| 131 | if (num_properties) |
Caroline Tice | 73fd272 | 2011-02-04 00:16:49 +0000 | [diff] [blame] | 132 | { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 133 | const bool dump_qualified_name = true; |
Caroline Tice | 73fd272 | 2011-02-04 00:16:49 +0000 | [diff] [blame] | 134 | 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] | 135 | for (size_t i=0; i<num_properties; ++i) |
| 136 | properties[i]->DumpDescription (m_interpreter, result.GetOutputStream(), 0, dump_qualified_name); |
| 137 | |
Caroline Tice | 73fd272 | 2011-02-04 00:16:49 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 140 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 141 | } |
| 142 | else |
| 143 | { |
| 144 | result.AppendError ("'' is not a valid search word.\n"); |
| 145 | result.SetStatus (eReturnStatusFailed); |
| 146 | } |
| 147 | } |
| 148 | else |
| 149 | { |
| 150 | result.AppendError ("'apropos' must be called with exactly one argument.\n"); |
| 151 | result.SetStatus (eReturnStatusFailed); |
| 152 | } |
| 153 | |
| 154 | return result.Succeeded(); |
| 155 | } |