2010-06-09 00:52:24 +08:00
|
|
|
//===-- CommandObjectExpression.h -------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-02-18 07:57:45 +08:00
|
|
|
#ifndef LLDB_SOURCE_COMMANDS_COMMANDOBJECTEXPRESSION_H
|
|
|
|
#define LLDB_SOURCE_COMMANDS_COMMANDOBJECTEXPRESSION_H
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
#include "lldb/Core/IOHandler.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Interpreter/CommandObject.h"
|
2015-10-20 08:55:21 +08:00
|
|
|
#include "lldb/Interpreter/OptionGroupBoolean.h"
|
2011-10-25 14:44:01 +08:00
|
|
|
#include "lldb/Interpreter/OptionGroupFormat.h"
|
2013-01-10 04:12:53 +08:00
|
|
|
#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
|
2020-03-07 10:27:46 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2016-03-25 09:57:14 +08:00
|
|
|
#include "lldb/lldb-private-enumerations.h"
|
2020-03-07 10:27:46 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
namespace lldb_private {
|
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
class CommandObjectExpression : public CommandObjectRaw,
|
|
|
|
public IOHandlerDelegate {
|
2010-06-09 00:52:24 +08:00
|
|
|
public:
|
2011-10-25 14:44:01 +08:00
|
|
|
class CommandOptions : public OptionGroup {
|
2016-09-07 04:57:50 +08:00
|
|
|
public:
|
2011-10-25 14:44:01 +08:00
|
|
|
CommandOptions();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-02 17:33:09 +08:00
|
|
|
~CommandOptions() override;
|
2016-09-07 04:57:50 +08: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-23 04:22:55 +08:00
|
|
|
llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
|
|
|
|
ExecutionContext *execution_context) override;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-08-12 07:51:28 +08:00
|
|
|
void OptionParsingStarting(ExecutionContext *execution_context) override;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-03-29 05:20:05 +08:00
|
|
|
bool top_level;
|
2010-11-06 03:25:48 +08:00
|
|
|
bool unwind_on_error;
|
2013-01-15 10:47:48 +08:00
|
|
|
bool ignore_breakpoints;
|
2016-05-13 04:00:53 +08:00
|
|
|
bool allow_jit;
|
2010-06-09 00:52:24 +08:00
|
|
|
bool show_types;
|
|
|
|
bool show_summary;
|
2013-11-05 03:35:17 +08:00
|
|
|
bool debug;
|
2012-10-17 05:41:58 +08:00
|
|
|
uint32_t timeout;
|
|
|
|
bool try_all_threads;
|
2015-07-25 08:19:39 +08:00
|
|
|
lldb::LanguageType language;
|
<rdar://problem/14393032>
DumpValueObject() 2.0
This checkin restores pre-Xcode5 functionality to the "po" (expr -O) command:
- expr now has a new --description-verbosity (-v) argument, which takes either compact or full as a value (-v is the same as -vfull)
When the full mode is on, "po" will show the extended output with type name, persistent variable name and value, as in
(lldb) expr -O -v -- foo
(id) $0 = 0x000000010010baf0 {
1 = 2;
2 = 3;
}
When -v is omitted, or -vcompact is passed, the Xcode5-style output will be shown, as in
(lldb) expr -O -- foo
{
1 = 2;
2 = 3;
}
- for a non-ObjectiveC object, LLDB will still try to retrieve a summary and/or value to display
(lldb) po 5
5
-v also works in this mode
(lldb) expr -O -vfull -- 5
(int) $4 = 5
On top of that, this is a major refactoring of the ValueObject printing code. The functionality is now factored into a ValueObjectPrinter class for easier maintenance in the future
DumpValueObject() was turned into an instance method ValueObject::Dump() which simply calls through to the printer code, Dump_Impl has been removed
Test case to follow
llvm-svn: 191694
2013-10-01 03:11:51 +08:00
|
|
|
LanguageRuntimeDescriptionDisplayVerbosity m_verbosity;
|
2016-03-25 09:57:14 +08:00
|
|
|
LazyBool auto_apply_fixits;
|
2016-09-07 04:57:50 +08:00
|
|
|
};
|
|
|
|
|
2010-09-18 09:14:36 +08:00
|
|
|
CommandObjectExpression(CommandInterpreter &interpreter);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-02 17:33:09 +08:00
|
|
|
~CommandObjectExpression() override;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-08-12 07:51:28 +08:00
|
|
|
Options *GetOptions() override;
|
2010-06-09 00:52:24 +08: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 15:41:23 +08:00
|
|
|
void HandleCompletion(CompletionRequest &request) override;
|
2018-08-31 01:29:37 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
protected:
|
2014-01-28 07:43:24 +08:00
|
|
|
// IOHandler::Delegate functions
|
2015-09-02 17:33:09 +08:00
|
|
|
void IOHandlerInputComplete(IOHandler &io_handler,
|
|
|
|
std::string &line) override;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-05-10 05:13:27 +08:00
|
|
|
bool IOHandlerIsInputComplete(IOHandler &io_handler,
|
|
|
|
StringList &lines) override;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-07-13 06:28:52 +08:00
|
|
|
bool DoExecute(llvm::StringRef command, CommandReturnObject &result) override;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-03-07 10:27:46 +08:00
|
|
|
/// Return the appropriate expression options used for evaluating the
|
|
|
|
/// expression in the given target.
|
|
|
|
EvaluateExpressionOptions GetEvalOptions(const Target &target);
|
|
|
|
|
2020-03-23 22:25:51 +08:00
|
|
|
/// Evaluates the given expression.
|
|
|
|
/// \param output_stream The stream to which the evaluation result will be
|
|
|
|
/// printed.
|
|
|
|
/// \param error_stream Contains error messages that should be displayed to
|
|
|
|
/// the user in case the evaluation fails.
|
|
|
|
/// \param result A CommandReturnObject which status will be set to the
|
|
|
|
/// appropriate value depending on evaluation success and
|
|
|
|
/// whether the expression produced any result.
|
|
|
|
/// \return Returns true iff the expression was successfully evaluated,
|
|
|
|
/// executed and the result could be printed to the output stream.
|
2020-03-17 19:57:32 +08:00
|
|
|
bool EvaluateExpression(llvm::StringRef expr, Stream &output_stream,
|
|
|
|
Stream &error_stream, CommandReturnObject &result);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-03-14 07:42:30 +08:00
|
|
|
void GetMultilineExpression();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-10-25 14:44:01 +08:00
|
|
|
OptionGroupOptions m_option_group;
|
|
|
|
OptionGroupFormat m_format_options;
|
2013-01-10 04:12:53 +08:00
|
|
|
OptionGroupValueObjectDisplay m_varobj_options;
|
2015-10-20 08:55:21 +08:00
|
|
|
OptionGroupBoolean m_repl_option;
|
2011-10-25 14:44:01 +08:00
|
|
|
CommandOptions m_command_options;
|
2010-06-09 00:52:24 +08:00
|
|
|
uint32_t m_expr_line_count;
|
|
|
|
std::string m_expr_lines; // Multi-line expression support
|
2016-03-30 06:00:08 +08:00
|
|
|
std::string m_fixed_expression; // Holds the current expression's fixed text.
|
2010-06-09 00:52:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace lldb_private
|
|
|
|
|
2020-02-18 07:57:45 +08:00
|
|
|
#endif // LLDB_SOURCE_COMMANDS_COMMANDOBJECTEXPRESSION_H
|