[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 08:23:27 +01:00
|
|
|
//===-- CommandObjectCommands.cpp -----------------------------------------===//
|
2010-07-07 03:36:20 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00: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-07-07 03:36:20 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2016-02-22 23:46:47 +00:00
|
|
|
#include "CommandObjectCommands.h"
|
2016-02-29 23:22:53 +00:00
|
|
|
#include "CommandObjectHelp.h"
|
2020-09-01 17:28:29 -07:00
|
|
|
#include "CommandObjectRegexCommand.h"
|
2010-07-07 03:36:20 +00:00
|
|
|
#include "lldb/Core/Debugger.h"
|
2014-01-27 23:43:24 +00:00
|
|
|
#include "lldb/Core/IOHandler.h"
|
2013-06-17 22:51:50 +00:00
|
|
|
#include "lldb/Interpreter/CommandHistory.h"
|
2010-07-07 03:36:20 +00:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
2022-07-13 20:11:37 -07:00
|
|
|
#include "lldb/Interpreter/CommandOptionArgumentTable.h"
|
2010-07-07 03:36:20 +00:00
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
2018-04-10 09:03:59 +00:00
|
|
|
#include "lldb/Interpreter/OptionArgParser.h"
|
2013-06-11 01:26:35 +00:00
|
|
|
#include "lldb/Interpreter/OptionValueBoolean.h"
|
2016-03-31 01:10:54 +00:00
|
|
|
#include "lldb/Interpreter/OptionValueString.h"
|
2013-06-17 22:51:50 +00:00
|
|
|
#include "lldb/Interpreter/OptionValueUInt64.h"
|
2010-07-07 03:36:20 +00:00
|
|
|
#include "lldb/Interpreter/Options.h"
|
2011-08-17 01:30:04 +00:00
|
|
|
#include "lldb/Interpreter/ScriptInterpreter.h"
|
2018-04-17 18:53:35 +00:00
|
|
|
#include "lldb/Utility/Args.h"
|
2017-03-21 18:25:04 +00:00
|
|
|
#include "lldb/Utility/StringList.h"
|
2020-09-01 17:28:29 -07:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2023-01-07 13:43:00 -08:00
|
|
|
#include <optional>
|
2010-07-07 03:36:20 +00:00
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
2011-07-12 03:12:18 +00:00
|
|
|
// CommandObjectCommandsSource
|
|
|
|
|
|
2019-07-18 14:10:49 +00:00
|
|
|
#define LLDB_OPTIONS_source
|
|
|
|
|
#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-22 20:22:55 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
class CommandObjectCommandsSource : public CommandObjectParsed {
|
|
|
|
|
public:
|
2016-07-14 22:03:10 +00:00
|
|
|
CommandObjectCommandsSource(CommandInterpreter &interpreter)
|
|
|
|
|
: CommandObjectParsed(
|
|
|
|
|
interpreter, "command source",
|
|
|
|
|
"Read and execute LLDB commands from the file <filename>.",
|
2022-01-23 11:07:14 -08:00
|
|
|
nullptr) {
|
2012-06-08 21:56:10 +00:00
|
|
|
CommandArgumentEntry arg;
|
|
|
|
|
CommandArgumentData file_arg;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
|
file_arg.arg_type = eArgTypeFilename;
|
|
|
|
|
file_arg.arg_repetition = eArgRepeatPlain;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
|
// argument entry.
|
|
|
|
|
arg.push_back(file_arg);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
|
m_arguments.push_back(arg);
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-02-22 23:46:47 +00:00
|
|
|
~CommandObjectCommandsSource() override = default;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2023-01-07 14:18:35 -08:00
|
|
|
std::optional<std::string> GetRepeatCommand(Args ¤t_command_args,
|
|
|
|
|
uint32_t index) override {
|
2022-02-04 15:16:31 -08:00
|
|
|
return std::string("");
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
[lldb][NFC] Remove WordComplete mode, make result array indexed from 0 and remove any undocumented/redundant return values
Summary:
We still have some leftovers of the old completion API in the internals of
LLDB that haven't been replaced by the new CompletionRequest. These leftovers
are:
* The return values (int/size_t) in all completion functions.
* Our result array that starts indexing at 1.
* `WordComplete` mode.
I didn't replace them back then because it's tricky to figure out what exactly they
are used for and the completion code is relatively untested. I finally got around
to writing more tests for the API and understanding the semantics, so I think it's
a good time to get rid of them.
A few words why those things should be removed/replaced:
* The return values are really cryptic, partly redundant and rarely documented.
They are also completely ignored by Xcode, so whatever information they contain will end up
breaking Xcode's completion mechanism. They are also partly impossible to even implement
as we assign negative values special meaning and our completion API sometimes returns size_t.
Completion functions are supposed to return -2 to rewrite the current line. We seem to use this
in some untested code path to expand the history repeat character to the full command, but
I haven't figured out why that doesn't work at the moment.
Completion functions return -1 to 'insert the completion character', but that isn't implemented
(even though we seem to activate this feature in LLDB sometimes).
All positive values have to match the number of results. This is obviously just redundant information
as the user can just look at the result list to get that information (which is what Xcode does).
* The result array that starts indexing at 1 is obviously unexpected. The first element of the array is
reserved for the common prefix of all completions (e.g. "foobar" and "footar" -> "foo"). The idea is
that we calculate this to make the life of the API caller easier, but obviously forcing people to have
1-based indices is not helpful (or even worse, forces them to manually copy the results to make it
0-based like Xcode has to do).
* The `WordComplete` mode indicates that LLDB should enter a space behind the completion. The
idea is that we let the top-level API know that we just provided a full completion. Interestingly we
`WordComplete` is just a single bool that somehow represents all N completions. And we always
provide full completions in LLDB, so in theory it should always be true.
The only use it currently serves is providing redundant information about whether we have a single
definitive completion or not (which we already know from the number of results we get).
This patch essentially removes `WordComplete` mode and makes the result array indexed from 0.
It also removes all return values from all internal completion functions. The only non-redundant information
they contain is about rewriting the current line (which is broken), so that functionality was moved
to the CompletionRequest API. So you can now do `addCompletion("blub", "description", CompletionMode::RewriteLine)`
to do the same.
For the SB API we emulate the old behaviour by making the array indexed from 1 again with the common
prefix at index 0. I didn't keep the special negative return codes as we either never sent them before (e.g. -2) or we
didn't even implement them in the Editline handler (e.g. -1).
I tried to keep this patch minimal and I'm aware we can probably now even further simplify a bunch of related code,
but I would prefer doing this in follow-up NFC commits
Reviewers: JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arphaman, abidh, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D66536
llvm-svn: 369624
2019-08-22 07:41:23 +00:00
|
|
|
void
|
|
|
|
|
HandleArgumentCompletion(CompletionRequest &request,
|
|
|
|
|
OptionElementVector &opt_element_vector) override {
|
2016-08-11 23:51:28 +00:00
|
|
|
CommandCompletions::InvokeCommonCompletionCallbacks(
|
|
|
|
|
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
|
2018-07-13 18:28:14 +00:00
|
|
|
request, nullptr);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-27 16:22:29 +00:00
|
|
|
Options *GetOptions() override { return &m_options; }
|
2012-06-08 21:56:10 +00:00
|
|
|
|
|
|
|
|
protected:
|
2015-10-07 16:56:17 +00:00
|
|
|
class CommandOptions : public Options {
|
2016-09-06 20:57:50 +00:00
|
|
|
public:
|
2015-10-07 16:56:17 +00:00
|
|
|
CommandOptions()
|
2022-01-23 11:07:14 -08:00
|
|
|
: m_stop_on_error(true), m_silent_run(false), m_stop_on_continue(true),
|
|
|
|
|
m_cmd_relative_to_command_file(false) {}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-10-07 16:56:17 +00:00
|
|
|
~CommandOptions() override = default;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
|
|
|
|
|
ExecutionContext *execution_context) override {
|
|
|
|
|
Status error;
|
2012-06-08 21:56:10 +00:00
|
|
|
const int short_option = m_getopt_table[option_idx].val;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
switch (short_option) {
|
2015-10-07 16:56:17 +00:00
|
|
|
case 'e':
|
2016-11-12 16:56:47 +00:00
|
|
|
error = m_stop_on_error.SetValueFromString(option_arg);
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
case 'c':
|
2016-11-12 16:56:47 +00:00
|
|
|
error = m_stop_on_continue.SetValueFromString(option_arg);
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
|
2021-09-27 17:51:37 -07:00
|
|
|
case 'C':
|
|
|
|
|
m_cmd_relative_to_command_file = true;
|
|
|
|
|
break;
|
|
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
case 's':
|
2016-11-12 16:56:47 +00:00
|
|
|
error = m_silent_run.SetValueFromString(option_arg);
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2019-08-22 08:08:05 +00:00
|
|
|
llvm_unreachable("Unimplemented option");
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-07 16:56:17 +00:00
|
|
|
void OptionParsingStarting(ExecutionContext *execution_context) override {
|
|
|
|
|
m_stop_on_error.Clear();
|
2014-02-05 17:57:57 +00:00
|
|
|
m_silent_run.Clear();
|
2012-06-08 21:56:10 +00:00
|
|
|
m_stop_on_continue.Clear();
|
2021-09-27 17:51:37 -07:00
|
|
|
m_cmd_relative_to_command_file.Clear();
|
2012-06-08 21:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
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-22 20:22:55 +00:00
|
|
|
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
|
2023-01-09 18:11:07 +01:00
|
|
|
return llvm::ArrayRef(g_source_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-22 20:22:55 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-12-04 00:32:51 +00:00
|
|
|
// Instance variables to hold the values for command options.
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-02-20 11:14:59 +00:00
|
|
|
OptionValueBoolean m_stop_on_error;
|
2011-02-18 00:54:25 +00:00
|
|
|
OptionValueBoolean m_silent_run;
|
2015-02-20 11:14:59 +00:00
|
|
|
OptionValueBoolean m_stop_on_continue;
|
2021-09-27 17:51:37 -07:00
|
|
|
OptionValueBoolean m_cmd_relative_to_command_file;
|
2016-09-06 20:57:50 +00:00
|
|
|
};
|
|
|
|
|
|
2015-02-20 11:14:59 +00:00
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
2016-12-08 01:31:04 +00:00
|
|
|
if (command.GetArgumentCount() != 1) {
|
2010-07-07 03:36:20 +00:00
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
|
"'%s' takes exactly one executable filename argument.\n",
|
2016-10-05 21:14:38 +00:00
|
|
|
GetCommandName().str().c_str());
|
2016-12-08 01:31:04 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-27 17:51:37 -07:00
|
|
|
FileSpec source_dir = {};
|
|
|
|
|
if (m_options.m_cmd_relative_to_command_file) {
|
|
|
|
|
source_dir = GetDebugger().GetCommandInterpreter().GetCurrentSourceDir();
|
|
|
|
|
if (!source_dir) {
|
|
|
|
|
result.AppendError("command source -C can only be specified "
|
|
|
|
|
"from a command file");
|
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-13 11:26:48 +00:00
|
|
|
FileSpec cmd_file(command[0].ref());
|
2021-09-27 17:51:37 -07:00
|
|
|
if (source_dir) {
|
|
|
|
|
// Prepend the source_dir to the cmd_file path:
|
|
|
|
|
if (!cmd_file.IsRelative()) {
|
|
|
|
|
result.AppendError("command source -C can only be used "
|
|
|
|
|
"with a relative path.");
|
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
cmd_file.MakeAbsolute(source_dir);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-01 21:05:36 +00:00
|
|
|
FileSystem::Instance().Resolve(cmd_file);
|
2016-12-08 01:31:04 +00:00
|
|
|
|
2020-12-18 16:36:15 +03:00
|
|
|
CommandInterpreterRunOptions options;
|
2016-12-08 01:31:04 +00:00
|
|
|
// If any options were set, then use them
|
|
|
|
|
if (m_options.m_stop_on_error.OptionWasSet() ||
|
|
|
|
|
m_options.m_silent_run.OptionWasSet() ||
|
|
|
|
|
m_options.m_stop_on_continue.OptionWasSet()) {
|
2019-05-02 01:54:02 +00:00
|
|
|
if (m_options.m_stop_on_continue.OptionWasSet())
|
|
|
|
|
options.SetStopOnContinue(
|
|
|
|
|
m_options.m_stop_on_continue.GetCurrentValue());
|
|
|
|
|
|
|
|
|
|
if (m_options.m_stop_on_error.OptionWasSet())
|
|
|
|
|
options.SetStopOnError(m_options.m_stop_on_error.GetCurrentValue());
|
2018-10-05 16:49:47 +00:00
|
|
|
|
|
|
|
|
// Individual silent setting is override for global command echo settings.
|
|
|
|
|
if (m_options.m_silent_run.GetCurrentValue()) {
|
|
|
|
|
options.SetSilent(true);
|
|
|
|
|
} else {
|
|
|
|
|
options.SetPrintResults(true);
|
2019-05-08 01:23:47 +00:00
|
|
|
options.SetPrintErrors(true);
|
2018-10-05 16:49:47 +00:00
|
|
|
options.SetEchoCommands(m_interpreter.GetEchoCommands());
|
|
|
|
|
options.SetEchoCommentCommands(m_interpreter.GetEchoCommentCommands());
|
|
|
|
|
}
|
2020-12-17 17:10:17 +01:00
|
|
|
}
|
2020-12-18 16:36:15 +03:00
|
|
|
|
|
|
|
|
m_interpreter.HandleCommandsFromFile(cmd_file, options, result);
|
2010-07-07 03:36:20 +00:00
|
|
|
return result.Succeeded();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-02-22 23:46:47 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
CommandOptions m_options;
|
2010-07-07 03:36:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#pragma mark CommandObjectCommandsAlias
|
|
|
|
|
// CommandObjectCommandsAlias
|
|
|
|
|
|
2019-07-18 14:10:49 +00:00
|
|
|
#define LLDB_OPTIONS_alias
|
|
|
|
|
#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-22 20:22:55 +00:00
|
|
|
|
2011-08-16 16:49:25 +00:00
|
|
|
static const char *g_python_command_instructions =
|
|
|
|
|
"Enter your Python command(s). Type 'DONE' to end.\n"
|
|
|
|
|
"You must define a Python function with this signature:\n"
|
2022-12-08 17:23:04 -08:00
|
|
|
"def my_command_impl(debugger, args, exe_ctx, result, internal_dict):\n";
|
2011-08-16 16:49:25 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
class CommandObjectCommandsAlias : public CommandObjectRaw {
|
2016-03-31 01:10:54 +00:00
|
|
|
protected:
|
|
|
|
|
class CommandOptions : public OptionGroup {
|
|
|
|
|
public:
|
2022-03-31 13:20:46 -07:00
|
|
|
CommandOptions() = default;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-03-31 01:10:54 +00:00
|
|
|
~CommandOptions() override = default;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
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-22 20:22:55 +00:00
|
|
|
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
|
2023-01-09 18:11:07 +01:00
|
|
|
return llvm::ArrayRef(g_alias_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-22 20:22:55 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
|
|
|
|
|
ExecutionContext *execution_context) override {
|
|
|
|
|
Status error;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
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-22 20:22:55 +00:00
|
|
|
const int short_option = GetDefinitions()[option_idx].short_option;
|
2016-09-23 17:48:13 +00:00
|
|
|
std::string option_str(option_value);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-03-31 01:10:54 +00:00
|
|
|
switch (short_option) {
|
|
|
|
|
case 'h':
|
2016-09-23 17:48:13 +00:00
|
|
|
m_help.SetCurrentValue(option_str);
|
2016-03-31 01:10:54 +00:00
|
|
|
m_help.SetOptionWasSet();
|
|
|
|
|
break;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-03-31 01:10:54 +00:00
|
|
|
case 'H':
|
2016-09-23 17:48:13 +00:00
|
|
|
m_long_help.SetCurrentValue(option_str);
|
2016-03-31 01:10:54 +00:00
|
|
|
m_long_help.SetOptionWasSet();
|
|
|
|
|
break;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-08-11 23:51:28 +00:00
|
|
|
default:
|
2019-08-22 08:08:05 +00:00
|
|
|
llvm_unreachable("Unimplemented option");
|
2016-03-31 01:10:54 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-03-31 01:10:54 +00:00
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-14 22:03:10 +00:00
|
|
|
void OptionParsingStarting(ExecutionContext *execution_context) override {
|
2016-03-31 01:10:54 +00:00
|
|
|
m_help.Clear();
|
|
|
|
|
m_long_help.Clear();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-31 01:10:54 +00:00
|
|
|
OptionValueString m_help;
|
|
|
|
|
OptionValueString m_long_help;
|
2016-09-06 20:57:50 +00:00
|
|
|
};
|
2016-03-31 01:10:54 +00:00
|
|
|
|
|
|
|
|
OptionGroupOptions m_option_group;
|
|
|
|
|
CommandOptions m_command_options;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
|
|
|
|
public:
|
2014-10-11 00:38:27 +00:00
|
|
|
Options *GetOptions() override { return &m_option_group; }
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-07-14 22:03:10 +00:00
|
|
|
CommandObjectCommandsAlias(CommandInterpreter &interpreter)
|
2012-06-08 21:56:10 +00:00
|
|
|
: CommandObjectRaw(
|
2016-07-14 22:03:10 +00:00
|
|
|
interpreter, "command alias",
|
2022-01-23 11:07:14 -08:00
|
|
|
"Define a custom command in terms of an existing command.") {
|
2016-03-31 01:10:54 +00:00
|
|
|
m_option_group.Append(&m_command_options);
|
2016-08-11 23:51:28 +00:00
|
|
|
m_option_group.Finalize();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-07-07 03:36:20 +00:00
|
|
|
SetHelpLong(
|
2015-07-14 05:48:36 +00:00
|
|
|
"'alias' allows the user to create a short-cut or abbreviation for long \
|
|
|
|
|
commands, multi-word commands, and commands that take particular options. \
|
|
|
|
|
Below are some simple examples of how one might use the 'alias' command:"
|
|
|
|
|
R"(
|
|
|
|
|
|
|
|
|
|
(lldb) command alias sc script
|
|
|
|
|
|
|
|
|
|
Creates the abbreviation 'sc' for the 'script' command.
|
|
|
|
|
|
|
|
|
|
(lldb) command alias bp breakpoint
|
|
|
|
|
|
|
|
|
|
)"
|
|
|
|
|
" Creates the abbreviation 'bp' for the 'breakpoint' command. Since \
|
|
|
|
|
breakpoint commands are two-word commands, the user would still need to \
|
|
|
|
|
enter the second word after 'bp', e.g. 'bp enable' or 'bp delete'."
|
|
|
|
|
R"(
|
|
|
|
|
|
|
|
|
|
(lldb) command alias bpl breakpoint list
|
|
|
|
|
|
|
|
|
|
Creates the abbreviation 'bpl' for the two-word command 'breakpoint list'.
|
|
|
|
|
|
|
|
|
|
)"
|
|
|
|
|
"An alias can include some options for the command, with the values either \
|
|
|
|
|
filled in at the time the alias is created, or specified as positional \
|
|
|
|
|
arguments, to be filled in when the alias is invoked. The following example \
|
|
|
|
|
shows how to create aliases with options:"
|
|
|
|
|
R"(
|
|
|
|
|
|
|
|
|
|
(lldb) command alias bfl breakpoint set -f %1 -l %2
|
|
|
|
|
|
|
|
|
|
)"
|
|
|
|
|
" Creates the abbreviation 'bfl' (for break-file-line), with the -f and -l \
|
|
|
|
|
options already part of the alias. So if the user wants to set a breakpoint \
|
|
|
|
|
by file and line without explicitly having to use the -f and -l options, the \
|
|
|
|
|
user can now use 'bfl' instead. The '%1' and '%2' are positional placeholders \
|
|
|
|
|
for the actual arguments that will be passed when the alias command is used. \
|
|
|
|
|
The number in the placeholder refers to the position/order the actual value \
|
|
|
|
|
occupies when the alias is used. All the occurrences of '%1' in the alias \
|
|
|
|
|
will be replaced with the first argument, all the occurrences of '%2' in the \
|
|
|
|
|
alias will be replaced with the second argument, and so on. This also allows \
|
|
|
|
|
actual arguments to be used multiple times within an alias (see 'process \
|
|
|
|
|
launch' example below)."
|
|
|
|
|
R"(
|
|
|
|
|
|
|
|
|
|
)"
|
|
|
|
|
"Note: the positional arguments must substitute as whole words in the resultant \
|
|
|
|
|
command, so you can't at present do something like this to append the file extension \
|
|
|
|
|
\".cpp\":"
|
|
|
|
|
R"(
|
|
|
|
|
|
|
|
|
|
(lldb) command alias bcppfl breakpoint set -f %1.cpp -l %2
|
|
|
|
|
|
|
|
|
|
)"
|
|
|
|
|
"For more complex aliasing, use the \"command regex\" command instead. In the \
|
|
|
|
|
'bfl' case above, the actual file value will be filled in with the first argument \
|
|
|
|
|
following 'bfl' and the actual line number value will be filled in with the second \
|
|
|
|
|
argument. The user would use this alias as follows:"
|
|
|
|
|
R"(
|
|
|
|
|
|
|
|
|
|
(lldb) command alias bfl breakpoint set -f %1 -l %2
|
|
|
|
|
(lldb) bfl my-file.c 137
|
|
|
|
|
|
|
|
|
|
This would be the same as if the user had entered 'breakpoint set -f my-file.c -l 137'.
|
|
|
|
|
|
|
|
|
|
Another example:
|
|
|
|
|
|
|
|
|
|
(lldb) command alias pltty process launch -s -o %1 -e %1
|
|
|
|
|
(lldb) pltty /dev/tty0
|
|
|
|
|
|
|
|
|
|
Interpreted as 'process launch -s -o /dev/tty0 -e /dev/tty0'
|
|
|
|
|
|
|
|
|
|
)"
|
|
|
|
|
"If the user always wanted to pass the same value to a particular option, the \
|
|
|
|
|
alias could be defined with that value directly in the alias as a constant, \
|
|
|
|
|
rather than using a positional placeholder:"
|
|
|
|
|
R"(
|
|
|
|
|
|
|
|
|
|
(lldb) command alias bl3 breakpoint set -f %1 -l 3
|
|
|
|
|
|
|
|
|
|
Always sets a breakpoint on line 3 of whatever file is indicated.)");
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-10-04 22:28:36 +00:00
|
|
|
CommandArgumentEntry arg1;
|
|
|
|
|
CommandArgumentEntry arg2;
|
|
|
|
|
CommandArgumentEntry arg3;
|
|
|
|
|
CommandArgumentData alias_arg;
|
|
|
|
|
CommandArgumentData cmd_arg;
|
|
|
|
|
CommandArgumentData options_arg;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-10-04 22:28:36 +00:00
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
|
alias_arg.arg_type = eArgTypeAliasName;
|
|
|
|
|
alias_arg.arg_repetition = eArgRepeatPlain;
|
2010-07-07 03:36:20 +00:00
|
|
|
|
2010-10-04 22:28:36 +00:00
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
|
// argument entry.
|
|
|
|
|
arg1.push_back(alias_arg);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-10-04 22:28:36 +00:00
|
|
|
// Define the first (and only) variant of this arg.
|
2012-06-08 21:56:10 +00:00
|
|
|
cmd_arg.arg_type = eArgTypeCommandName;
|
2010-10-04 22:28:36 +00:00
|
|
|
cmd_arg.arg_repetition = eArgRepeatPlain;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-10-04 22:28:36 +00:00
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
|
// argument entry.
|
|
|
|
|
arg2.push_back(cmd_arg);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-10-04 22:28:36 +00:00
|
|
|
// Define the first (and only) variant of this arg.
|
2016-08-26 23:28:47 +00:00
|
|
|
options_arg.arg_type = eArgTypeAliasOptions;
|
2010-10-04 22:28:36 +00:00
|
|
|
options_arg.arg_repetition = eArgRepeatOptional;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-10-04 22:28:36 +00:00
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
|
// argument entry.
|
|
|
|
|
arg3.push_back(options_arg);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-10-04 22:28:36 +00:00
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
|
m_arguments.push_back(arg1);
|
|
|
|
|
m_arguments.push_back(arg2);
|
|
|
|
|
m_arguments.push_back(arg3);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:46:47 +00:00
|
|
|
~CommandObjectCommandsAlias() override = default;
|
2010-07-07 03:36:20 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
protected:
|
2018-07-12 22:28:52 +00:00
|
|
|
bool DoExecute(llvm::StringRef raw_command_line,
|
2015-10-07 16:56:17 +00:00
|
|
|
CommandReturnObject &result) override {
|
2018-07-12 22:28:52 +00:00
|
|
|
if (raw_command_line.empty()) {
|
2016-04-08 17:56:57 +00:00
|
|
|
result.AppendError("'command alias' requires at least two arguments");
|
2016-03-31 01:10:54 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2016-08-11 23:51:28 +00:00
|
|
|
|
|
|
|
|
ExecutionContext exe_ctx = GetCommandInterpreter().GetExecutionContext();
|
|
|
|
|
m_option_group.NotifyOptionParsingStarting(&exe_ctx);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-07-10 20:17:38 +00:00
|
|
|
OptionsWithRaw args_with_suffix(raw_command_line);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-07-10 20:17:38 +00:00
|
|
|
if (args_with_suffix.HasArgs())
|
|
|
|
|
if (!ParseOptionsAndNotify(args_with_suffix.GetArgs(), result,
|
|
|
|
|
m_option_group, exe_ctx))
|
|
|
|
|
return false;
|
2012-06-08 21:56:10 +00:00
|
|
|
|
2020-03-26 11:15:07 +01:00
|
|
|
llvm::StringRef raw_command_string = args_with_suffix.GetRawPart();
|
2016-10-05 21:14:56 +00:00
|
|
|
Args args(raw_command_string);
|
2016-03-08 05:37:15 +00:00
|
|
|
|
2016-10-05 20:03:37 +00:00
|
|
|
if (args.GetArgumentCount() < 2) {
|
2012-06-08 21:56:10 +00:00
|
|
|
result.AppendError("'command alias' requires at least two arguments");
|
|
|
|
|
return false;
|
2010-12-09 22:52:49 +00:00
|
|
|
}
|
2010-07-07 03:36:20 +00:00
|
|
|
|
2010-12-09 22:52:49 +00:00
|
|
|
// Get the alias command.
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-09-13 11:26:48 +00:00
|
|
|
auto alias_command = args[0].ref();
|
2016-12-08 01:31:04 +00:00
|
|
|
if (alias_command.startswith("-")) {
|
2016-04-08 17:56:57 +00:00
|
|
|
result.AppendError("aliases starting with a dash are not supported");
|
2010-07-09 20:39:50 +00:00
|
|
|
if (alias_command == "--help" || alias_command == "--long-help") {
|
2016-04-08 17:56:57 +00:00
|
|
|
result.AppendWarning("if trying to pass options to 'command alias' add "
|
|
|
|
|
"a -- at the end of the options");
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-03-31 01:10:54 +00:00
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-08 17:56:57 +00:00
|
|
|
// Strip the new alias name off 'raw_command_string' (leave it on args,
|
2018-04-30 16:49:04 +00:00
|
|
|
// which gets passed to 'Execute', which does the stripping itself.
|
2010-12-09 22:52:49 +00:00
|
|
|
size_t pos = raw_command_string.find(alias_command);
|
|
|
|
|
if (pos == 0) {
|
|
|
|
|
raw_command_string = raw_command_string.substr(alias_command.size());
|
2016-04-08 17:56:57 +00:00
|
|
|
pos = raw_command_string.find_first_not_of(' ');
|
2010-12-09 22:52:49 +00:00
|
|
|
if ((pos != std::string::npos) && (pos > 0))
|
|
|
|
|
raw_command_string = raw_command_string.substr(pos);
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2016-04-08 17:56:57 +00:00
|
|
|
result.AppendError("Error parsing command string. No alias created.");
|
2010-07-07 03:36:20 +00:00
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2010-12-09 22:52:49 +00:00
|
|
|
// Verify that the command is alias-able.
|
2016-11-02 20:34:10 +00:00
|
|
|
if (m_interpreter.CommandExists(alias_command)) {
|
2016-07-14 22:03:10 +00:00
|
|
|
result.AppendErrorWithFormat(
|
2010-12-09 22:52:49 +00:00
|
|
|
"'%s' is a permanent debugger command and cannot be redefined.\n",
|
2016-12-08 01:31:04 +00:00
|
|
|
args[0].c_str());
|
2016-03-31 01:10:54 +00:00
|
|
|
return false;
|
2010-07-09 20:39:50 +00:00
|
|
|
}
|
2010-07-07 03:36:20 +00:00
|
|
|
|
2021-10-12 10:55:24 -07:00
|
|
|
if (m_interpreter.UserMultiwordCommandExists(alias_command)) {
|
|
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
|
"'%s' is a user container command and cannot be overwritten.\n"
|
|
|
|
|
"Delete it first with 'command container delete'\n",
|
|
|
|
|
args[0].c_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-07 03:36:20 +00:00
|
|
|
// Get CommandObject that is being aliased. The command name is read from
|
2016-10-05 21:14:56 +00:00
|
|
|
// the front of raw_command_string. raw_command_string is returned with the
|
|
|
|
|
// name of the command object stripped off the front.
|
|
|
|
|
llvm::StringRef original_raw_command_string = raw_command_string;
|
2010-07-07 03:36:20 +00:00
|
|
|
CommandObject *cmd_obj =
|
|
|
|
|
m_interpreter.GetCommandObjectForCommand(raw_command_string);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-12-09 22:52:49 +00:00
|
|
|
if (!cmd_obj) {
|
2010-07-07 03:36:20 +00:00
|
|
|
result.AppendErrorWithFormat("invalid command given to 'command alias'. "
|
2016-04-08 17:56:57 +00:00
|
|
|
"'%s' does not begin with a valid command."
|
|
|
|
|
" No alias created.",
|
2016-10-05 21:14:56 +00:00
|
|
|
original_raw_command_string.str().c_str());
|
2016-03-31 01:10:54 +00:00
|
|
|
return false;
|
2010-12-09 22:52:49 +00:00
|
|
|
} else if (!cmd_obj->WantsRawCommandString()) {
|
2010-07-07 03:36:20 +00:00
|
|
|
// Note that args was initialized with the original command, and has not
|
2018-04-30 16:49:04 +00:00
|
|
|
// been updated to this point. Therefore can we pass it to the version of
|
|
|
|
|
// Execute that does not need/expect raw input in the alias.
|
2010-07-07 03:36:20 +00:00
|
|
|
return HandleAliasingNormalCommand(args, result);
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2012-06-08 21:56:10 +00:00
|
|
|
return HandleAliasingRawCommand(alias_command, raw_command_string,
|
|
|
|
|
*cmd_obj, result);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-06-08 21:56:10 +00:00
|
|
|
return result.Succeeded();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-10-05 21:14:56 +00:00
|
|
|
bool HandleAliasingRawCommand(llvm::StringRef alias_command,
|
|
|
|
|
llvm::StringRef raw_command_string,
|
2012-06-08 21:56:10 +00:00
|
|
|
CommandObject &cmd_obj,
|
2010-07-07 03:36:20 +00:00
|
|
|
CommandReturnObject &result) {
|
|
|
|
|
// Verify & handle any options/arguments passed to the alias command
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-07-07 03:36:20 +00:00
|
|
|
OptionArgVectorSP option_arg_vector_sp =
|
2010-12-09 22:52:49 +00:00
|
|
|
OptionArgVectorSP(new OptionArgVector);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2022-01-13 16:02:45 -08:00
|
|
|
const bool include_aliases = true;
|
2022-11-09 10:11:16 -08:00
|
|
|
// Look up the command using command's name first. This is to resolve
|
|
|
|
|
// aliases when you are making nested aliases. But if you don't find
|
|
|
|
|
// it that way, then it wasn't an alias and we can just use the object
|
|
|
|
|
// we were passed in.
|
|
|
|
|
CommandObjectSP cmd_obj_sp = m_interpreter.GetCommandSPExact(
|
|
|
|
|
cmd_obj.GetCommandName(), include_aliases);
|
|
|
|
|
if (!cmd_obj_sp)
|
|
|
|
|
cmd_obj_sp = cmd_obj.shared_from_this();
|
|
|
|
|
|
|
|
|
|
if (m_interpreter.AliasExists(alias_command) ||
|
|
|
|
|
m_interpreter.UserCommandExists(alias_command)) {
|
|
|
|
|
result.AppendWarningWithFormat(
|
|
|
|
|
"Overwriting existing definition for '%s'.\n",
|
|
|
|
|
alias_command.str().c_str());
|
|
|
|
|
}
|
|
|
|
|
if (CommandAlias *alias = m_interpreter.AddAlias(
|
|
|
|
|
alias_command, cmd_obj_sp, raw_command_string)) {
|
|
|
|
|
if (m_command_options.m_help.OptionWasSet())
|
|
|
|
|
alias->SetHelp(m_command_options.m_help.GetCurrentValue());
|
|
|
|
|
if (m_command_options.m_long_help.OptionWasSet())
|
|
|
|
|
alias->SetHelpLong(m_command_options.m_long_help.GetCurrentValue());
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2016-03-08 05:37:15 +00:00
|
|
|
result.AppendError("Unable to create requested alias.\n");
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-07-07 03:36:20 +00:00
|
|
|
return result.Succeeded();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-07-07 03:36:20 +00:00
|
|
|
|
|
|
|
|
bool HandleAliasingNormalCommand(Args &args, CommandReturnObject &result) {
|
|
|
|
|
size_t argc = args.GetArgumentCount();
|
|
|
|
|
|
2010-09-18 01:14:36 +00:00
|
|
|
if (argc < 2) {
|
2010-11-02 19:00:04 +00:00
|
|
|
result.AppendError("'command alias' requires at least two arguments");
|
2011-05-06 21:37:15 +00:00
|
|
|
return false;
|
2016-03-08 05:37:15 +00:00
|
|
|
}
|
2010-07-07 03:36:20 +00:00
|
|
|
|
2016-12-08 01:31:04 +00:00
|
|
|
// Save these in std::strings since we're going to shift them off.
|
2020-01-28 20:23:46 +01:00
|
|
|
const std::string alias_command(std::string(args[0].ref()));
|
|
|
|
|
const std::string actual_command(std::string(args[1].ref()));
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-07-07 03:36:20 +00:00
|
|
|
args.Shift(); // Shift the alias command word off the argument vector.
|
|
|
|
|
args.Shift(); // Shift the old command word off the argument vector.
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-12-09 22:52:49 +00:00
|
|
|
// Verify that the command is alias'able, and get the appropriate command
|
|
|
|
|
// object.
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-11-02 20:34:10 +00:00
|
|
|
if (m_interpreter.CommandExists(alias_command)) {
|
2016-07-14 22:03:10 +00:00
|
|
|
result.AppendErrorWithFormat(
|
2010-07-07 03:36:20 +00:00
|
|
|
"'%s' is a permanent debugger command and cannot be redefined.\n",
|
2010-12-09 22:52:49 +00:00
|
|
|
alias_command.c_str());
|
2016-12-08 01:31:04 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-12 10:55:24 -07:00
|
|
|
if (m_interpreter.UserMultiwordCommandExists(alias_command)) {
|
|
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
|
"'%s' is user container command and cannot be overwritten.\n"
|
|
|
|
|
"Delete it first with 'command container delete'",
|
|
|
|
|
alias_command.c_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-08 01:31:04 +00:00
|
|
|
CommandObjectSP command_obj_sp(
|
|
|
|
|
m_interpreter.GetCommandSPExact(actual_command, true));
|
|
|
|
|
CommandObjectSP subcommand_obj_sp;
|
|
|
|
|
bool use_subcommand = false;
|
|
|
|
|
if (!command_obj_sp) {
|
|
|
|
|
result.AppendErrorWithFormat("'%s' is not an existing command.\n",
|
|
|
|
|
actual_command.c_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
CommandObject *cmd_obj = command_obj_sp.get();
|
|
|
|
|
CommandObject *sub_cmd_obj = nullptr;
|
|
|
|
|
OptionArgVectorSP option_arg_vector_sp =
|
|
|
|
|
OptionArgVectorSP(new OptionArgVector);
|
|
|
|
|
|
|
|
|
|
while (cmd_obj->IsMultiwordObject() && !args.empty()) {
|
2019-09-13 11:26:48 +00:00
|
|
|
auto sub_command = args[0].ref();
|
2016-12-08 01:31:04 +00:00
|
|
|
assert(!sub_command.empty());
|
|
|
|
|
subcommand_obj_sp = cmd_obj->GetSubcommandSP(sub_command);
|
|
|
|
|
if (!subcommand_obj_sp) {
|
|
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
|
"'%s' is not a valid sub-command of '%s'. "
|
|
|
|
|
"Unable to create alias.\n",
|
|
|
|
|
args[0].c_str(), actual_command.c_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-12-08 01:31:04 +00:00
|
|
|
sub_cmd_obj = subcommand_obj_sp.get();
|
|
|
|
|
use_subcommand = true;
|
|
|
|
|
args.Shift(); // Shift the sub_command word off the argument vector.
|
|
|
|
|
cmd_obj = sub_cmd_obj;
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-12-08 01:31:04 +00:00
|
|
|
// Verify & handle any options/arguments passed to the alias command
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-12-08 01:31:04 +00:00
|
|
|
std::string args_string;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-12-08 01:31:04 +00:00
|
|
|
if (!args.empty()) {
|
|
|
|
|
CommandObjectSP tmp_sp =
|
2020-12-22 14:02:18 -08:00
|
|
|
m_interpreter.GetCommandSPExact(cmd_obj->GetCommandName());
|
2016-12-08 01:31:04 +00:00
|
|
|
if (use_subcommand)
|
2020-12-22 14:02:18 -08:00
|
|
|
tmp_sp = m_interpreter.GetCommandSPExact(sub_cmd_obj->GetCommandName());
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-12-08 01:31:04 +00:00
|
|
|
args.GetCommandString(args_string);
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-12-08 01:31:04 +00:00
|
|
|
if (m_interpreter.AliasExists(alias_command) ||
|
|
|
|
|
m_interpreter.UserCommandExists(alias_command)) {
|
|
|
|
|
result.AppendWarningWithFormat(
|
|
|
|
|
"Overwriting existing definition for '%s'.\n", alias_command.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CommandAlias *alias = m_interpreter.AddAlias(
|
|
|
|
|
alias_command, use_subcommand ? subcommand_obj_sp : command_obj_sp,
|
|
|
|
|
args_string)) {
|
|
|
|
|
if (m_command_options.m_help.OptionWasSet())
|
|
|
|
|
alias->SetHelp(m_command_options.m_help.GetCurrentValue());
|
|
|
|
|
if (m_command_options.m_long_help.OptionWasSet())
|
|
|
|
|
alias->SetHelpLong(m_command_options.m_long_help.GetCurrentValue());
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
|
|
|
|
} else {
|
|
|
|
|
result.AppendError("Unable to create requested alias.\n");
|
|
|
|
|
return false;
|
2010-07-07 03:36:20 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
return result.Succeeded();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-07-07 03:36:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#pragma mark CommandObjectCommandsUnalias
|
|
|
|
|
// CommandObjectCommandsUnalias
|
|
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
class CommandObjectCommandsUnalias : public CommandObjectParsed {
|
2010-07-07 03:36:20 +00:00
|
|
|
public:
|
2016-07-14 22:03:10 +00:00
|
|
|
CommandObjectCommandsUnalias(CommandInterpreter &interpreter)
|
|
|
|
|
: CommandObjectParsed(
|
|
|
|
|
interpreter, "command unalias",
|
|
|
|
|
"Delete one or more custom commands defined by 'command alias'.",
|
|
|
|
|
nullptr) {
|
2010-10-04 22:28:36 +00:00
|
|
|
CommandArgumentEntry arg;
|
|
|
|
|
CommandArgumentData alias_arg;
|
2010-07-07 03:36:20 +00:00
|
|
|
|
2010-10-04 22:28:36 +00:00
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
|
alias_arg.arg_type = eArgTypeAliasName;
|
|
|
|
|
alias_arg.arg_repetition = eArgRepeatPlain;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-10-04 22:28:36 +00:00
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
|
// argument entry.
|
|
|
|
|
arg.push_back(alias_arg);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-10-04 22:28:36 +00:00
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
|
m_arguments.push_back(arg);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:46:47 +00:00
|
|
|
~CommandObjectCommandsUnalias() override = default;
|
2010-07-07 03:36:20 +00:00
|
|
|
|
2020-08-11 10:10:08 +02:00
|
|
|
void
|
|
|
|
|
HandleArgumentCompletion(CompletionRequest &request,
|
|
|
|
|
OptionElementVector &opt_element_vector) override {
|
|
|
|
|
if (!m_interpreter.HasCommands() || request.GetCursorIndex() != 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (const auto &ent : m_interpreter.GetAliases()) {
|
|
|
|
|
request.TryCompleteCurrentArg(ent.first, ent.second->GetHelp());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
protected:
|
2015-10-07 16:56:17 +00:00
|
|
|
bool DoExecute(Args &args, CommandReturnObject &result) override {
|
2010-07-07 03:36:20 +00:00
|
|
|
CommandObject::CommandMap::iterator pos;
|
|
|
|
|
CommandObject *cmd_obj;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-10-05 20:03:37 +00:00
|
|
|
if (args.empty()) {
|
|
|
|
|
result.AppendError("must call 'unalias' with a valid alias");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-13 11:26:48 +00:00
|
|
|
auto command_name = args[0].ref();
|
2016-10-05 20:03:37 +00:00
|
|
|
cmd_obj = m_interpreter.GetCommandObject(command_name);
|
2016-12-08 01:31:04 +00:00
|
|
|
if (!cmd_obj) {
|
2016-10-05 20:03:37 +00:00
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
|
"'%s' is not a known command.\nTry 'help' to see a "
|
|
|
|
|
"current list of commands.\n",
|
2016-12-09 01:20:58 +00:00
|
|
|
args[0].c_str());
|
2016-12-08 01:31:04 +00:00
|
|
|
return false;
|
2010-07-07 03:36:20 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-12-08 01:31:04 +00:00
|
|
|
if (m_interpreter.CommandExists(command_name)) {
|
|
|
|
|
if (cmd_obj->IsRemovable()) {
|
|
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
|
"'%s' is not an alias, it is a debugger command which can be "
|
|
|
|
|
"removed using the 'command delete' command.\n",
|
2016-12-09 01:20:58 +00:00
|
|
|
args[0].c_str());
|
2016-12-08 01:31:04 +00:00
|
|
|
} else {
|
|
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
|
"'%s' is a permanent debugger command and cannot be removed.\n",
|
2016-12-09 01:20:58 +00:00
|
|
|
args[0].c_str());
|
2016-12-08 01:31:04 +00:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_interpreter.RemoveAlias(command_name)) {
|
|
|
|
|
if (m_interpreter.AliasExists(command_name))
|
|
|
|
|
result.AppendErrorWithFormat(
|
2016-12-09 01:20:58 +00:00
|
|
|
"Error occurred while attempting to unalias '%s'.\n",
|
|
|
|
|
args[0].c_str());
|
2016-12-08 01:31:04 +00:00
|
|
|
else
|
|
|
|
|
result.AppendErrorWithFormat("'%s' is not an existing alias.\n",
|
2016-12-09 01:20:58 +00:00
|
|
|
args[0].c_str());
|
2016-12-08 01:31:04 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
2010-07-07 03:36:20 +00:00
|
|
|
return result.Succeeded();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-07-07 03:36:20 +00:00
|
|
|
};
|
|
|
|
|
|
2015-01-09 19:08:20 +00:00
|
|
|
#pragma mark CommandObjectCommandsDelete
|
|
|
|
|
// CommandObjectCommandsDelete
|
|
|
|
|
|
|
|
|
|
class CommandObjectCommandsDelete : public CommandObjectParsed {
|
|
|
|
|
public:
|
2016-07-14 22:03:10 +00:00
|
|
|
CommandObjectCommandsDelete(CommandInterpreter &interpreter)
|
|
|
|
|
: CommandObjectParsed(
|
|
|
|
|
interpreter, "command delete",
|
|
|
|
|
"Delete one or more custom commands defined by 'command regex'.",
|
|
|
|
|
nullptr) {
|
2015-01-09 19:08:20 +00:00
|
|
|
CommandArgumentEntry arg;
|
|
|
|
|
CommandArgumentData alias_arg;
|
|
|
|
|
|
|
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
|
alias_arg.arg_type = eArgTypeCommandName;
|
|
|
|
|
alias_arg.arg_repetition = eArgRepeatPlain;
|
|
|
|
|
|
|
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
|
// argument entry.
|
|
|
|
|
arg.push_back(alias_arg);
|
|
|
|
|
|
|
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
|
m_arguments.push_back(arg);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:46:47 +00:00
|
|
|
~CommandObjectCommandsDelete() override = default;
|
2015-01-09 19:08:20 +00:00
|
|
|
|
2020-08-11 10:10:08 +02:00
|
|
|
void
|
|
|
|
|
HandleArgumentCompletion(CompletionRequest &request,
|
|
|
|
|
OptionElementVector &opt_element_vector) override {
|
|
|
|
|
if (!m_interpreter.HasCommands() || request.GetCursorIndex() != 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (const auto &ent : m_interpreter.GetCommands()) {
|
|
|
|
|
if (ent.second->IsRemovable())
|
|
|
|
|
request.TryCompleteCurrentArg(ent.first, ent.second->GetHelp());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-09 19:08:20 +00:00
|
|
|
protected:
|
2015-10-07 16:56:17 +00:00
|
|
|
bool DoExecute(Args &args, CommandReturnObject &result) override {
|
2015-01-09 19:08:20 +00:00
|
|
|
CommandObject::CommandMap::iterator pos;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-10-05 20:03:37 +00:00
|
|
|
if (args.empty()) {
|
|
|
|
|
result.AppendErrorWithFormat("must call '%s' with one or more valid user "
|
|
|
|
|
"defined regular expression command names",
|
2016-10-05 21:14:38 +00:00
|
|
|
GetCommandName().str().c_str());
|
2019-09-03 09:06:12 +00:00
|
|
|
return false;
|
2016-10-05 20:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-13 11:26:48 +00:00
|
|
|
auto command_name = args[0].ref();
|
2016-12-08 01:31:04 +00:00
|
|
|
if (!m_interpreter.CommandExists(command_name)) {
|
2016-10-05 20:03:37 +00:00
|
|
|
StreamString error_msg_stream;
|
2019-02-13 06:25:41 +00:00
|
|
|
const bool generate_upropos = true;
|
2016-10-05 20:03:37 +00:00
|
|
|
const bool generate_type_lookup = false;
|
|
|
|
|
CommandObjectHelp::GenerateAdditionalHelpAvenuesMessage(
|
2016-12-08 01:31:04 +00:00
|
|
|
&error_msg_stream, command_name, llvm::StringRef(), llvm::StringRef(),
|
2019-02-13 06:25:41 +00:00
|
|
|
generate_upropos, generate_type_lookup);
|
2016-11-16 21:15:24 +00:00
|
|
|
result.AppendError(error_msg_stream.GetString());
|
2016-12-08 01:31:04 +00:00
|
|
|
return false;
|
2015-01-09 19:08:20 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-12-08 01:31:04 +00:00
|
|
|
if (!m_interpreter.RemoveCommand(command_name)) {
|
|
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
|
"'%s' is a permanent debugger command and cannot be removed.\n",
|
2016-12-09 01:20:58 +00:00
|
|
|
args[0].c_str());
|
2016-12-08 01:31:04 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
|
|
|
|
return true;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2015-01-09 19:08:20 +00:00
|
|
|
};
|
|
|
|
|
|
2011-04-20 16:37:46 +00:00
|
|
|
// CommandObjectCommandsAddRegex
|
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-22 20:22:55 +00:00
|
|
|
|
2019-07-18 14:10:49 +00:00
|
|
|
#define LLDB_OPTIONS_regex
|
|
|
|
|
#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-22 20:22:55 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
#pragma mark CommandObjectCommandsAddRegex
|
2011-04-20 16:37:46 +00:00
|
|
|
|
2014-01-27 23:43:24 +00:00
|
|
|
class CommandObjectCommandsAddRegex : public CommandObjectParsed,
|
2014-11-18 00:43:17 +00:00
|
|
|
public IOHandlerDelegateMultiline {
|
2011-04-20 16:37:46 +00:00
|
|
|
public:
|
2016-07-14 22:03:10 +00:00
|
|
|
CommandObjectCommandsAddRegex(CommandInterpreter &interpreter)
|
|
|
|
|
: CommandObjectParsed(
|
2019-10-30 15:26:19 -07:00
|
|
|
interpreter, "command regex",
|
|
|
|
|
"Define a custom command in terms of "
|
|
|
|
|
"existing commands by matching "
|
|
|
|
|
"regular expressions.",
|
2016-07-14 22:03:10 +00:00
|
|
|
"command regex <cmd-name> [s/<regex>/<subst>/ ...]"),
|
|
|
|
|
IOHandlerDelegateMultiline("",
|
2022-01-23 11:07:14 -08:00
|
|
|
IOHandlerDelegate::Completion::LLDBCommand) {
|
2015-07-14 05:48:36 +00:00
|
|
|
SetHelpLong(
|
|
|
|
|
R"(
|
|
|
|
|
)"
|
|
|
|
|
"This command allows the user to create powerful regular expression commands \
|
|
|
|
|
with substitutions. The regular expressions and substitutions are specified \
|
|
|
|
|
using the regular expression substitution format of:"
|
|
|
|
|
R"(
|
|
|
|
|
|
|
|
|
|
s/<regex>/<subst>/
|
|
|
|
|
|
|
|
|
|
)"
|
|
|
|
|
"<regex> is a regular expression that can use parenthesis to capture regular \
|
|
|
|
|
expression input and substitute the captured matches in the output using %1 \
|
|
|
|
|
for the first match, %2 for the second, and so on."
|
|
|
|
|
R"(
|
|
|
|
|
|
|
|
|
|
)"
|
|
|
|
|
"The regular expressions can all be specified on the command line if more than \
|
|
|
|
|
one argument is provided. If just the command name is provided on the command \
|
|
|
|
|
line, then the regular expressions and substitutions can be entered on separate \
|
|
|
|
|
lines, followed by an empty line to terminate the command definition."
|
|
|
|
|
R"(
|
|
|
|
|
|
|
|
|
|
EXAMPLES
|
|
|
|
|
|
|
|
|
|
)"
|
|
|
|
|
"The following example will define a regular expression command named 'f' that \
|
|
|
|
|
will call 'finish' if there are no arguments, or 'frame select <frame-idx>' if \
|
|
|
|
|
a number follows 'f':"
|
|
|
|
|
R"(
|
|
|
|
|
|
|
|
|
|
(lldb) command regex f s/^$/finish/ 's/([0-9]+)/frame select %1/')");
|
2022-06-23 09:33:40 -07:00
|
|
|
CommandArgumentData thread_arg{eArgTypeSEDStylePair, eArgRepeatOptional};
|
|
|
|
|
m_arguments.push_back({thread_arg});
|
2011-04-20 16:37:46 +00:00
|
|
|
}
|
2016-02-22 23:46:47 +00:00
|
|
|
|
|
|
|
|
~CommandObjectCommandsAddRegex() override = default;
|
|
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
protected:
|
Quiet command regex instructions during batch execution
Summary:
Within .lldbinit, regex commands can be structured as a list of substitutions over
multiple lines. It's possible that this is uninentional, but it works and has
benefits.
For example:
command regex <command-name>
s/pat1/repl1/
s/pat2/repl2/
...
I use this form of `command regex` in my `~/.lldbinit`, because it makes it
clearer to write and read compared to a single line definition, because
multiline substitutions don't need to be quoted, and are broken up one per line.
However, multiline definitions result in usage instructions being printed for
each use. The result is that every time I run `lldb`, I get a dozen or more
lines of noise. With this change, the instructions are only printed when
`command regex` is invoked interactively, or from a terminal, neither of which
are true when lldb is sourcing `~/.lldbinit`.
Reviewers: clayborg, jingham
Reviewed By: clayborg
Subscribers: jdoerfert, kastiglione, xiaobai, keith, lldb-commits
Differential Revision: https://reviews.llvm.org/D48752
llvm-svn: 355793
2019-03-10 23:15:48 +00:00
|
|
|
void IOHandlerActivated(IOHandler &io_handler, bool interactive) override {
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 14:33:35 +00:00
|
|
|
StreamFileSP output_sp(io_handler.GetOutputStreamFileSP());
|
Quiet command regex instructions during batch execution
Summary:
Within .lldbinit, regex commands can be structured as a list of substitutions over
multiple lines. It's possible that this is uninentional, but it works and has
benefits.
For example:
command regex <command-name>
s/pat1/repl1/
s/pat2/repl2/
...
I use this form of `command regex` in my `~/.lldbinit`, because it makes it
clearer to write and read compared to a single line definition, because
multiline substitutions don't need to be quoted, and are broken up one per line.
However, multiline definitions result in usage instructions being printed for
each use. The result is that every time I run `lldb`, I get a dozen or more
lines of noise. With this change, the instructions are only printed when
`command regex` is invoked interactively, or from a terminal, neither of which
are true when lldb is sourcing `~/.lldbinit`.
Reviewers: clayborg, jingham
Reviewed By: clayborg
Subscribers: jdoerfert, kastiglione, xiaobai, keith, lldb-commits
Differential Revision: https://reviews.llvm.org/D48752
llvm-svn: 355793
2019-03-10 23:15:48 +00:00
|
|
|
if (output_sp && interactive) {
|
|
|
|
|
output_sp->PutCString("Enter one or more sed substitution commands in "
|
2014-01-27 23:43:24 +00:00
|
|
|
"the form: 's/<regex>/<subst>/'.\nTerminate the "
|
|
|
|
|
"substitution list with an empty line.\n");
|
|
|
|
|
output_sp->Flush();
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-18 00:43:17 +00:00
|
|
|
void IOHandlerInputComplete(IOHandler &io_handler,
|
|
|
|
|
std::string &data) override {
|
2014-01-27 23:43:24 +00:00
|
|
|
io_handler.SetIsDone(true);
|
2019-02-13 06:25:41 +00:00
|
|
|
if (m_regex_cmd_up) {
|
2014-01-27 23:43:24 +00:00
|
|
|
StringList lines;
|
|
|
|
|
if (lines.SplitIntoLines(data)) {
|
|
|
|
|
bool check_only = false;
|
2019-08-16 14:27:35 +00:00
|
|
|
for (const std::string &line : lines) {
|
|
|
|
|
Status error = AppendRegexSubstitution(line, check_only);
|
2014-01-27 23:43:24 +00:00
|
|
|
if (error.Fail()) {
|
2019-04-27 06:19:42 +00:00
|
|
|
if (!GetDebugger().GetCommandInterpreter().GetBatchCommandMode()) {
|
|
|
|
|
StreamSP out_stream = GetDebugger().GetAsyncOutputStream();
|
2014-01-27 23:43:24 +00:00
|
|
|
out_stream->Printf("error: %s\n", error.AsCString());
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2014-01-27 23:43:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2019-02-13 06:25:41 +00:00
|
|
|
if (m_regex_cmd_up->HasRegexEntries()) {
|
|
|
|
|
CommandObjectSP cmd_sp(m_regex_cmd_up.release());
|
2014-01-27 23:43:24 +00:00
|
|
|
m_interpreter.AddCommand(cmd_sp->GetCommandName(), cmd_sp, true);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-07 16:56:17 +00:00
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
2012-06-08 21:56:10 +00:00
|
|
|
const size_t argc = command.GetArgumentCount();
|
2011-04-20 22:55:21 +00:00
|
|
|
if (argc == 0) {
|
2011-11-10 22:43:35 +00:00
|
|
|
result.AppendError("usage: 'command regex <command-name> "
|
|
|
|
|
"[s/<regex1>/<subst1>/ s/<regex2>/<subst2>/ ...]'\n");
|
2016-10-05 20:03:37 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status error;
|
2019-09-13 11:26:48 +00:00
|
|
|
auto name = command[0].ref();
|
2019-08-14 22:19:23 +00:00
|
|
|
m_regex_cmd_up = std::make_unique<CommandObjectRegexCommand>(
|
2023-02-03 21:44:07 -08:00
|
|
|
m_interpreter, name, m_options.GetHelp(), m_options.GetSyntax(), 0,
|
2016-12-08 01:31:04 +00:00
|
|
|
true);
|
2016-10-05 20:03:37 +00:00
|
|
|
|
|
|
|
|
if (argc == 1) {
|
2019-04-27 06:19:42 +00:00
|
|
|
Debugger &debugger = GetDebugger();
|
2016-10-05 20:03:37 +00:00
|
|
|
bool color_prompt = debugger.GetUseColor();
|
|
|
|
|
const bool multiple_lines = true; // Get multiple lines
|
|
|
|
|
IOHandlerSP io_handler_sp(new IOHandlerEditline(
|
|
|
|
|
debugger, IOHandler::Type::Other,
|
|
|
|
|
"lldb-regex", // Name of input reader for history
|
|
|
|
|
llvm::StringRef("> "), // Prompt
|
|
|
|
|
llvm::StringRef(), // Continuation prompt
|
|
|
|
|
multiple_lines, color_prompt,
|
|
|
|
|
0, // Don't show line numbers
|
2022-09-19 10:47:09 -07:00
|
|
|
*this));
|
2016-10-05 20:03:37 +00:00
|
|
|
|
|
|
|
|
if (io_handler_sp) {
|
2020-01-15 14:56:28 -08:00
|
|
|
debugger.RunIOHandlerAsync(io_handler_sp);
|
2016-10-05 20:03:37 +00:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-10-05 20:03:37 +00:00
|
|
|
} else {
|
2016-10-05 23:40:23 +00:00
|
|
|
for (auto &entry : command.entries().drop_front()) {
|
2016-10-05 20:03:37 +00:00
|
|
|
bool check_only = false;
|
2019-09-13 11:26:48 +00:00
|
|
|
error = AppendRegexSubstitution(entry.ref(), check_only);
|
2016-10-05 20:03:37 +00:00
|
|
|
if (error.Fail())
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error.Success()) {
|
|
|
|
|
AddRegexCommandToInterpreter();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2014-01-27 23:43:24 +00:00
|
|
|
}
|
2016-10-05 20:03:37 +00:00
|
|
|
if (error.Fail()) {
|
|
|
|
|
result.AppendError(error.AsCString());
|
|
|
|
|
}
|
2014-01-27 23:43:24 +00:00
|
|
|
|
2011-04-20 22:55:21 +00:00
|
|
|
return result.Succeeded();
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status AppendRegexSubstitution(const llvm::StringRef ®ex_sed,
|
|
|
|
|
bool check_only) {
|
|
|
|
|
Status error;
|
2011-04-20 22:55:21 +00:00
|
|
|
|
2019-02-13 06:25:41 +00:00
|
|
|
if (!m_regex_cmd_up) {
|
2011-04-20 16:37:46 +00:00
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
|
"invalid regular expression command object for: '%.*s'",
|
|
|
|
|
(int)regex_sed.size(), regex_sed.data());
|
|
|
|
|
return error;
|
|
|
|
|
}
|
2011-04-20 22:55:21 +00:00
|
|
|
|
|
|
|
|
size_t regex_sed_size = regex_sed.size();
|
|
|
|
|
|
|
|
|
|
if (regex_sed_size <= 1) {
|
2014-11-18 00:43:17 +00:00
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
|
"regular expression substitution string is too short: '%.*s'",
|
2011-04-20 22:55:21 +00:00
|
|
|
(int)regex_sed.size(), regex_sed.data());
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (regex_sed[0] != 's') {
|
|
|
|
|
error.SetErrorStringWithFormat("regular expression substitution string "
|
|
|
|
|
"doesn't start with 's': '%.*s'",
|
|
|
|
|
(int)regex_sed.size(), regex_sed.data());
|
|
|
|
|
return error;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2011-04-20 22:55:21 +00:00
|
|
|
const size_t first_separator_char_pos = 1;
|
2018-04-30 16:49:04 +00:00
|
|
|
// use the char that follows 's' as the regex separator character so we can
|
|
|
|
|
// have "s/<regex>/<subst>/" or "s|<regex>|<subst>|"
|
2011-04-20 22:55:21 +00:00
|
|
|
const char separator_char = regex_sed[first_separator_char_pos];
|
|
|
|
|
const size_t second_separator_char_pos =
|
|
|
|
|
regex_sed.find(separator_char, first_separator_char_pos + 1);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-04-20 22:55:21 +00:00
|
|
|
if (second_separator_char_pos == std::string::npos) {
|
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
|
"missing second '%c' separator char after '%.*s' in '%.*s'",
|
|
|
|
|
separator_char,
|
|
|
|
|
(int)(regex_sed.size() - first_separator_char_pos - 1),
|
2014-11-18 00:43:17 +00:00
|
|
|
regex_sed.data() + (first_separator_char_pos + 1),
|
2011-04-20 22:55:21 +00:00
|
|
|
(int)regex_sed.size(), regex_sed.data());
|
|
|
|
|
return error;
|
|
|
|
|
}
|
2014-01-27 23:43:24 +00:00
|
|
|
|
|
|
|
|
const size_t third_separator_char_pos =
|
|
|
|
|
regex_sed.find(separator_char, second_separator_char_pos + 1);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-01-27 23:43:24 +00:00
|
|
|
if (third_separator_char_pos == std::string::npos) {
|
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
|
"missing third '%c' separator char after '%.*s' in '%.*s'",
|
|
|
|
|
separator_char,
|
|
|
|
|
(int)(regex_sed.size() - second_separator_char_pos - 1),
|
|
|
|
|
regex_sed.data() + (second_separator_char_pos + 1),
|
|
|
|
|
(int)regex_sed.size(), regex_sed.data());
|
2011-04-20 22:55:21 +00:00
|
|
|
return error;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2014-01-27 23:43:24 +00:00
|
|
|
if (third_separator_char_pos != regex_sed_size - 1) {
|
2018-04-30 16:49:04 +00:00
|
|
|
// Make sure that everything that follows the last regex separator char
|
2014-01-27 23:43:24 +00:00
|
|
|
if (regex_sed.find_first_not_of("\t\n\v\f\r ",
|
|
|
|
|
third_separator_char_pos + 1) !=
|
|
|
|
|
std::string::npos) {
|
2011-04-20 22:55:21 +00:00
|
|
|
error.SetErrorStringWithFormat(
|
2014-01-27 23:43:24 +00:00
|
|
|
"extra data found after the '%.*s' regular expression substitution "
|
2011-04-20 22:55:21 +00:00
|
|
|
"string: '%.*s'",
|
2014-11-18 00:43:17 +00:00
|
|
|
(int)third_separator_char_pos + 1, regex_sed.data(),
|
2011-04-20 22:55:21 +00:00
|
|
|
(int)(regex_sed.size() - third_separator_char_pos - 1),
|
2014-01-27 23:43:24 +00:00
|
|
|
regex_sed.data() + (third_separator_char_pos + 1));
|
2011-04-20 22:55:21 +00:00
|
|
|
return error;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2011-04-20 22:55:21 +00:00
|
|
|
} else if (first_separator_char_pos + 1 == second_separator_char_pos) {
|
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
|
"<regex> can't be empty in 's%c<regex>%c<subst>%c' string: '%.*s'",
|
|
|
|
|
separator_char, separator_char, separator_char, (int)regex_sed.size(),
|
|
|
|
|
regex_sed.data());
|
|
|
|
|
return error;
|
|
|
|
|
} else if (second_separator_char_pos + 1 == third_separator_char_pos) {
|
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
|
"<subst> can't be empty in 's%c<regex>%c<subst>%c' string: '%.*s'",
|
|
|
|
|
separator_char, separator_char, separator_char, (int)regex_sed.size(),
|
|
|
|
|
regex_sed.data());
|
|
|
|
|
return error;
|
2011-04-20 16:37:46 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-02-22 23:46:47 +00:00
|
|
|
if (!check_only) {
|
2020-01-28 20:23:46 +01:00
|
|
|
std::string regex(std::string(regex_sed.substr(
|
|
|
|
|
first_separator_char_pos + 1,
|
|
|
|
|
second_separator_char_pos - first_separator_char_pos - 1)));
|
|
|
|
|
std::string subst(std::string(regex_sed.substr(
|
|
|
|
|
second_separator_char_pos + 1,
|
|
|
|
|
third_separator_char_pos - second_separator_char_pos - 1)));
|
2020-07-27 14:28:30 +02:00
|
|
|
m_regex_cmd_up->AddRegexCommand(regex, subst);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2011-04-20 22:55:21 +00:00
|
|
|
return error;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2011-04-20 22:55:21 +00:00
|
|
|
void AddRegexCommandToInterpreter() {
|
2019-02-13 06:25:41 +00:00
|
|
|
if (m_regex_cmd_up) {
|
|
|
|
|
if (m_regex_cmd_up->HasRegexEntries()) {
|
|
|
|
|
CommandObjectSP cmd_sp(m_regex_cmd_up.release());
|
2011-04-20 16:37:46 +00:00
|
|
|
m_interpreter.AddCommand(cmd_sp->GetCommandName(), cmd_sp, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2011-04-20 16:37:46 +00:00
|
|
|
|
|
|
|
|
private:
|
2019-02-13 06:25:41 +00:00
|
|
|
std::unique_ptr<CommandObjectRegexCommand> m_regex_cmd_up;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-04-20 16:37:46 +00:00
|
|
|
class CommandOptions : public Options {
|
|
|
|
|
public:
|
2022-03-31 13:20:46 -07:00
|
|
|
CommandOptions() = default;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-02-22 23:46:47 +00:00
|
|
|
~CommandOptions() override = default;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
|
|
|
|
|
ExecutionContext *execution_context) override {
|
|
|
|
|
Status error;
|
2012-12-04 00:32:51 +00:00
|
|
|
const int short_option = m_getopt_table[option_idx].val;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-04-20 16:37:46 +00:00
|
|
|
switch (short_option) {
|
|
|
|
|
case 'h':
|
2020-01-28 20:23:46 +01:00
|
|
|
m_help.assign(std::string(option_arg));
|
2011-04-20 16:37:46 +00:00
|
|
|
break;
|
|
|
|
|
case 's':
|
2020-01-28 20:23:46 +01:00
|
|
|
m_syntax.assign(std::string(option_arg));
|
2011-04-20 16:37:46 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
2019-08-22 08:08:05 +00:00
|
|
|
llvm_unreachable("Unimplemented option");
|
2011-04-20 16:37:46 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-04-20 16:37:46 +00:00
|
|
|
return error;
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-08-11 23:51:28 +00:00
|
|
|
void OptionParsingStarting(ExecutionContext *execution_context) override {
|
2011-04-20 16:37:46 +00:00
|
|
|
m_help.clear();
|
|
|
|
|
m_syntax.clear();
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
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-22 20:22:55 +00:00
|
|
|
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
|
2023-01-09 18:11:07 +01:00
|
|
|
return llvm::ArrayRef(g_regex_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-22 20:22:55 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2020-03-26 11:15:07 +01:00
|
|
|
llvm::StringRef GetHelp() { return m_help; }
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2020-03-26 11:15:07 +01:00
|
|
|
llvm::StringRef GetSyntax() { return m_syntax; }
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-04-20 16:37:46 +00:00
|
|
|
protected:
|
2016-02-22 23:46:47 +00:00
|
|
|
// Instance variables to hold the values for command options.
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-04-20 16:37:46 +00:00
|
|
|
std::string m_help;
|
|
|
|
|
std::string m_syntax;
|
|
|
|
|
};
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-11-18 22:40:27 +00:00
|
|
|
Options *GetOptions() override { return &m_options; }
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
CommandOptions m_options;
|
2011-04-20 16:37:46 +00:00
|
|
|
};
|
|
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
class CommandObjectPythonFunction : public CommandObjectRaw {
|
2011-08-16 23:24:13 +00:00
|
|
|
public:
|
|
|
|
|
CommandObjectPythonFunction(CommandInterpreter &interpreter, std::string name,
|
2011-11-07 22:57:04 +00:00
|
|
|
std::string funct, std::string help,
|
|
|
|
|
ScriptedCommandSynchronicity synch)
|
2019-10-30 15:26:19 -07:00
|
|
|
: CommandObjectRaw(interpreter, name), m_function_name(funct),
|
2022-03-14 13:32:03 -07:00
|
|
|
m_synchro(synch) {
|
2014-09-15 17:52:44 +00:00
|
|
|
if (!help.empty())
|
2016-11-12 20:41:02 +00:00
|
|
|
SetHelp(help);
|
2014-09-15 17:52:44 +00:00
|
|
|
else {
|
|
|
|
|
StreamString stream;
|
|
|
|
|
stream.Printf("For more information run 'help %s'", name.c_str());
|
2016-11-16 21:15:24 +00:00
|
|
|
SetHelp(stream.GetString());
|
2011-08-16 23:24:13 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-02-22 23:46:47 +00:00
|
|
|
|
|
|
|
|
~CommandObjectPythonFunction() override = default;
|
|
|
|
|
|
2015-10-07 16:56:17 +00:00
|
|
|
bool IsRemovable() const override { return true; }
|
2012-06-08 21:56:10 +00:00
|
|
|
|
|
|
|
|
const std::string &GetFunctionName() { return m_function_name; }
|
|
|
|
|
|
|
|
|
|
ScriptedCommandSynchronicity GetSynchronicity() { return m_synchro; }
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-11-12 20:41:02 +00:00
|
|
|
llvm::StringRef GetHelpLong() override {
|
|
|
|
|
if (m_fetched_help_long)
|
|
|
|
|
return CommandObjectRaw::GetHelpLong();
|
|
|
|
|
|
2019-04-26 22:43:16 +00:00
|
|
|
ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter();
|
2016-11-12 20:41:02 +00:00
|
|
|
if (!scripter)
|
|
|
|
|
return CommandObjectRaw::GetHelpLong();
|
|
|
|
|
|
|
|
|
|
std::string docstring;
|
|
|
|
|
m_fetched_help_long =
|
|
|
|
|
scripter->GetDocumentationForItem(m_function_name.c_str(), docstring);
|
|
|
|
|
if (!docstring.empty())
|
|
|
|
|
SetHelpLong(docstring);
|
2012-09-18 21:53:02 +00:00
|
|
|
return CommandObjectRaw::GetHelpLong();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
protected:
|
2018-07-12 22:28:52 +00:00
|
|
|
bool DoExecute(llvm::StringRef raw_command_line,
|
2015-10-07 16:56:17 +00:00
|
|
|
CommandReturnObject &result) override {
|
2019-04-26 22:43:16 +00:00
|
|
|
ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status error;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-06-27 17:25:36 +00:00
|
|
|
result.SetStatus(eReturnStatusInvalid);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-10-30 15:26:19 -07:00
|
|
|
if (!scripter || !scripter->RunScriptBasedCommand(
|
|
|
|
|
m_function_name.c_str(), raw_command_line, m_synchro,
|
|
|
|
|
result, error, m_exe_ctx)) {
|
2011-08-16 23:24:13 +00:00
|
|
|
result.AppendError(error.AsCString());
|
|
|
|
|
} else {
|
2012-06-27 17:25:36 +00:00
|
|
|
// Don't change the status if the command already set it...
|
|
|
|
|
if (result.GetStatus() == eReturnStatusInvalid) {
|
2016-11-16 21:15:24 +00:00
|
|
|
if (result.GetOutputData().empty())
|
2012-06-27 17:25:36 +00:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
2011-08-16 23:24:13 +00:00
|
|
|
else
|
2012-06-27 17:25:36 +00:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
|
}
|
2011-08-16 23:24:13 +00:00
|
|
|
}
|
2016-02-22 23:46:47 +00:00
|
|
|
|
2011-08-16 23:24:13 +00:00
|
|
|
return result.Succeeded();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:46:47 +00:00
|
|
|
private:
|
|
|
|
|
std::string m_function_name;
|
|
|
|
|
ScriptedCommandSynchronicity m_synchro;
|
2022-03-14 13:32:03 -07:00
|
|
|
bool m_fetched_help_long = false;
|
2012-06-08 21:56:10 +00:00
|
|
|
};
|
2011-11-07 22:57:04 +00:00
|
|
|
|
2015-03-13 02:20:41 +00:00
|
|
|
class CommandObjectScriptingObject : public CommandObjectRaw {
|
|
|
|
|
public:
|
|
|
|
|
CommandObjectScriptingObject(CommandInterpreter &interpreter,
|
|
|
|
|
std::string name,
|
2015-03-17 20:04:04 +00:00
|
|
|
StructuredData::GenericSP cmd_obj_sp,
|
2015-03-13 02:20:41 +00:00
|
|
|
ScriptedCommandSynchronicity synch)
|
2019-10-30 15:26:19 -07:00
|
|
|
: CommandObjectRaw(interpreter, name), m_cmd_obj_sp(cmd_obj_sp),
|
|
|
|
|
m_synchro(synch), m_fetched_help_short(false),
|
2016-02-22 23:46:47 +00:00
|
|
|
m_fetched_help_long(false) {
|
2015-03-13 02:20:41 +00:00
|
|
|
StreamString stream;
|
|
|
|
|
stream.Printf("For more information run 'help %s'", name.c_str());
|
2016-11-16 21:15:24 +00:00
|
|
|
SetHelp(stream.GetString());
|
2019-04-26 22:43:16 +00:00
|
|
|
if (ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter())
|
2015-05-27 05:04:35 +00:00
|
|
|
GetFlags().Set(scripter->GetFlagsForCommandObject(cmd_obj_sp));
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:46:47 +00:00
|
|
|
~CommandObjectScriptingObject() override = default;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-10-07 16:56:17 +00:00
|
|
|
bool IsRemovable() const override { return true; }
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-08-26 23:28:47 +00:00
|
|
|
ScriptedCommandSynchronicity GetSynchronicity() { return m_synchro; }
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-11-12 20:41:02 +00:00
|
|
|
llvm::StringRef GetHelp() override {
|
|
|
|
|
if (m_fetched_help_short)
|
|
|
|
|
return CommandObjectRaw::GetHelp();
|
2019-04-26 22:43:16 +00:00
|
|
|
ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter();
|
2016-11-12 20:41:02 +00:00
|
|
|
if (!scripter)
|
|
|
|
|
return CommandObjectRaw::GetHelp();
|
|
|
|
|
std::string docstring;
|
|
|
|
|
m_fetched_help_short =
|
|
|
|
|
scripter->GetShortHelpForCommandObject(m_cmd_obj_sp, docstring);
|
|
|
|
|
if (!docstring.empty())
|
|
|
|
|
SetHelp(docstring);
|
|
|
|
|
|
2016-02-22 23:46:47 +00:00
|
|
|
return CommandObjectRaw::GetHelp();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-11-12 20:41:02 +00:00
|
|
|
llvm::StringRef GetHelpLong() override {
|
|
|
|
|
if (m_fetched_help_long)
|
|
|
|
|
return CommandObjectRaw::GetHelpLong();
|
|
|
|
|
|
2019-04-26 22:43:16 +00:00
|
|
|
ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter();
|
2016-11-12 20:41:02 +00:00
|
|
|
if (!scripter)
|
|
|
|
|
return CommandObjectRaw::GetHelpLong();
|
|
|
|
|
|
|
|
|
|
std::string docstring;
|
|
|
|
|
m_fetched_help_long =
|
|
|
|
|
scripter->GetLongHelpForCommandObject(m_cmd_obj_sp, docstring);
|
|
|
|
|
if (!docstring.empty())
|
|
|
|
|
SetHelpLong(docstring);
|
2012-09-18 21:53:02 +00:00
|
|
|
return CommandObjectRaw::GetHelpLong();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2015-03-13 22:22:28 +00:00
|
|
|
|
2015-03-13 02:20:41 +00:00
|
|
|
protected:
|
2018-07-12 22:28:52 +00:00
|
|
|
bool DoExecute(llvm::StringRef raw_command_line,
|
2015-10-07 16:56:17 +00:00
|
|
|
CommandReturnObject &result) override {
|
2019-04-26 22:43:16 +00:00
|
|
|
ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status error;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-03-13 02:20:41 +00:00
|
|
|
result.SetStatus(eReturnStatusInvalid);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-02-22 23:46:47 +00:00
|
|
|
if (!scripter ||
|
|
|
|
|
!scripter->RunScriptBasedCommand(m_cmd_obj_sp, raw_command_line,
|
|
|
|
|
m_synchro, result, error, m_exe_ctx)) {
|
2015-03-13 02:20:41 +00:00
|
|
|
result.AppendError(error.AsCString());
|
|
|
|
|
} else {
|
2012-06-27 17:25:36 +00:00
|
|
|
// Don't change the status if the command already set it...
|
|
|
|
|
if (result.GetStatus() == eReturnStatusInvalid) {
|
2016-11-16 21:15:24 +00:00
|
|
|
if (result.GetOutputData().empty())
|
2012-06-27 17:25:36 +00:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
2015-03-13 02:20:41 +00:00
|
|
|
else
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-22 23:46:47 +00:00
|
|
|
|
2011-08-16 23:24:13 +00:00
|
|
|
return result.Succeeded();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:46:47 +00:00
|
|
|
private:
|
|
|
|
|
StructuredData::GenericSP m_cmd_obj_sp;
|
|
|
|
|
ScriptedCommandSynchronicity m_synchro;
|
|
|
|
|
bool m_fetched_help_short : 1;
|
|
|
|
|
bool m_fetched_help_long : 1;
|
2015-03-13 02:20:41 +00:00
|
|
|
};
|
|
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
// CommandObjectCommandsScriptImport
|
2019-07-18 14:10:49 +00:00
|
|
|
#define LLDB_OPTIONS_script_import
|
|
|
|
|
#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-22 20:22:55 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
class CommandObjectCommandsScriptImport : public CommandObjectParsed {
|
|
|
|
|
public:
|
|
|
|
|
CommandObjectCommandsScriptImport(CommandInterpreter &interpreter)
|
2016-02-22 23:46:47 +00:00
|
|
|
: CommandObjectParsed(interpreter, "command script import",
|
2022-01-23 11:07:14 -08:00
|
|
|
"Import a scripting module in LLDB.", nullptr) {
|
2012-06-08 21:56:10 +00:00
|
|
|
CommandArgumentEntry arg1;
|
|
|
|
|
CommandArgumentData cmd_arg;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
|
cmd_arg.arg_type = eArgTypeFilename;
|
2015-06-16 18:31:04 +00:00
|
|
|
cmd_arg.arg_repetition = eArgRepeatPlus;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
|
// argument entry.
|
|
|
|
|
arg1.push_back(cmd_arg);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
|
m_arguments.push_back(arg1);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:46:47 +00:00
|
|
|
~CommandObjectCommandsScriptImport() override = default;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
[lldb][NFC] Remove WordComplete mode, make result array indexed from 0 and remove any undocumented/redundant return values
Summary:
We still have some leftovers of the old completion API in the internals of
LLDB that haven't been replaced by the new CompletionRequest. These leftovers
are:
* The return values (int/size_t) in all completion functions.
* Our result array that starts indexing at 1.
* `WordComplete` mode.
I didn't replace them back then because it's tricky to figure out what exactly they
are used for and the completion code is relatively untested. I finally got around
to writing more tests for the API and understanding the semantics, so I think it's
a good time to get rid of them.
A few words why those things should be removed/replaced:
* The return values are really cryptic, partly redundant and rarely documented.
They are also completely ignored by Xcode, so whatever information they contain will end up
breaking Xcode's completion mechanism. They are also partly impossible to even implement
as we assign negative values special meaning and our completion API sometimes returns size_t.
Completion functions are supposed to return -2 to rewrite the current line. We seem to use this
in some untested code path to expand the history repeat character to the full command, but
I haven't figured out why that doesn't work at the moment.
Completion functions return -1 to 'insert the completion character', but that isn't implemented
(even though we seem to activate this feature in LLDB sometimes).
All positive values have to match the number of results. This is obviously just redundant information
as the user can just look at the result list to get that information (which is what Xcode does).
* The result array that starts indexing at 1 is obviously unexpected. The first element of the array is
reserved for the common prefix of all completions (e.g. "foobar" and "footar" -> "foo"). The idea is
that we calculate this to make the life of the API caller easier, but obviously forcing people to have
1-based indices is not helpful (or even worse, forces them to manually copy the results to make it
0-based like Xcode has to do).
* The `WordComplete` mode indicates that LLDB should enter a space behind the completion. The
idea is that we let the top-level API know that we just provided a full completion. Interestingly we
`WordComplete` is just a single bool that somehow represents all N completions. And we always
provide full completions in LLDB, so in theory it should always be true.
The only use it currently serves is providing redundant information about whether we have a single
definitive completion or not (which we already know from the number of results we get).
This patch essentially removes `WordComplete` mode and makes the result array indexed from 0.
It also removes all return values from all internal completion functions. The only non-redundant information
they contain is about rewriting the current line (which is broken), so that functionality was moved
to the CompletionRequest API. So you can now do `addCompletion("blub", "description", CompletionMode::RewriteLine)`
to do the same.
For the SB API we emulate the old behaviour by making the array indexed from 1 again with the common
prefix at index 0. I didn't keep the special negative return codes as we either never sent them before (e.g. -2) or we
didn't even implement them in the Editline handler (e.g. -1).
I tried to keep this patch minimal and I'm aware we can probably now even further simplify a bunch of related code,
but I would prefer doing this in follow-up NFC commits
Reviewers: JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arphaman, abidh, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D66536
llvm-svn: 369624
2019-08-22 07:41:23 +00:00
|
|
|
void
|
|
|
|
|
HandleArgumentCompletion(CompletionRequest &request,
|
|
|
|
|
OptionElementVector &opt_element_vector) override {
|
2012-06-08 21:56:10 +00:00
|
|
|
CommandCompletions::InvokeCommonCompletionCallbacks(
|
2016-08-11 23:51:28 +00:00
|
|
|
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
|
2018-07-13 18:28:14 +00:00
|
|
|
request, nullptr);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-27 16:22:29 +00:00
|
|
|
Options *GetOptions() override { return &m_options; }
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
protected:
|
2011-11-07 22:57:04 +00:00
|
|
|
class CommandOptions : public Options {
|
2016-09-06 20:57:50 +00:00
|
|
|
public:
|
2022-03-31 13:20:46 -07:00
|
|
|
CommandOptions() = default;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-02-22 23:46:47 +00:00
|
|
|
~CommandOptions() override = default;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
|
|
|
|
|
ExecutionContext *execution_context) override {
|
|
|
|
|
Status error;
|
2012-12-04 00:32:51 +00:00
|
|
|
const int short_option = m_getopt_table[option_idx].val;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
switch (short_option) {
|
2011-11-07 22:57:04 +00:00
|
|
|
case 'r':
|
2019-12-22 21:35:05 -08:00
|
|
|
// NO-OP
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
2020-10-27 09:14:40 -07:00
|
|
|
case 'c':
|
|
|
|
|
relative_to_command_file = true;
|
|
|
|
|
break;
|
[lldb] Add the ability to silently import scripted commands
Add the ability to silence command script import. The motivation for
this change is being able to add command script import -s
lldb.macosx.crashlog to your ~/.lldbinit without it printing the
following message at the beginning of every debug session.
"malloc_info", "ptr_refs", "cstr_refs", "find_variable", and
"objc_refs" commands have been installed, use the "--help" options on
these commands for detailed help.
In addition to forwarding the silent option to LoadScriptingModule, this
also changes ScriptInterpreterPythonImpl::ExecuteOneLineWithReturn and
ScriptInterpreterPythonImpl::ExecuteMultipleLines to honor the enable IO
option in ExecuteScriptOptions, which until now was ignored.
Note that IO is only enabled (or disabled) at the start of a session,
and for this particular use case, that's done when taking the Python
lock in LoadScriptingModule, which means that the changes to these two
functions are not strictly necessary, but (IMO) desirable nonetheless.
Differential revision: https://reviews.llvm.org/D105327
2021-07-09 09:23:54 -07:00
|
|
|
case 's':
|
|
|
|
|
silent = true;
|
|
|
|
|
break;
|
2016-09-06 20:57:50 +00:00
|
|
|
default:
|
2019-08-22 08:08:05 +00:00
|
|
|
llvm_unreachable("Unimplemented option");
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2011-04-20 22:55:21 +00:00
|
|
|
return error;
|
2011-11-07 22:57:04 +00:00
|
|
|
}
|
2016-02-22 23:46:47 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
void OptionParsingStarting(ExecutionContext *execution_context) override {
|
2020-10-27 09:14:40 -07:00
|
|
|
relative_to_command_file = false;
|
2011-11-07 22:57:04 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
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-22 20:22:55 +00:00
|
|
|
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
|
2023-01-09 18:11:07 +01:00
|
|
|
return llvm::ArrayRef(g_script_import_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-22 20:22:55 +00:00
|
|
|
}
|
2020-10-27 09:14:40 -07:00
|
|
|
bool relative_to_command_file = false;
|
[lldb] Add the ability to silently import scripted commands
Add the ability to silence command script import. The motivation for
this change is being able to add command script import -s
lldb.macosx.crashlog to your ~/.lldbinit without it printing the
following message at the beginning of every debug session.
"malloc_info", "ptr_refs", "cstr_refs", "find_variable", and
"objc_refs" commands have been installed, use the "--help" options on
these commands for detailed help.
In addition to forwarding the silent option to LoadScriptingModule, this
also changes ScriptInterpreterPythonImpl::ExecuteOneLineWithReturn and
ScriptInterpreterPythonImpl::ExecuteMultipleLines to honor the enable IO
option in ExecuteScriptOptions, which until now was ignored.
Note that IO is only enabled (or disabled) at the start of a session,
and for this particular use case, that's done when taking the Python
lock in LoadScriptingModule, which means that the changes to these two
functions are not strictly necessary, but (IMO) desirable nonetheless.
Differential revision: https://reviews.llvm.org/D105327
2021-07-09 09:23:54 -07:00
|
|
|
bool silent = false;
|
2016-09-06 20:57:50 +00:00
|
|
|
};
|
|
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
2016-10-05 20:03:37 +00:00
|
|
|
if (command.empty()) {
|
2011-11-07 22:57:04 +00:00
|
|
|
result.AppendError("command script import needs one or more arguments");
|
2011-10-17 21:45:27 +00:00
|
|
|
return false;
|
2011-11-07 22:57:04 +00:00
|
|
|
}
|
2016-02-22 23:46:47 +00:00
|
|
|
|
2020-10-27 09:14:40 -07:00
|
|
|
FileSpec source_dir = {};
|
|
|
|
|
if (m_options.relative_to_command_file) {
|
|
|
|
|
source_dir = GetDebugger().GetCommandInterpreter().GetCurrentSourceDir();
|
|
|
|
|
if (!source_dir) {
|
|
|
|
|
result.AppendError("command script import -c can only be specified "
|
|
|
|
|
"from a command file");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 20:03:37 +00:00
|
|
|
for (auto &entry : command.entries()) {
|
2017-05-12 04:51:55 +00:00
|
|
|
Status error;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
[lldb] Add the ability to silently import scripted commands
Add the ability to silence command script import. The motivation for
this change is being able to add command script import -s
lldb.macosx.crashlog to your ~/.lldbinit without it printing the
following message at the beginning of every debug session.
"malloc_info", "ptr_refs", "cstr_refs", "find_variable", and
"objc_refs" commands have been installed, use the "--help" options on
these commands for detailed help.
In addition to forwarding the silent option to LoadScriptingModule, this
also changes ScriptInterpreterPythonImpl::ExecuteOneLineWithReturn and
ScriptInterpreterPythonImpl::ExecuteMultipleLines to honor the enable IO
option in ExecuteScriptOptions, which until now was ignored.
Note that IO is only enabled (or disabled) at the start of a session,
and for this particular use case, that's done when taking the Python
lock in LoadScriptingModule, which means that the changes to these two
functions are not strictly necessary, but (IMO) desirable nonetheless.
Differential revision: https://reviews.llvm.org/D105327
2021-07-09 09:23:54 -07:00
|
|
|
LoadScriptOptions options;
|
|
|
|
|
options.SetInitSession(true);
|
|
|
|
|
options.SetSilent(m_options.silent);
|
|
|
|
|
|
2011-11-07 22:57:04 +00:00
|
|
|
// FIXME: this is necessary because CommandObject::CheckRequirements()
|
2016-10-05 20:03:37 +00:00
|
|
|
// assumes that commands won't ever be recursively invoked, but it's
|
|
|
|
|
// actually possible to craft a Python script that does other "command
|
2018-04-30 16:49:04 +00:00
|
|
|
// script imports" in __lldb_init_module the real fix is to have
|
|
|
|
|
// recursive commands possible with a CommandInvocation object separate
|
|
|
|
|
// from the CommandObject itself, so that recursive command invocations
|
|
|
|
|
// won't stomp on each other (wrt to execution contents, options, and
|
|
|
|
|
// more)
|
2015-06-16 18:31:04 +00:00
|
|
|
m_exe_ctx.Clear();
|
2019-04-26 22:43:16 +00:00
|
|
|
if (GetDebugger().GetScriptInterpreter()->LoadScriptingModule(
|
[lldb] Add the ability to silently import scripted commands
Add the ability to silence command script import. The motivation for
this change is being able to add command script import -s
lldb.macosx.crashlog to your ~/.lldbinit without it printing the
following message at the beginning of every debug session.
"malloc_info", "ptr_refs", "cstr_refs", "find_variable", and
"objc_refs" commands have been installed, use the "--help" options on
these commands for detailed help.
In addition to forwarding the silent option to LoadScriptingModule, this
also changes ScriptInterpreterPythonImpl::ExecuteOneLineWithReturn and
ScriptInterpreterPythonImpl::ExecuteMultipleLines to honor the enable IO
option in ExecuteScriptOptions, which until now was ignored.
Note that IO is only enabled (or disabled) at the start of a session,
and for this particular use case, that's done when taking the Python
lock in LoadScriptingModule, which means that the changes to these two
functions are not strictly necessary, but (IMO) desirable nonetheless.
Differential revision: https://reviews.llvm.org/D105327
2021-07-09 09:23:54 -07:00
|
|
|
entry.c_str(), options, error, /*module_sp=*/nullptr,
|
|
|
|
|
source_dir)) {
|
2015-06-16 18:31:04 +00:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
|
|
|
|
} else {
|
|
|
|
|
result.AppendErrorWithFormat("module importing failed: %s",
|
|
|
|
|
error.AsCString());
|
2011-10-17 21:45:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-08-16 23:24:13 +00:00
|
|
|
return result.Succeeded();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
CommandOptions m_options;
|
2011-11-07 22:57:04 +00:00
|
|
|
};
|
|
|
|
|
|
2019-07-18 14:10:49 +00:00
|
|
|
#define LLDB_OPTIONS_script_add
|
|
|
|
|
#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-22 20:22:55 +00:00
|
|
|
|
2014-01-27 23:43:24 +00:00
|
|
|
class CommandObjectCommandsScriptAdd : public CommandObjectParsed,
|
|
|
|
|
public IOHandlerDelegateMultiline {
|
2012-06-08 21:56:10 +00:00
|
|
|
public:
|
|
|
|
|
CommandObjectCommandsScriptAdd(CommandInterpreter &interpreter)
|
2016-02-22 23:46:47 +00:00
|
|
|
: CommandObjectParsed(interpreter, "command script add",
|
|
|
|
|
"Add a scripted function as an LLDB command.",
|
2021-10-12 10:55:24 -07:00
|
|
|
"Add a scripted function as an lldb command. "
|
|
|
|
|
"If you provide a single argument, the command "
|
|
|
|
|
"will be added at the root level of the command "
|
|
|
|
|
"hierarchy. If there are more arguments they "
|
|
|
|
|
"must be a path to a user-added container "
|
|
|
|
|
"command, and the last element will be the new "
|
|
|
|
|
"command name."),
|
2022-01-23 11:07:14 -08:00
|
|
|
IOHandlerDelegateMultiline("DONE") {
|
2012-06-08 21:56:10 +00:00
|
|
|
CommandArgumentEntry arg1;
|
|
|
|
|
CommandArgumentData cmd_arg;
|
2016-02-22 23:46:47 +00:00
|
|
|
|
2021-10-12 10:55:24 -07:00
|
|
|
// This is one or more command names, which form the path to the command
|
|
|
|
|
// you want to add.
|
|
|
|
|
cmd_arg.arg_type = eArgTypeCommand;
|
|
|
|
|
cmd_arg.arg_repetition = eArgRepeatPlus;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
|
// argument entry.
|
|
|
|
|
arg1.push_back(cmd_arg);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
|
m_arguments.push_back(arg1);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:46:47 +00:00
|
|
|
~CommandObjectCommandsScriptAdd() override = default;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-08-27 16:22:29 +00:00
|
|
|
Options *GetOptions() override { return &m_options; }
|
2016-02-22 23:46:47 +00:00
|
|
|
|
2021-10-12 10:55:24 -07:00
|
|
|
void
|
|
|
|
|
HandleArgumentCompletion(CompletionRequest &request,
|
|
|
|
|
OptionElementVector &opt_element_vector) override {
|
|
|
|
|
CommandCompletions::CompleteModifiableCmdPathArgs(m_interpreter, request,
|
|
|
|
|
opt_element_vector);
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
protected:
|
2011-08-16 23:24:13 +00:00
|
|
|
class CommandOptions : public Options {
|
|
|
|
|
public:
|
2022-03-31 13:20:46 -07:00
|
|
|
CommandOptions() = default;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-02-22 23:46:47 +00:00
|
|
|
~CommandOptions() override = default;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
|
|
|
|
|
ExecutionContext *execution_context) override {
|
|
|
|
|
Status error;
|
2012-12-04 00:32:51 +00:00
|
|
|
const int short_option = m_getopt_table[option_idx].val;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-08-16 23:24:13 +00:00
|
|
|
switch (short_option) {
|
|
|
|
|
case 'f':
|
2016-11-12 16:56:47 +00:00
|
|
|
if (!option_arg.empty())
|
2020-01-28 20:23:46 +01:00
|
|
|
m_funct_name = std::string(option_arg);
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
2015-03-13 02:20:41 +00:00
|
|
|
case 'c':
|
2016-11-12 16:56:47 +00:00
|
|
|
if (!option_arg.empty())
|
2020-01-28 20:23:46 +01:00
|
|
|
m_class_name = std::string(option_arg);
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
2014-09-15 17:52:44 +00:00
|
|
|
case 'h':
|
2016-11-12 16:56:47 +00:00
|
|
|
if (!option_arg.empty())
|
2020-01-28 20:23:46 +01:00
|
|
|
m_short_help = std::string(option_arg);
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
2021-10-12 10:55:24 -07:00
|
|
|
case 'o':
|
2022-03-31 14:11:39 -07:00
|
|
|
m_overwrite_lazy = eLazyBoolYes;
|
2021-10-12 10:55:24 -07:00
|
|
|
break;
|
2011-11-07 22:57:04 +00:00
|
|
|
case 's':
|
2014-01-27 23:43:24 +00:00
|
|
|
m_synchronicity =
|
2018-04-10 09:03:59 +00:00
|
|
|
(ScriptedCommandSynchronicity)OptionArgParser::ToOptionEnum(
|
2016-11-12 16:56:47 +00:00
|
|
|
option_arg, GetDefinitions()[option_idx].enum_values, 0, error);
|
2011-11-07 22:57:04 +00:00
|
|
|
if (!error.Success())
|
2011-04-20 22:55:21 +00:00
|
|
|
error.SetErrorStringWithFormat(
|
2016-11-12 16:56:47 +00:00
|
|
|
"unrecognized value for synchronicity '%s'",
|
|
|
|
|
option_arg.str().c_str());
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
2019-08-22 08:08:05 +00:00
|
|
|
llvm_unreachable("Unimplemented option");
|
2011-08-16 23:24:13 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-11-07 22:57:04 +00:00
|
|
|
return error;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-02-22 23:46:47 +00:00
|
|
|
|
2016-08-11 23:51:28 +00:00
|
|
|
void OptionParsingStarting(ExecutionContext *execution_context) override {
|
2015-03-13 02:20:41 +00:00
|
|
|
m_class_name.clear();
|
2014-09-15 17:52:44 +00:00
|
|
|
m_funct_name.clear();
|
|
|
|
|
m_short_help.clear();
|
2022-03-31 14:11:39 -07:00
|
|
|
m_overwrite_lazy = eLazyBoolCalculate;
|
2014-01-27 23:43:24 +00:00
|
|
|
m_synchronicity = eScriptedCommandSynchronicitySynchronous;
|
|
|
|
|
}
|
|
|
|
|
|
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-22 20:22:55 +00:00
|
|
|
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
|
2023-01-09 18:11:07 +01:00
|
|
|
return llvm::ArrayRef(g_script_add_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-22 20:22:55 +00:00
|
|
|
}
|
2014-01-27 23:43:24 +00:00
|
|
|
|
|
|
|
|
// Instance variables to hold the values for command options.
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-03-13 02:20:41 +00:00
|
|
|
std::string m_class_name;
|
2011-08-16 23:24:13 +00:00
|
|
|
std::string m_funct_name;
|
2014-09-15 17:52:44 +00:00
|
|
|
std::string m_short_help;
|
2022-04-06 14:10:40 +03:00
|
|
|
LazyBool m_overwrite_lazy = eLazyBoolCalculate;
|
2014-01-27 23:43:24 +00:00
|
|
|
ScriptedCommandSynchronicity m_synchronicity =
|
|
|
|
|
eScriptedCommandSynchronicitySynchronous;
|
2016-09-06 20:57:50 +00:00
|
|
|
};
|
|
|
|
|
|
Quiet command regex instructions during batch execution
Summary:
Within .lldbinit, regex commands can be structured as a list of substitutions over
multiple lines. It's possible that this is uninentional, but it works and has
benefits.
For example:
command regex <command-name>
s/pat1/repl1/
s/pat2/repl2/
...
I use this form of `command regex` in my `~/.lldbinit`, because it makes it
clearer to write and read compared to a single line definition, because
multiline substitutions don't need to be quoted, and are broken up one per line.
However, multiline definitions result in usage instructions being printed for
each use. The result is that every time I run `lldb`, I get a dozen or more
lines of noise. With this change, the instructions are only printed when
`command regex` is invoked interactively, or from a terminal, neither of which
are true when lldb is sourcing `~/.lldbinit`.
Reviewers: clayborg, jingham
Reviewed By: clayborg
Subscribers: jdoerfert, kastiglione, xiaobai, keith, lldb-commits
Differential Revision: https://reviews.llvm.org/D48752
llvm-svn: 355793
2019-03-10 23:15:48 +00:00
|
|
|
void IOHandlerActivated(IOHandler &io_handler, bool interactive) override {
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 14:33:35 +00:00
|
|
|
StreamFileSP output_sp(io_handler.GetOutputStreamFileSP());
|
Quiet command regex instructions during batch execution
Summary:
Within .lldbinit, regex commands can be structured as a list of substitutions over
multiple lines. It's possible that this is uninentional, but it works and has
benefits.
For example:
command regex <command-name>
s/pat1/repl1/
s/pat2/repl2/
...
I use this form of `command regex` in my `~/.lldbinit`, because it makes it
clearer to write and read compared to a single line definition, because
multiline substitutions don't need to be quoted, and are broken up one per line.
However, multiline definitions result in usage instructions being printed for
each use. The result is that every time I run `lldb`, I get a dozen or more
lines of noise. With this change, the instructions are only printed when
`command regex` is invoked interactively, or from a terminal, neither of which
are true when lldb is sourcing `~/.lldbinit`.
Reviewers: clayborg, jingham
Reviewed By: clayborg
Subscribers: jdoerfert, kastiglione, xiaobai, keith, lldb-commits
Differential Revision: https://reviews.llvm.org/D48752
llvm-svn: 355793
2019-03-10 23:15:48 +00:00
|
|
|
if (output_sp && interactive) {
|
2014-01-27 23:43:24 +00:00
|
|
|
output_sp->PutCString(g_python_command_instructions);
|
|
|
|
|
output_sp->Flush();
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-07 16:56:17 +00:00
|
|
|
void IOHandlerInputComplete(IOHandler &io_handler,
|
|
|
|
|
std::string &data) override {
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 14:33:35 +00:00
|
|
|
StreamFileSP error_sp = io_handler.GetErrorStreamFileSP();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-04-26 22:43:16 +00:00
|
|
|
ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
|
2014-01-27 23:43:24 +00:00
|
|
|
if (interpreter) {
|
|
|
|
|
StringList lines;
|
|
|
|
|
lines.SplitIntoLines(data);
|
|
|
|
|
if (lines.GetSize() > 0) {
|
|
|
|
|
std::string funct_name_str;
|
|
|
|
|
if (interpreter->GenerateScriptAliasFunction(lines, funct_name_str)) {
|
|
|
|
|
if (funct_name_str.empty()) {
|
|
|
|
|
error_sp->Printf("error: unable to obtain a function name, didn't "
|
|
|
|
|
"add python command.\n");
|
|
|
|
|
error_sp->Flush();
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2014-01-27 23:43:24 +00:00
|
|
|
// everything should be fine now, let's add this alias
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-01-27 23:43:24 +00:00
|
|
|
CommandObjectSP command_obj_sp(new CommandObjectPythonFunction(
|
2016-11-02 20:34:10 +00:00
|
|
|
m_interpreter, m_cmd_name, funct_name_str, m_short_help,
|
2014-01-27 23:43:24 +00:00
|
|
|
m_synchronicity));
|
2021-10-12 10:55:24 -07:00
|
|
|
if (!m_container) {
|
|
|
|
|
Status error = m_interpreter.AddUserCommand(
|
|
|
|
|
m_cmd_name, command_obj_sp, m_overwrite);
|
|
|
|
|
if (error.Fail()) {
|
|
|
|
|
error_sp->Printf("error: unable to add selected command: '%s'",
|
|
|
|
|
error.AsCString());
|
|
|
|
|
error_sp->Flush();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
llvm::Error llvm_error = m_container->LoadUserSubcommand(
|
|
|
|
|
m_cmd_name, command_obj_sp, m_overwrite);
|
|
|
|
|
if (llvm_error) {
|
|
|
|
|
error_sp->Printf("error: unable to add selected command: '%s'",
|
|
|
|
|
llvm::toString(std::move(llvm_error)).c_str());
|
|
|
|
|
error_sp->Flush();
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2014-01-27 23:43:24 +00:00
|
|
|
error_sp->Printf(
|
2021-10-12 10:55:24 -07:00
|
|
|
"error: unable to create function, didn't add python command\n");
|
2014-01-27 23:43:24 +00:00
|
|
|
error_sp->Flush();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2021-10-12 10:55:24 -07:00
|
|
|
error_sp->Printf("error: empty function, didn't add python command\n");
|
2014-01-27 23:43:24 +00:00
|
|
|
error_sp->Flush();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2014-01-27 23:43:24 +00:00
|
|
|
error_sp->Printf(
|
2021-10-12 10:55:24 -07:00
|
|
|
"error: script interpreter missing, didn't add python command\n");
|
2014-01-27 23:43:24 +00:00
|
|
|
error_sp->Flush();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2014-01-27 23:43:24 +00:00
|
|
|
io_handler.SetIsDone(true);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2014-01-27 23:43:24 +00:00
|
|
|
|
2015-10-07 16:56:17 +00:00
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
2019-04-27 06:19:42 +00:00
|
|
|
if (GetDebugger().GetScriptLanguage() != lldb::eScriptLanguagePython) {
|
2015-03-13 02:20:41 +00:00
|
|
|
result.AppendError("only scripting language supported for scripted "
|
|
|
|
|
"commands is currently Python");
|
|
|
|
|
return false;
|
2011-08-16 23:24:13 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-12 10:55:24 -07:00
|
|
|
if (command.GetArgumentCount() == 0) {
|
|
|
|
|
result.AppendError("'command script add' requires at least one argument");
|
2011-10-17 21:45:27 +00:00
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2022-03-31 14:11:39 -07:00
|
|
|
// Store the options in case we get multi-line input, also figure out the
|
|
|
|
|
// default if not user supplied:
|
|
|
|
|
switch (m_options.m_overwrite_lazy) {
|
|
|
|
|
case eLazyBoolCalculate:
|
|
|
|
|
m_overwrite = !GetDebugger().GetCommandInterpreter().GetRequireCommandOverwrite();
|
|
|
|
|
break;
|
|
|
|
|
case eLazyBoolYes:
|
|
|
|
|
m_overwrite = true;
|
|
|
|
|
break;
|
|
|
|
|
case eLazyBoolNo:
|
|
|
|
|
m_overwrite = false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-12 10:55:24 -07:00
|
|
|
Status path_error;
|
|
|
|
|
m_container = GetCommandInterpreter().VerifyUserMultiwordCmdPath(
|
|
|
|
|
command, true, path_error);
|
|
|
|
|
|
|
|
|
|
if (path_error.Fail()) {
|
|
|
|
|
result.AppendErrorWithFormat("error in command path: %s",
|
|
|
|
|
path_error.AsCString());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_container) {
|
|
|
|
|
// This is getting inserted into the root of the interpreter.
|
|
|
|
|
m_cmd_name = std::string(command[0].ref());
|
|
|
|
|
} else {
|
|
|
|
|
size_t num_args = command.GetArgumentCount();
|
|
|
|
|
m_cmd_name = std::string(command[num_args - 1].ref());
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-15 17:52:44 +00:00
|
|
|
m_short_help.assign(m_options.m_short_help);
|
2014-01-27 23:43:24 +00:00
|
|
|
m_synchronicity = m_options.m_synchronicity;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2021-10-12 10:55:24 -07:00
|
|
|
// Handle the case where we prompt for the script code first:
|
|
|
|
|
if (m_options.m_class_name.empty() && m_options.m_funct_name.empty()) {
|
|
|
|
|
m_interpreter.GetPythonCommandsFromIOHandler(" ", // Prompt
|
|
|
|
|
*this); // IOHandlerDelegate
|
|
|
|
|
return result.Succeeded();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CommandObjectSP new_cmd_sp;
|
2015-03-13 02:20:41 +00:00
|
|
|
if (m_options.m_class_name.empty()) {
|
2021-10-12 10:55:24 -07:00
|
|
|
new_cmd_sp.reset(new CommandObjectPythonFunction(
|
|
|
|
|
m_interpreter, m_cmd_name, m_options.m_funct_name,
|
|
|
|
|
m_options.m_short_help, m_synchronicity));
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2019-04-26 22:43:16 +00:00
|
|
|
ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
|
2015-03-13 02:20:41 +00:00
|
|
|
if (!interpreter) {
|
|
|
|
|
result.AppendError("cannot find ScriptInterpreter");
|
2011-10-17 21:45:27 +00:00
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-13 02:20:41 +00:00
|
|
|
auto cmd_obj_sp = interpreter->CreateScriptCommandObject(
|
|
|
|
|
m_options.m_class_name.c_str());
|
|
|
|
|
if (!cmd_obj_sp) {
|
|
|
|
|
result.AppendError("cannot create helper object");
|
2011-10-17 21:45:27 +00:00
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-12 10:55:24 -07:00
|
|
|
new_cmd_sp.reset(new CommandObjectScriptingObject(
|
2014-01-27 23:43:24 +00:00
|
|
|
m_interpreter, m_cmd_name, cmd_obj_sp, m_synchronicity));
|
2011-08-16 23:24:13 +00:00
|
|
|
}
|
2021-10-12 10:55:24 -07:00
|
|
|
|
|
|
|
|
// Assume we're going to succeed...
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
|
|
|
|
if (!m_container) {
|
|
|
|
|
Status add_error =
|
|
|
|
|
m_interpreter.AddUserCommand(m_cmd_name, new_cmd_sp, m_overwrite);
|
|
|
|
|
if (add_error.Fail())
|
|
|
|
|
result.AppendErrorWithFormat("cannot add command: %s",
|
|
|
|
|
add_error.AsCString());
|
|
|
|
|
} else {
|
|
|
|
|
llvm::Error llvm_error =
|
|
|
|
|
m_container->LoadUserSubcommand(m_cmd_name, new_cmd_sp, m_overwrite);
|
|
|
|
|
if (llvm_error)
|
|
|
|
|
result.AppendErrorWithFormat("cannot add command: %s",
|
|
|
|
|
llvm::toString(std::move(llvm_error)).c_str());
|
|
|
|
|
}
|
2011-11-07 22:57:04 +00:00
|
|
|
return result.Succeeded();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-07 22:57:04 +00:00
|
|
|
CommandOptions m_options;
|
|
|
|
|
std::string m_cmd_name;
|
2021-10-12 10:55:24 -07:00
|
|
|
CommandObjectMultiword *m_container = nullptr;
|
2011-11-07 22:57:04 +00:00
|
|
|
std::string m_short_help;
|
2022-04-06 14:10:40 +03:00
|
|
|
bool m_overwrite = false;
|
2022-02-17 20:51:01 -08:00
|
|
|
ScriptedCommandSynchronicity m_synchronicity =
|
|
|
|
|
eScriptedCommandSynchronicitySynchronous;
|
2011-11-07 22:57:04 +00:00
|
|
|
};
|
|
|
|
|
|
2011-08-16 23:24:13 +00:00
|
|
|
// CommandObjectCommandsScriptList
|
|
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
class CommandObjectCommandsScriptList : public CommandObjectParsed {
|
2011-08-16 23:24:13 +00:00
|
|
|
public:
|
|
|
|
|
CommandObjectCommandsScriptList(CommandInterpreter &interpreter)
|
2016-02-22 23:46:47 +00:00
|
|
|
: CommandObjectParsed(interpreter, "command script list",
|
2021-10-12 10:55:24 -07:00
|
|
|
"List defined top-level scripted commands.",
|
|
|
|
|
nullptr) {}
|
2016-02-22 23:46:47 +00:00
|
|
|
|
|
|
|
|
~CommandObjectCommandsScriptList() override = default;
|
|
|
|
|
|
2015-10-07 16:56:17 +00:00
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
2011-08-16 23:24:13 +00:00
|
|
|
m_interpreter.GetHelp(result, CommandInterpreter::eCommandTypesUserDef);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-08-16 23:24:13 +00:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-08-16 23:24:13 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// CommandObjectCommandsScriptClear
|
|
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
class CommandObjectCommandsScriptClear : public CommandObjectParsed {
|
2011-08-16 23:24:13 +00:00
|
|
|
public:
|
|
|
|
|
CommandObjectCommandsScriptClear(CommandInterpreter &interpreter)
|
2016-02-22 23:46:47 +00:00
|
|
|
: CommandObjectParsed(interpreter, "command script clear",
|
|
|
|
|
"Delete all scripted commands.", nullptr) {}
|
|
|
|
|
|
|
|
|
|
~CommandObjectCommandsScriptClear() override = default;
|
|
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
protected:
|
2015-10-07 16:56:17 +00:00
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
2011-08-16 23:24:13 +00:00
|
|
|
m_interpreter.RemoveAllUser();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-08-16 23:24:13 +00:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-08-16 23:24:13 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// CommandObjectCommandsScriptDelete
|
|
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
class CommandObjectCommandsScriptDelete : public CommandObjectParsed {
|
2011-08-16 23:24:13 +00:00
|
|
|
public:
|
|
|
|
|
CommandObjectCommandsScriptDelete(CommandInterpreter &interpreter)
|
2021-10-12 10:55:24 -07:00
|
|
|
: CommandObjectParsed(
|
|
|
|
|
interpreter, "command script delete",
|
|
|
|
|
"Delete a scripted command by specifying the path to the command.",
|
|
|
|
|
nullptr) {
|
2011-08-16 23:24:13 +00:00
|
|
|
CommandArgumentEntry arg1;
|
|
|
|
|
CommandArgumentData cmd_arg;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2021-10-12 10:55:24 -07:00
|
|
|
// This is a list of command names forming the path to the command
|
|
|
|
|
// to be deleted.
|
|
|
|
|
cmd_arg.arg_type = eArgTypeCommand;
|
|
|
|
|
cmd_arg.arg_repetition = eArgRepeatPlus;
|
2016-02-22 23:46:47 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
|
// argument entry.
|
|
|
|
|
arg1.push_back(cmd_arg);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
|
m_arguments.push_back(arg1);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:46:47 +00:00
|
|
|
~CommandObjectCommandsScriptDelete() override = default;
|
|
|
|
|
|
2020-06-04 09:53:05 +02:00
|
|
|
void
|
|
|
|
|
HandleArgumentCompletion(CompletionRequest &request,
|
|
|
|
|
OptionElementVector &opt_element_vector) override {
|
2021-10-12 10:55:24 -07:00
|
|
|
CommandCompletions::CompleteModifiableCmdPathArgs(m_interpreter, request,
|
|
|
|
|
opt_element_vector);
|
2020-06-04 09:53:05 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
protected:
|
2015-10-07 16:56:17 +00:00
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2021-10-12 10:55:24 -07:00
|
|
|
llvm::StringRef root_cmd = command[0].ref();
|
|
|
|
|
size_t num_args = command.GetArgumentCount();
|
|
|
|
|
|
|
|
|
|
if (root_cmd.empty()) {
|
|
|
|
|
result.AppendErrorWithFormat("empty root command name");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!m_interpreter.HasUserCommands() &&
|
|
|
|
|
!m_interpreter.HasUserMultiwordCommands()) {
|
|
|
|
|
result.AppendErrorWithFormat("can only delete user defined commands, "
|
|
|
|
|
"but no user defined commands found");
|
2011-08-16 23:24:13 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2021-10-12 10:55:24 -07:00
|
|
|
CommandObjectSP cmd_sp = m_interpreter.GetCommandSPExact(root_cmd);
|
|
|
|
|
if (!cmd_sp) {
|
|
|
|
|
result.AppendErrorWithFormat("command '%s' not found.",
|
|
|
|
|
command[0].c_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!cmd_sp->IsUserCommand()) {
|
|
|
|
|
result.AppendErrorWithFormat("command '%s' is not a user command.",
|
|
|
|
|
command[0].c_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (cmd_sp->GetAsMultiwordCommand() && num_args == 1) {
|
|
|
|
|
result.AppendErrorWithFormat("command '%s' is a multi-word command.\n "
|
|
|
|
|
"Delete with \"command container delete\"",
|
|
|
|
|
command[0].c_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2021-10-12 10:55:24 -07:00
|
|
|
if (command.GetArgumentCount() == 1) {
|
|
|
|
|
m_interpreter.RemoveUser(root_cmd);
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// We're deleting a command from a multiword command. Verify the command
|
|
|
|
|
// path:
|
|
|
|
|
Status error;
|
|
|
|
|
CommandObjectMultiword *container =
|
|
|
|
|
GetCommandInterpreter().VerifyUserMultiwordCmdPath(command, true,
|
|
|
|
|
error);
|
|
|
|
|
if (error.Fail()) {
|
|
|
|
|
result.AppendErrorWithFormat("could not resolve command path: %s",
|
|
|
|
|
error.AsCString());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!container) {
|
|
|
|
|
// This means that command only had a leaf command, so the container is
|
|
|
|
|
// the root. That should have been handled above.
|
|
|
|
|
result.AppendErrorWithFormat("could not find a container for '%s'",
|
|
|
|
|
command[0].c_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
const char *leaf_cmd = command[num_args - 1].c_str();
|
|
|
|
|
llvm::Error llvm_error = container->RemoveUserSubcommand(leaf_cmd,
|
|
|
|
|
/* multiword not okay */ false);
|
|
|
|
|
if (llvm_error) {
|
|
|
|
|
result.AppendErrorWithFormat("could not delete command '%s': %s",
|
|
|
|
|
leaf_cmd,
|
|
|
|
|
llvm::toString(std::move(llvm_error)).c_str());
|
2016-12-08 01:31:04 +00:00
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-12 10:55:24 -07:00
|
|
|
Stream &out_stream = result.GetOutputStream();
|
|
|
|
|
|
|
|
|
|
out_stream << "Deleted command:";
|
|
|
|
|
for (size_t idx = 0; idx < num_args; idx++) {
|
|
|
|
|
out_stream << ' ';
|
|
|
|
|
out_stream << command[idx].c_str();
|
|
|
|
|
}
|
|
|
|
|
out_stream << '\n';
|
2016-12-08 01:31:04 +00:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
|
return true;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2011-08-16 23:24:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#pragma mark CommandObjectMultiwordCommandsScript
|
|
|
|
|
|
|
|
|
|
// CommandObjectMultiwordCommandsScript
|
|
|
|
|
|
|
|
|
|
class CommandObjectMultiwordCommandsScript : public CommandObjectMultiword {
|
|
|
|
|
public:
|
2016-07-14 22:03:10 +00:00
|
|
|
CommandObjectMultiwordCommandsScript(CommandInterpreter &interpreter)
|
|
|
|
|
: CommandObjectMultiword(
|
2019-10-30 15:26:19 -07:00
|
|
|
interpreter, "command script",
|
|
|
|
|
"Commands for managing custom "
|
|
|
|
|
"commands implemented by "
|
|
|
|
|
"interpreter scripts.",
|
2016-07-14 22:03:10 +00:00
|
|
|
"command script <subcommand> [<subcommand-options>]") {
|
2015-01-09 19:08:20 +00:00
|
|
|
LoadSubCommand("add", CommandObjectSP(
|
|
|
|
|
new CommandObjectCommandsScriptAdd(interpreter)));
|
|
|
|
|
LoadSubCommand(
|
|
|
|
|
"delete",
|
|
|
|
|
CommandObjectSP(new CommandObjectCommandsScriptDelete(interpreter)));
|
|
|
|
|
LoadSubCommand(
|
|
|
|
|
"clear",
|
|
|
|
|
CommandObjectSP(new CommandObjectCommandsScriptClear(interpreter)));
|
2011-08-16 23:24:13 +00:00
|
|
|
LoadSubCommand("list", CommandObjectSP(new CommandObjectCommandsScriptList(
|
|
|
|
|
interpreter)));
|
2015-01-09 19:08:20 +00:00
|
|
|
LoadSubCommand(
|
|
|
|
|
"import",
|
|
|
|
|
CommandObjectSP(new CommandObjectCommandsScriptImport(interpreter)));
|
2011-08-16 23:24:13 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-02-22 23:46:47 +00:00
|
|
|
~CommandObjectMultiwordCommandsScript() override = default;
|
2011-08-16 23:24:13 +00:00
|
|
|
};
|
|
|
|
|
|
2021-10-12 10:55:24 -07:00
|
|
|
#pragma mark CommandObjectCommandContainer
|
|
|
|
|
#define LLDB_OPTIONS_container_add
|
|
|
|
|
#include "CommandOptions.inc"
|
|
|
|
|
|
|
|
|
|
class CommandObjectCommandsContainerAdd : public CommandObjectParsed {
|
|
|
|
|
public:
|
|
|
|
|
CommandObjectCommandsContainerAdd(CommandInterpreter &interpreter)
|
|
|
|
|
: CommandObjectParsed(
|
|
|
|
|
interpreter, "command container add",
|
|
|
|
|
"Add a container command to lldb. Adding to built-"
|
|
|
|
|
"in container commands is not allowed.",
|
|
|
|
|
"command container add [[path1]...] container-name") {
|
|
|
|
|
CommandArgumentEntry arg1;
|
|
|
|
|
CommandArgumentData cmd_arg;
|
|
|
|
|
|
|
|
|
|
// This is one or more command names, which form the path to the command
|
|
|
|
|
// you want to add.
|
|
|
|
|
cmd_arg.arg_type = eArgTypeCommand;
|
|
|
|
|
cmd_arg.arg_repetition = eArgRepeatPlus;
|
|
|
|
|
|
|
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
|
// argument entry.
|
|
|
|
|
arg1.push_back(cmd_arg);
|
|
|
|
|
|
|
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
|
m_arguments.push_back(arg1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~CommandObjectCommandsContainerAdd() override = default;
|
|
|
|
|
|
|
|
|
|
Options *GetOptions() override { return &m_options; }
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
HandleArgumentCompletion(CompletionRequest &request,
|
|
|
|
|
OptionElementVector &opt_element_vector) override {
|
|
|
|
|
CommandCompletions::CompleteModifiableCmdPathArgs(m_interpreter, request,
|
|
|
|
|
opt_element_vector);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
class CommandOptions : public Options {
|
|
|
|
|
public:
|
2022-03-31 13:20:46 -07:00
|
|
|
CommandOptions() = default;
|
2021-10-12 10:55:24 -07:00
|
|
|
|
|
|
|
|
~CommandOptions() override = default;
|
|
|
|
|
|
|
|
|
|
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
|
|
|
|
|
ExecutionContext *execution_context) override {
|
|
|
|
|
Status error;
|
|
|
|
|
const int short_option = m_getopt_table[option_idx].val;
|
|
|
|
|
|
|
|
|
|
switch (short_option) {
|
|
|
|
|
case 'h':
|
|
|
|
|
if (!option_arg.empty())
|
|
|
|
|
m_short_help = std::string(option_arg);
|
|
|
|
|
break;
|
|
|
|
|
case 'o':
|
|
|
|
|
m_overwrite = true;
|
|
|
|
|
break;
|
|
|
|
|
case 'H':
|
|
|
|
|
if (!option_arg.empty())
|
|
|
|
|
m_long_help = std::string(option_arg);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
llvm_unreachable("Unimplemented option");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OptionParsingStarting(ExecutionContext *execution_context) override {
|
|
|
|
|
m_short_help.clear();
|
|
|
|
|
m_long_help.clear();
|
|
|
|
|
m_overwrite = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
|
2023-01-09 18:11:07 +01:00
|
|
|
return llvm::ArrayRef(g_container_add_options);
|
2021-10-12 10:55:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Instance variables to hold the values for command options.
|
|
|
|
|
|
|
|
|
|
std::string m_short_help;
|
|
|
|
|
std::string m_long_help;
|
|
|
|
|
bool m_overwrite = false;
|
|
|
|
|
};
|
|
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
|
|
|
|
size_t num_args = command.GetArgumentCount();
|
|
|
|
|
|
|
|
|
|
if (num_args == 0) {
|
|
|
|
|
result.AppendError("no command was specified");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (num_args == 1) {
|
|
|
|
|
// We're adding this as a root command, so use the interpreter.
|
|
|
|
|
const char *cmd_name = command.GetArgumentAtIndex(0);
|
|
|
|
|
auto cmd_sp = CommandObjectSP(new CommandObjectMultiword(
|
|
|
|
|
GetCommandInterpreter(), cmd_name, m_options.m_short_help.c_str(),
|
|
|
|
|
m_options.m_long_help.c_str()));
|
|
|
|
|
cmd_sp->GetAsMultiwordCommand()->SetRemovable(true);
|
|
|
|
|
Status add_error = GetCommandInterpreter().AddUserCommand(
|
|
|
|
|
cmd_name, cmd_sp, m_options.m_overwrite);
|
|
|
|
|
if (add_error.Fail()) {
|
|
|
|
|
result.AppendErrorWithFormat("error adding command: %s",
|
|
|
|
|
add_error.AsCString());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We're adding this to a subcommand, first find the subcommand:
|
|
|
|
|
Status path_error;
|
|
|
|
|
CommandObjectMultiword *add_to_me =
|
|
|
|
|
GetCommandInterpreter().VerifyUserMultiwordCmdPath(command, true,
|
|
|
|
|
path_error);
|
|
|
|
|
|
|
|
|
|
if (!add_to_me) {
|
|
|
|
|
result.AppendErrorWithFormat("error adding command: %s",
|
|
|
|
|
path_error.AsCString());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *cmd_name = command.GetArgumentAtIndex(num_args - 1);
|
|
|
|
|
auto cmd_sp = CommandObjectSP(new CommandObjectMultiword(
|
|
|
|
|
GetCommandInterpreter(), cmd_name, m_options.m_short_help.c_str(),
|
|
|
|
|
m_options.m_long_help.c_str()));
|
|
|
|
|
llvm::Error llvm_error =
|
|
|
|
|
add_to_me->LoadUserSubcommand(cmd_name, cmd_sp, m_options.m_overwrite);
|
|
|
|
|
if (llvm_error) {
|
|
|
|
|
result.AppendErrorWithFormat("error adding subcommand: %s",
|
|
|
|
|
llvm::toString(std::move(llvm_error)).c_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
CommandOptions m_options;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define LLDB_OPTIONS_multiword_delete
|
|
|
|
|
#include "CommandOptions.inc"
|
|
|
|
|
class CommandObjectCommandsContainerDelete : public CommandObjectParsed {
|
|
|
|
|
public:
|
|
|
|
|
CommandObjectCommandsContainerDelete(CommandInterpreter &interpreter)
|
|
|
|
|
: CommandObjectParsed(
|
|
|
|
|
interpreter, "command container delete",
|
|
|
|
|
"Delete a container command previously added to "
|
|
|
|
|
"lldb.",
|
|
|
|
|
"command container delete [[path1] ...] container-cmd") {
|
|
|
|
|
CommandArgumentEntry arg1;
|
|
|
|
|
CommandArgumentData cmd_arg;
|
|
|
|
|
|
|
|
|
|
// This is one or more command names, which form the path to the command
|
|
|
|
|
// you want to add.
|
|
|
|
|
cmd_arg.arg_type = eArgTypeCommand;
|
|
|
|
|
cmd_arg.arg_repetition = eArgRepeatPlus;
|
|
|
|
|
|
|
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
|
// argument entry.
|
|
|
|
|
arg1.push_back(cmd_arg);
|
|
|
|
|
|
|
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
|
m_arguments.push_back(arg1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~CommandObjectCommandsContainerDelete() override = default;
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
HandleArgumentCompletion(CompletionRequest &request,
|
|
|
|
|
OptionElementVector &opt_element_vector) override {
|
|
|
|
|
CommandCompletions::CompleteModifiableCmdPathArgs(m_interpreter, request,
|
|
|
|
|
opt_element_vector);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
|
|
|
|
size_t num_args = command.GetArgumentCount();
|
|
|
|
|
|
|
|
|
|
if (num_args == 0) {
|
|
|
|
|
result.AppendError("No command was specified.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (num_args == 1) {
|
|
|
|
|
// We're removing a root command, so we need to delete it from the
|
|
|
|
|
// interpreter.
|
|
|
|
|
const char *cmd_name = command.GetArgumentAtIndex(0);
|
|
|
|
|
// Let's do a little more work here so we can do better error reporting.
|
|
|
|
|
CommandInterpreter &interp = GetCommandInterpreter();
|
|
|
|
|
CommandObjectSP cmd_sp = interp.GetCommandSPExact(cmd_name);
|
|
|
|
|
if (!cmd_sp) {
|
|
|
|
|
result.AppendErrorWithFormat("container command %s doesn't exist.",
|
|
|
|
|
cmd_name);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!cmd_sp->IsUserCommand()) {
|
|
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
|
"container command %s is not a user command", cmd_name);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!cmd_sp->GetAsMultiwordCommand()) {
|
|
|
|
|
result.AppendErrorWithFormat("command %s is not a container command",
|
|
|
|
|
cmd_name);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool did_remove = GetCommandInterpreter().RemoveUserMultiword(cmd_name);
|
|
|
|
|
if (!did_remove) {
|
|
|
|
|
result.AppendErrorWithFormat("error removing command %s.", cmd_name);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We're removing a subcommand, first find the subcommand's owner:
|
|
|
|
|
Status path_error;
|
|
|
|
|
CommandObjectMultiword *container =
|
|
|
|
|
GetCommandInterpreter().VerifyUserMultiwordCmdPath(command, true,
|
|
|
|
|
path_error);
|
|
|
|
|
|
|
|
|
|
if (!container) {
|
|
|
|
|
result.AppendErrorWithFormat("error removing container command: %s",
|
|
|
|
|
path_error.AsCString());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
const char *leaf = command.GetArgumentAtIndex(num_args - 1);
|
|
|
|
|
llvm::Error llvm_error =
|
|
|
|
|
container->RemoveUserSubcommand(leaf, /* multiword okay */ true);
|
|
|
|
|
if (llvm_error) {
|
|
|
|
|
result.AppendErrorWithFormat("error removing container command: %s",
|
|
|
|
|
llvm::toString(std::move(llvm_error)).c_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CommandObjectCommandContainer : public CommandObjectMultiword {
|
|
|
|
|
public:
|
|
|
|
|
CommandObjectCommandContainer(CommandInterpreter &interpreter)
|
|
|
|
|
: CommandObjectMultiword(
|
|
|
|
|
interpreter, "command container",
|
|
|
|
|
"Commands for adding container commands to lldb. "
|
2022-05-21 12:26:22 +02:00
|
|
|
"Container commands are containers for other commands. You can "
|
|
|
|
|
"add nested container commands by specifying a command path, "
|
2021-10-12 10:55:24 -07:00
|
|
|
"but you can't add commands into the built-in command hierarchy.",
|
|
|
|
|
"command container <subcommand> [<subcommand-options>]") {
|
|
|
|
|
LoadSubCommand("add", CommandObjectSP(new CommandObjectCommandsContainerAdd(
|
|
|
|
|
interpreter)));
|
|
|
|
|
LoadSubCommand(
|
|
|
|
|
"delete",
|
|
|
|
|
CommandObjectSP(new CommandObjectCommandsContainerDelete(interpreter)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~CommandObjectCommandContainer() override = default;
|
|
|
|
|
};
|
|
|
|
|
|
2010-07-07 03:36:20 +00:00
|
|
|
#pragma mark CommandObjectMultiwordCommands
|
|
|
|
|
|
|
|
|
|
// CommandObjectMultiwordCommands
|
|
|
|
|
|
2016-07-14 22:03:10 +00:00
|
|
|
CommandObjectMultiwordCommands::CommandObjectMultiwordCommands(
|
|
|
|
|
CommandInterpreter &interpreter)
|
|
|
|
|
: CommandObjectMultiword(interpreter, "command",
|
|
|
|
|
"Commands for managing custom LLDB commands.",
|
|
|
|
|
"command <subcommand> [<subcommand-options>]") {
|
2010-09-18 01:14:36 +00:00
|
|
|
LoadSubCommand("source",
|
|
|
|
|
CommandObjectSP(new CommandObjectCommandsSource(interpreter)));
|
|
|
|
|
LoadSubCommand("alias",
|
|
|
|
|
CommandObjectSP(new CommandObjectCommandsAlias(interpreter)));
|
|
|
|
|
LoadSubCommand("unalias", CommandObjectSP(
|
|
|
|
|
new CommandObjectCommandsUnalias(interpreter)));
|
2015-01-09 19:08:20 +00:00
|
|
|
LoadSubCommand("delete",
|
|
|
|
|
CommandObjectSP(new CommandObjectCommandsDelete(interpreter)));
|
2021-10-12 10:55:24 -07:00
|
|
|
LoadSubCommand("container", CommandObjectSP(new CommandObjectCommandContainer(
|
|
|
|
|
interpreter)));
|
2011-04-20 16:37:46 +00:00
|
|
|
LoadSubCommand(
|
|
|
|
|
"regex", CommandObjectSP(new CommandObjectCommandsAddRegex(interpreter)));
|
2015-01-09 19:08:20 +00:00
|
|
|
LoadSubCommand(
|
|
|
|
|
"script",
|
|
|
|
|
CommandObjectSP(new CommandObjectMultiwordCommandsScript(interpreter)));
|
2010-07-07 03:36:20 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:46:47 +00:00
|
|
|
CommandObjectMultiwordCommands::~CommandObjectMultiwordCommands() = default;
|