[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- CommandObjectLog.cpp ----------------------------------------------===//
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-02-20 08:58:29 +08:00
|
|
|
#include "CommandObjectLog.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Debugger.h"
|
2017-03-23 07:33:16 +08:00
|
|
|
#include "lldb/Host/OptionParser.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
2018-04-10 17:03:59 +08:00
|
|
|
#include "lldb/Interpreter/OptionArgParser.h"
|
2010-06-16 03:49:27 +08:00
|
|
|
#include "lldb/Interpreter/Options.h"
|
2018-04-18 02:53:35 +08:00
|
|
|
#include "lldb/Utility/Args.h"
|
2017-03-23 02:40:07 +08:00
|
|
|
#include "lldb/Utility/FileSpec.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2017-06-29 22:32:17 +08:00
|
|
|
#include "lldb/Utility/Timer.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2019-07-25 19:22:46 +08:00
|
|
|
#define LLDB_OPTIONS_log
|
|
|
|
#include "CommandOptions.inc"
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
|
2019-09-24 15:18:09 +08:00
|
|
|
/// Common completion logic for log enable/disable.
|
|
|
|
static void CompleteEnableDisable(CompletionRequest &request) {
|
|
|
|
size_t arg_index = request.GetCursorIndex();
|
|
|
|
if (arg_index == 0) { // We got: log enable/disable x[tab]
|
|
|
|
for (llvm::StringRef channel : Log::ListChannels())
|
|
|
|
request.TryCompleteCurrentArg(channel);
|
|
|
|
} else if (arg_index >= 1) { // We got: log enable/disable channel x[tab]
|
|
|
|
llvm::StringRef channel = request.GetParsedLine().GetArgumentAtIndex(0);
|
|
|
|
Log::ForEachChannelCategory(
|
|
|
|
channel, [&request](llvm::StringRef name, llvm::StringRef desc) {
|
|
|
|
request.TryCompleteCurrentArg(name, desc);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
class CommandObjectLogEnable : public CommandObjectParsed {
|
2010-06-09 00:52:24 +08:00
|
|
|
public:
|
|
|
|
// Constructors and Destructors
|
2010-09-18 09:14:36 +08:00
|
|
|
CommandObjectLogEnable(CommandInterpreter &interpreter)
|
2016-02-20 08:58:29 +08:00
|
|
|
: CommandObjectParsed(interpreter, "log enable",
|
|
|
|
"Enable logging for a single log channel.",
|
|
|
|
nullptr),
|
2016-08-12 07:51:28 +08:00
|
|
|
m_options() {
|
2010-10-26 11:11:13 +08:00
|
|
|
CommandArgumentEntry arg1;
|
|
|
|
CommandArgumentEntry arg2;
|
2010-10-05 06:28:36 +08:00
|
|
|
CommandArgumentData channel_arg;
|
2010-10-26 11:11:13 +08:00
|
|
|
CommandArgumentData category_arg;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-05 06:28:36 +08:00
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
channel_arg.arg_type = eArgTypeLogChannel;
|
|
|
|
channel_arg.arg_repetition = eArgRepeatPlain;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-05 06:28:36 +08:00
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
// argument entry.
|
2010-10-26 11:11:13 +08:00
|
|
|
arg1.push_back(channel_arg);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-30 05:56:41 +08:00
|
|
|
category_arg.arg_type = eArgTypeLogCategory;
|
|
|
|
category_arg.arg_repetition = eArgRepeatPlus;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-30 05:56:41 +08:00
|
|
|
arg2.push_back(category_arg);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-26 11:11:13 +08:00
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
m_arguments.push_back(arg1);
|
2010-10-30 05:56:41 +08:00
|
|
|
m_arguments.push_back(arg2);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-10-26 11:11:13 +08:00
|
|
|
~CommandObjectLogEnable() override = default;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-26 11:11:13 +08:00
|
|
|
Options *GetOptions() override { return &m_options; }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-05 06:28:36 +08:00
|
|
|
class CommandOptions : public Options {
|
2016-09-07 04:57:50 +08:00
|
|
|
public:
|
2010-10-05 06:28:36 +08:00
|
|
|
CommandOptions() : Options(), log_file(), log_options(0) {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-05 06:28:36 +08:00
|
|
|
~CommandOptions() override = default;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
|
|
|
|
ExecutionContext *execution_context) override {
|
|
|
|
Status error;
|
2010-10-05 06:28:36 +08:00
|
|
|
const int short_option = m_getopt_table[option_idx].val;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-26 11:11:13 +08:00
|
|
|
switch (short_option) {
|
2012-12-08 02:37:09 +08:00
|
|
|
case 'f':
|
2018-11-02 05:05:36 +08:00
|
|
|
log_file.SetFile(option_arg, FileSpec::Style::native);
|
|
|
|
FileSystem::Instance().Resolve(log_file);
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
case 't':
|
|
|
|
log_options |= LLDB_LOG_OPTION_THREADSAFE;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
case 'v':
|
|
|
|
log_options |= LLDB_LOG_OPTION_VERBOSE;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
case 's':
|
|
|
|
log_options |= LLDB_LOG_OPTION_PREPEND_SEQUENCE;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
case 'T':
|
|
|
|
log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
case 'p':
|
|
|
|
log_options |= LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
case 'n':
|
2010-10-26 11:11:13 +08:00
|
|
|
log_options |= LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2012-10-09 06:41:53 +08:00
|
|
|
case 'S':
|
2010-10-26 11:11:13 +08:00
|
|
|
log_options |= LLDB_LOG_OPTION_BACKTRACE;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2015-03-20 17:43:20 +08:00
|
|
|
case 'a':
|
2010-10-26 11:11:13 +08:00
|
|
|
log_options |= LLDB_LOG_OPTION_APPEND;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
Add a more succinct logging syntax
This adds the LLDB_LOG macro, which enables one to write more succinct log
statements.
if (log)
log->Printf("log something: %d", var);
becomes
LLDB_LOG(log, "log something: {0}, var);
The macro still internally does the "if(log)" dance, so the arguments are only
evaluated if logging is enabled, meaning it has the same overhead as the
previous syntax.
Additionally, the log statements will be automatically prefixed with the file
and function generating the log (if the corresponding new argument to the "log
enable" command is enabled), so one does not need to manually specify this in
the log statement.
It also uses the new llvm formatv syntax, which means we don't have to worry
about PRIx64 macros and similar, and we can log complex object (llvm::StringRef,
lldb_private::Error, ...) more easily.
Differential Revision: https://reviews.llvm.org/D27459
llvm-svn: 292360
2017-01-18 19:00:26 +08:00
|
|
|
case 'F':
|
|
|
|
log_options |= LLDB_LOG_OPTION_PREPEND_FILE_FUNCTION;
|
2017-02-04 04:26:57 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
default:
|
2019-08-22 16:08:05 +08:00
|
|
|
llvm_unreachable("Unimplemented option");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2015-10-08 00:56:17 +08:00
|
|
|
void OptionParsingStarting(ExecutionContext *execution_context) override {
|
|
|
|
log_file.Clear();
|
2010-06-09 00:52:24 +08:00
|
|
|
log_options = 0;
|
|
|
|
}
|
|
|
|
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
|
2016-09-23 05:06:13 +08:00
|
|
|
return llvm::makeArrayRef(g_log_options);
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-08-12 07:51:28 +08:00
|
|
|
// Instance variables to hold the values for command options.
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-12-08 02:37:09 +08:00
|
|
|
FileSpec log_file;
|
2010-06-09 00:52:24 +08:00
|
|
|
uint32_t log_options;
|
|
|
|
};
|
|
|
|
|
2019-09-24 15:18:09 +08:00
|
|
|
void
|
|
|
|
HandleArgumentCompletion(CompletionRequest &request,
|
|
|
|
OptionElementVector &opt_element_vector) override {
|
|
|
|
CompleteEnableDisable(request);
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
protected:
|
2015-10-08 00:56:17 +08:00
|
|
|
bool DoExecute(Args &args, CommandReturnObject &result) override {
|
2012-06-09 05:56:10 +08:00
|
|
|
if (args.GetArgumentCount() < 2) {
|
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
"%s takes a log channel and one or more log types.\n",
|
|
|
|
m_cmd_name.c_str());
|
2019-09-02 03:29:01 +08:00
|
|
|
result.SetStatus(eReturnStatusFailed);
|
2016-10-06 04:03:37 +08:00
|
|
|
return false;
|
2012-06-09 05:56:10 +08:00
|
|
|
}
|
2016-10-06 04:03:37 +08:00
|
|
|
|
|
|
|
// Store into a std::string since we're about to shift the channel off.
|
2020-01-29 03:23:46 +08:00
|
|
|
const std::string channel = std::string(args[0].ref());
|
2016-10-06 04:03:37 +08:00
|
|
|
args.Shift(); // Shift off the channel
|
|
|
|
char log_file[PATH_MAX];
|
|
|
|
if (m_options.log_file)
|
|
|
|
m_options.log_file.GetPath(log_file, sizeof(log_file));
|
|
|
|
else
|
|
|
|
log_file[0] = '\0';
|
2017-03-15 17:06:58 +08:00
|
|
|
|
|
|
|
std::string error;
|
|
|
|
llvm::raw_string_ostream error_stream(error);
|
2019-04-27 14:19:42 +08:00
|
|
|
bool success =
|
|
|
|
GetDebugger().EnableLog(channel, args.GetArgumentArrayRef(), log_file,
|
|
|
|
m_options.log_options, error_stream);
|
2017-03-15 17:06:58 +08:00
|
|
|
result.GetErrorStream() << error_stream.str();
|
|
|
|
|
2016-10-06 04:03:37 +08:00
|
|
|
if (success)
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
|
|
|
else
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
2012-06-09 05:56:10 +08:00
|
|
|
return result.Succeeded();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-06-09 05:56:10 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
CommandOptions m_options;
|
|
|
|
};
|
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
class CommandObjectLogDisable : public CommandObjectParsed {
|
2010-06-09 00:52:24 +08:00
|
|
|
public:
|
|
|
|
// Constructors and Destructors
|
2010-09-18 09:14:36 +08:00
|
|
|
CommandObjectLogDisable(CommandInterpreter &interpreter)
|
2016-02-20 08:58:29 +08:00
|
|
|
: CommandObjectParsed(interpreter, "log disable",
|
|
|
|
"Disable one or more log channel categories.",
|
|
|
|
nullptr) {
|
2010-10-30 05:56:41 +08:00
|
|
|
CommandArgumentEntry arg1;
|
|
|
|
CommandArgumentEntry arg2;
|
2010-10-05 06:28:36 +08:00
|
|
|
CommandArgumentData channel_arg;
|
2010-10-30 05:56:41 +08:00
|
|
|
CommandArgumentData category_arg;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-05 06:28:36 +08:00
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
channel_arg.arg_type = eArgTypeLogChannel;
|
2010-10-30 05:56:41 +08:00
|
|
|
channel_arg.arg_repetition = eArgRepeatPlain;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-05 06:28:36 +08:00
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
// argument entry.
|
2010-10-30 05:56:41 +08:00
|
|
|
arg1.push_back(channel_arg);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-30 05:56:41 +08:00
|
|
|
category_arg.arg_type = eArgTypeLogCategory;
|
|
|
|
category_arg.arg_repetition = eArgRepeatPlus;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-10-30 05:56:41 +08:00
|
|
|
arg2.push_back(category_arg);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-05 06:28:36 +08:00
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
2010-10-30 05:56:41 +08:00
|
|
|
m_arguments.push_back(arg1);
|
|
|
|
m_arguments.push_back(arg2);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2016-02-20 08:58:29 +08:00
|
|
|
~CommandObjectLogDisable() override = default;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-09-24 15:18:09 +08:00
|
|
|
void
|
|
|
|
HandleArgumentCompletion(CompletionRequest &request,
|
|
|
|
OptionElementVector &opt_element_vector) override {
|
|
|
|
CompleteEnableDisable(request);
|
|
|
|
}
|
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
protected:
|
2015-10-08 00:56:17 +08:00
|
|
|
bool DoExecute(Args &args, CommandReturnObject &result) override {
|
2016-10-06 04:03:37 +08:00
|
|
|
if (args.empty()) {
|
2012-05-12 08:38:30 +08:00
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
"%s takes a log channel and one or more log types.\n",
|
|
|
|
m_cmd_name.c_str());
|
2019-09-02 03:29:01 +08:00
|
|
|
result.SetStatus(eReturnStatusFailed);
|
2016-10-06 04:03:37 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-29 03:23:46 +08:00
|
|
|
const std::string channel = std::string(args[0].ref());
|
2016-10-06 04:03:37 +08:00
|
|
|
args.Shift(); // Shift off the channel
|
2017-02-17 21:27:42 +08:00
|
|
|
if (channel == "all") {
|
2017-03-15 17:06:58 +08:00
|
|
|
Log::DisableAllLogChannels();
|
2017-02-17 21:27:42 +08:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
2010-06-09 00:52:24 +08:00
|
|
|
} else {
|
2017-03-15 17:06:58 +08:00
|
|
|
std::string error;
|
|
|
|
llvm::raw_string_ostream error_stream(error);
|
2017-03-01 18:08:40 +08:00
|
|
|
if (Log::DisableLogChannel(channel, args.GetArgumentArrayRef(),
|
2017-03-15 17:06:58 +08:00
|
|
|
error_stream))
|
2010-10-30 05:48:37 +08:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
2017-03-15 17:06:58 +08:00
|
|
|
result.GetErrorStream() << error_stream.str();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return result.Succeeded();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
};
|
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
class CommandObjectLogList : public CommandObjectParsed {
|
2010-06-09 00:52:24 +08:00
|
|
|
public:
|
|
|
|
// Constructors and Destructors
|
2010-09-18 09:14:36 +08:00
|
|
|
CommandObjectLogList(CommandInterpreter &interpreter)
|
2016-02-20 08:58:29 +08:00
|
|
|
: CommandObjectParsed(interpreter, "log list",
|
|
|
|
"List the log categories for one or more log "
|
|
|
|
"channels. If none specified, lists them all.",
|
|
|
|
nullptr) {
|
2010-10-05 06:28:36 +08:00
|
|
|
CommandArgumentEntry arg;
|
|
|
|
CommandArgumentData channel_arg;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-05 06:28:36 +08:00
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
channel_arg.arg_type = eArgTypeLogChannel;
|
|
|
|
channel_arg.arg_repetition = eArgRepeatStar;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-05 06:28:36 +08:00
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
// argument entry.
|
|
|
|
arg.push_back(channel_arg);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-05 06:28:36 +08:00
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
m_arguments.push_back(arg);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-02-20 08:58:29 +08:00
|
|
|
~CommandObjectLogList() override = default;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-09-24 15:18:09 +08:00
|
|
|
void
|
|
|
|
HandleArgumentCompletion(CompletionRequest &request,
|
|
|
|
OptionElementVector &opt_element_vector) override {
|
|
|
|
for (llvm::StringRef channel : Log::ListChannels())
|
|
|
|
request.TryCompleteCurrentArg(channel);
|
|
|
|
}
|
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
protected:
|
2015-10-08 00:56:17 +08:00
|
|
|
bool DoExecute(Args &args, CommandReturnObject &result) override {
|
2017-03-15 17:06:58 +08:00
|
|
|
std::string output;
|
|
|
|
llvm::raw_string_ostream output_stream(output);
|
2016-10-06 04:03:37 +08:00
|
|
|
if (args.empty()) {
|
2017-03-15 17:06:58 +08:00
|
|
|
Log::ListAllLogChannels(output_stream);
|
2010-06-09 00:52:24 +08:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
} else {
|
2017-02-17 21:27:42 +08:00
|
|
|
bool success = true;
|
|
|
|
for (const auto &entry : args.entries())
|
2017-03-15 17:06:58 +08:00
|
|
|
success =
|
2019-09-13 19:26:48 +08:00
|
|
|
success && Log::ListChannelCategories(entry.ref(), output_stream);
|
2017-02-17 21:27:42 +08:00
|
|
|
if (success)
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2017-03-15 17:06:58 +08:00
|
|
|
result.GetOutputStream() << output_stream.str();
|
2010-06-09 00:52:24 +08:00
|
|
|
return result.Succeeded();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
};
|
|
|
|
|
2020-04-09 14:11:55 +08:00
|
|
|
class CommandObjectLogTimerEnable : public CommandObjectParsed {
|
2010-06-09 00:52:24 +08:00
|
|
|
public:
|
|
|
|
// Constructors and Destructors
|
2020-04-09 14:11:55 +08:00
|
|
|
CommandObjectLogTimerEnable(CommandInterpreter &interpreter)
|
|
|
|
: CommandObjectParsed(interpreter, "log timers enable",
|
|
|
|
"enable LLDB internal performance timers",
|
|
|
|
"log timers enable <depth>") {
|
|
|
|
CommandArgumentEntry arg;
|
|
|
|
CommandArgumentData depth_arg;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-04-09 14:11:55 +08:00
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
depth_arg.arg_type = eArgTypeCount;
|
|
|
|
depth_arg.arg_repetition = eArgRepeatOptional;
|
|
|
|
|
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
// argument entry.
|
|
|
|
arg.push_back(depth_arg);
|
|
|
|
|
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
m_arguments.push_back(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
~CommandObjectLogTimerEnable() override = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool DoExecute(Args &args, CommandReturnObject &result) override {
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
|
|
|
|
if (args.GetArgumentCount() == 0) {
|
|
|
|
Timer::SetDisplayDepth(UINT32_MAX);
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
|
|
|
} else if (args.GetArgumentCount() == 1) {
|
|
|
|
uint32_t depth;
|
|
|
|
if (args[0].ref().consumeInteger(0, depth)) {
|
|
|
|
result.AppendError(
|
|
|
|
"Could not convert enable depth to an unsigned integer.");
|
|
|
|
} else {
|
|
|
|
Timer::SetDisplayDepth(depth);
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!result.Succeeded()) {
|
|
|
|
result.AppendError("Missing subcommand");
|
|
|
|
result.AppendErrorWithFormat("Usage: %s\n", m_cmd_syntax.c_str());
|
|
|
|
}
|
|
|
|
return result.Succeeded();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class CommandObjectLogTimerDisable : public CommandObjectParsed {
|
|
|
|
public:
|
|
|
|
// Constructors and Destructors
|
|
|
|
CommandObjectLogTimerDisable(CommandInterpreter &interpreter)
|
|
|
|
: CommandObjectParsed(interpreter, "log timers disable",
|
|
|
|
"disable LLDB internal performance timers",
|
|
|
|
nullptr) {}
|
|
|
|
|
|
|
|
~CommandObjectLogTimerDisable() override = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool DoExecute(Args &args, CommandReturnObject &result) override {
|
|
|
|
Timer::DumpCategoryTimes(&result.GetOutputStream());
|
|
|
|
Timer::SetDisplayDepth(0);
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
|
|
|
|
if (!result.Succeeded()) {
|
|
|
|
result.AppendError("Missing subcommand");
|
|
|
|
result.AppendErrorWithFormat("Usage: %s\n", m_cmd_syntax.c_str());
|
|
|
|
}
|
|
|
|
return result.Succeeded();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class CommandObjectLogTimerDump : public CommandObjectParsed {
|
|
|
|
public:
|
|
|
|
// Constructors and Destructors
|
|
|
|
CommandObjectLogTimerDump(CommandInterpreter &interpreter)
|
|
|
|
: CommandObjectParsed(interpreter, "log timers dump",
|
|
|
|
"dump LLDB internal performance timers", nullptr) {}
|
|
|
|
|
|
|
|
~CommandObjectLogTimerDump() override = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool DoExecute(Args &args, CommandReturnObject &result) override {
|
|
|
|
Timer::DumpCategoryTimes(&result.GetOutputStream());
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
|
|
|
|
if (!result.Succeeded()) {
|
|
|
|
result.AppendError("Missing subcommand");
|
|
|
|
result.AppendErrorWithFormat("Usage: %s\n", m_cmd_syntax.c_str());
|
|
|
|
}
|
|
|
|
return result.Succeeded();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class CommandObjectLogTimerReset : public CommandObjectParsed {
|
|
|
|
public:
|
|
|
|
// Constructors and Destructors
|
|
|
|
CommandObjectLogTimerReset(CommandInterpreter &interpreter)
|
|
|
|
: CommandObjectParsed(interpreter, "log timers reset",
|
|
|
|
"reset LLDB internal performance timers", nullptr) {
|
|
|
|
}
|
|
|
|
|
|
|
|
~CommandObjectLogTimerReset() override = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool DoExecute(Args &args, CommandReturnObject &result) override {
|
|
|
|
Timer::ResetCategoryTimes();
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
|
|
|
|
if (!result.Succeeded()) {
|
|
|
|
result.AppendError("Missing subcommand");
|
|
|
|
result.AppendErrorWithFormat("Usage: %s\n", m_cmd_syntax.c_str());
|
|
|
|
}
|
|
|
|
return result.Succeeded();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class CommandObjectLogTimerIncrement : public CommandObjectParsed {
|
|
|
|
public:
|
|
|
|
// Constructors and Destructors
|
|
|
|
CommandObjectLogTimerIncrement(CommandInterpreter &interpreter)
|
|
|
|
: CommandObjectParsed(interpreter, "log timers increment",
|
|
|
|
"increment LLDB internal performance timers",
|
|
|
|
"log timers increment <bool>") {
|
|
|
|
CommandArgumentEntry arg;
|
|
|
|
CommandArgumentData bool_arg;
|
|
|
|
|
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
bool_arg.arg_type = eArgTypeBoolean;
|
|
|
|
bool_arg.arg_repetition = eArgRepeatPlain;
|
|
|
|
|
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
// argument entry.
|
|
|
|
arg.push_back(bool_arg);
|
|
|
|
|
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
m_arguments.push_back(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
~CommandObjectLogTimerIncrement() override = default;
|
|
|
|
|
|
|
|
void
|
|
|
|
HandleArgumentCompletion(CompletionRequest &request,
|
|
|
|
OptionElementVector &opt_element_vector) override {
|
|
|
|
request.TryCompleteCurrentArg("true");
|
|
|
|
request.TryCompleteCurrentArg("false");
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
protected:
|
2015-10-08 00:56:17 +08:00
|
|
|
bool DoExecute(Args &args, CommandReturnObject &result) override {
|
2010-06-09 00:52:24 +08:00
|
|
|
result.SetStatus(eReturnStatusFailed);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-10-06 04:03:37 +08:00
|
|
|
if (args.GetArgumentCount() == 1) {
|
2020-04-09 14:11:55 +08:00
|
|
|
bool success;
|
|
|
|
bool increment =
|
|
|
|
OptionArgParser::ToBoolean(args[0].ref(), false, &success);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-04-09 14:11:55 +08:00
|
|
|
if (success) {
|
|
|
|
Timer::SetQuiet(!increment);
|
2010-06-09 00:52:24 +08:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
2020-04-09 14:11:55 +08:00
|
|
|
} else
|
|
|
|
result.AppendError("Could not convert increment value to boolean.");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (!result.Succeeded()) {
|
2010-11-05 07:08:26 +08:00
|
|
|
result.AppendError("Missing subcommand");
|
2010-06-09 00:52:24 +08:00
|
|
|
result.AppendErrorWithFormat("Usage: %s\n", m_cmd_syntax.c_str());
|
|
|
|
}
|
|
|
|
return result.Succeeded();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
};
|
|
|
|
|
2020-04-09 14:11:55 +08:00
|
|
|
class CommandObjectLogTimer : public CommandObjectMultiword {
|
|
|
|
public:
|
|
|
|
CommandObjectLogTimer(CommandInterpreter &interpreter)
|
|
|
|
: CommandObjectMultiword(interpreter, "log timers",
|
|
|
|
"Enable, disable, dump, and reset LLDB internal "
|
|
|
|
"performance timers.",
|
|
|
|
"log timers < enable <depth> | disable | dump | "
|
|
|
|
"increment <bool> | reset >") {
|
|
|
|
LoadSubCommand("enable", CommandObjectSP(
|
|
|
|
new CommandObjectLogTimerEnable(interpreter)));
|
|
|
|
LoadSubCommand("disable", CommandObjectSP(new CommandObjectLogTimerDisable(
|
|
|
|
interpreter)));
|
|
|
|
LoadSubCommand("dump",
|
|
|
|
CommandObjectSP(new CommandObjectLogTimerDump(interpreter)));
|
|
|
|
LoadSubCommand(
|
|
|
|
"reset", CommandObjectSP(new CommandObjectLogTimerReset(interpreter)));
|
|
|
|
LoadSubCommand(
|
|
|
|
"increment",
|
|
|
|
CommandObjectSP(new CommandObjectLogTimerIncrement(interpreter)));
|
|
|
|
}
|
|
|
|
|
|
|
|
~CommandObjectLogTimer() override = default;
|
|
|
|
};
|
|
|
|
|
2016-07-15 06:03:10 +08:00
|
|
|
CommandObjectLog::CommandObjectLog(CommandInterpreter &interpreter)
|
|
|
|
: CommandObjectMultiword(interpreter, "log",
|
|
|
|
"Commands controlling LLDB internal logging.",
|
|
|
|
"log <subcommand> [<command-options>]") {
|
2010-09-18 09:14:36 +08:00
|
|
|
LoadSubCommand("enable",
|
|
|
|
CommandObjectSP(new CommandObjectLogEnable(interpreter)));
|
|
|
|
LoadSubCommand("disable",
|
|
|
|
CommandObjectSP(new CommandObjectLogDisable(interpreter)));
|
|
|
|
LoadSubCommand("list",
|
|
|
|
CommandObjectSP(new CommandObjectLogList(interpreter)));
|
|
|
|
LoadSubCommand("timers",
|
|
|
|
CommandObjectSP(new CommandObjectLogTimer(interpreter)));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-02-20 08:58:29 +08:00
|
|
|
CommandObjectLog::~CommandObjectLog() = default;
|