blob: ca6b39c0ebfa78a0c61e417a0a070166f4097fa3 [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),
Greg Claytoneb0103f2011-04-07 22:46:35 +000050 m_options (interpreter)
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:
Greg Claytoneb0103f2011-04-07 22:46:35 +0000107 CommandOptions (CommandInterpreter &interpreter) :
108 Options (interpreter),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109 log_file (),
110 log_options (0)
111 {
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
117 SetOptionValue (uint32_t option_idx, const char *option_arg) override
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000118 {
119 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000120 const int short_option = m_getopt_table[option_idx].val;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000121
122 switch (short_option)
123 {
Greg Clayton889037d2012-12-07 18:37:09 +0000124 case 'f': log_file.SetFile(option_arg, true); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000125 case 't': log_options |= LLDB_LOG_OPTION_THREADSAFE; break;
126 case 'v': log_options |= LLDB_LOG_OPTION_VERBOSE; break;
127 case 'g': log_options |= LLDB_LOG_OPTION_DEBUG; break;
128 case 's': log_options |= LLDB_LOG_OPTION_PREPEND_SEQUENCE; break;
129 case 'T': log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP; break;
130 case 'p': log_options |= LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD;break;
131 case 'n': log_options |= LLDB_LOG_OPTION_PREPEND_THREAD_NAME; break;
Greg Clayton3a18e312012-10-08 22:41:53 +0000132 case 'S': log_options |= LLDB_LOG_OPTION_BACKTRACE; break;
Pavel Labath8ac06992015-03-20 09:43:20 +0000133 case 'a': log_options |= LLDB_LOG_OPTION_APPEND; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000134 default:
Greg Clayton86edbf42011-10-26 00:56:27 +0000135 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000136 break;
137 }
138
139 return error;
140 }
141
142 void
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000143 OptionParsingStarting () override
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000144 {
Greg Clayton889037d2012-12-07 18:37:09 +0000145 log_file.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000146 log_options = 0;
147 }
148
Greg Claytone0d378b2011-03-24 21:19:54 +0000149 const OptionDefinition*
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000150 GetDefinitions () override
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000151 {
152 return g_option_table;
153 }
154
155 // Options table: Required for subclasses of Options.
156
Greg Claytone0d378b2011-03-24 21:19:54 +0000157 static OptionDefinition g_option_table[];
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000158
159 // Instance variables to hold the values for command options.
160
Greg Clayton889037d2012-12-07 18:37:09 +0000161 FileSpec log_file;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000162 uint32_t log_options;
163 };
164
165protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000166 bool
Jim Ingham5a988412012-06-08 21:56:10 +0000167 DoExecute (Args& args,
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000168 CommandReturnObject &result) override
Jim Ingham5a988412012-06-08 21:56:10 +0000169 {
170 if (args.GetArgumentCount() < 2)
171 {
172 result.AppendErrorWithFormat("%s takes a log channel and one or more log types.\n", m_cmd_name.c_str());
173 }
174 else
175 {
176 std::string channel(args.GetArgumentAtIndex(0));
177 args.Shift (); // Shift off the channel
Greg Clayton889037d2012-12-07 18:37:09 +0000178 char log_file[PATH_MAX];
179 if (m_options.log_file)
180 m_options.log_file.GetPath(log_file, sizeof(log_file));
181 else
182 log_file[0] = '\0';
Jim Ingham5a988412012-06-08 21:56:10 +0000183 bool success = m_interpreter.GetDebugger().EnableLog (channel.c_str(),
184 args.GetConstArgumentVector(),
Greg Clayton889037d2012-12-07 18:37:09 +0000185 log_file,
Jim Ingham5a988412012-06-08 21:56:10 +0000186 m_options.log_options,
187 result.GetErrorStream());
188 if (success)
189 result.SetStatus (eReturnStatusSuccessFinishNoResult);
190 else
191 result.SetStatus (eReturnStatusFailed);
192 }
193 return result.Succeeded();
194 }
195
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000196 CommandOptions m_options;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000197};
198
Greg Claytone0d378b2011-03-24 21:19:54 +0000199OptionDefinition
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000200CommandObjectLogEnable::CommandOptions::g_option_table[] =
201{
Eugene Zelenko26cac3a2016-02-20 00:58:29 +0000202{ LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFilename, "Set the destination file to log to."},
203{ LLDB_OPT_SET_1, false, "threadsafe", 't', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable thread safe logging to avoid interweaved log lines." },
204{ LLDB_OPT_SET_1, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable verbose logging." },
205{ LLDB_OPT_SET_1, false, "debug", 'g', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable debug logging." },
206{ LLDB_OPT_SET_1, false, "sequence", 's', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Prepend all log lines with an increasing integer sequence id." },
207{ LLDB_OPT_SET_1, false, "timestamp", 'T', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Prepend all log lines with a timestamp." },
208{ 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." },
209{ 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." },
210{ LLDB_OPT_SET_1, false, "stack", 'S', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Append a stack backtrace to each log line." },
211{ LLDB_OPT_SET_1, false, "append", 'a', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Append to the log file instead of overwriting." },
212{ 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000213};
214
Jim Ingham5a988412012-06-08 21:56:10 +0000215class CommandObjectLogDisable : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000216{
217public:
218 //------------------------------------------------------------------
219 // Constructors and Destructors
220 //------------------------------------------------------------------
Greg Claytona7015092010-09-18 01:14:36 +0000221 CommandObjectLogDisable(CommandInterpreter &interpreter) :
Eugene Zelenko26cac3a2016-02-20 00:58:29 +0000222 CommandObjectParsed(interpreter,
223 "log disable",
224 "Disable one or more log channel categories.",
225 nullptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000226 {
Caroline Tice7149fab2010-10-29 21:56:41 +0000227 CommandArgumentEntry arg1;
228 CommandArgumentEntry arg2;
Caroline Tice405fe672010-10-04 22:28:36 +0000229 CommandArgumentData channel_arg;
Caroline Tice7149fab2010-10-29 21:56:41 +0000230 CommandArgumentData category_arg;
Caroline Tice405fe672010-10-04 22:28:36 +0000231
232 // Define the first (and only) variant of this arg.
233 channel_arg.arg_type = eArgTypeLogChannel;
Caroline Tice7149fab2010-10-29 21:56:41 +0000234 channel_arg.arg_repetition = eArgRepeatPlain;
Caroline Tice405fe672010-10-04 22:28:36 +0000235
236 // There is only one variant this argument could be; put it into the argument entry.
Caroline Tice7149fab2010-10-29 21:56:41 +0000237 arg1.push_back (channel_arg);
Caroline Tice405fe672010-10-04 22:28:36 +0000238
Caroline Tice7149fab2010-10-29 21:56:41 +0000239 category_arg.arg_type = eArgTypeLogCategory;
240 category_arg.arg_repetition = eArgRepeatPlus;
241
242 arg2.push_back (category_arg);
243
Caroline Tice405fe672010-10-04 22:28:36 +0000244 // Push the data for the first argument into the m_arguments vector.
Caroline Tice7149fab2010-10-29 21:56:41 +0000245 m_arguments.push_back (arg1);
246 m_arguments.push_back (arg2);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000247 }
248
Eugene Zelenko26cac3a2016-02-20 00:58:29 +0000249 ~CommandObjectLogDisable() override = default;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000250
Jim Ingham5a988412012-06-08 21:56:10 +0000251protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000252 bool
Jim Ingham5a988412012-06-08 21:56:10 +0000253 DoExecute (Args& args,
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000254 CommandReturnObject &result) override
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000255 {
256 const size_t argc = args.GetArgumentCount();
257 if (argc == 0)
258 {
Jim Inghamdff04402012-05-12 00:38:30 +0000259 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 +0000260 }
261 else
262 {
Caroline Tice20ad3c42010-10-29 21:48:37 +0000263 Log::Callbacks log_callbacks;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000264
Caroline Tice20ad3c42010-10-29 21:48:37 +0000265 std::string channel(args.GetArgumentAtIndex(0));
266 args.Shift (); // Shift off the channel
Greg Clayton57abc5d2013-05-10 21:47:16 +0000267 if (Log::GetLogChannelCallbacks (ConstString(channel.c_str()), log_callbacks))
Caroline Tice20ad3c42010-10-29 21:48:37 +0000268 {
Jim Ingham228063c2012-02-21 02:23:08 +0000269 log_callbacks.disable (args.GetConstArgumentVector(), &result.GetErrorStream());
Caroline Tice20ad3c42010-10-29 21:48:37 +0000270 result.SetStatus(eReturnStatusSuccessFinishNoResult);
271 }
272 else if (channel == "all")
273 {
274 Log::DisableAllLogChannels(&result.GetErrorStream());
275 }
276 else
277 {
Greg Claytonab65b342011-04-13 22:47:15 +0000278 LogChannelSP log_channel_sp (LogChannel::FindPlugin(channel.c_str()));
Caroline Tice20ad3c42010-10-29 21:48:37 +0000279 if (log_channel_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000280 {
Jim Ingham228063c2012-02-21 02:23:08 +0000281 log_channel_sp->Disable(args.GetConstArgumentVector(), &result.GetErrorStream());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282 result.SetStatus(eReturnStatusSuccessFinishNoResult);
283 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000284 else
Caroline Tice20ad3c42010-10-29 21:48:37 +0000285 result.AppendErrorWithFormat("Invalid log channel '%s'.\n", args.GetArgumentAtIndex(0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000286 }
287 }
288 return result.Succeeded();
289 }
290};
291
Jim Ingham5a988412012-06-08 21:56:10 +0000292class CommandObjectLogList : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000293{
294public:
295 //------------------------------------------------------------------
296 // Constructors and Destructors
297 //------------------------------------------------------------------
Greg Claytona7015092010-09-18 01:14:36 +0000298 CommandObjectLogList(CommandInterpreter &interpreter) :
Eugene Zelenko26cac3a2016-02-20 00:58:29 +0000299 CommandObjectParsed(interpreter,
300 "log list",
301 "List the log categories for one or more log channels. If none specified, lists them all.",
302 nullptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000303 {
Caroline Tice405fe672010-10-04 22:28:36 +0000304 CommandArgumentEntry arg;
305 CommandArgumentData channel_arg;
306
307 // Define the first (and only) variant of this arg.
308 channel_arg.arg_type = eArgTypeLogChannel;
309 channel_arg.arg_repetition = eArgRepeatStar;
310
311 // There is only one variant this argument could be; put it into the argument entry.
312 arg.push_back (channel_arg);
313
314 // Push the data for the first argument into the m_arguments vector.
315 m_arguments.push_back (arg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000316 }
317
Eugene Zelenko26cac3a2016-02-20 00:58:29 +0000318 ~CommandObjectLogList() override = default;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000319
Jim Ingham5a988412012-06-08 21:56:10 +0000320protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000321 bool
Jim Ingham5a988412012-06-08 21:56:10 +0000322 DoExecute (Args& args,
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000323 CommandReturnObject &result) override
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000324 {
325 const size_t argc = args.GetArgumentCount();
326 if (argc == 0)
327 {
328 Log::ListAllLogChannels (&result.GetOutputStream());
329 result.SetStatus(eReturnStatusSuccessFinishResult);
330 }
331 else
332 {
333 for (size_t i=0; i<argc; ++i)
334 {
335 Log::Callbacks log_callbacks;
336
337 std::string channel(args.GetArgumentAtIndex(i));
Greg Clayton57abc5d2013-05-10 21:47:16 +0000338 if (Log::GetLogChannelCallbacks (ConstString(channel.c_str()), log_callbacks))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000339 {
340 log_callbacks.list_categories (&result.GetOutputStream());
341 result.SetStatus(eReturnStatusSuccessFinishResult);
342 }
343 else if (channel == "all")
344 {
345 Log::ListAllLogChannels (&result.GetOutputStream());
346 result.SetStatus(eReturnStatusSuccessFinishResult);
347 }
348 else
349 {
Greg Claytonab65b342011-04-13 22:47:15 +0000350 LogChannelSP log_channel_sp (LogChannel::FindPlugin(channel.c_str()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000351 if (log_channel_sp)
352 {
353 log_channel_sp->ListCategories(&result.GetOutputStream());
354 result.SetStatus(eReturnStatusSuccessFinishNoResult);
355 }
356 else
357 result.AppendErrorWithFormat("Invalid log channel '%s'.\n", args.GetArgumentAtIndex(0));
358 }
359 }
360 }
361 return result.Succeeded();
362 }
363};
364
Jim Ingham5a988412012-06-08 21:56:10 +0000365class CommandObjectLogTimer : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000366{
367public:
368 //------------------------------------------------------------------
369 // Constructors and Destructors
370 //------------------------------------------------------------------
Greg Claytona7015092010-09-18 01:14:36 +0000371 CommandObjectLogTimer(CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000372 CommandObjectParsed (interpreter,
373 "log timers",
374 "Enable, disable, dump, and reset LLDB internal performance timers.",
375 "log timers < enable <depth> | disable | dump | increment <bool> | reset >")
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000376 {
377 }
378
Eugene Zelenko26cac3a2016-02-20 00:58:29 +0000379 ~CommandObjectLogTimer() override = default;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000380
Jim Ingham5a988412012-06-08 21:56:10 +0000381protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000382 bool
Jim Ingham5a988412012-06-08 21:56:10 +0000383 DoExecute (Args& args,
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000384 CommandReturnObject &result) override
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000385 {
386 const size_t argc = args.GetArgumentCount();
387 result.SetStatus(eReturnStatusFailed);
388
389 if (argc == 1)
390 {
391 const char *sub_command = args.GetArgumentAtIndex(0);
392
393 if (strcasecmp(sub_command, "enable") == 0)
394 {
395 Timer::SetDisplayDepth (UINT32_MAX);
396 result.SetStatus(eReturnStatusSuccessFinishNoResult);
397 }
398 else if (strcasecmp(sub_command, "disable") == 0)
399 {
400 Timer::DumpCategoryTimes (&result.GetOutputStream());
401 Timer::SetDisplayDepth (0);
402 result.SetStatus(eReturnStatusSuccessFinishResult);
403 }
404 else if (strcasecmp(sub_command, "dump") == 0)
405 {
406 Timer::DumpCategoryTimes (&result.GetOutputStream());
407 result.SetStatus(eReturnStatusSuccessFinishResult);
408 }
409 else if (strcasecmp(sub_command, "reset") == 0)
410 {
411 Timer::ResetCategoryTimes ();
412 result.SetStatus(eReturnStatusSuccessFinishResult);
413 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414 }
Jim Ingham932725f2010-11-04 23:08:26 +0000415 else if (argc == 2)
416 {
417 const char *sub_command = args.GetArgumentAtIndex(0);
418
419 if (strcasecmp(sub_command, "enable") == 0)
420 {
421 bool success;
Vince Harron5275aaa2015-01-15 20:08:35 +0000422 uint32_t depth = StringConvert::ToUInt32(args.GetArgumentAtIndex(1), 0, 0, &success);
Jim Ingham932725f2010-11-04 23:08:26 +0000423 if (success)
424 {
425 Timer::SetDisplayDepth (depth);
426 result.SetStatus(eReturnStatusSuccessFinishNoResult);
427 }
428 else
429 result.AppendError("Could not convert enable depth to an unsigned integer.");
430 }
Jim Inghamf7f4f502010-11-04 23:19:21 +0000431 if (strcasecmp(sub_command, "increment") == 0)
432 {
433 bool success;
434 bool increment = Args::StringToBoolean(args.GetArgumentAtIndex(1), false, &success);
435 if (success)
436 {
437 Timer::SetQuiet (!increment);
438 result.SetStatus(eReturnStatusSuccessFinishNoResult);
439 }
440 else
441 result.AppendError("Could not convert increment value to boolean.");
442 }
Jim Ingham932725f2010-11-04 23:08:26 +0000443 }
444
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000445 if (!result.Succeeded())
446 {
447 result.AppendError("Missing subcommand");
448 result.AppendErrorWithFormat("Usage: %s\n", m_cmd_syntax.c_str());
449 }
450 return result.Succeeded();
451 }
452};
453
Kate Stone7428a182016-07-14 22:03:10 +0000454CommandObjectLog::CommandObjectLog(CommandInterpreter &interpreter)
455 : CommandObjectMultiword(interpreter, "log", "Commands controlling LLDB internal logging.",
456 "log <subcommand> [<command-options>]")
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000457{
Greg Claytona7015092010-09-18 01:14:36 +0000458 LoadSubCommand ("enable", CommandObjectSP (new CommandObjectLogEnable (interpreter)));
459 LoadSubCommand ("disable", CommandObjectSP (new CommandObjectLogDisable (interpreter)));
460 LoadSubCommand ("list", CommandObjectSP (new CommandObjectLogList (interpreter)));
461 LoadSubCommand ("timers", CommandObjectSP (new CommandObjectLogTimer (interpreter)));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000462}
463
Eugene Zelenko26cac3a2016-02-20 00:58:29 +0000464CommandObjectLog::~CommandObjectLog() = default;