blob: 79560bb2a97799ada18b604e62ba829dca9ae684 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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 Lattner30fdc8d2010-06-08 16:52:24 +000010// C Includes
11// C++ Includes
12// Other libraries and framework includes
13// Project includes
Eugene Zelenko26cac3a2016-02-20 00:58:29 +000014#include "CommandObjectLog.h"
Jim Ingham40af72e2010-06-15 19:49:27 +000015#include "lldb/Interpreter/Args.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000016#include "lldb/Core/Debugger.h"
Greg Clayton53239f02011-02-08 05:05:52 +000017#include "lldb/Host/FileSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018#include "lldb/Core/Log.h"
19#include "lldb/Core/Module.h"
Jim Ingham40af72e2010-06-15 19:49:27 +000020#include "lldb/Interpreter/Options.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021#include "lldb/Core/RegularExpression.h"
22#include "lldb/Core/Stream.h"
23#include "lldb/Core/StreamFile.h"
24#include "lldb/Core/Timer.h"
Greg Clayton66111032010-06-23 01:19:29 +000025#include "lldb/Core/Debugger.h"
Vince Harron5275aaa2015-01-15 20:08:35 +000026#include "lldb/Host/StringConvert.h"
Sean Callanan4be39902010-06-23 21:28:25 +000027#include "lldb/Interpreter/CommandInterpreter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028#include "lldb/Interpreter/CommandReturnObject.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Symbol/LineTable.h"
30#include "lldb/Symbol/ObjectFile.h"
31#include "lldb/Symbol/SymbolFile.h"
32#include "lldb/Symbol/SymbolVendor.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Target/Process.h"
34#include "lldb/Target/Target.h"
35
36using namespace lldb;
37using namespace lldb_private;
38
Jim Ingham5a988412012-06-08 21:56:10 +000039class CommandObjectLogEnable : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040{
41public:
42 //------------------------------------------------------------------
43 // Constructors and Destructors
44 //------------------------------------------------------------------
Greg Claytona7015092010-09-18 01:14:36 +000045 CommandObjectLogEnable(CommandInterpreter &interpreter) :
Eugene Zelenko26cac3a2016-02-20 00:58:29 +000046 CommandObjectParsed(interpreter,
47 "log enable",
48 "Enable logging for a single log channel.",
49 nullptr),
Todd Fialae1cfbc72016-08-11 23:51:28 +000050 m_options()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051 {
Caroline Ticeceb6b132010-10-26 03:11:13 +000052 CommandArgumentEntry arg1;
53 CommandArgumentEntry arg2;
Caroline Tice405fe672010-10-04 22:28:36 +000054 CommandArgumentData channel_arg;
Caroline Ticeceb6b132010-10-26 03:11:13 +000055 CommandArgumentData category_arg;
Caroline Tice405fe672010-10-04 22:28:36 +000056
57 // Define the first (and only) variant of this arg.
58 channel_arg.arg_type = eArgTypeLogChannel;
59 channel_arg.arg_repetition = eArgRepeatPlain;
60
61 // There is only one variant this argument could be; put it into the argument entry.
Caroline Ticeceb6b132010-10-26 03:11:13 +000062 arg1.push_back (channel_arg);
Caroline Tice405fe672010-10-04 22:28:36 +000063
Caroline Ticeceb6b132010-10-26 03:11:13 +000064 category_arg.arg_type = eArgTypeLogCategory;
65 category_arg.arg_repetition = eArgRepeatPlus;
66
67 arg2.push_back (category_arg);
68
Caroline Tice405fe672010-10-04 22:28:36 +000069 // Push the data for the first argument into the m_arguments vector.
Caroline Ticeceb6b132010-10-26 03:11:13 +000070 m_arguments.push_back (arg1);
71 m_arguments.push_back (arg2);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000072 }
73
Eugene Zelenko26cac3a2016-02-20 00:58:29 +000074 ~CommandObjectLogEnable() override = default;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075
76 Options *
Bruce Mitchener13d21e92015-10-07 16:56:17 +000077 GetOptions () override
Chris Lattner30fdc8d2010-06-08 16:52:24 +000078 {
79 return &m_options;
80 }
81
Greg Claytonab65b342011-04-13 22:47:15 +000082// int
83// HandleArgumentCompletion (Args &input,
84// int &cursor_index,
85// int &cursor_char_position,
86// OptionElementVector &opt_element_vector,
87// int match_start_point,
88// int max_return_elements,
89// bool &word_complete,
90// StringList &matches)
91// {
92// std::string completion_str (input.GetArgumentAtIndex(cursor_index));
93// completion_str.erase (cursor_char_position);
94//
95// if (cursor_index == 1)
96// {
97// //
98// Log::AutoCompleteChannelName (completion_str.c_str(), matches);
99// }
100// return matches.GetSize();
101// }
102//
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000103
104 class CommandOptions : public Options
105 {
106 public:
Todd Fialae1cfbc72016-08-11 23:51:28 +0000107 CommandOptions() :
108 Options(),
109 log_file(),
110 log_options(0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111 {
112 }
113
Eugene Zelenko26cac3a2016-02-20 00:58:29 +0000114 ~CommandOptions () override = default;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000116 Error
Todd Fialae1cfbc72016-08-11 23:51:28 +0000117 SetOptionValue (uint32_t option_idx, const char *option_arg,
118 ExecutionContext *execution_context) override
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000119 {
120 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000121 const int short_option = m_getopt_table[option_idx].val;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000122
123 switch (short_option)
124 {
Greg Clayton889037d2012-12-07 18:37:09 +0000125 case 'f': log_file.SetFile(option_arg, true); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000126 case 't': log_options |= LLDB_LOG_OPTION_THREADSAFE; break;
127 case 'v': log_options |= LLDB_LOG_OPTION_VERBOSE; break;
128 case 'g': log_options |= LLDB_LOG_OPTION_DEBUG; break;
129 case 's': log_options |= LLDB_LOG_OPTION_PREPEND_SEQUENCE; break;
130 case 'T': log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP; break;
131 case 'p': log_options |= LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD;break;
132 case 'n': log_options |= LLDB_LOG_OPTION_PREPEND_THREAD_NAME; break;
Greg Clayton3a18e312012-10-08 22:41:53 +0000133 case 'S': log_options |= LLDB_LOG_OPTION_BACKTRACE; break;
Pavel Labath8ac06992015-03-20 09:43:20 +0000134 case 'a': log_options |= LLDB_LOG_OPTION_APPEND; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000135 default:
Greg Clayton86edbf42011-10-26 00:56:27 +0000136 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000137 break;
138 }
139
140 return error;
141 }
142
143 void
Todd Fialae1cfbc72016-08-11 23:51:28 +0000144 OptionParsingStarting(ExecutionContext *execution_context) override
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000145 {
Greg Clayton889037d2012-12-07 18:37:09 +0000146 log_file.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000147 log_options = 0;
148 }
149
Greg Claytone0d378b2011-03-24 21:19:54 +0000150 const OptionDefinition*
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000151 GetDefinitions () override
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000152 {
153 return g_option_table;
154 }
155
156 // Options table: Required for subclasses of Options.
157
Greg Claytone0d378b2011-03-24 21:19:54 +0000158 static OptionDefinition g_option_table[];
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000159
160 // Instance variables to hold the values for command options.
161
Greg Clayton889037d2012-12-07 18:37:09 +0000162 FileSpec log_file;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000163 uint32_t log_options;
164 };
165
166protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000167 bool
Jim Ingham5a988412012-06-08 21:56:10 +0000168 DoExecute (Args& args,
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000169 CommandReturnObject &result) override
Jim Ingham5a988412012-06-08 21:56:10 +0000170 {
171 if (args.GetArgumentCount() < 2)
172 {
173 result.AppendErrorWithFormat("%s takes a log channel and one or more log types.\n", m_cmd_name.c_str());
174 }
175 else
176 {
177 std::string channel(args.GetArgumentAtIndex(0));
178 args.Shift (); // Shift off the channel
Greg Clayton889037d2012-12-07 18:37:09 +0000179 char log_file[PATH_MAX];
180 if (m_options.log_file)
181 m_options.log_file.GetPath(log_file, sizeof(log_file));
182 else
183 log_file[0] = '\0';
Jim Ingham5a988412012-06-08 21:56:10 +0000184 bool success = m_interpreter.GetDebugger().EnableLog (channel.c_str(),
185 args.GetConstArgumentVector(),
Greg Clayton889037d2012-12-07 18:37:09 +0000186 log_file,
Jim Ingham5a988412012-06-08 21:56:10 +0000187 m_options.log_options,
188 result.GetErrorStream());
189 if (success)
190 result.SetStatus (eReturnStatusSuccessFinishNoResult);
191 else
192 result.SetStatus (eReturnStatusFailed);
193 }
194 return result.Succeeded();
195 }
196
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000197 CommandOptions m_options;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000198};
199
Greg Claytone0d378b2011-03-24 21:19:54 +0000200OptionDefinition
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000201CommandObjectLogEnable::CommandOptions::g_option_table[] =
202{
Eugene Zelenko26cac3a2016-02-20 00:58:29 +0000203{ LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFilename, "Set the destination file to log to."},
204{ LLDB_OPT_SET_1, false, "threadsafe", 't', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable thread safe logging to avoid interweaved log lines." },
205{ LLDB_OPT_SET_1, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable verbose logging." },
206{ LLDB_OPT_SET_1, false, "debug", 'g', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable debug logging." },
207{ LLDB_OPT_SET_1, false, "sequence", 's', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Prepend all log lines with an increasing integer sequence id." },
208{ LLDB_OPT_SET_1, false, "timestamp", 'T', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Prepend all log lines with a timestamp." },
209{ 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." },
210{ 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." },
211{ LLDB_OPT_SET_1, false, "stack", 'S', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Append a stack backtrace to each log line." },
212{ LLDB_OPT_SET_1, false, "append", 'a', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Append to the log file instead of overwriting." },
213{ 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000214};
215
Jim Ingham5a988412012-06-08 21:56:10 +0000216class CommandObjectLogDisable : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000217{
218public:
219 //------------------------------------------------------------------
220 // Constructors and Destructors
221 //------------------------------------------------------------------
Greg Claytona7015092010-09-18 01:14:36 +0000222 CommandObjectLogDisable(CommandInterpreter &interpreter) :
Eugene Zelenko26cac3a2016-02-20 00:58:29 +0000223 CommandObjectParsed(interpreter,
224 "log disable",
225 "Disable one or more log channel categories.",
226 nullptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000227 {
Caroline Tice7149fab2010-10-29 21:56:41 +0000228 CommandArgumentEntry arg1;
229 CommandArgumentEntry arg2;
Caroline Tice405fe672010-10-04 22:28:36 +0000230 CommandArgumentData channel_arg;
Caroline Tice7149fab2010-10-29 21:56:41 +0000231 CommandArgumentData category_arg;
Caroline Tice405fe672010-10-04 22:28:36 +0000232
233 // Define the first (and only) variant of this arg.
234 channel_arg.arg_type = eArgTypeLogChannel;
Caroline Tice7149fab2010-10-29 21:56:41 +0000235 channel_arg.arg_repetition = eArgRepeatPlain;
Caroline Tice405fe672010-10-04 22:28:36 +0000236
237 // There is only one variant this argument could be; put it into the argument entry.
Caroline Tice7149fab2010-10-29 21:56:41 +0000238 arg1.push_back (channel_arg);
Caroline Tice405fe672010-10-04 22:28:36 +0000239
Caroline Tice7149fab2010-10-29 21:56:41 +0000240 category_arg.arg_type = eArgTypeLogCategory;
241 category_arg.arg_repetition = eArgRepeatPlus;
242
243 arg2.push_back (category_arg);
244
Caroline Tice405fe672010-10-04 22:28:36 +0000245 // Push the data for the first argument into the m_arguments vector.
Caroline Tice7149fab2010-10-29 21:56:41 +0000246 m_arguments.push_back (arg1);
247 m_arguments.push_back (arg2);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000248 }
249
Eugene Zelenko26cac3a2016-02-20 00:58:29 +0000250 ~CommandObjectLogDisable() override = default;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000251
Jim Ingham5a988412012-06-08 21:56:10 +0000252protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000253 bool
Jim Ingham5a988412012-06-08 21:56:10 +0000254 DoExecute (Args& args,
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000255 CommandReturnObject &result) override
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000256 {
257 const size_t argc = args.GetArgumentCount();
258 if (argc == 0)
259 {
Jim Inghamdff04402012-05-12 00:38:30 +0000260 result.AppendErrorWithFormat("%s takes a log channel and one or more log types.\n", m_cmd_name.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000261 }
262 else
263 {
Caroline Tice20ad3c42010-10-29 21:48:37 +0000264 Log::Callbacks log_callbacks;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000265
Caroline Tice20ad3c42010-10-29 21:48:37 +0000266 std::string channel(args.GetArgumentAtIndex(0));
267 args.Shift (); // Shift off the channel
Greg Clayton57abc5d2013-05-10 21:47:16 +0000268 if (Log::GetLogChannelCallbacks (ConstString(channel.c_str()), log_callbacks))
Caroline Tice20ad3c42010-10-29 21:48:37 +0000269 {
Jim Ingham228063c2012-02-21 02:23:08 +0000270 log_callbacks.disable (args.GetConstArgumentVector(), &result.GetErrorStream());
Caroline Tice20ad3c42010-10-29 21:48:37 +0000271 result.SetStatus(eReturnStatusSuccessFinishNoResult);
272 }
273 else if (channel == "all")
274 {
275 Log::DisableAllLogChannels(&result.GetErrorStream());
276 }
277 else
278 {
Greg Claytonab65b342011-04-13 22:47:15 +0000279 LogChannelSP log_channel_sp (LogChannel::FindPlugin(channel.c_str()));
Caroline Tice20ad3c42010-10-29 21:48:37 +0000280 if (log_channel_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000281 {
Jim Ingham228063c2012-02-21 02:23:08 +0000282 log_channel_sp->Disable(args.GetConstArgumentVector(), &result.GetErrorStream());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000283 result.SetStatus(eReturnStatusSuccessFinishNoResult);
284 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000285 else
Caroline Tice20ad3c42010-10-29 21:48:37 +0000286 result.AppendErrorWithFormat("Invalid log channel '%s'.\n", args.GetArgumentAtIndex(0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000287 }
288 }
289 return result.Succeeded();
290 }
291};
292
Jim Ingham5a988412012-06-08 21:56:10 +0000293class CommandObjectLogList : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000294{
295public:
296 //------------------------------------------------------------------
297 // Constructors and Destructors
298 //------------------------------------------------------------------
Greg Claytona7015092010-09-18 01:14:36 +0000299 CommandObjectLogList(CommandInterpreter &interpreter) :
Eugene Zelenko26cac3a2016-02-20 00:58:29 +0000300 CommandObjectParsed(interpreter,
301 "log list",
302 "List the log categories for one or more log channels. If none specified, lists them all.",
303 nullptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000304 {
Caroline Tice405fe672010-10-04 22:28:36 +0000305 CommandArgumentEntry arg;
306 CommandArgumentData channel_arg;
307
308 // Define the first (and only) variant of this arg.
309 channel_arg.arg_type = eArgTypeLogChannel;
310 channel_arg.arg_repetition = eArgRepeatStar;
311
312 // There is only one variant this argument could be; put it into the argument entry.
313 arg.push_back (channel_arg);
314
315 // Push the data for the first argument into the m_arguments vector.
316 m_arguments.push_back (arg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000317 }
318
Eugene Zelenko26cac3a2016-02-20 00:58:29 +0000319 ~CommandObjectLogList() override = default;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000320
Jim Ingham5a988412012-06-08 21:56:10 +0000321protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000322 bool
Jim Ingham5a988412012-06-08 21:56:10 +0000323 DoExecute (Args& args,
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000324 CommandReturnObject &result) override
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000325 {
326 const size_t argc = args.GetArgumentCount();
327 if (argc == 0)
328 {
329 Log::ListAllLogChannels (&result.GetOutputStream());
330 result.SetStatus(eReturnStatusSuccessFinishResult);
331 }
332 else
333 {
334 for (size_t i=0; i<argc; ++i)
335 {
336 Log::Callbacks log_callbacks;
337
338 std::string channel(args.GetArgumentAtIndex(i));
Greg Clayton57abc5d2013-05-10 21:47:16 +0000339 if (Log::GetLogChannelCallbacks (ConstString(channel.c_str()), log_callbacks))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000340 {
341 log_callbacks.list_categories (&result.GetOutputStream());
342 result.SetStatus(eReturnStatusSuccessFinishResult);
343 }
344 else if (channel == "all")
345 {
346 Log::ListAllLogChannels (&result.GetOutputStream());
347 result.SetStatus(eReturnStatusSuccessFinishResult);
348 }
349 else
350 {
Greg Claytonab65b342011-04-13 22:47:15 +0000351 LogChannelSP log_channel_sp (LogChannel::FindPlugin(channel.c_str()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000352 if (log_channel_sp)
353 {
354 log_channel_sp->ListCategories(&result.GetOutputStream());
355 result.SetStatus(eReturnStatusSuccessFinishNoResult);
356 }
357 else
358 result.AppendErrorWithFormat("Invalid log channel '%s'.\n", args.GetArgumentAtIndex(0));
359 }
360 }
361 }
362 return result.Succeeded();
363 }
364};
365
Jim Ingham5a988412012-06-08 21:56:10 +0000366class CommandObjectLogTimer : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000367{
368public:
369 //------------------------------------------------------------------
370 // Constructors and Destructors
371 //------------------------------------------------------------------
Greg Claytona7015092010-09-18 01:14:36 +0000372 CommandObjectLogTimer(CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000373 CommandObjectParsed (interpreter,
374 "log timers",
375 "Enable, disable, dump, and reset LLDB internal performance timers.",
376 "log timers < enable <depth> | disable | dump | increment <bool> | reset >")
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000377 {
378 }
379
Eugene Zelenko26cac3a2016-02-20 00:58:29 +0000380 ~CommandObjectLogTimer() override = default;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000381
Jim Ingham5a988412012-06-08 21:56:10 +0000382protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000383 bool
Jim Ingham5a988412012-06-08 21:56:10 +0000384 DoExecute (Args& args,
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000385 CommandReturnObject &result) override
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000386 {
387 const size_t argc = args.GetArgumentCount();
388 result.SetStatus(eReturnStatusFailed);
389
390 if (argc == 1)
391 {
392 const char *sub_command = args.GetArgumentAtIndex(0);
393
394 if (strcasecmp(sub_command, "enable") == 0)
395 {
396 Timer::SetDisplayDepth (UINT32_MAX);
397 result.SetStatus(eReturnStatusSuccessFinishNoResult);
398 }
399 else if (strcasecmp(sub_command, "disable") == 0)
400 {
401 Timer::DumpCategoryTimes (&result.GetOutputStream());
402 Timer::SetDisplayDepth (0);
403 result.SetStatus(eReturnStatusSuccessFinishResult);
404 }
405 else if (strcasecmp(sub_command, "dump") == 0)
406 {
407 Timer::DumpCategoryTimes (&result.GetOutputStream());
408 result.SetStatus(eReturnStatusSuccessFinishResult);
409 }
410 else if (strcasecmp(sub_command, "reset") == 0)
411 {
412 Timer::ResetCategoryTimes ();
413 result.SetStatus(eReturnStatusSuccessFinishResult);
414 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415 }
Jim Ingham932725f2010-11-04 23:08:26 +0000416 else if (argc == 2)
417 {
418 const char *sub_command = args.GetArgumentAtIndex(0);
419
420 if (strcasecmp(sub_command, "enable") == 0)
421 {
422 bool success;
Vince Harron5275aaa2015-01-15 20:08:35 +0000423 uint32_t depth = StringConvert::ToUInt32(args.GetArgumentAtIndex(1), 0, 0, &success);
Jim Ingham932725f2010-11-04 23:08:26 +0000424 if (success)
425 {
426 Timer::SetDisplayDepth (depth);
427 result.SetStatus(eReturnStatusSuccessFinishNoResult);
428 }
429 else
430 result.AppendError("Could not convert enable depth to an unsigned integer.");
431 }
Jim Inghamf7f4f502010-11-04 23:19:21 +0000432 if (strcasecmp(sub_command, "increment") == 0)
433 {
434 bool success;
435 bool increment = Args::StringToBoolean(args.GetArgumentAtIndex(1), false, &success);
436 if (success)
437 {
438 Timer::SetQuiet (!increment);
439 result.SetStatus(eReturnStatusSuccessFinishNoResult);
440 }
441 else
442 result.AppendError("Could not convert increment value to boolean.");
443 }
Jim Ingham932725f2010-11-04 23:08:26 +0000444 }
445
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000446 if (!result.Succeeded())
447 {
448 result.AppendError("Missing subcommand");
449 result.AppendErrorWithFormat("Usage: %s\n", m_cmd_syntax.c_str());
450 }
451 return result.Succeeded();
452 }
453};
454
Kate Stone7428a182016-07-14 22:03:10 +0000455CommandObjectLog::CommandObjectLog(CommandInterpreter &interpreter)
456 : CommandObjectMultiword(interpreter, "log", "Commands controlling LLDB internal logging.",
457 "log <subcommand> [<command-options>]")
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000458{
Greg Claytona7015092010-09-18 01:14:36 +0000459 LoadSubCommand ("enable", CommandObjectSP (new CommandObjectLogEnable (interpreter)));
460 LoadSubCommand ("disable", CommandObjectSP (new CommandObjectLogDisable (interpreter)));
461 LoadSubCommand ("list", CommandObjectSP (new CommandObjectLogList (interpreter)));
462 LoadSubCommand ("timers", CommandObjectSP (new CommandObjectLogTimer (interpreter)));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000463}
464
Eugene Zelenko26cac3a2016-02-20 00:58:29 +0000465CommandObjectLog::~CommandObjectLog() = default;