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