2010-06-08 16:52:24 +00:00
|
|
|
//===-- CommandObjectExpression.cpp -----------------------------*- C++ -*-===//
|
|
|
|
|
//
|
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-06-08 16:52:24 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2016-02-19 19:33:46 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
|
|
|
|
|
|
#include "CommandObjectExpression.h"
|
2016-09-06 20:57:50 +00:00
|
|
|
#include "lldb/Core/Debugger.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
#include "lldb/Core/Value.h"
|
2010-09-30 00:54:27 +00:00
|
|
|
#include "lldb/Core/ValueObjectVariable.h"
|
<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-09-30 19:11:51 +00:00
|
|
|
#include "lldb/DataFormatters/ValueObjectPrinter.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
#include "lldb/Expression/DWARFExpression.h"
|
2015-10-20 00:55:21 +00:00
|
|
|
#include "lldb/Expression/REPL.h"
|
2016-09-06 20:57:50 +00:00
|
|
|
#include "lldb/Expression/UserExpression.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
#include "lldb/Host/Host.h"
|
2017-03-22 23:33:16 +00:00
|
|
|
#include "lldb/Host/OptionParser.h"
|
2010-06-23 01:19:29 +00:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
2018-04-10 09:03:59 +00:00
|
|
|
#include "lldb/Interpreter/OptionArgParser.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
#include "lldb/Symbol/ObjectFile.h"
|
|
|
|
|
#include "lldb/Symbol/Variable.h"
|
2016-09-06 20:57:50 +00:00
|
|
|
#include "lldb/Target/Language.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
#include "lldb/Target/Process.h"
|
2013-11-04 09:33:30 +00:00
|
|
|
#include "lldb/Target/StackFrame.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
#include "lldb/Target/Target.h"
|
Centralized a lot of the status information for processes,
threads, and stack frame down in the lldb_private::Process,
lldb_private::Thread, lldb_private::StackFrameList and the
lldb_private::StackFrame classes. We had some command line
commands that had duplicate versions of the process status
output ("thread list" and "process status" for example).
Removed the "file" command and placed it where it should
have been: "target create". Made an alias for "file" to
"target create" so we stay compatible with GDB commands.
We can now have multple usable targets in lldb at the
same time. This is nice for comparing two runs of a program
or debugging more than one binary at the same time. The
new command is "target select <target-idx>" and also to see
a list of the current targets you can use the new "target list"
command. The flow in a debug session can be:
(lldb) target create /path/to/exe/a.out
(lldb) breakpoint set --name main
(lldb) run
... hit breakpoint
(lldb) target create /bin/ls
(lldb) run /tmp
Process 36001 exited with status = 0 (0x00000000)
(lldb) target list
Current targets:
target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
* target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) target select 0
Current targets:
* target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) bt
* thread #1: tid = 0x2d03, 0x0000000100000b9a a.out`main + 42 at main.c:16, stop reason = breakpoint 1.1
frame #0: 0x0000000100000b9a a.out`main + 42 at main.c:16
frame #1: 0x0000000100000b64 a.out`start + 52
Above we created a target for "a.out" and ran and hit a
breakpoint at "main". Then we created a new target for /bin/ls
and ran it. Then we listed the targest and selected our original
"a.out" program, so we showed two concurent debug sessions
going on at the same time.
llvm-svn: 129695
2011-04-18 08:33:37 +00:00
|
|
|
#include "lldb/Target/Thread.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
CommandObjectExpression::CommandOptions::CommandOptions() : OptionGroup() {}
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2016-02-19 19:33:46 +00:00
|
|
|
CommandObjectExpression::CommandOptions::~CommandOptions() = default;
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2018-09-26 18:50:19 +00:00
|
|
|
static constexpr OptionEnumValueElement g_description_verbosity_type[] = {
|
2019-08-02 00:18:44 +00:00
|
|
|
{
|
|
|
|
|
eLanguageRuntimeDescriptionDisplayVerbosityCompact,
|
|
|
|
|
"compact",
|
|
|
|
|
"Only show the description string",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
eLanguageRuntimeDescriptionDisplayVerbosityFull,
|
|
|
|
|
"full",
|
|
|
|
|
"Show the full output, including persistent variable's name and type",
|
|
|
|
|
},
|
|
|
|
|
};
|
<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-09-30 19:11:51 +00:00
|
|
|
|
2018-09-26 18:50:19 +00:00
|
|
|
static constexpr OptionEnumValues DescriptionVerbosityTypes() {
|
|
|
|
|
return OptionEnumValues(g_description_verbosity_type);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-25 11:22:46 +00:00
|
|
|
#define LLDB_OPTIONS_expression
|
|
|
|
|
#include "CommandOptions.inc"
|
2011-10-25 06:44:01 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status CommandObjectExpression::CommandOptions::SetOptionValue(
|
2016-09-23 17:48:13 +00:00
|
|
|
uint32_t option_idx, llvm::StringRef option_arg,
|
2016-09-06 20:57:50 +00:00
|
|
|
ExecutionContext *execution_context) {
|
2017-05-12 04:51:55 +00:00
|
|
|
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-06 20:57:50 +00:00
|
|
|
|
|
|
|
|
switch (short_option) {
|
|
|
|
|
case 'l':
|
|
|
|
|
language = Language::GetLanguageTypeFromString(option_arg);
|
|
|
|
|
if (language == eLanguageTypeUnknown)
|
|
|
|
|
error.SetErrorStringWithFormat(
|
2016-09-23 17:48:13 +00:00
|
|
|
"unknown language type: '%s' for expression",
|
|
|
|
|
option_arg.str().c_str());
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'a': {
|
|
|
|
|
bool success;
|
|
|
|
|
bool result;
|
2018-04-10 09:03:59 +00:00
|
|
|
result = OptionArgParser::ToBoolean(option_arg, true, &success);
|
2016-09-06 20:57:50 +00:00
|
|
|
if (!success)
|
|
|
|
|
error.SetErrorStringWithFormat(
|
2016-09-23 17:48:13 +00:00
|
|
|
"invalid all-threads value setting: \"%s\"",
|
|
|
|
|
option_arg.str().c_str());
|
2016-09-06 20:57:50 +00:00
|
|
|
else
|
|
|
|
|
try_all_threads = result;
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
case 'i': {
|
|
|
|
|
bool success;
|
2018-04-10 09:03:59 +00:00
|
|
|
bool tmp_value = OptionArgParser::ToBoolean(option_arg, true, &success);
|
2016-09-06 20:57:50 +00:00
|
|
|
if (success)
|
|
|
|
|
ignore_breakpoints = tmp_value;
|
|
|
|
|
else
|
|
|
|
|
error.SetErrorStringWithFormat(
|
2016-09-23 17:48:13 +00:00
|
|
|
"could not convert \"%s\" to a boolean value.",
|
|
|
|
|
option_arg.str().c_str());
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case 'j': {
|
|
|
|
|
bool success;
|
2018-04-10 09:03:59 +00:00
|
|
|
bool tmp_value = OptionArgParser::ToBoolean(option_arg, true, &success);
|
2016-09-06 20:57:50 +00:00
|
|
|
if (success)
|
|
|
|
|
allow_jit = tmp_value;
|
|
|
|
|
else
|
|
|
|
|
error.SetErrorStringWithFormat(
|
2016-09-23 17:48:13 +00:00
|
|
|
"could not convert \"%s\" to a boolean value.",
|
|
|
|
|
option_arg.str().c_str());
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-23 17:48:13 +00:00
|
|
|
case 't':
|
|
|
|
|
if (option_arg.getAsInteger(0, timeout)) {
|
|
|
|
|
timeout = 0;
|
2016-09-06 20:57:50 +00:00
|
|
|
error.SetErrorStringWithFormat("invalid timeout setting \"%s\"",
|
2016-09-23 17:48:13 +00:00
|
|
|
option_arg.str().c_str());
|
|
|
|
|
}
|
|
|
|
|
break;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
|
|
|
|
case 'u': {
|
|
|
|
|
bool success;
|
2018-04-10 09:03:59 +00:00
|
|
|
bool tmp_value = OptionArgParser::ToBoolean(option_arg, true, &success);
|
2016-09-06 20:57:50 +00:00
|
|
|
if (success)
|
|
|
|
|
unwind_on_error = tmp_value;
|
|
|
|
|
else
|
|
|
|
|
error.SetErrorStringWithFormat(
|
2016-09-23 17:48:13 +00:00
|
|
|
"could not convert \"%s\" to a boolean value.",
|
|
|
|
|
option_arg.str().c_str());
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case 'v':
|
2016-09-26 21:36:17 +00:00
|
|
|
if (option_arg.empty()) {
|
2016-09-06 20:57:50 +00:00
|
|
|
m_verbosity = eLanguageRuntimeDescriptionDisplayVerbosityFull;
|
|
|
|
|
break;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2018-04-10 09:03:59 +00:00
|
|
|
m_verbosity = (LanguageRuntimeDescriptionDisplayVerbosity)
|
|
|
|
|
OptionArgParser::ToOptionEnum(
|
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
|
|
|
option_arg, GetDefinitions()[option_idx].enum_values, 0, error);
|
2016-09-06 20:57:50 +00:00
|
|
|
if (!error.Success())
|
|
|
|
|
error.SetErrorStringWithFormat(
|
2016-09-23 17:48:13 +00:00
|
|
|
"unrecognized value for description-verbosity '%s'",
|
|
|
|
|
option_arg.str().c_str());
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'g':
|
|
|
|
|
debug = true;
|
|
|
|
|
unwind_on_error = false;
|
|
|
|
|
ignore_breakpoints = false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'p':
|
|
|
|
|
top_level = true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'X': {
|
|
|
|
|
bool success;
|
2018-04-10 09:03:59 +00:00
|
|
|
bool tmp_value = OptionArgParser::ToBoolean(option_arg, true, &success);
|
2016-09-06 20:57:50 +00:00
|
|
|
if (success)
|
|
|
|
|
auto_apply_fixits = tmp_value ? eLazyBoolYes : eLazyBoolNo;
|
|
|
|
|
else
|
|
|
|
|
error.SetErrorStringWithFormat(
|
2016-09-23 17:48:13 +00:00
|
|
|
"could not convert \"%s\" to a boolean value.",
|
|
|
|
|
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");
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return error;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
void CommandObjectExpression::CommandOptions::OptionParsingStarting(
|
|
|
|
|
ExecutionContext *execution_context) {
|
|
|
|
|
auto process_sp =
|
|
|
|
|
execution_context ? execution_context->GetProcessSP() : ProcessSP();
|
|
|
|
|
if (process_sp) {
|
|
|
|
|
ignore_breakpoints = process_sp->GetIgnoreBreakpointsInExpressions();
|
|
|
|
|
unwind_on_error = process_sp->GetUnwindOnErrorInExpressions();
|
|
|
|
|
} else {
|
|
|
|
|
ignore_breakpoints = true;
|
|
|
|
|
unwind_on_error = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
show_summary = true;
|
|
|
|
|
try_all_threads = true;
|
|
|
|
|
timeout = 0;
|
|
|
|
|
debug = false;
|
|
|
|
|
language = eLanguageTypeUnknown;
|
|
|
|
|
m_verbosity = eLanguageRuntimeDescriptionDisplayVerbosityCompact;
|
|
|
|
|
auto_apply_fixits = eLazyBoolCalculate;
|
|
|
|
|
top_level = false;
|
|
|
|
|
allow_jit = true;
|
2010-06-08 16:52:24 +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>
|
2016-09-06 20:57:50 +00:00
|
|
|
CommandObjectExpression::CommandOptions::GetDefinitions() {
|
2016-09-22 21:06:13 +00:00
|
|
|
return llvm::makeArrayRef(g_expression_options);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
CommandObjectExpression::CommandObjectExpression(
|
|
|
|
|
CommandInterpreter &interpreter)
|
2016-07-14 22:03:10 +00:00
|
|
|
: CommandObjectRaw(
|
2016-09-06 20:57:50 +00:00
|
|
|
interpreter, "expression", "Evaluate an expression on the current "
|
|
|
|
|
"thread. Displays any returned value "
|
|
|
|
|
"with LLDB's default formatting.",
|
2016-10-05 21:14:38 +00:00
|
|
|
"", eCommandProcessMustBePaused | eCommandTryTargetAPILock),
|
2016-07-14 22:03:10 +00:00
|
|
|
IOHandlerDelegate(IOHandlerDelegate::Completion::Expression),
|
2016-09-06 20:57:50 +00:00
|
|
|
m_option_group(), m_format_options(eFormatDefault),
|
|
|
|
|
m_repl_option(LLDB_OPT_SET_1, false, "repl", 'r', "Drop into REPL", false,
|
|
|
|
|
true),
|
|
|
|
|
m_command_options(), m_expr_line_count(0), m_expr_lines() {
|
|
|
|
|
SetHelpLong(
|
|
|
|
|
R"(
|
2017-07-19 23:25:42 +00:00
|
|
|
Single and multi-line expressions:
|
|
|
|
|
|
|
|
|
|
)"
|
|
|
|
|
" The expression provided on the command line must be a complete expression \
|
|
|
|
|
with no newlines. To evaluate a multi-line expression, \
|
|
|
|
|
hit a return after an empty expression, and lldb will enter the multi-line expression editor. \
|
|
|
|
|
Hit return on an empty line to end the multi-line expression."
|
2019-03-02 00:20:26 +00:00
|
|
|
|
2017-07-19 23:25:42 +00:00
|
|
|
R"(
|
|
|
|
|
|
2015-07-14 05:48:36 +00:00
|
|
|
Timeouts:
|
|
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
)"
|
|
|
|
|
" If the expression can be evaluated statically (without running code) then it will be. \
|
2015-07-14 05:48:36 +00:00
|
|
|
Otherwise, by default the expression will run on the current thread with a short timeout: \
|
|
|
|
|
currently .25 seconds. If it doesn't return in that time, the evaluation will be interrupted \
|
|
|
|
|
and resumed with all threads running. You can use the -a option to disable retrying on all \
|
2016-09-06 20:57:50 +00:00
|
|
|
threads. You can use the -t option to set a shorter timeout."
|
|
|
|
|
R"(
|
2015-07-14 05:48:36 +00:00
|
|
|
|
|
|
|
|
User defined variables:
|
|
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
)"
|
|
|
|
|
" You can define your own variables for convenience or to be used in subsequent expressions. \
|
2015-07-14 05:48:36 +00:00
|
|
|
You define them the same way you would define variables in C. If the first character of \
|
|
|
|
|
your user defined variable is a $, then the variable's value will be available in future \
|
2016-09-06 20:57:50 +00:00
|
|
|
expressions, otherwise it will just be available in the current expression."
|
|
|
|
|
R"(
|
2015-07-14 05:48:36 +00:00
|
|
|
|
|
|
|
|
Continuing evaluation after a breakpoint:
|
|
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
)"
|
|
|
|
|
" If the \"-i false\" option is used, and execution is interrupted by a breakpoint hit, once \
|
2015-07-14 05:48:36 +00:00
|
|
|
you are done with your investigation, you can either remove the expression execution frames \
|
|
|
|
|
from the stack with \"thread return -x\" or if you are still interested in the expression result \
|
|
|
|
|
you can issue the \"continue\" command and the expression evaluation will complete and the \
|
|
|
|
|
expression result will be available using the \"thread.completed-expression\" key in the thread \
|
2016-09-06 20:57:50 +00:00
|
|
|
format."
|
2017-07-19 23:25:42 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
R"(
|
2015-07-14 05:48:36 +00:00
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
|
|
expr my_struct->a = my_array[3]
|
|
|
|
|
expr -f bin -- (index * 8) + 5
|
|
|
|
|
expr unsigned int $foo = 5
|
2016-09-06 20:57:50 +00:00
|
|
|
expr char c[] = \"foo\"; c[0])");
|
|
|
|
|
|
|
|
|
|
CommandArgumentEntry arg;
|
|
|
|
|
CommandArgumentData expression_arg;
|
|
|
|
|
|
|
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
|
expression_arg.arg_type = eArgTypeExpression;
|
|
|
|
|
expression_arg.arg_repetition = eArgRepeatPlain;
|
|
|
|
|
|
|
|
|
|
// There is only one variant this argument could be; put it into the argument
|
|
|
|
|
// entry.
|
|
|
|
|
arg.push_back(expression_arg);
|
|
|
|
|
|
|
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
|
m_arguments.push_back(arg);
|
|
|
|
|
|
|
|
|
|
// Add the "--format" and "--gdb-format"
|
|
|
|
|
m_option_group.Append(&m_format_options,
|
|
|
|
|
OptionGroupFormat::OPTION_GROUP_FORMAT |
|
|
|
|
|
OptionGroupFormat::OPTION_GROUP_GDB_FMT,
|
|
|
|
|
LLDB_OPT_SET_1);
|
|
|
|
|
m_option_group.Append(&m_command_options);
|
|
|
|
|
m_option_group.Append(&m_varobj_options, LLDB_OPT_SET_ALL,
|
|
|
|
|
LLDB_OPT_SET_1 | LLDB_OPT_SET_2);
|
|
|
|
|
m_option_group.Append(&m_repl_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_3);
|
|
|
|
|
m_option_group.Finalize();
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-19 19:33:46 +00:00
|
|
|
CommandObjectExpression::~CommandObjectExpression() = default;
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
Options *CommandObjectExpression::GetOptions() { return &m_option_group; }
|
2010-06-08 16:52:24 +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 CommandObjectExpression::HandleCompletion(CompletionRequest &request) {
|
2018-08-30 17:29:37 +00:00
|
|
|
EvaluateExpressionOptions options;
|
|
|
|
|
options.SetCoerceToId(m_varobj_options.use_objc);
|
|
|
|
|
options.SetLanguage(m_command_options.language);
|
|
|
|
|
options.SetExecutionPolicy(lldb_private::eExecutionPolicyNever);
|
|
|
|
|
options.SetAutoApplyFixIts(false);
|
|
|
|
|
options.SetGenerateDebugInfo(false);
|
|
|
|
|
|
|
|
|
|
// We need a valid execution context with a frame pointer for this
|
|
|
|
|
// completion, so if we don't have one we should try to make a valid
|
|
|
|
|
// execution context.
|
|
|
|
|
if (m_interpreter.GetExecutionContext().GetFramePtr() == nullptr)
|
|
|
|
|
m_interpreter.UpdateExecutionContext(nullptr);
|
|
|
|
|
|
|
|
|
|
// This didn't work, so let's get out before we start doing things that
|
|
|
|
|
// expect a valid frame pointer.
|
|
|
|
|
if (m_interpreter.GetExecutionContext().GetFramePtr() == nullptr)
|
[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
|
|
|
return;
|
2018-08-30 17:29:37 +00:00
|
|
|
|
|
|
|
|
ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
|
|
|
|
|
|
|
|
|
|
Target *target = exe_ctx.GetTargetPtr();
|
|
|
|
|
|
|
|
|
|
if (!target)
|
|
|
|
|
target = GetDummyTarget();
|
|
|
|
|
|
|
|
|
|
if (!target)
|
[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
|
|
|
return;
|
2018-08-30 17:29:37 +00:00
|
|
|
|
|
|
|
|
unsigned cursor_pos = request.GetRawCursorPos();
|
|
|
|
|
llvm::StringRef code = request.GetRawLine();
|
|
|
|
|
|
|
|
|
|
const std::size_t original_code_size = code.size();
|
|
|
|
|
|
|
|
|
|
// Remove the first token which is 'expr' or some alias/abbreviation of that.
|
|
|
|
|
code = llvm::getToken(code).second.ltrim();
|
|
|
|
|
OptionsWithRaw args(code);
|
|
|
|
|
code = args.GetRawPart();
|
|
|
|
|
|
|
|
|
|
// The position where the expression starts in the command line.
|
|
|
|
|
assert(original_code_size >= code.size());
|
|
|
|
|
std::size_t raw_start = original_code_size - code.size();
|
|
|
|
|
|
|
|
|
|
// Check if the cursor is actually in the expression string, and if not, we
|
|
|
|
|
// exit.
|
|
|
|
|
// FIXME: We should complete the options here.
|
|
|
|
|
if (cursor_pos < raw_start)
|
[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
|
|
|
return;
|
2018-08-30 17:29:37 +00:00
|
|
|
|
|
|
|
|
// Make the cursor_pos again relative to the start of the code string.
|
|
|
|
|
assert(cursor_pos >= raw_start);
|
|
|
|
|
cursor_pos -= raw_start;
|
|
|
|
|
|
|
|
|
|
auto language = exe_ctx.GetFrameRef().GetLanguage();
|
|
|
|
|
|
|
|
|
|
Status error;
|
|
|
|
|
lldb::UserExpressionSP expr(target->GetUserExpressionForLanguage(
|
|
|
|
|
code, llvm::StringRef(), language, UserExpression::eResultTypeAny,
|
2019-02-05 09:14:36 +00:00
|
|
|
options, nullptr, error));
|
2018-08-30 17:29:37 +00:00
|
|
|
if (error.Fail())
|
[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
|
|
|
return;
|
2018-08-30 17:29:37 +00:00
|
|
|
|
2018-08-30 21:26:32 +00:00
|
|
|
expr->Complete(exe_ctx, request, cursor_pos);
|
2018-08-30 17:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
static lldb_private::Status
|
2016-09-06 20:57:50 +00:00
|
|
|
CanBeUsedForElementCountPrinting(ValueObject &valobj) {
|
|
|
|
|
CompilerType type(valobj.GetCompilerType());
|
|
|
|
|
CompilerType pointee;
|
|
|
|
|
if (!type.IsPointerType(&pointee))
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status("as it does not refer to a pointer");
|
2016-09-06 20:57:50 +00:00
|
|
|
if (pointee.IsVoidType())
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status("as it refers to a pointer to void");
|
|
|
|
|
return Status();
|
2016-04-25 00:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
2018-07-12 22:28:52 +00:00
|
|
|
bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
|
2016-09-06 20:57:50 +00:00
|
|
|
Stream *output_stream,
|
|
|
|
|
Stream *error_stream,
|
|
|
|
|
CommandReturnObject *result) {
|
2018-04-30 16:49:04 +00:00
|
|
|
// Don't use m_exe_ctx as this might be called asynchronously after the
|
|
|
|
|
// command object DoExecute has finished when doing multi-line expression
|
|
|
|
|
// that use an input reader...
|
2016-09-06 20:57:50 +00:00
|
|
|
ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
|
|
|
|
|
|
|
|
|
|
Target *target = exe_ctx.GetTargetPtr();
|
|
|
|
|
|
|
|
|
|
if (!target)
|
|
|
|
|
target = GetDummyTarget();
|
|
|
|
|
|
|
|
|
|
if (target) {
|
|
|
|
|
lldb::ValueObjectSP result_valobj_sp;
|
|
|
|
|
bool keep_in_memory = true;
|
|
|
|
|
StackFrame *frame = exe_ctx.GetFramePtr();
|
|
|
|
|
|
|
|
|
|
EvaluateExpressionOptions options;
|
|
|
|
|
options.SetCoerceToId(m_varobj_options.use_objc);
|
|
|
|
|
options.SetUnwindOnError(m_command_options.unwind_on_error);
|
|
|
|
|
options.SetIgnoreBreakpoints(m_command_options.ignore_breakpoints);
|
|
|
|
|
options.SetKeepInMemory(keep_in_memory);
|
|
|
|
|
options.SetUseDynamic(m_varobj_options.use_dynamic);
|
|
|
|
|
options.SetTryAllThreads(m_command_options.try_all_threads);
|
|
|
|
|
options.SetDebug(m_command_options.debug);
|
|
|
|
|
options.SetLanguage(m_command_options.language);
|
|
|
|
|
options.SetExecutionPolicy(
|
|
|
|
|
m_command_options.allow_jit
|
|
|
|
|
? EvaluateExpressionOptions::default_execution_policy
|
|
|
|
|
: lldb_private::eExecutionPolicyNever);
|
|
|
|
|
|
|
|
|
|
bool auto_apply_fixits;
|
|
|
|
|
if (m_command_options.auto_apply_fixits == eLazyBoolCalculate)
|
|
|
|
|
auto_apply_fixits = target->GetEnableAutoApplyFixIts();
|
|
|
|
|
else
|
2018-12-15 00:15:33 +00:00
|
|
|
auto_apply_fixits = m_command_options.auto_apply_fixits == eLazyBoolYes;
|
2013-07-30 19:54:09 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
options.SetAutoApplyFixIts(auto_apply_fixits);
|
|
|
|
|
|
|
|
|
|
if (m_command_options.top_level)
|
|
|
|
|
options.SetExecutionPolicy(eExecutionPolicyTopLevel);
|
|
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// If there is any chance we are going to stop and want to see what went
|
|
|
|
|
// wrong with our expression, we should generate debug info
|
2016-09-06 20:57:50 +00:00
|
|
|
if (!m_command_options.ignore_breakpoints ||
|
|
|
|
|
!m_command_options.unwind_on_error)
|
|
|
|
|
options.SetGenerateDebugInfo(true);
|
|
|
|
|
|
|
|
|
|
if (m_command_options.timeout > 0)
|
2016-12-06 11:24:51 +00:00
|
|
|
options.SetTimeout(std::chrono::microseconds(m_command_options.timeout));
|
2010-12-14 02:59:59 +00:00
|
|
|
else
|
2016-12-06 11:24:51 +00:00
|
|
|
options.SetTimeout(llvm::None);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
|
|
|
|
ExpressionResults success = target->EvaluateExpression(
|
|
|
|
|
expr, frame, result_valobj_sp, options, &m_fixed_expression);
|
|
|
|
|
|
|
|
|
|
// We only tell you about the FixIt if we applied it. The compiler errors
|
|
|
|
|
// will suggest the FixIt if it parsed.
|
|
|
|
|
if (error_stream && !m_fixed_expression.empty() &&
|
|
|
|
|
target->GetEnableNotifyAboutFixIts()) {
|
|
|
|
|
if (success == eExpressionCompleted)
|
|
|
|
|
error_stream->Printf(
|
|
|
|
|
" Fix-it applied, fixed expression was: \n %s\n",
|
|
|
|
|
m_fixed_expression.c_str());
|
2010-07-23 00:16:21 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
if (result_valobj_sp) {
|
|
|
|
|
Format format = m_format_options.GetFormat();
|
|
|
|
|
|
|
|
|
|
if (result_valobj_sp->GetError().Success()) {
|
|
|
|
|
if (format != eFormatVoid) {
|
|
|
|
|
if (format != eFormatDefault)
|
|
|
|
|
result_valobj_sp->SetFormat(format);
|
|
|
|
|
|
|
|
|
|
if (m_varobj_options.elem_count > 0) {
|
2017-05-12 04:51:55 +00:00
|
|
|
Status error(CanBeUsedForElementCountPrinting(*result_valobj_sp));
|
2016-09-06 20:57:50 +00:00
|
|
|
if (error.Fail()) {
|
|
|
|
|
result->AppendErrorWithFormat(
|
|
|
|
|
"expression cannot be used with --element-count %s\n",
|
|
|
|
|
error.AsCString(""));
|
|
|
|
|
result->SetStatus(eReturnStatusFailed);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions(
|
|
|
|
|
m_command_options.m_verbosity, format));
|
|
|
|
|
options.SetVariableFormatDisplayLanguage(
|
|
|
|
|
result_valobj_sp->GetPreferredDisplayLanguage());
|
|
|
|
|
|
|
|
|
|
result_valobj_sp->Dump(*output_stream, options);
|
2014-01-27 23:43:24 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
if (result)
|
|
|
|
|
result->SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (result_valobj_sp->GetError().GetError() ==
|
2018-10-18 03:10:43 +00:00
|
|
|
UserExpression::kNoResult) {
|
2019-04-27 06:19:42 +00:00
|
|
|
if (format != eFormatVoid && GetDebugger().GetNotifyVoid()) {
|
2016-09-06 20:57:50 +00:00
|
|
|
error_stream->PutCString("(void)\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
|
result->SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
|
} else {
|
|
|
|
|
const char *error_cstr = result_valobj_sp->GetError().AsCString();
|
|
|
|
|
if (error_cstr && error_cstr[0]) {
|
|
|
|
|
const size_t error_cstr_len = strlen(error_cstr);
|
|
|
|
|
const bool ends_with_newline =
|
|
|
|
|
error_cstr[error_cstr_len - 1] == '\n';
|
|
|
|
|
if (strstr(error_cstr, "error:") != error_cstr)
|
|
|
|
|
error_stream->PutCString("error: ");
|
|
|
|
|
error_stream->Write(error_cstr, error_cstr_len);
|
|
|
|
|
if (!ends_with_newline)
|
|
|
|
|
error_stream->EOL();
|
|
|
|
|
} else {
|
|
|
|
|
error_stream->PutCString("error: unknown error\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
|
result->SetStatus(eReturnStatusFailed);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-27 23:43:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
|
|
|
|
error_stream->Printf("error: invalid execution context for expression\n");
|
2016-05-09 21:13:27 +00:00
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2014-01-27 23:43:24 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
void CommandObjectExpression::IOHandlerInputComplete(IOHandler &io_handler,
|
|
|
|
|
std::string &line) {
|
|
|
|
|
io_handler.SetIsDone(true);
|
|
|
|
|
// StreamSP output_stream =
|
|
|
|
|
// io_handler.GetDebugger().GetAsyncOutputStream();
|
|
|
|
|
// StreamSP error_stream = io_handler.GetDebugger().GetAsyncErrorStream();
|
|
|
|
|
StreamFileSP output_sp(io_handler.GetOutputStreamFile());
|
|
|
|
|
StreamFileSP error_sp(io_handler.GetErrorStreamFile());
|
|
|
|
|
|
|
|
|
|
EvaluateExpression(line.c_str(), output_sp.get(), error_sp.get());
|
|
|
|
|
if (output_sp)
|
|
|
|
|
output_sp->Flush();
|
|
|
|
|
if (error_sp)
|
|
|
|
|
error_sp->Flush();
|
2014-03-13 23:42:30 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
bool CommandObjectExpression::IOHandlerIsInputComplete(IOHandler &io_handler,
|
|
|
|
|
StringList &lines) {
|
|
|
|
|
// An empty lines is used to indicate the end of input
|
|
|
|
|
const size_t num_lines = lines.GetSize();
|
|
|
|
|
if (num_lines > 0 && lines[num_lines - 1].empty()) {
|
2018-04-30 16:49:04 +00:00
|
|
|
// Remove the last empty line from "lines" so it doesn't appear in our
|
|
|
|
|
// resulting input and return true to indicate we are done getting lines
|
2016-09-06 20:57:50 +00:00
|
|
|
lines.PopBack();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
void CommandObjectExpression::GetMultilineExpression() {
|
|
|
|
|
m_expr_lines.clear();
|
|
|
|
|
m_expr_line_count = 0;
|
|
|
|
|
|
|
|
|
|
Debugger &debugger = GetCommandInterpreter().GetDebugger();
|
|
|
|
|
bool color_prompt = debugger.GetUseColor();
|
|
|
|
|
const bool multiple_lines = true; // Get multiple lines
|
|
|
|
|
IOHandlerSP io_handler_sp(
|
|
|
|
|
new IOHandlerEditline(debugger, IOHandler::Type::Expression,
|
|
|
|
|
"lldb-expr", // Name of input reader for history
|
2016-09-23 18:06:53 +00:00
|
|
|
llvm::StringRef(), // No prompt
|
|
|
|
|
llvm::StringRef(), // Continuation prompt
|
2016-09-06 20:57:50 +00:00
|
|
|
multiple_lines, color_prompt,
|
|
|
|
|
1, // Show line numbers starting at 1
|
2019-03-02 00:20:26 +00:00
|
|
|
*this, nullptr));
|
2016-09-06 20:57:50 +00:00
|
|
|
|
|
|
|
|
StreamFileSP output_sp(io_handler_sp->GetOutputStreamFile());
|
|
|
|
|
if (output_sp) {
|
|
|
|
|
output_sp->PutCString(
|
|
|
|
|
"Enter expressions, then terminate with an empty line to evaluate:\n");
|
|
|
|
|
output_sp->Flush();
|
|
|
|
|
}
|
|
|
|
|
debugger.PushIOHandler(io_handler_sp);
|
|
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2019-03-09 00:10:52 +00:00
|
|
|
static EvaluateExpressionOptions
|
|
|
|
|
GetExprOptions(ExecutionContext &ctx,
|
|
|
|
|
CommandObjectExpression::CommandOptions command_options) {
|
|
|
|
|
command_options.OptionParsingStarting(&ctx);
|
|
|
|
|
|
|
|
|
|
// Default certain settings for REPL regardless of the global settings.
|
|
|
|
|
command_options.unwind_on_error = false;
|
|
|
|
|
command_options.ignore_breakpoints = false;
|
|
|
|
|
command_options.debug = false;
|
|
|
|
|
|
|
|
|
|
EvaluateExpressionOptions expr_options;
|
|
|
|
|
expr_options.SetUnwindOnError(command_options.unwind_on_error);
|
|
|
|
|
expr_options.SetIgnoreBreakpoints(command_options.ignore_breakpoints);
|
|
|
|
|
expr_options.SetTryAllThreads(command_options.try_all_threads);
|
|
|
|
|
|
|
|
|
|
if (command_options.timeout > 0)
|
|
|
|
|
expr_options.SetTimeout(std::chrono::microseconds(command_options.timeout));
|
|
|
|
|
else
|
|
|
|
|
expr_options.SetTimeout(llvm::None);
|
|
|
|
|
|
|
|
|
|
return expr_options;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-12 22:28:52 +00:00
|
|
|
bool CommandObjectExpression::DoExecute(llvm::StringRef command,
|
2016-09-06 20:57:50 +00:00
|
|
|
CommandReturnObject &result) {
|
|
|
|
|
m_fixed_expression.clear();
|
|
|
|
|
auto exe_ctx = GetCommandInterpreter().GetExecutionContext();
|
|
|
|
|
m_option_group.NotifyOptionParsingStarting(&exe_ctx);
|
|
|
|
|
|
2018-07-12 22:28:52 +00:00
|
|
|
if (command.empty()) {
|
2016-09-06 20:57:50 +00:00
|
|
|
GetMultilineExpression();
|
|
|
|
|
return result.Succeeded();
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-10 20:17:38 +00:00
|
|
|
OptionsWithRaw args(command);
|
2018-07-12 22:28:52 +00:00
|
|
|
llvm::StringRef expr = args.GetRawPart();
|
2018-07-10 20:17:38 +00:00
|
|
|
|
|
|
|
|
if (args.HasArgs()) {
|
|
|
|
|
if (!ParseOptionsAndNotify(args.GetArgs(), result, m_option_group, exe_ctx))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (m_repl_option.GetOptionValue().GetCurrentValue()) {
|
|
|
|
|
Target *target = m_interpreter.GetExecutionContext().GetTargetPtr();
|
|
|
|
|
if (target) {
|
|
|
|
|
// Drop into REPL
|
|
|
|
|
m_expr_lines.clear();
|
|
|
|
|
m_expr_line_count = 0;
|
|
|
|
|
|
|
|
|
|
Debugger &debugger = target->GetDebugger();
|
|
|
|
|
|
|
|
|
|
// Check if the LLDB command interpreter is sitting on top of a REPL
|
|
|
|
|
// that launched it...
|
|
|
|
|
if (debugger.CheckTopIOHandlerTypes(IOHandler::Type::CommandInterpreter,
|
|
|
|
|
IOHandler::Type::REPL)) {
|
|
|
|
|
// the LLDB command interpreter is sitting on top of a REPL that
|
|
|
|
|
// launched it, so just say the command interpreter is done and
|
|
|
|
|
// fall back to the existing REPL
|
|
|
|
|
m_interpreter.GetIOHandler(false)->SetIsDone(true);
|
|
|
|
|
} else {
|
|
|
|
|
// We are launching the REPL on top of the current LLDB command
|
|
|
|
|
// interpreter, so just push one
|
|
|
|
|
bool initialize = false;
|
|
|
|
|
Status repl_error;
|
|
|
|
|
REPLSP repl_sp(target->GetREPL(repl_error, m_command_options.language,
|
|
|
|
|
nullptr, false));
|
|
|
|
|
|
|
|
|
|
if (!repl_sp) {
|
|
|
|
|
initialize = true;
|
|
|
|
|
repl_sp = target->GetREPL(repl_error, m_command_options.language,
|
|
|
|
|
nullptr, true);
|
|
|
|
|
if (!repl_error.Success()) {
|
|
|
|
|
result.SetError(repl_error);
|
|
|
|
|
return result.Succeeded();
|
2014-03-13 23:42:30 +00:00
|
|
|
}
|
2018-07-10 20:17:38 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2018-07-10 20:17:38 +00:00
|
|
|
if (repl_sp) {
|
|
|
|
|
if (initialize) {
|
2019-03-09 00:10:52 +00:00
|
|
|
repl_sp->SetEvaluateOptions(
|
|
|
|
|
GetExprOptions(exe_ctx, m_command_options));
|
2018-07-10 20:17:38 +00:00
|
|
|
repl_sp->SetFormatOptions(m_format_options);
|
|
|
|
|
repl_sp->SetValueObjectDisplayOptions(m_varobj_options);
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-07-10 20:17:38 +00:00
|
|
|
IOHandlerSP io_handler_sp(repl_sp->GetIOHandler());
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-07-10 20:17:38 +00:00
|
|
|
io_handler_sp->SetIsDone(false);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-07-10 20:17:38 +00:00
|
|
|
debugger.PushIOHandler(io_handler_sp);
|
|
|
|
|
} else {
|
|
|
|
|
repl_error.SetErrorStringWithFormat(
|
|
|
|
|
"Couldn't create a REPL for %s",
|
|
|
|
|
Language::GetNameForLanguageType(m_command_options.language));
|
|
|
|
|
result.SetError(repl_error);
|
|
|
|
|
return result.Succeeded();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-03-29 22:00:08 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2018-07-10 20:17:38 +00:00
|
|
|
}
|
|
|
|
|
// No expression following options
|
2018-07-12 22:28:52 +00:00
|
|
|
else if (expr.empty()) {
|
2018-07-10 20:17:38 +00:00
|
|
|
GetMultilineExpression();
|
|
|
|
|
return result.Succeeded();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 18:37:14 +00:00
|
|
|
Target *target = GetSelectedOrDummyTarget();
|
2016-09-06 20:57:50 +00:00
|
|
|
if (EvaluateExpression(expr, &(result.GetOutputStream()),
|
|
|
|
|
&(result.GetErrorStream()), &result)) {
|
2016-10-17 23:59:41 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
if (!m_fixed_expression.empty() && target->GetEnableNotifyAboutFixIts()) {
|
|
|
|
|
CommandHistory &history = m_interpreter.GetCommandHistory();
|
|
|
|
|
// FIXME: Can we figure out what the user actually typed (e.g. some alias
|
|
|
|
|
// for expr???)
|
|
|
|
|
// If we can it would be nice to show that.
|
|
|
|
|
std::string fixed_command("expression ");
|
2018-07-10 20:17:38 +00:00
|
|
|
if (args.HasArgs()) {
|
2016-09-06 20:57:50 +00:00
|
|
|
// Add in any options that might have been in the original command:
|
2018-07-10 20:17:38 +00:00
|
|
|
fixed_command.append(args.GetArgStringWithDelimiter());
|
|
|
|
|
fixed_command.append(m_fixed_expression);
|
|
|
|
|
} else
|
2016-09-06 20:57:50 +00:00
|
|
|
fixed_command.append(m_fixed_expression);
|
|
|
|
|
history.AppendString(fixed_command);
|
2016-03-29 22:00:08 +00:00
|
|
|
}
|
2018-04-30 16:49:04 +00:00
|
|
|
// Increment statistics to record this expression evaluation success.
|
2018-04-13 18:02:39 +00:00
|
|
|
target->IncrementStats(StatisticKind::ExpressionSuccessful);
|
2016-09-06 20:57:50 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2010-08-13 00:42:30 +00:00
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// Increment statistics to record this expression evaluation failure.
|
2018-04-13 18:02:39 +00:00
|
|
|
target->IncrementStats(StatisticKind::ExpressionFailure);
|
2016-09-06 20:57:50 +00:00
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
|
return false;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|