blob: 02dc7269775d9331f68d1aab43b5cfbf20087e8f [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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 Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "CommandObjectApropos.h"
13
14// C Includes
15// C++ Includes
16// Other libraries and framework includes
17// Project includes
Jim Ingham40af72e2010-06-15 19:49:27 +000018#include "lldb/Interpreter/Args.h"
19#include "lldb/Interpreter/Options.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020
21#include "lldb/Interpreter/CommandInterpreter.h"
22#include "lldb/Interpreter/CommandReturnObject.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023
24using namespace lldb;
25using namespace lldb_private;
26
27//-------------------------------------------------------------------------
28// CommandObjectApropos
29//-------------------------------------------------------------------------
30
Greg Claytona7015092010-09-18 01:14:36 +000031CommandObjectApropos::CommandObjectApropos (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +000032 CommandObjectParsed (interpreter,
33 "apropos",
34 "Find a list of debugger commands related to a particular word/subject.",
35 NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036{
Caroline Tice405fe672010-10-04 22:28:36 +000037 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 Lattner30fdc8d2010-06-08 16:52:24 +000049}
50
51CommandObjectApropos::~CommandObjectApropos()
52{
53}
54
55
56bool
Jim Ingham5a988412012-06-08 21:56:10 +000057CommandObjectApropos::DoExecute (Args& args, CommandReturnObject &result)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058{
Greg Claytonc7bece562013-01-25 18:06:21 +000059 const size_t argc = args.GetArgumentCount ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060
61 if (argc == 1)
62 {
Greg Clayton66111032010-06-23 01:19:29 +000063 const char *search_word = args.GetArgumentAtIndex(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064 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;
Jim Inghamaf3753e2013-05-17 01:30:37 +000071 StringList user_commands_found;
72 StringList user_commands_help;
73
74 m_interpreter.FindCommandsForApropos (search_word, commands_found, commands_help, true, false);
75 m_interpreter.FindCommandsForApropos (search_word, user_commands_found, user_commands_help, false, true);
76
77 if (commands_found.GetSize() == 0 && user_commands_found.GetSize() == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000078 {
Greg Clayton3bcbf842010-11-02 18:23:13 +000079 result.AppendMessageWithFormat ("No commands found pertaining to '%s'. Try 'help' to see a complete list of debugger commands.\n", search_word);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000080 }
81 else
82 {
Jim Inghamaf3753e2013-05-17 01:30:37 +000083 if (commands_found.GetSize() > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084 {
Jim Inghamaf3753e2013-05-17 01:30:37 +000085 result.AppendMessageWithFormat ("The following built-in commands may relate to '%s':\n", search_word);
86 size_t max_len = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087
Jim Inghamaf3753e2013-05-17 01:30:37 +000088 for (size_t i = 0; i < commands_found.GetSize(); ++i)
89 {
90 size_t len = strlen (commands_found.GetStringAtIndex (i));
91 if (len > max_len)
92 max_len = len;
93 }
94
95 for (size_t i = 0; i < commands_found.GetSize(); ++i)
96 m_interpreter.OutputFormattedHelpText (result.GetOutputStream(),
97 commands_found.GetStringAtIndex(i),
98 "--",
99 commands_help.GetStringAtIndex(i),
100 max_len);
101 if (user_commands_found.GetSize() > 0)
102 result.AppendMessage("");
103 }
104
105 if (user_commands_found.GetSize() > 0)
106 {
107 result.AppendMessageWithFormat ("The following user commands may relate to '%s':\n", search_word);
108 size_t max_len = 0;
109
110 for (size_t i = 0; i < user_commands_found.GetSize(); ++i)
111 {
112 size_t len = strlen (user_commands_found.GetStringAtIndex (i));
113 if (len > max_len)
114 max_len = len;
115 }
116
117 for (size_t i = 0; i < user_commands_found.GetSize(); ++i)
118 m_interpreter.OutputFormattedHelpText (result.GetOutputStream(),
119 user_commands_found.GetStringAtIndex(i),
120 "--",
121 user_commands_help.GetStringAtIndex(i),
122 max_len);
123 }
Greg Claytona7015092010-09-18 01:14:36 +0000124
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000125 }
Caroline Tice73fd2722011-02-04 00:16:49 +0000126
127
Greg Clayton67cc0632012-08-22 17:17:09 +0000128 std::vector<const Property *> properties;
129 const size_t num_properties = m_interpreter.GetDebugger().Apropos(search_word, properties);
130 if (num_properties)
Caroline Tice73fd2722011-02-04 00:16:49 +0000131 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000132 const bool dump_qualified_name = true;
Caroline Tice73fd2722011-02-04 00:16:49 +0000133 result.AppendMessageWithFormat ("\nThe following settings variables may relate to '%s': \n\n", search_word);
Greg Clayton67cc0632012-08-22 17:17:09 +0000134 for (size_t i=0; i<num_properties; ++i)
135 properties[i]->DumpDescription (m_interpreter, result.GetOutputStream(), 0, dump_qualified_name);
136
Caroline Tice73fd2722011-02-04 00:16:49 +0000137 }
138
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000139 result.SetStatus (eReturnStatusSuccessFinishNoResult);
140 }
141 else
142 {
143 result.AppendError ("'' is not a valid search word.\n");
144 result.SetStatus (eReturnStatusFailed);
145 }
146 }
147 else
148 {
149 result.AppendError ("'apropos' must be called with exactly one argument.\n");
150 result.SetStatus (eReturnStatusFailed);
151 }
152
153 return result.Succeeded();
154}