Chris Lattner | 24943d2 | 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 | d891f9b | 2012-12-05 00:20:57 +0000 | [diff] [blame^] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Chris Lattner | 24943d2 | 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 | 84cdc15 | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 18 | #include "lldb/Interpreter/Args.h" |
| 19 | #include "lldb/Interpreter/Options.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | |
| 21 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 22 | #include "lldb/Interpreter/CommandReturnObject.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | |
| 24 | using namespace lldb; |
| 25 | using namespace lldb_private; |
| 26 | |
| 27 | //------------------------------------------------------------------------- |
| 28 | // CommandObjectApropos |
| 29 | //------------------------------------------------------------------------- |
| 30 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 31 | CommandObjectApropos::CommandObjectApropos (CommandInterpreter &interpreter) : |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 32 | CommandObjectParsed (interpreter, |
| 33 | "apropos", |
| 34 | "Find a list of debugger commands related to a particular word/subject.", |
| 35 | NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 37 | CommandArgumentEntry arg; |
| 38 | CommandArgumentData search_word_arg; |
| 39 | |
| 40 | // Define the first (and only) variant of this arg. |
| 41 | search_word_arg.arg_type = eArgTypeSearchWord; |
| 42 | search_word_arg.arg_repetition = eArgRepeatPlain; |
| 43 | |
| 44 | // There is only one variant this argument could be; put it into the argument entry. |
| 45 | arg.push_back (search_word_arg); |
| 46 | |
| 47 | // Push the data for the first argument into the m_arguments vector. |
| 48 | m_arguments.push_back (arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | CommandObjectApropos::~CommandObjectApropos() |
| 52 | { |
| 53 | } |
| 54 | |
| 55 | |
| 56 | bool |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 57 | CommandObjectApropos::DoExecute (Args& args, CommandReturnObject &result) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 59 | const int argc = args.GetArgumentCount (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | |
| 61 | if (argc == 1) |
| 62 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 63 | const char *search_word = args.GetArgumentAtIndex(0); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 64 | if ((search_word != NULL) |
| 65 | && (strlen (search_word) > 0)) |
| 66 | { |
| 67 | // The bulk of the work must be done inside the Command Interpreter, since the command dictionary |
| 68 | // is private. |
| 69 | StringList commands_found; |
| 70 | StringList commands_help; |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 71 | m_interpreter.FindCommandsForApropos (search_word, commands_found, commands_help); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | if (commands_found.GetSize() == 0) |
| 73 | { |
Greg Clayton | 02c20f1 | 2010-11-02 18:23:13 +0000 | [diff] [blame] | 74 | result.AppendMessageWithFormat ("No commands found pertaining to '%s'. Try 'help' to see a complete list of debugger commands.\n", search_word); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 75 | } |
| 76 | else |
| 77 | { |
| 78 | result.AppendMessageWithFormat ("The following commands may relate to '%s':\n", search_word); |
| 79 | size_t max_len = 0; |
| 80 | |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 81 | for (size_t i = 0; i < commands_found.GetSize(); ++i) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 82 | { |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 83 | size_t len = strlen (commands_found.GetStringAtIndex (i)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 84 | if (len > max_len) |
| 85 | max_len = len; |
| 86 | } |
| 87 | |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 88 | for (size_t i = 0; i < commands_found.GetSize(); ++i) |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 89 | m_interpreter.OutputFormattedHelpText (result.GetOutputStream(), |
| 90 | commands_found.GetStringAtIndex(i), |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 91 | "--", |
| 92 | commands_help.GetStringAtIndex(i), |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 93 | max_len); |
| 94 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 95 | } |
Caroline Tice | a04acd8 | 2011-02-04 00:16:49 +0000 | [diff] [blame] | 96 | |
| 97 | |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 98 | std::vector<const Property *> properties; |
| 99 | const size_t num_properties = m_interpreter.GetDebugger().Apropos(search_word, properties); |
| 100 | if (num_properties) |
Caroline Tice | a04acd8 | 2011-02-04 00:16:49 +0000 | [diff] [blame] | 101 | { |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 102 | const bool dump_qualified_name = true; |
Caroline Tice | a04acd8 | 2011-02-04 00:16:49 +0000 | [diff] [blame] | 103 | result.AppendMessageWithFormat ("\nThe following settings variables may relate to '%s': \n\n", search_word); |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 104 | for (size_t i=0; i<num_properties; ++i) |
| 105 | properties[i]->DumpDescription (m_interpreter, result.GetOutputStream(), 0, dump_qualified_name); |
| 106 | |
Caroline Tice | a04acd8 | 2011-02-04 00:16:49 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 109 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 110 | } |
| 111 | else |
| 112 | { |
| 113 | result.AppendError ("'' is not a valid search word.\n"); |
| 114 | result.SetStatus (eReturnStatusFailed); |
| 115 | } |
| 116 | } |
| 117 | else |
| 118 | { |
| 119 | result.AppendError ("'apropos' must be called with exactly one argument.\n"); |
| 120 | result.SetStatus (eReturnStatusFailed); |
| 121 | } |
| 122 | |
| 123 | return result.Succeeded(); |
| 124 | } |