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 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | class CommandObjectLogEnable : public CommandObject |
| 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) : |
| 52 | CommandObject (interpreter, |
| 53 | "log enable", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | "Enable logging for a single log channel.", |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 55 | NULL), |
| 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 | virtual bool |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 114 | Execute (Args& args, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 115 | CommandReturnObject &result) |
| 116 | { |
| 117 | if (args.GetArgumentCount() < 1) |
| 118 | { |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame] | 119 | result.AppendErrorWithFormat("Usage: %s\n", m_cmd_syntax.c_str()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 120 | } |
| 121 | else |
| 122 | { |
| 123 | Log::Callbacks log_callbacks; |
| 124 | |
| 125 | std::string channel(args.GetArgumentAtIndex(0)); |
| 126 | args.Shift (); // Shift off the channel |
| 127 | StreamSP log_stream_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 128 | if (m_options.log_file.empty()) |
| 129 | { |
Greg Clayton | 5892856 | 2011-02-09 01:08:52 +0000 | [diff] [blame] | 130 | log_stream_sp.reset(new StreamFile(m_interpreter.GetDebugger().GetOutputFile().GetDescriptor(), false)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 131 | } |
| 132 | else |
| 133 | { |
| 134 | LogStreamMap::iterator pos = m_log_streams.find(m_options.log_file); |
| 135 | if (pos == m_log_streams.end()) |
| 136 | { |
Greg Clayton | 5892856 | 2011-02-09 01:08:52 +0000 | [diff] [blame] | 137 | log_stream_sp.reset (new StreamFile (m_options.log_file.c_str())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 138 | m_log_streams[m_options.log_file] = log_stream_sp; |
| 139 | } |
| 140 | else |
| 141 | log_stream_sp = pos->second; |
| 142 | } |
| 143 | assert (log_stream_sp.get()); |
Jim Ingham | d1eb73f | 2011-01-24 04:09:25 +0000 | [diff] [blame] | 144 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 145 | uint32_t log_options = m_options.log_options; |
| 146 | if (log_options == 0) |
| 147 | log_options = LLDB_LOG_OPTION_PREPEND_THREAD_NAME | LLDB_LOG_OPTION_THREADSAFE; |
| 148 | if (Log::GetLogChannelCallbacks (channel.c_str(), log_callbacks)) |
| 149 | { |
| 150 | log_callbacks.enable (log_stream_sp, log_options, args, &result.GetErrorStream()); |
| 151 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 152 | } |
| 153 | else |
| 154 | { |
Greg Clayton | 5e342f5 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 155 | LogChannelSP log_channel_sp (LogChannel::FindPlugin (channel.c_str())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 156 | if (log_channel_sp) |
| 157 | { |
| 158 | if (log_channel_sp->Enable (log_stream_sp, log_options, &result.GetErrorStream(), args)) |
| 159 | { |
| 160 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 161 | } |
| 162 | else |
| 163 | { |
| 164 | result.AppendErrorWithFormat("Invalid log channel '%s'.\n", channel.c_str()); |
| 165 | result.SetStatus (eReturnStatusFailed); |
| 166 | } |
| 167 | } |
| 168 | else |
| 169 | { |
| 170 | result.AppendErrorWithFormat("Invalid log channel '%s'.\n", channel.c_str()); |
| 171 | result.SetStatus (eReturnStatusFailed); |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | return result.Succeeded(); |
| 176 | } |
| 177 | |
| 178 | |
| 179 | class CommandOptions : public Options |
| 180 | { |
| 181 | public: |
| 182 | |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 183 | CommandOptions (CommandInterpreter &interpreter) : |
| 184 | Options (interpreter), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 185 | log_file (), |
| 186 | log_options (0) |
| 187 | { |
| 188 | } |
| 189 | |
| 190 | |
| 191 | virtual |
| 192 | ~CommandOptions () |
| 193 | { |
| 194 | } |
| 195 | |
| 196 | virtual Error |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 197 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 198 | { |
| 199 | Error error; |
| 200 | char short_option = (char) m_getopt_table[option_idx].val; |
| 201 | |
| 202 | switch (short_option) |
| 203 | { |
| 204 | case 'f': log_file = option_arg; break; |
| 205 | case 't': log_options |= LLDB_LOG_OPTION_THREADSAFE; break; |
| 206 | case 'v': log_options |= LLDB_LOG_OPTION_VERBOSE; break; |
| 207 | case 'g': log_options |= LLDB_LOG_OPTION_DEBUG; break; |
| 208 | case 's': log_options |= LLDB_LOG_OPTION_PREPEND_SEQUENCE; break; |
| 209 | case 'T': log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP; break; |
| 210 | case 'p': log_options |= LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD;break; |
| 211 | case 'n': log_options |= LLDB_LOG_OPTION_PREPEND_THREAD_NAME; break; |
| 212 | default: |
| 213 | error.SetErrorStringWithFormat ("Unrecognized option '%c'\n", short_option); |
| 214 | break; |
| 215 | } |
| 216 | |
| 217 | return error; |
| 218 | } |
| 219 | |
| 220 | void |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 221 | OptionParsingStarting () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 222 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 223 | log_file.clear(); |
| 224 | log_options = 0; |
| 225 | } |
| 226 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 227 | const OptionDefinition* |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 228 | GetDefinitions () |
| 229 | { |
| 230 | return g_option_table; |
| 231 | } |
| 232 | |
| 233 | // Options table: Required for subclasses of Options. |
| 234 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 235 | static OptionDefinition g_option_table[]; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 236 | |
| 237 | // Instance variables to hold the values for command options. |
| 238 | |
| 239 | std::string log_file; |
| 240 | uint32_t log_options; |
| 241 | }; |
| 242 | |
| 243 | protected: |
| 244 | typedef std::map<std::string, StreamSP> LogStreamMap; |
| 245 | CommandOptions m_options; |
| 246 | LogStreamMap m_log_streams; |
| 247 | }; |
| 248 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 249 | OptionDefinition |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 250 | CommandObjectLogEnable::CommandOptions::g_option_table[] = |
| 251 | { |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 252 | { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, 0, eArgTypeFilename, "Set the destination file to log to."}, |
| 253 | { LLDB_OPT_SET_1, false, "threadsafe", 't', no_argument, NULL, 0, eArgTypeNone, "Enable thread safe logging to avoid interweaved log lines." }, |
| 254 | { LLDB_OPT_SET_1, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone, "Enable verbose logging." }, |
| 255 | { LLDB_OPT_SET_1, false, "debug", 'g', no_argument, NULL, 0, eArgTypeNone, "Enable debug logging." }, |
| 256 | { LLDB_OPT_SET_1, false, "sequence", 's', no_argument, NULL, 0, eArgTypeNone, "Prepend all log lines with an increasing integer sequence id." }, |
| 257 | { LLDB_OPT_SET_1, false, "timestamp", 'T', no_argument, NULL, 0, eArgTypeNone, "Prepend all log lines with a timestamp." }, |
| 258 | { 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." }, |
| 259 | { 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." }, |
| 260 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 261 | }; |
| 262 | |
| 263 | class CommandObjectLogDisable : public CommandObject |
| 264 | { |
| 265 | public: |
| 266 | //------------------------------------------------------------------ |
| 267 | // Constructors and Destructors |
| 268 | //------------------------------------------------------------------ |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 269 | CommandObjectLogDisable(CommandInterpreter &interpreter) : |
| 270 | CommandObject (interpreter, |
| 271 | "log disable", |
Caroline Tice | 6a9e5c2 | 2010-10-29 21:56:41 +0000 | [diff] [blame] | 272 | "Disable one or more log channel categories.", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 273 | NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 274 | { |
Caroline Tice | 6a9e5c2 | 2010-10-29 21:56:41 +0000 | [diff] [blame] | 275 | CommandArgumentEntry arg1; |
| 276 | CommandArgumentEntry arg2; |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 277 | CommandArgumentData channel_arg; |
Caroline Tice | 6a9e5c2 | 2010-10-29 21:56:41 +0000 | [diff] [blame] | 278 | CommandArgumentData category_arg; |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 279 | |
| 280 | // Define the first (and only) variant of this arg. |
| 281 | channel_arg.arg_type = eArgTypeLogChannel; |
Caroline Tice | 6a9e5c2 | 2010-10-29 21:56:41 +0000 | [diff] [blame] | 282 | channel_arg.arg_repetition = eArgRepeatPlain; |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 283 | |
| 284 | // 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] | 285 | arg1.push_back (channel_arg); |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 286 | |
Caroline Tice | 6a9e5c2 | 2010-10-29 21:56:41 +0000 | [diff] [blame] | 287 | category_arg.arg_type = eArgTypeLogCategory; |
| 288 | category_arg.arg_repetition = eArgRepeatPlus; |
| 289 | |
| 290 | arg2.push_back (category_arg); |
| 291 | |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 292 | // Push the data for the first argument into the m_arguments vector. |
Caroline Tice | 6a9e5c2 | 2010-10-29 21:56:41 +0000 | [diff] [blame] | 293 | m_arguments.push_back (arg1); |
| 294 | m_arguments.push_back (arg2); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | virtual |
| 298 | ~CommandObjectLogDisable() |
| 299 | { |
| 300 | } |
| 301 | |
| 302 | virtual bool |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 303 | Execute (Args& args, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 304 | CommandReturnObject &result) |
| 305 | { |
| 306 | const size_t argc = args.GetArgumentCount(); |
| 307 | if (argc == 0) |
| 308 | { |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame] | 309 | result.AppendErrorWithFormat("Usage: %s\n", m_cmd_syntax.c_str()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 310 | } |
| 311 | else |
| 312 | { |
Caroline Tice | 926060e | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 313 | Log::Callbacks log_callbacks; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 314 | |
Caroline Tice | 926060e | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 315 | std::string channel(args.GetArgumentAtIndex(0)); |
| 316 | args.Shift (); // Shift off the channel |
| 317 | if (Log::GetLogChannelCallbacks (channel.c_str(), log_callbacks)) |
| 318 | { |
| 319 | log_callbacks.disable (args, &result.GetErrorStream()); |
| 320 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 321 | } |
| 322 | else if (channel == "all") |
| 323 | { |
| 324 | Log::DisableAllLogChannels(&result.GetErrorStream()); |
| 325 | } |
| 326 | else |
| 327 | { |
Greg Clayton | 5e342f5 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 328 | LogChannelSP log_channel_sp (LogChannel::FindPlugin(channel.c_str())); |
Caroline Tice | 926060e | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 329 | if (log_channel_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 330 | { |
Caroline Tice | 926060e | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 331 | log_channel_sp->Disable(args, &result.GetErrorStream()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 332 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 333 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 334 | else |
Caroline Tice | 926060e | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 335 | result.AppendErrorWithFormat("Invalid log channel '%s'.\n", args.GetArgumentAtIndex(0)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | return result.Succeeded(); |
| 339 | } |
| 340 | }; |
| 341 | |
| 342 | class CommandObjectLogList : public CommandObject |
| 343 | { |
| 344 | public: |
| 345 | //------------------------------------------------------------------ |
| 346 | // Constructors and Destructors |
| 347 | //------------------------------------------------------------------ |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 348 | CommandObjectLogList(CommandInterpreter &interpreter) : |
| 349 | CommandObject (interpreter, |
| 350 | "log list", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 351 | "List the log categories for one or more log channels. If none specified, lists them all.", |
| 352 | NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 353 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 354 | CommandArgumentEntry arg; |
| 355 | CommandArgumentData channel_arg; |
| 356 | |
| 357 | // Define the first (and only) variant of this arg. |
| 358 | channel_arg.arg_type = eArgTypeLogChannel; |
| 359 | channel_arg.arg_repetition = eArgRepeatStar; |
| 360 | |
| 361 | // There is only one variant this argument could be; put it into the argument entry. |
| 362 | arg.push_back (channel_arg); |
| 363 | |
| 364 | // Push the data for the first argument into the m_arguments vector. |
| 365 | m_arguments.push_back (arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | virtual |
| 369 | ~CommandObjectLogList() |
| 370 | { |
| 371 | } |
| 372 | |
| 373 | virtual bool |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 374 | Execute (Args& args, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 375 | CommandReturnObject &result) |
| 376 | { |
| 377 | const size_t argc = args.GetArgumentCount(); |
| 378 | if (argc == 0) |
| 379 | { |
| 380 | Log::ListAllLogChannels (&result.GetOutputStream()); |
| 381 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 382 | } |
| 383 | else |
| 384 | { |
| 385 | for (size_t i=0; i<argc; ++i) |
| 386 | { |
| 387 | Log::Callbacks log_callbacks; |
| 388 | |
| 389 | std::string channel(args.GetArgumentAtIndex(i)); |
| 390 | if (Log::GetLogChannelCallbacks (channel.c_str(), log_callbacks)) |
| 391 | { |
| 392 | log_callbacks.list_categories (&result.GetOutputStream()); |
| 393 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 394 | } |
| 395 | else if (channel == "all") |
| 396 | { |
| 397 | Log::ListAllLogChannels (&result.GetOutputStream()); |
| 398 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 399 | } |
| 400 | else |
| 401 | { |
Greg Clayton | 5e342f5 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 402 | LogChannelSP log_channel_sp (LogChannel::FindPlugin(channel.c_str())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 403 | if (log_channel_sp) |
| 404 | { |
| 405 | log_channel_sp->ListCategories(&result.GetOutputStream()); |
| 406 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 407 | } |
| 408 | else |
| 409 | result.AppendErrorWithFormat("Invalid log channel '%s'.\n", args.GetArgumentAtIndex(0)); |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | return result.Succeeded(); |
| 414 | } |
| 415 | }; |
| 416 | |
| 417 | class CommandObjectLogTimer : public CommandObject |
| 418 | { |
| 419 | public: |
| 420 | //------------------------------------------------------------------ |
| 421 | // Constructors and Destructors |
| 422 | //------------------------------------------------------------------ |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 423 | CommandObjectLogTimer(CommandInterpreter &interpreter) : |
| 424 | CommandObject (interpreter, |
| 425 | "log timers", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 426 | "Enable, disable, dump, and reset LLDB internal performance timers.", |
Jim Ingham | 4ba3999 | 2010-11-04 23:19:21 +0000 | [diff] [blame] | 427 | "log timers < enable <depth> | disable | dump | increment <bool> | reset >") |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 428 | { |
| 429 | } |
| 430 | |
| 431 | virtual |
| 432 | ~CommandObjectLogTimer() |
| 433 | { |
| 434 | } |
| 435 | |
| 436 | virtual bool |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 437 | Execute (Args& args, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 438 | CommandReturnObject &result) |
| 439 | { |
| 440 | const size_t argc = args.GetArgumentCount(); |
| 441 | result.SetStatus(eReturnStatusFailed); |
| 442 | |
| 443 | if (argc == 1) |
| 444 | { |
| 445 | const char *sub_command = args.GetArgumentAtIndex(0); |
| 446 | |
| 447 | if (strcasecmp(sub_command, "enable") == 0) |
| 448 | { |
| 449 | Timer::SetDisplayDepth (UINT32_MAX); |
| 450 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 451 | } |
| 452 | else if (strcasecmp(sub_command, "disable") == 0) |
| 453 | { |
| 454 | Timer::DumpCategoryTimes (&result.GetOutputStream()); |
| 455 | Timer::SetDisplayDepth (0); |
| 456 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 457 | } |
| 458 | else if (strcasecmp(sub_command, "dump") == 0) |
| 459 | { |
| 460 | Timer::DumpCategoryTimes (&result.GetOutputStream()); |
| 461 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 462 | } |
| 463 | else if (strcasecmp(sub_command, "reset") == 0) |
| 464 | { |
| 465 | Timer::ResetCategoryTimes (); |
| 466 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 467 | } |
| 468 | |
| 469 | } |
Jim Ingham | 19e29a8 | 2010-11-04 23:08:26 +0000 | [diff] [blame] | 470 | else if (argc == 2) |
| 471 | { |
| 472 | const char *sub_command = args.GetArgumentAtIndex(0); |
| 473 | |
| 474 | if (strcasecmp(sub_command, "enable") == 0) |
| 475 | { |
| 476 | bool success; |
| 477 | uint32_t depth = Args::StringToUInt32(args.GetArgumentAtIndex(1), 0, 0, &success); |
| 478 | if (success) |
| 479 | { |
| 480 | Timer::SetDisplayDepth (depth); |
| 481 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 482 | } |
| 483 | else |
| 484 | result.AppendError("Could not convert enable depth to an unsigned integer."); |
| 485 | } |
Jim Ingham | 4ba3999 | 2010-11-04 23:19:21 +0000 | [diff] [blame] | 486 | if (strcasecmp(sub_command, "increment") == 0) |
| 487 | { |
| 488 | bool success; |
| 489 | bool increment = Args::StringToBoolean(args.GetArgumentAtIndex(1), false, &success); |
| 490 | if (success) |
| 491 | { |
| 492 | Timer::SetQuiet (!increment); |
| 493 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 494 | } |
| 495 | else |
| 496 | result.AppendError("Could not convert increment value to boolean."); |
| 497 | } |
Jim Ingham | 19e29a8 | 2010-11-04 23:08:26 +0000 | [diff] [blame] | 498 | } |
| 499 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 500 | if (!result.Succeeded()) |
| 501 | { |
| 502 | result.AppendError("Missing subcommand"); |
| 503 | result.AppendErrorWithFormat("Usage: %s\n", m_cmd_syntax.c_str()); |
| 504 | } |
| 505 | return result.Succeeded(); |
| 506 | } |
| 507 | }; |
| 508 | |
| 509 | //---------------------------------------------------------------------- |
| 510 | // CommandObjectLog constructor |
| 511 | //---------------------------------------------------------------------- |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 512 | CommandObjectLog::CommandObjectLog(CommandInterpreter &interpreter) : |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 513 | CommandObjectMultiword (interpreter, |
| 514 | "log", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 515 | "A set of commands for operating on logs.", |
| 516 | "log <command> [<command-options>]") |
| 517 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 518 | LoadSubCommand ("enable", CommandObjectSP (new CommandObjectLogEnable (interpreter))); |
| 519 | LoadSubCommand ("disable", CommandObjectSP (new CommandObjectLogDisable (interpreter))); |
| 520 | LoadSubCommand ("list", CommandObjectSP (new CommandObjectLogList (interpreter))); |
| 521 | LoadSubCommand ("timers", CommandObjectSP (new CommandObjectLogTimer (interpreter))); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | //---------------------------------------------------------------------- |
| 525 | // Destructor |
| 526 | //---------------------------------------------------------------------- |
| 527 | CommandObjectLog::~CommandObjectLog() |
| 528 | { |
| 529 | } |
| 530 | |
| 531 | |
| 532 | |
| 533 | |