[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
|
|
|
//===-- CommandObjectScript.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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CommandObjectScript.h"
|
2011-07-24 08:14:56 +08:00
|
|
|
#include "lldb/Core/Debugger.h"
|
2013-01-29 07:47:25 +08:00
|
|
|
#include "lldb/DataFormatters/DataVisualization.h"
|
2019-12-11 00:54:30 +08:00
|
|
|
#include "lldb/Host/Config.h"
|
2020-09-16 00:36:28 +08:00
|
|
|
#include "lldb/Host/OptionParser.h"
|
2013-01-29 07:47:25 +08:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
2020-09-16 00:36:28 +08:00
|
|
|
#include "lldb/Interpreter/OptionArgParser.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Interpreter/ScriptInterpreter.h"
|
2018-04-18 02:53:35 +08:00
|
|
|
#include "lldb/Utility/Args.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2020-09-16 00:36:28 +08:00
|
|
|
static constexpr OptionEnumValueElement g_script_option_enumeration[] = {
|
|
|
|
{
|
|
|
|
eScriptLanguagePython,
|
|
|
|
"python",
|
|
|
|
"Python",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
eScriptLanguageLua,
|
|
|
|
"lua",
|
|
|
|
"Lua",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
eScriptLanguageNone,
|
|
|
|
"default",
|
|
|
|
"The default scripting language.",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr OptionEnumValues ScriptOptionEnum() {
|
|
|
|
return OptionEnumValues(g_script_option_enumeration);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define LLDB_OPTIONS_script
|
|
|
|
#include "CommandOptions.inc"
|
|
|
|
|
|
|
|
Status CommandObjectScript::CommandOptions::SetOptionValue(
|
|
|
|
uint32_t option_idx, llvm::StringRef option_arg,
|
|
|
|
ExecutionContext *execution_context) {
|
|
|
|
Status error;
|
|
|
|
const int short_option = m_getopt_table[option_idx].val;
|
|
|
|
|
|
|
|
switch (short_option) {
|
|
|
|
case 'l':
|
|
|
|
language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum(
|
|
|
|
option_arg, GetDefinitions()[option_idx].enum_values,
|
|
|
|
eScriptLanguageNone, error);
|
|
|
|
if (!error.Success())
|
|
|
|
error.SetErrorStringWithFormat("unrecognized value for language '%s'",
|
|
|
|
option_arg.str().c_str());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unimplemented option");
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandObjectScript::CommandOptions::OptionParsingStarting(
|
|
|
|
ExecutionContext *execution_context) {
|
|
|
|
language = lldb::eScriptLanguageNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::ArrayRef<OptionDefinition>
|
|
|
|
CommandObjectScript::CommandOptions::GetDefinitions() {
|
|
|
|
return llvm::makeArrayRef(g_script_options);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2020-07-23 00:51:24 +08:00
|
|
|
CommandObjectScript::CommandObjectScript(CommandInterpreter &interpreter)
|
2016-07-15 06:03:10 +08:00
|
|
|
: CommandObjectRaw(
|
|
|
|
interpreter, "script",
|
|
|
|
"Invoke the script interpreter with provided code and display any "
|
|
|
|
"results. Start the interactive interpreter if no code is supplied.",
|
2020-09-16 00:36:28 +08:00
|
|
|
"script [--language <scripting-language> --] [<script-code>]") {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2021-07-03 02:27:37 +08:00
|
|
|
CommandObjectScript::~CommandObjectScript() = default;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2018-07-13 06:28:52 +08:00
|
|
|
bool CommandObjectScript::DoExecute(llvm::StringRef command,
|
2010-06-09 00:52:24 +08:00
|
|
|
CommandReturnObject &result) {
|
2020-09-16 00:36:28 +08:00
|
|
|
// Try parsing the language option but when the command contains a raw part
|
|
|
|
// separated by the -- delimiter.
|
|
|
|
OptionsWithRaw raw_args(command);
|
|
|
|
if (raw_args.HasArgs()) {
|
|
|
|
if (!ParseOptions(raw_args.GetArgs(), result))
|
|
|
|
return false;
|
|
|
|
command = raw_args.GetRawPart();
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::ScriptLanguage language =
|
|
|
|
(m_options.language == lldb::eScriptLanguageNone)
|
|
|
|
? m_interpreter.GetDebugger().GetScriptLanguage()
|
|
|
|
: m_options.language;
|
|
|
|
|
|
|
|
if (language == lldb::eScriptLanguageNone) {
|
2013-02-20 06:34:01 +08:00
|
|
|
result.AppendError(
|
|
|
|
"the script-lang setting is set to none - scripting not available");
|
2012-10-13 01:34:26 +08:00
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-09-16 00:36:28 +08:00
|
|
|
ScriptInterpreter *script_interpreter =
|
|
|
|
GetDebugger().GetScriptInterpreter(true, language);
|
2010-07-31 06:33:14 +08:00
|
|
|
|
2014-04-20 08:31:37 +08:00
|
|
|
if (script_interpreter == nullptr) {
|
2011-01-09 04:28:42 +08:00
|
|
|
result.AppendError("no script interpreter");
|
2013-02-20 06:34:01 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2019-12-19 08:42:07 +08:00
|
|
|
// Script might change Python code we use for formatting. Make sure we keep
|
|
|
|
// up to date with it.
|
|
|
|
DataVisualization::ForceUpdate();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-07-13 06:28:52 +08:00
|
|
|
if (command.empty()) {
|
2011-01-14 08:29:16 +08:00
|
|
|
script_interpreter->ExecuteInterpreterLoop();
|
2010-07-31 06:33:14 +08:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
2010-06-09 00:52:24 +08:00
|
|
|
return result.Succeeded();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-07-31 06:33:14 +08:00
|
|
|
// We can do better when reporting the status of one-liner script execution.
|
2012-10-31 08:01:26 +08:00
|
|
|
if (script_interpreter->ExecuteOneLine(command, &result))
|
2010-07-31 06:33:14 +08:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2010-07-31 06:33:14 +08:00
|
|
|
result.SetStatus(eReturnStatusFailed);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return result.Succeeded();
|
|
|
|
}
|