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