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