Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- CommandObjectLog.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 "CommandObjectLog.h" |
| 13 | |
| 14 | // C Includes |
| 15 | // C++ Includes |
| 16 | // Other libraries and framework includes |
| 17 | // Project includes |
| 18 | #include "lldb/lldb-private-log.h" |
| 19 | |
Jim Ingham | 40af72e | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 20 | #include "lldb/Interpreter/Args.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | #include "lldb/Core/Debugger.h" |
Greg Clayton | 53239f0 | 2011-02-08 05:05:52 +0000 | [diff] [blame] | 22 | #include "lldb/Host/FileSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | #include "lldb/Core/Log.h" |
| 24 | #include "lldb/Core/Module.h" |
Jim Ingham | 40af72e | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 25 | #include "lldb/Interpreter/Options.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | #include "lldb/Core/RegularExpression.h" |
| 27 | #include "lldb/Core/Stream.h" |
| 28 | #include "lldb/Core/StreamFile.h" |
| 29 | #include "lldb/Core/Timer.h" |
| 30 | |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 31 | #include "lldb/Core/Debugger.h" |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame^] | 32 | #include "lldb/Host/StringConvert.h" |
Sean Callanan | 4be3990 | 2010-06-23 21:28:25 +0000 | [diff] [blame] | 33 | #include "lldb/Interpreter/CommandInterpreter.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 35 | |
| 36 | #include "lldb/Symbol/LineTable.h" |
| 37 | #include "lldb/Symbol/ObjectFile.h" |
| 38 | #include "lldb/Symbol/SymbolFile.h" |
| 39 | #include "lldb/Symbol/SymbolVendor.h" |
| 40 | |
| 41 | #include "lldb/Target/Process.h" |
| 42 | #include "lldb/Target/Target.h" |
| 43 | |
| 44 | using namespace lldb; |
| 45 | using namespace lldb_private; |
| 46 | |
| 47 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 48 | class CommandObjectLogEnable : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | { |
| 50 | public: |
| 51 | //------------------------------------------------------------------ |
| 52 | // Constructors and Destructors |
| 53 | //------------------------------------------------------------------ |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 54 | CommandObjectLogEnable(CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 55 | CommandObjectParsed (interpreter, |
| 56 | "log enable", |
| 57 | "Enable logging for a single log channel.", |
| 58 | NULL), |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 59 | m_options (interpreter) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | { |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 61 | |
| 62 | CommandArgumentEntry arg1; |
| 63 | CommandArgumentEntry arg2; |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 64 | CommandArgumentData channel_arg; |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 65 | CommandArgumentData category_arg; |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 66 | |
| 67 | // Define the first (and only) variant of this arg. |
| 68 | channel_arg.arg_type = eArgTypeLogChannel; |
| 69 | channel_arg.arg_repetition = eArgRepeatPlain; |
| 70 | |
| 71 | // There is only one variant this argument could be; put it into the argument entry. |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 72 | arg1.push_back (channel_arg); |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 73 | |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 74 | category_arg.arg_type = eArgTypeLogCategory; |
| 75 | category_arg.arg_repetition = eArgRepeatPlus; |
| 76 | |
| 77 | arg2.push_back (category_arg); |
| 78 | |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 79 | // Push the data for the first argument into the m_arguments vector. |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 80 | m_arguments.push_back (arg1); |
| 81 | m_arguments.push_back (arg2); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | virtual |
| 85 | ~CommandObjectLogEnable() |
| 86 | { |
| 87 | } |
| 88 | |
| 89 | Options * |
| 90 | GetOptions () |
| 91 | { |
| 92 | return &m_options; |
| 93 | } |
| 94 | |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 95 | // int |
| 96 | // HandleArgumentCompletion (Args &input, |
| 97 | // int &cursor_index, |
| 98 | // int &cursor_char_position, |
| 99 | // OptionElementVector &opt_element_vector, |
| 100 | // int match_start_point, |
| 101 | // int max_return_elements, |
| 102 | // bool &word_complete, |
| 103 | // StringList &matches) |
| 104 | // { |
| 105 | // std::string completion_str (input.GetArgumentAtIndex(cursor_index)); |
| 106 | // completion_str.erase (cursor_char_position); |
| 107 | // |
| 108 | // if (cursor_index == 1) |
| 109 | // { |
| 110 | // // |
| 111 | // Log::AutoCompleteChannelName (completion_str.c_str(), matches); |
| 112 | // } |
| 113 | // return matches.GetSize(); |
| 114 | // } |
| 115 | // |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 116 | |
| 117 | class CommandOptions : public Options |
| 118 | { |
| 119 | public: |
| 120 | |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 121 | CommandOptions (CommandInterpreter &interpreter) : |
| 122 | Options (interpreter), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 123 | log_file (), |
| 124 | log_options (0) |
| 125 | { |
| 126 | } |
| 127 | |
| 128 | |
| 129 | virtual |
| 130 | ~CommandOptions () |
| 131 | { |
| 132 | } |
| 133 | |
| 134 | virtual Error |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 135 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 136 | { |
| 137 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 138 | const int short_option = m_getopt_table[option_idx].val; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 139 | |
| 140 | switch (short_option) |
| 141 | { |
Greg Clayton | 889037d | 2012-12-07 18:37:09 +0000 | [diff] [blame] | 142 | case 'f': log_file.SetFile(option_arg, true); break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 143 | case 't': log_options |= LLDB_LOG_OPTION_THREADSAFE; break; |
| 144 | case 'v': log_options |= LLDB_LOG_OPTION_VERBOSE; break; |
| 145 | case 'g': log_options |= LLDB_LOG_OPTION_DEBUG; break; |
| 146 | case 's': log_options |= LLDB_LOG_OPTION_PREPEND_SEQUENCE; break; |
| 147 | case 'T': log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP; break; |
| 148 | case 'p': log_options |= LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD;break; |
| 149 | case 'n': log_options |= LLDB_LOG_OPTION_PREPEND_THREAD_NAME; break; |
Greg Clayton | 3a18e31 | 2012-10-08 22:41:53 +0000 | [diff] [blame] | 150 | case 'S': log_options |= LLDB_LOG_OPTION_BACKTRACE; break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 151 | default: |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 152 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 153 | break; |
| 154 | } |
| 155 | |
| 156 | return error; |
| 157 | } |
| 158 | |
| 159 | void |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 160 | OptionParsingStarting () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 161 | { |
Greg Clayton | 889037d | 2012-12-07 18:37:09 +0000 | [diff] [blame] | 162 | log_file.Clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 163 | log_options = 0; |
| 164 | } |
| 165 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 166 | const OptionDefinition* |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 167 | GetDefinitions () |
| 168 | { |
| 169 | return g_option_table; |
| 170 | } |
| 171 | |
| 172 | // Options table: Required for subclasses of Options. |
| 173 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 174 | static OptionDefinition g_option_table[]; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 175 | |
| 176 | // Instance variables to hold the values for command options. |
| 177 | |
Greg Clayton | 889037d | 2012-12-07 18:37:09 +0000 | [diff] [blame] | 178 | FileSpec log_file; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 179 | uint32_t log_options; |
| 180 | }; |
| 181 | |
| 182 | protected: |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 183 | virtual bool |
| 184 | DoExecute (Args& args, |
| 185 | CommandReturnObject &result) |
| 186 | { |
| 187 | if (args.GetArgumentCount() < 2) |
| 188 | { |
| 189 | result.AppendErrorWithFormat("%s takes a log channel and one or more log types.\n", m_cmd_name.c_str()); |
| 190 | } |
| 191 | else |
| 192 | { |
| 193 | std::string channel(args.GetArgumentAtIndex(0)); |
| 194 | args.Shift (); // Shift off the channel |
Greg Clayton | 889037d | 2012-12-07 18:37:09 +0000 | [diff] [blame] | 195 | char log_file[PATH_MAX]; |
| 196 | if (m_options.log_file) |
| 197 | m_options.log_file.GetPath(log_file, sizeof(log_file)); |
| 198 | else |
| 199 | log_file[0] = '\0'; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 200 | bool success = m_interpreter.GetDebugger().EnableLog (channel.c_str(), |
| 201 | args.GetConstArgumentVector(), |
Greg Clayton | 889037d | 2012-12-07 18:37:09 +0000 | [diff] [blame] | 202 | log_file, |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 203 | m_options.log_options, |
| 204 | result.GetErrorStream()); |
| 205 | if (success) |
| 206 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 207 | else |
| 208 | result.SetStatus (eReturnStatusFailed); |
| 209 | } |
| 210 | return result.Succeeded(); |
| 211 | } |
| 212 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 213 | CommandOptions m_options; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 214 | }; |
| 215 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 216 | OptionDefinition |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 217 | CommandObjectLogEnable::CommandOptions::g_option_table[] = |
| 218 | { |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 219 | { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeFilename, "Set the destination file to log to."}, |
| 220 | { LLDB_OPT_SET_1, false, "threadsafe", 't', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Enable thread safe logging to avoid interweaved log lines." }, |
| 221 | { LLDB_OPT_SET_1, false, "verbose", 'v', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Enable verbose logging." }, |
| 222 | { LLDB_OPT_SET_1, false, "debug", 'g', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Enable debug logging." }, |
| 223 | { LLDB_OPT_SET_1, false, "sequence", 's', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Prepend all log lines with an increasing integer sequence id." }, |
| 224 | { LLDB_OPT_SET_1, false, "timestamp", 'T', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Prepend all log lines with a timestamp." }, |
| 225 | { LLDB_OPT_SET_1, false, "pid-tid", 'p', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Prepend all log lines with the process and thread ID that generates the log line." }, |
| 226 | { LLDB_OPT_SET_1, false, "thread-name",'n', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Prepend all log lines with the thread name for the thread that generates the log line." }, |
| 227 | { LLDB_OPT_SET_1, false, "stack", 'S', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Append a stack backtrace to each log line." }, |
| 228 | { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 229 | }; |
| 230 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 231 | class CommandObjectLogDisable : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 232 | { |
| 233 | public: |
| 234 | //------------------------------------------------------------------ |
| 235 | // Constructors and Destructors |
| 236 | //------------------------------------------------------------------ |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 237 | CommandObjectLogDisable(CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 238 | CommandObjectParsed (interpreter, |
| 239 | "log disable", |
| 240 | "Disable one or more log channel categories.", |
| 241 | NULL) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 242 | { |
Caroline Tice | 7149fab | 2010-10-29 21:56:41 +0000 | [diff] [blame] | 243 | CommandArgumentEntry arg1; |
| 244 | CommandArgumentEntry arg2; |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 245 | CommandArgumentData channel_arg; |
Caroline Tice | 7149fab | 2010-10-29 21:56:41 +0000 | [diff] [blame] | 246 | CommandArgumentData category_arg; |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 247 | |
| 248 | // Define the first (and only) variant of this arg. |
| 249 | channel_arg.arg_type = eArgTypeLogChannel; |
Caroline Tice | 7149fab | 2010-10-29 21:56:41 +0000 | [diff] [blame] | 250 | channel_arg.arg_repetition = eArgRepeatPlain; |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 251 | |
| 252 | // There is only one variant this argument could be; put it into the argument entry. |
Caroline Tice | 7149fab | 2010-10-29 21:56:41 +0000 | [diff] [blame] | 253 | arg1.push_back (channel_arg); |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 254 | |
Caroline Tice | 7149fab | 2010-10-29 21:56:41 +0000 | [diff] [blame] | 255 | category_arg.arg_type = eArgTypeLogCategory; |
| 256 | category_arg.arg_repetition = eArgRepeatPlus; |
| 257 | |
| 258 | arg2.push_back (category_arg); |
| 259 | |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 260 | // Push the data for the first argument into the m_arguments vector. |
Caroline Tice | 7149fab | 2010-10-29 21:56:41 +0000 | [diff] [blame] | 261 | m_arguments.push_back (arg1); |
| 262 | m_arguments.push_back (arg2); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | virtual |
| 266 | ~CommandObjectLogDisable() |
| 267 | { |
| 268 | } |
| 269 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 270 | protected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 271 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 272 | DoExecute (Args& args, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 273 | CommandReturnObject &result) |
| 274 | { |
| 275 | const size_t argc = args.GetArgumentCount(); |
| 276 | if (argc == 0) |
| 277 | { |
Jim Ingham | dff0440 | 2012-05-12 00:38:30 +0000 | [diff] [blame] | 278 | result.AppendErrorWithFormat("%s takes a log channel and one or more log types.\n", m_cmd_name.c_str()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 279 | } |
| 280 | else |
| 281 | { |
Caroline Tice | 20ad3c4 | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 282 | Log::Callbacks log_callbacks; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 283 | |
Caroline Tice | 20ad3c4 | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 284 | std::string channel(args.GetArgumentAtIndex(0)); |
| 285 | args.Shift (); // Shift off the channel |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 286 | if (Log::GetLogChannelCallbacks (ConstString(channel.c_str()), log_callbacks)) |
Caroline Tice | 20ad3c4 | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 287 | { |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 288 | log_callbacks.disable (args.GetConstArgumentVector(), &result.GetErrorStream()); |
Caroline Tice | 20ad3c4 | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 289 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 290 | } |
| 291 | else if (channel == "all") |
| 292 | { |
| 293 | Log::DisableAllLogChannels(&result.GetErrorStream()); |
| 294 | } |
| 295 | else |
| 296 | { |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 297 | LogChannelSP log_channel_sp (LogChannel::FindPlugin(channel.c_str())); |
Caroline Tice | 20ad3c4 | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 298 | if (log_channel_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 299 | { |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 300 | log_channel_sp->Disable(args.GetConstArgumentVector(), &result.GetErrorStream()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 301 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 302 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 303 | else |
Caroline Tice | 20ad3c4 | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 304 | result.AppendErrorWithFormat("Invalid log channel '%s'.\n", args.GetArgumentAtIndex(0)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | return result.Succeeded(); |
| 308 | } |
| 309 | }; |
| 310 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 311 | class CommandObjectLogList : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 312 | { |
| 313 | public: |
| 314 | //------------------------------------------------------------------ |
| 315 | // Constructors and Destructors |
| 316 | //------------------------------------------------------------------ |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 317 | CommandObjectLogList(CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 318 | CommandObjectParsed (interpreter, |
| 319 | "log list", |
| 320 | "List the log categories for one or more log channels. If none specified, lists them all.", |
| 321 | NULL) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 322 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 323 | CommandArgumentEntry arg; |
| 324 | CommandArgumentData channel_arg; |
| 325 | |
| 326 | // Define the first (and only) variant of this arg. |
| 327 | channel_arg.arg_type = eArgTypeLogChannel; |
| 328 | channel_arg.arg_repetition = eArgRepeatStar; |
| 329 | |
| 330 | // There is only one variant this argument could be; put it into the argument entry. |
| 331 | arg.push_back (channel_arg); |
| 332 | |
| 333 | // Push the data for the first argument into the m_arguments vector. |
| 334 | m_arguments.push_back (arg); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | virtual |
| 338 | ~CommandObjectLogList() |
| 339 | { |
| 340 | } |
| 341 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 342 | protected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 343 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 344 | DoExecute (Args& args, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 345 | CommandReturnObject &result) |
| 346 | { |
| 347 | const size_t argc = args.GetArgumentCount(); |
| 348 | if (argc == 0) |
| 349 | { |
| 350 | Log::ListAllLogChannels (&result.GetOutputStream()); |
| 351 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 352 | } |
| 353 | else |
| 354 | { |
| 355 | for (size_t i=0; i<argc; ++i) |
| 356 | { |
| 357 | Log::Callbacks log_callbacks; |
| 358 | |
| 359 | std::string channel(args.GetArgumentAtIndex(i)); |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 360 | if (Log::GetLogChannelCallbacks (ConstString(channel.c_str()), log_callbacks)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 361 | { |
| 362 | log_callbacks.list_categories (&result.GetOutputStream()); |
| 363 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 364 | } |
| 365 | else if (channel == "all") |
| 366 | { |
| 367 | Log::ListAllLogChannels (&result.GetOutputStream()); |
| 368 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 369 | } |
| 370 | else |
| 371 | { |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 372 | LogChannelSP log_channel_sp (LogChannel::FindPlugin(channel.c_str())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 373 | if (log_channel_sp) |
| 374 | { |
| 375 | log_channel_sp->ListCategories(&result.GetOutputStream()); |
| 376 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 377 | } |
| 378 | else |
| 379 | result.AppendErrorWithFormat("Invalid log channel '%s'.\n", args.GetArgumentAtIndex(0)); |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | return result.Succeeded(); |
| 384 | } |
| 385 | }; |
| 386 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 387 | class CommandObjectLogTimer : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 388 | { |
| 389 | public: |
| 390 | //------------------------------------------------------------------ |
| 391 | // Constructors and Destructors |
| 392 | //------------------------------------------------------------------ |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 393 | CommandObjectLogTimer(CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 394 | CommandObjectParsed (interpreter, |
| 395 | "log timers", |
| 396 | "Enable, disable, dump, and reset LLDB internal performance timers.", |
| 397 | "log timers < enable <depth> | disable | dump | increment <bool> | reset >") |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 398 | { |
| 399 | } |
| 400 | |
| 401 | virtual |
| 402 | ~CommandObjectLogTimer() |
| 403 | { |
| 404 | } |
| 405 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 406 | protected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 407 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 408 | DoExecute (Args& args, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 409 | CommandReturnObject &result) |
| 410 | { |
| 411 | const size_t argc = args.GetArgumentCount(); |
| 412 | result.SetStatus(eReturnStatusFailed); |
| 413 | |
| 414 | if (argc == 1) |
| 415 | { |
| 416 | const char *sub_command = args.GetArgumentAtIndex(0); |
| 417 | |
| 418 | if (strcasecmp(sub_command, "enable") == 0) |
| 419 | { |
| 420 | Timer::SetDisplayDepth (UINT32_MAX); |
| 421 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 422 | } |
| 423 | else if (strcasecmp(sub_command, "disable") == 0) |
| 424 | { |
| 425 | Timer::DumpCategoryTimes (&result.GetOutputStream()); |
| 426 | Timer::SetDisplayDepth (0); |
| 427 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 428 | } |
| 429 | else if (strcasecmp(sub_command, "dump") == 0) |
| 430 | { |
| 431 | Timer::DumpCategoryTimes (&result.GetOutputStream()); |
| 432 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 433 | } |
| 434 | else if (strcasecmp(sub_command, "reset") == 0) |
| 435 | { |
| 436 | Timer::ResetCategoryTimes (); |
| 437 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 438 | } |
| 439 | |
| 440 | } |
Jim Ingham | 932725f | 2010-11-04 23:08:26 +0000 | [diff] [blame] | 441 | else if (argc == 2) |
| 442 | { |
| 443 | const char *sub_command = args.GetArgumentAtIndex(0); |
| 444 | |
| 445 | if (strcasecmp(sub_command, "enable") == 0) |
| 446 | { |
| 447 | bool success; |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame^] | 448 | uint32_t depth = StringConvert::ToUInt32(args.GetArgumentAtIndex(1), 0, 0, &success); |
Jim Ingham | 932725f | 2010-11-04 23:08:26 +0000 | [diff] [blame] | 449 | if (success) |
| 450 | { |
| 451 | Timer::SetDisplayDepth (depth); |
| 452 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 453 | } |
| 454 | else |
| 455 | result.AppendError("Could not convert enable depth to an unsigned integer."); |
| 456 | } |
Jim Ingham | f7f4f50 | 2010-11-04 23:19:21 +0000 | [diff] [blame] | 457 | if (strcasecmp(sub_command, "increment") == 0) |
| 458 | { |
| 459 | bool success; |
| 460 | bool increment = Args::StringToBoolean(args.GetArgumentAtIndex(1), false, &success); |
| 461 | if (success) |
| 462 | { |
| 463 | Timer::SetQuiet (!increment); |
| 464 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 465 | } |
| 466 | else |
| 467 | result.AppendError("Could not convert increment value to boolean."); |
| 468 | } |
Jim Ingham | 932725f | 2010-11-04 23:08:26 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 471 | if (!result.Succeeded()) |
| 472 | { |
| 473 | result.AppendError("Missing subcommand"); |
| 474 | result.AppendErrorWithFormat("Usage: %s\n", m_cmd_syntax.c_str()); |
| 475 | } |
| 476 | return result.Succeeded(); |
| 477 | } |
| 478 | }; |
| 479 | |
| 480 | //---------------------------------------------------------------------- |
| 481 | // CommandObjectLog constructor |
| 482 | //---------------------------------------------------------------------- |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 483 | CommandObjectLog::CommandObjectLog(CommandInterpreter &interpreter) : |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 484 | CommandObjectMultiword (interpreter, |
| 485 | "log", |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 486 | "A set of commands for operating on logs.", |
| 487 | "log <command> [<command-options>]") |
| 488 | { |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 489 | LoadSubCommand ("enable", CommandObjectSP (new CommandObjectLogEnable (interpreter))); |
| 490 | LoadSubCommand ("disable", CommandObjectSP (new CommandObjectLogDisable (interpreter))); |
| 491 | LoadSubCommand ("list", CommandObjectSP (new CommandObjectLogList (interpreter))); |
| 492 | LoadSubCommand ("timers", CommandObjectSP (new CommandObjectLogTimer (interpreter))); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | //---------------------------------------------------------------------- |
| 496 | // Destructor |
| 497 | //---------------------------------------------------------------------- |
| 498 | CommandObjectLog::~CommandObjectLog() |
| 499 | { |
| 500 | } |
| 501 | |
| 502 | |
| 503 | |
| 504 | |