[lldb] Introduce dwim-print command
Implements `dwim-print`, a printing command that chooses the most direct,
efficient, and resilient means of printing a given expression.
DWIM is an acronym for Do What I Mean. From Wikipedia, DWIM is described as:
> attempt to anticipate what users intend to do, correcting trivial errors
> automatically rather than blindly executing users' explicit but
> potentially incorrect input
The `dwim-print` command serves as a single print command for users who don't
yet know, or prefer not to know, the various lldb commands that can be used to
print, and when to use them.
This initial implementation is the base foundation for `dwim-print`. It accepts
no flags, only an expression. If the expression is the name of a variable in
the frame, then effectively `frame variable` is used to get, and print, its
value. Otherwise, printing falls back to using `expression` evaluation. In this
initial version, frame variable paths will be handled with `expression`.
Following this, there are a number of improvements that can be made. Some
improvements include supporting `frame variable` expressions or registers.
To provide transparency, especially as the `dwim-print` command evolves, a new
setting is also introduced: `dwim-print-verbosity`. This setting instructs
`dwim-print` to optionally print a message showing the effective command being
run. For example `dwim-print var.meth()` can print a message such as: "note:
ran `expression var.meth()`".
See https://discourse.llvm.org/t/dwim-print-command/66078 for the proposal and
discussion.
Differential Revision: https://reviews.llvm.org/D138315
2022-11-17 17:11:30 -08:00
|
|
|
//===-- CommandObjectDWIMPrint.cpp ------------------------------*- C++ -*-===//
|
|
|
|
|
//
|
|
|
|
|
// 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
|
|
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "CommandObjectDWIMPrint.h"
|
|
|
|
|
|
2022-12-19 15:33:56 -08:00
|
|
|
#include "lldb/DataFormatters/DumpValueObjectOptions.h"
|
[lldb] Delay removal of persistent results
Follow up to "Suppress persistent result when running po" (D144044).
This change delays removal of the persistent result until after `Dump` has been called.
In doing so, the persistent result is available for the purpose of getting its object
description.
In the original change, the persistent result removal happens indirectly, by setting
`EvaluateExpressionOptions::SetSuppressPersistentResult`. In practice this has worked,
however this exposed a latent bug in swift-lldb. The subtlety, and the bug, depend on
when the persisteted result variable is removed.
When the result is removed via `SetSuppressPersistentResult`, it happens within the call
to `Target::EvaluateExpression`. That is, by the time the call returns, the persistent
result is already removed.
The issue occurs shortly thereafter, when `ValueObject::Dump` is called, it cannot make
use of the persistent result variable (instead it uses the `ValueObjectConstResult`). In
swift-lldb, this causes an additional expression evaluation to happen. It first tries an
expression that reference `$R0` etc, but that always fails because `$R0` is removed. The
fallback to this failure does work most of the time, but there's at least one bug
involving imported Clang types.
Differential Revision: https://reviews.llvm.org/D150619
2023-05-15 14:36:17 -07:00
|
|
|
#include "lldb/Expression/ExpressionVariable.h"
|
2023-05-24 10:30:49 -07:00
|
|
|
#include "lldb/Expression/UserExpression.h"
|
[lldb] Introduce dwim-print command
Implements `dwim-print`, a printing command that chooses the most direct,
efficient, and resilient means of printing a given expression.
DWIM is an acronym for Do What I Mean. From Wikipedia, DWIM is described as:
> attempt to anticipate what users intend to do, correcting trivial errors
> automatically rather than blindly executing users' explicit but
> potentially incorrect input
The `dwim-print` command serves as a single print command for users who don't
yet know, or prefer not to know, the various lldb commands that can be used to
print, and when to use them.
This initial implementation is the base foundation for `dwim-print`. It accepts
no flags, only an expression. If the expression is the name of a variable in
the frame, then effectively `frame variable` is used to get, and print, its
value. Otherwise, printing falls back to using `expression` evaluation. In this
initial version, frame variable paths will be handled with `expression`.
Following this, there are a number of improvements that can be made. Some
improvements include supporting `frame variable` expressions or registers.
To provide transparency, especially as the `dwim-print` command evolves, a new
setting is also introduced: `dwim-print-verbosity`. This setting instructs
`dwim-print` to optionally print a message showing the effective command being
run. For example `dwim-print var.meth()` can print a message such as: "note:
ran `expression var.meth()`".
See https://discourse.llvm.org/t/dwim-print-command/66078 for the proposal and
discussion.
Differential Revision: https://reviews.llvm.org/D138315
2022-11-17 17:11:30 -08:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
|
|
|
|
#include "lldb/Interpreter/CommandObject.h"
|
|
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
2022-12-19 15:33:56 -08:00
|
|
|
#include "lldb/Interpreter/OptionGroupFormat.h"
|
|
|
|
|
#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
|
[lldb] Introduce dwim-print command
Implements `dwim-print`, a printing command that chooses the most direct,
efficient, and resilient means of printing a given expression.
DWIM is an acronym for Do What I Mean. From Wikipedia, DWIM is described as:
> attempt to anticipate what users intend to do, correcting trivial errors
> automatically rather than blindly executing users' explicit but
> potentially incorrect input
The `dwim-print` command serves as a single print command for users who don't
yet know, or prefer not to know, the various lldb commands that can be used to
print, and when to use them.
This initial implementation is the base foundation for `dwim-print`. It accepts
no flags, only an expression. If the expression is the name of a variable in
the frame, then effectively `frame variable` is used to get, and print, its
value. Otherwise, printing falls back to using `expression` evaluation. In this
initial version, frame variable paths will be handled with `expression`.
Following this, there are a number of improvements that can be made. Some
improvements include supporting `frame variable` expressions or registers.
To provide transparency, especially as the `dwim-print` command evolves, a new
setting is also introduced: `dwim-print-verbosity`. This setting instructs
`dwim-print` to optionally print a message showing the effective command being
run. For example `dwim-print var.meth()` can print a message such as: "note:
ran `expression var.meth()`".
See https://discourse.llvm.org/t/dwim-print-command/66078 for the proposal and
discussion.
Differential Revision: https://reviews.llvm.org/D138315
2022-11-17 17:11:30 -08:00
|
|
|
#include "lldb/Target/StackFrame.h"
|
|
|
|
|
#include "lldb/Utility/ConstString.h"
|
2024-10-24 20:20:48 -07:00
|
|
|
#include "lldb/ValueObject/ValueObject.h"
|
2022-12-19 15:33:56 -08:00
|
|
|
#include "lldb/lldb-defines.h"
|
[lldb] Introduce dwim-print command
Implements `dwim-print`, a printing command that chooses the most direct,
efficient, and resilient means of printing a given expression.
DWIM is an acronym for Do What I Mean. From Wikipedia, DWIM is described as:
> attempt to anticipate what users intend to do, correcting trivial errors
> automatically rather than blindly executing users' explicit but
> potentially incorrect input
The `dwim-print` command serves as a single print command for users who don't
yet know, or prefer not to know, the various lldb commands that can be used to
print, and when to use them.
This initial implementation is the base foundation for `dwim-print`. It accepts
no flags, only an expression. If the expression is the name of a variable in
the frame, then effectively `frame variable` is used to get, and print, its
value. Otherwise, printing falls back to using `expression` evaluation. In this
initial version, frame variable paths will be handled with `expression`.
Following this, there are a number of improvements that can be made. Some
improvements include supporting `frame variable` expressions or registers.
To provide transparency, especially as the `dwim-print` command evolves, a new
setting is also introduced: `dwim-print-verbosity`. This setting instructs
`dwim-print` to optionally print a message showing the effective command being
run. For example `dwim-print var.meth()` can print a message such as: "note:
ran `expression var.meth()`".
See https://discourse.llvm.org/t/dwim-print-command/66078 for the proposal and
discussion.
Differential Revision: https://reviews.llvm.org/D138315
2022-11-17 17:11:30 -08:00
|
|
|
#include "lldb/lldb-enumerations.h"
|
|
|
|
|
#include "lldb/lldb-forward.h"
|
2022-12-19 15:33:56 -08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
[lldb] Introduce dwim-print command
Implements `dwim-print`, a printing command that chooses the most direct,
efficient, and resilient means of printing a given expression.
DWIM is an acronym for Do What I Mean. From Wikipedia, DWIM is described as:
> attempt to anticipate what users intend to do, correcting trivial errors
> automatically rather than blindly executing users' explicit but
> potentially incorrect input
The `dwim-print` command serves as a single print command for users who don't
yet know, or prefer not to know, the various lldb commands that can be used to
print, and when to use them.
This initial implementation is the base foundation for `dwim-print`. It accepts
no flags, only an expression. If the expression is the name of a variable in
the frame, then effectively `frame variable` is used to get, and print, its
value. Otherwise, printing falls back to using `expression` evaluation. In this
initial version, frame variable paths will be handled with `expression`.
Following this, there are a number of improvements that can be made. Some
improvements include supporting `frame variable` expressions or registers.
To provide transparency, especially as the `dwim-print` command evolves, a new
setting is also introduced: `dwim-print-verbosity`. This setting instructs
`dwim-print` to optionally print a message showing the effective command being
run. For example `dwim-print var.meth()` can print a message such as: "note:
ran `expression var.meth()`".
See https://discourse.llvm.org/t/dwim-print-command/66078 for the proposal and
discussion.
Differential Revision: https://reviews.llvm.org/D138315
2022-11-17 17:11:30 -08:00
|
|
|
|
2023-06-28 16:34:26 -07:00
|
|
|
#include <regex>
|
|
|
|
|
|
[lldb] Introduce dwim-print command
Implements `dwim-print`, a printing command that chooses the most direct,
efficient, and resilient means of printing a given expression.
DWIM is an acronym for Do What I Mean. From Wikipedia, DWIM is described as:
> attempt to anticipate what users intend to do, correcting trivial errors
> automatically rather than blindly executing users' explicit but
> potentially incorrect input
The `dwim-print` command serves as a single print command for users who don't
yet know, or prefer not to know, the various lldb commands that can be used to
print, and when to use them.
This initial implementation is the base foundation for `dwim-print`. It accepts
no flags, only an expression. If the expression is the name of a variable in
the frame, then effectively `frame variable` is used to get, and print, its
value. Otherwise, printing falls back to using `expression` evaluation. In this
initial version, frame variable paths will be handled with `expression`.
Following this, there are a number of improvements that can be made. Some
improvements include supporting `frame variable` expressions or registers.
To provide transparency, especially as the `dwim-print` command evolves, a new
setting is also introduced: `dwim-print-verbosity`. This setting instructs
`dwim-print` to optionally print a message showing the effective command being
run. For example `dwim-print var.meth()` can print a message such as: "note:
ran `expression var.meth()`".
See https://discourse.llvm.org/t/dwim-print-command/66078 for the proposal and
discussion.
Differential Revision: https://reviews.llvm.org/D138315
2022-11-17 17:11:30 -08:00
|
|
|
using namespace llvm;
|
|
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
|
CommandObjectDWIMPrint::CommandObjectDWIMPrint(CommandInterpreter &interpreter)
|
2022-11-29 16:35:36 -08:00
|
|
|
: CommandObjectRaw(interpreter, "dwim-print",
|
|
|
|
|
"Print a variable or expression.",
|
|
|
|
|
"dwim-print [<variable-name> | <expression>]",
|
|
|
|
|
eCommandProcessMustBePaused | eCommandTryTargetAPILock) {
|
2023-03-01 14:59:31 -08:00
|
|
|
|
2024-02-27 10:34:01 -08:00
|
|
|
AddSimpleArgumentList(eArgTypeVarName);
|
2023-03-01 14:59:31 -08:00
|
|
|
|
2022-12-19 15:33:56 -08:00
|
|
|
m_option_group.Append(&m_format_options,
|
|
|
|
|
OptionGroupFormat::OPTION_GROUP_FORMAT |
|
|
|
|
|
OptionGroupFormat::OPTION_GROUP_GDB_FMT,
|
|
|
|
|
LLDB_OPT_SET_1);
|
2023-02-15 08:23:57 -08:00
|
|
|
StringRef exclude_expr_options[] = {"debug", "top-level"};
|
|
|
|
|
m_option_group.Append(&m_expr_options, exclude_expr_options);
|
2022-12-19 15:33:56 -08:00
|
|
|
m_option_group.Append(&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
|
|
|
|
|
m_option_group.Finalize();
|
2022-11-29 16:35:36 -08:00
|
|
|
}
|
[lldb] Introduce dwim-print command
Implements `dwim-print`, a printing command that chooses the most direct,
efficient, and resilient means of printing a given expression.
DWIM is an acronym for Do What I Mean. From Wikipedia, DWIM is described as:
> attempt to anticipate what users intend to do, correcting trivial errors
> automatically rather than blindly executing users' explicit but
> potentially incorrect input
The `dwim-print` command serves as a single print command for users who don't
yet know, or prefer not to know, the various lldb commands that can be used to
print, and when to use them.
This initial implementation is the base foundation for `dwim-print`. It accepts
no flags, only an expression. If the expression is the name of a variable in
the frame, then effectively `frame variable` is used to get, and print, its
value. Otherwise, printing falls back to using `expression` evaluation. In this
initial version, frame variable paths will be handled with `expression`.
Following this, there are a number of improvements that can be made. Some
improvements include supporting `frame variable` expressions or registers.
To provide transparency, especially as the `dwim-print` command evolves, a new
setting is also introduced: `dwim-print-verbosity`. This setting instructs
`dwim-print` to optionally print a message showing the effective command being
run. For example `dwim-print var.meth()` can print a message such as: "note:
ran `expression var.meth()`".
See https://discourse.llvm.org/t/dwim-print-command/66078 for the proposal and
discussion.
Differential Revision: https://reviews.llvm.org/D138315
2022-11-17 17:11:30 -08:00
|
|
|
|
2022-12-19 15:33:56 -08:00
|
|
|
Options *CommandObjectDWIMPrint::GetOptions() { return &m_option_group; }
|
|
|
|
|
|
2023-10-30 10:21:00 -10:00
|
|
|
void CommandObjectDWIMPrint::DoExecute(StringRef command,
|
[lldb] Introduce dwim-print command
Implements `dwim-print`, a printing command that chooses the most direct,
efficient, and resilient means of printing a given expression.
DWIM is an acronym for Do What I Mean. From Wikipedia, DWIM is described as:
> attempt to anticipate what users intend to do, correcting trivial errors
> automatically rather than blindly executing users' explicit but
> potentially incorrect input
The `dwim-print` command serves as a single print command for users who don't
yet know, or prefer not to know, the various lldb commands that can be used to
print, and when to use them.
This initial implementation is the base foundation for `dwim-print`. It accepts
no flags, only an expression. If the expression is the name of a variable in
the frame, then effectively `frame variable` is used to get, and print, its
value. Otherwise, printing falls back to using `expression` evaluation. In this
initial version, frame variable paths will be handled with `expression`.
Following this, there are a number of improvements that can be made. Some
improvements include supporting `frame variable` expressions or registers.
To provide transparency, especially as the `dwim-print` command evolves, a new
setting is also introduced: `dwim-print-verbosity`. This setting instructs
`dwim-print` to optionally print a message showing the effective command being
run. For example `dwim-print var.meth()` can print a message such as: "note:
ran `expression var.meth()`".
See https://discourse.llvm.org/t/dwim-print-command/66078 for the proposal and
discussion.
Differential Revision: https://reviews.llvm.org/D138315
2022-11-17 17:11:30 -08:00
|
|
|
CommandReturnObject &result) {
|
2022-12-19 15:33:56 -08:00
|
|
|
m_option_group.NotifyOptionParsingStarting(&m_exe_ctx);
|
|
|
|
|
OptionsWithRaw args{command};
|
|
|
|
|
StringRef expr = args.GetRawPart();
|
[lldb] Introduce dwim-print command
Implements `dwim-print`, a printing command that chooses the most direct,
efficient, and resilient means of printing a given expression.
DWIM is an acronym for Do What I Mean. From Wikipedia, DWIM is described as:
> attempt to anticipate what users intend to do, correcting trivial errors
> automatically rather than blindly executing users' explicit but
> potentially incorrect input
The `dwim-print` command serves as a single print command for users who don't
yet know, or prefer not to know, the various lldb commands that can be used to
print, and when to use them.
This initial implementation is the base foundation for `dwim-print`. It accepts
no flags, only an expression. If the expression is the name of a variable in
the frame, then effectively `frame variable` is used to get, and print, its
value. Otherwise, printing falls back to using `expression` evaluation. In this
initial version, frame variable paths will be handled with `expression`.
Following this, there are a number of improvements that can be made. Some
improvements include supporting `frame variable` expressions or registers.
To provide transparency, especially as the `dwim-print` command evolves, a new
setting is also introduced: `dwim-print-verbosity`. This setting instructs
`dwim-print` to optionally print a message showing the effective command being
run. For example `dwim-print var.meth()` can print a message such as: "note:
ran `expression var.meth()`".
See https://discourse.llvm.org/t/dwim-print-command/66078 for the proposal and
discussion.
Differential Revision: https://reviews.llvm.org/D138315
2022-11-17 17:11:30 -08:00
|
|
|
|
2023-03-09 11:10:32 -08:00
|
|
|
if (expr.empty()) {
|
|
|
|
|
result.AppendErrorWithFormatv("'{0}' takes a variable or expression",
|
|
|
|
|
m_cmd_name);
|
2023-10-30 10:21:00 -10:00
|
|
|
return;
|
2023-03-09 11:10:32 -08:00
|
|
|
}
|
|
|
|
|
|
2022-12-19 15:33:56 -08:00
|
|
|
if (args.HasArgs()) {
|
|
|
|
|
if (!ParseOptionsAndNotify(args.GetArgs(), result, m_option_group,
|
|
|
|
|
m_exe_ctx))
|
2023-10-30 10:21:00 -10:00
|
|
|
return;
|
[lldb] Introduce dwim-print command
Implements `dwim-print`, a printing command that chooses the most direct,
efficient, and resilient means of printing a given expression.
DWIM is an acronym for Do What I Mean. From Wikipedia, DWIM is described as:
> attempt to anticipate what users intend to do, correcting trivial errors
> automatically rather than blindly executing users' explicit but
> potentially incorrect input
The `dwim-print` command serves as a single print command for users who don't
yet know, or prefer not to know, the various lldb commands that can be used to
print, and when to use them.
This initial implementation is the base foundation for `dwim-print`. It accepts
no flags, only an expression. If the expression is the name of a variable in
the frame, then effectively `frame variable` is used to get, and print, its
value. Otherwise, printing falls back to using `expression` evaluation. In this
initial version, frame variable paths will be handled with `expression`.
Following this, there are a number of improvements that can be made. Some
improvements include supporting `frame variable` expressions or registers.
To provide transparency, especially as the `dwim-print` command evolves, a new
setting is also introduced: `dwim-print-verbosity`. This setting instructs
`dwim-print` to optionally print a message showing the effective command being
run. For example `dwim-print var.meth()` can print a message such as: "note:
ran `expression var.meth()`".
See https://discourse.llvm.org/t/dwim-print-command/66078 for the proposal and
discussion.
Differential Revision: https://reviews.llvm.org/D138315
2022-11-17 17:11:30 -08:00
|
|
|
}
|
2023-02-15 08:23:57 -08:00
|
|
|
|
2023-03-08 13:22:00 -08:00
|
|
|
// If the user has not specified, default to disabling persistent results.
|
|
|
|
|
if (m_expr_options.suppress_persistent_result == eLazyBoolCalculate)
|
|
|
|
|
m_expr_options.suppress_persistent_result = eLazyBoolYes;
|
[lldb] Delay removal of persistent results
Follow up to "Suppress persistent result when running po" (D144044).
This change delays removal of the persistent result until after `Dump` has been called.
In doing so, the persistent result is available for the purpose of getting its object
description.
In the original change, the persistent result removal happens indirectly, by setting
`EvaluateExpressionOptions::SetSuppressPersistentResult`. In practice this has worked,
however this exposed a latent bug in swift-lldb. The subtlety, and the bug, depend on
when the persisteted result variable is removed.
When the result is removed via `SetSuppressPersistentResult`, it happens within the call
to `Target::EvaluateExpression`. That is, by the time the call returns, the persistent
result is already removed.
The issue occurs shortly thereafter, when `ValueObject::Dump` is called, it cannot make
use of the persistent result variable (instead it uses the `ValueObjectConstResult`). In
swift-lldb, this causes an additional expression evaluation to happen. It first tries an
expression that reference `$R0` etc, but that always fails because `$R0` is removed. The
fallback to this failure does work most of the time, but there's at least one bug
involving imported Clang types.
Differential Revision: https://reviews.llvm.org/D150619
2023-05-15 14:36:17 -07:00
|
|
|
bool suppress_result = m_expr_options.ShouldSuppressResult(m_varobj_options);
|
2023-03-08 13:22:00 -08:00
|
|
|
|
[lldb] Introduce dwim-print command
Implements `dwim-print`, a printing command that chooses the most direct,
efficient, and resilient means of printing a given expression.
DWIM is an acronym for Do What I Mean. From Wikipedia, DWIM is described as:
> attempt to anticipate what users intend to do, correcting trivial errors
> automatically rather than blindly executing users' explicit but
> potentially incorrect input
The `dwim-print` command serves as a single print command for users who don't
yet know, or prefer not to know, the various lldb commands that can be used to
print, and when to use them.
This initial implementation is the base foundation for `dwim-print`. It accepts
no flags, only an expression. If the expression is the name of a variable in
the frame, then effectively `frame variable` is used to get, and print, its
value. Otherwise, printing falls back to using `expression` evaluation. In this
initial version, frame variable paths will be handled with `expression`.
Following this, there are a number of improvements that can be made. Some
improvements include supporting `frame variable` expressions or registers.
To provide transparency, especially as the `dwim-print` command evolves, a new
setting is also introduced: `dwim-print-verbosity`. This setting instructs
`dwim-print` to optionally print a message showing the effective command being
run. For example `dwim-print var.meth()` can print a message such as: "note:
ran `expression var.meth()`".
See https://discourse.llvm.org/t/dwim-print-command/66078 for the proposal and
discussion.
Differential Revision: https://reviews.llvm.org/D138315
2022-11-17 17:11:30 -08:00
|
|
|
auto verbosity = GetDebugger().GetDWIMPrintVerbosity();
|
|
|
|
|
|
2023-02-16 15:39:09 -08:00
|
|
|
Target *target_ptr = m_exe_ctx.GetTargetPtr();
|
|
|
|
|
// Fallback to the dummy target, which can allow for expression evaluation.
|
|
|
|
|
Target &target = target_ptr ? *target_ptr : GetDummyTarget();
|
|
|
|
|
|
[lldb] Delay removal of persistent results
Follow up to "Suppress persistent result when running po" (D144044).
This change delays removal of the persistent result until after `Dump` has been called.
In doing so, the persistent result is available for the purpose of getting its object
description.
In the original change, the persistent result removal happens indirectly, by setting
`EvaluateExpressionOptions::SetSuppressPersistentResult`. In practice this has worked,
however this exposed a latent bug in swift-lldb. The subtlety, and the bug, depend on
when the persisteted result variable is removed.
When the result is removed via `SetSuppressPersistentResult`, it happens within the call
to `Target::EvaluateExpression`. That is, by the time the call returns, the persistent
result is already removed.
The issue occurs shortly thereafter, when `ValueObject::Dump` is called, it cannot make
use of the persistent result variable (instead it uses the `ValueObjectConstResult`). In
swift-lldb, this causes an additional expression evaluation to happen. It first tries an
expression that reference `$R0` etc, but that always fails because `$R0` is removed. The
fallback to this failure does work most of the time, but there's at least one bug
involving imported Clang types.
Differential Revision: https://reviews.llvm.org/D150619
2023-05-15 14:36:17 -07:00
|
|
|
EvaluateExpressionOptions eval_options =
|
2023-02-16 15:39:09 -08:00
|
|
|
m_expr_options.GetEvaluateExpressionOptions(target, m_varobj_options);
|
[lldb] Delay removal of persistent results
Follow up to "Suppress persistent result when running po" (D144044).
This change delays removal of the persistent result until after `Dump` has been called.
In doing so, the persistent result is available for the purpose of getting its object
description.
In the original change, the persistent result removal happens indirectly, by setting
`EvaluateExpressionOptions::SetSuppressPersistentResult`. In practice this has worked,
however this exposed a latent bug in swift-lldb. The subtlety, and the bug, depend on
when the persisteted result variable is removed.
When the result is removed via `SetSuppressPersistentResult`, it happens within the call
to `Target::EvaluateExpression`. That is, by the time the call returns, the persistent
result is already removed.
The issue occurs shortly thereafter, when `ValueObject::Dump` is called, it cannot make
use of the persistent result variable (instead it uses the `ValueObjectConstResult`). In
swift-lldb, this causes an additional expression evaluation to happen. It first tries an
expression that reference `$R0` etc, but that always fails because `$R0` is removed. The
fallback to this failure does work most of the time, but there's at least one bug
involving imported Clang types.
Differential Revision: https://reviews.llvm.org/D150619
2023-05-15 14:36:17 -07:00
|
|
|
// This command manually removes the result variable, make sure expression
|
|
|
|
|
// evaluation doesn't do it first.
|
|
|
|
|
eval_options.SetSuppressPersistentResult(false);
|
2023-02-16 15:39:09 -08:00
|
|
|
|
2022-12-19 15:33:56 -08:00
|
|
|
DumpValueObjectOptions dump_options = m_varobj_options.GetAsDumpOptions(
|
2023-02-15 08:23:57 -08:00
|
|
|
m_expr_options.m_verbosity, m_format_options.GetFormat());
|
2025-03-15 08:57:51 -07:00
|
|
|
dump_options.SetHideRootName(suppress_result)
|
|
|
|
|
.SetExpandPointerTypeFlags(lldb::eTypeIsObjC);
|
[lldb] Delay removal of persistent results
Follow up to "Suppress persistent result when running po" (D144044).
This change delays removal of the persistent result until after `Dump` has been called.
In doing so, the persistent result is available for the purpose of getting its object
description.
In the original change, the persistent result removal happens indirectly, by setting
`EvaluateExpressionOptions::SetSuppressPersistentResult`. In practice this has worked,
however this exposed a latent bug in swift-lldb. The subtlety, and the bug, depend on
when the persisteted result variable is removed.
When the result is removed via `SetSuppressPersistentResult`, it happens within the call
to `Target::EvaluateExpression`. That is, by the time the call returns, the persistent
result is already removed.
The issue occurs shortly thereafter, when `ValueObject::Dump` is called, it cannot make
use of the persistent result variable (instead it uses the `ValueObjectConstResult`). In
swift-lldb, this causes an additional expression evaluation to happen. It first tries an
expression that reference `$R0` etc, but that always fails because `$R0` is removed. The
fallback to this failure does work most of the time, but there's at least one bug
involving imported Clang types.
Differential Revision: https://reviews.llvm.org/D150619
2023-05-15 14:36:17 -07:00
|
|
|
|
2023-06-28 16:34:26 -07:00
|
|
|
bool is_po = m_varobj_options.use_objc;
|
|
|
|
|
|
[lldb] Delay removal of persistent results
Follow up to "Suppress persistent result when running po" (D144044).
This change delays removal of the persistent result until after `Dump` has been called.
In doing so, the persistent result is available for the purpose of getting its object
description.
In the original change, the persistent result removal happens indirectly, by setting
`EvaluateExpressionOptions::SetSuppressPersistentResult`. In practice this has worked,
however this exposed a latent bug in swift-lldb. The subtlety, and the bug, depend on
when the persisteted result variable is removed.
When the result is removed via `SetSuppressPersistentResult`, it happens within the call
to `Target::EvaluateExpression`. That is, by the time the call returns, the persistent
result is already removed.
The issue occurs shortly thereafter, when `ValueObject::Dump` is called, it cannot make
use of the persistent result variable (instead it uses the `ValueObjectConstResult`). In
swift-lldb, this causes an additional expression evaluation to happen. It first tries an
expression that reference `$R0` etc, but that always fails because `$R0` is removed. The
fallback to this failure does work most of the time, but there's at least one bug
involving imported Clang types.
Differential Revision: https://reviews.llvm.org/D150619
2023-05-15 14:36:17 -07:00
|
|
|
StackFrame *frame = m_exe_ctx.GetFramePtr();
|
2022-12-19 15:33:56 -08:00
|
|
|
|
2024-04-29 13:37:26 -07:00
|
|
|
// Either the language was explicitly specified, or we check the frame.
|
2023-06-28 16:34:26 -07:00
|
|
|
lldb::LanguageType language = m_expr_options.language;
|
|
|
|
|
if (language == lldb::eLanguageTypeUnknown && frame)
|
2024-04-29 13:26:24 -07:00
|
|
|
language = frame->GuessLanguage().AsLanguageType();
|
2023-06-28 16:34:26 -07:00
|
|
|
|
|
|
|
|
// Add a hint if object description was requested, but no description
|
|
|
|
|
// function was implemented.
|
|
|
|
|
auto maybe_add_hint = [&](llvm::StringRef output) {
|
2025-03-07 21:57:05 -08:00
|
|
|
static bool note_shown = false;
|
|
|
|
|
if (note_shown)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-06-28 16:34:26 -07:00
|
|
|
// Identify the default output of object description for Swift and
|
|
|
|
|
// Objective-C
|
|
|
|
|
// "<Name: 0x...>. The regex is:
|
|
|
|
|
// - Start with "<".
|
|
|
|
|
// - Followed by 1 or more non-whitespace characters.
|
|
|
|
|
// - Followed by ": 0x".
|
|
|
|
|
// - Followed by 5 or more hex digits.
|
|
|
|
|
// - Followed by ">".
|
|
|
|
|
// - End with zero or more whitespace characters.
|
2025-03-07 21:57:05 -08:00
|
|
|
static const std::regex swift_class_regex(
|
|
|
|
|
"^<\\S+: 0x[[:xdigit:]]{5,}>\\s*$");
|
2023-06-28 16:34:26 -07:00
|
|
|
|
|
|
|
|
if (GetDebugger().GetShowDontUsePoHint() && target_ptr &&
|
|
|
|
|
(language == lldb::eLanguageTypeSwift ||
|
|
|
|
|
language == lldb::eLanguageTypeObjC) &&
|
|
|
|
|
std::regex_match(output.data(), swift_class_regex)) {
|
|
|
|
|
|
2024-11-02 08:52:32 -07:00
|
|
|
result.AppendNote(
|
|
|
|
|
"object description requested, but type doesn't implement "
|
|
|
|
|
"a custom object description. Consider using \"p\" instead of "
|
|
|
|
|
"\"po\" (this note will only be shown once per debug session).\n");
|
2023-06-28 16:34:26 -07:00
|
|
|
note_shown = true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-18 14:34:08 -07:00
|
|
|
// Dump `valobj` according to whether `po` was requested or not.
|
|
|
|
|
auto dump_val_object = [&](ValueObject &valobj) {
|
|
|
|
|
if (is_po) {
|
|
|
|
|
StreamString temp_result_stream;
|
2024-06-17 14:29:01 -07:00
|
|
|
if (llvm::Error error = valobj.Dump(temp_result_stream, dump_options)) {
|
|
|
|
|
result.AppendError(toString(std::move(error)));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-03-18 14:34:08 -07:00
|
|
|
llvm::StringRef output = temp_result_stream.GetString();
|
|
|
|
|
maybe_add_hint(output);
|
|
|
|
|
result.GetOutputStream() << output;
|
|
|
|
|
} else {
|
2024-06-20 12:50:26 -07:00
|
|
|
llvm::Error error =
|
|
|
|
|
valobj.Dump(result.GetOutputStream(), dump_options);
|
|
|
|
|
if (error) {
|
2024-06-17 14:29:01 -07:00
|
|
|
result.AppendError(toString(std::move(error)));
|
2024-06-20 12:50:26 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2024-03-18 14:34:08 -07:00
|
|
|
}
|
2024-06-20 12:50:26 -07:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
2024-03-18 14:34:08 -07:00
|
|
|
};
|
|
|
|
|
|
2024-12-02 13:55:35 -08:00
|
|
|
// First, try `expr` as a _limited_ frame variable expression path: only the
|
|
|
|
|
// dot operator (`.`) is permitted for this case.
|
|
|
|
|
//
|
|
|
|
|
// This is limited to support only unambiguous expression paths. Of note,
|
|
|
|
|
// expression paths are not attempted if the expression contain either the
|
|
|
|
|
// arrow operator (`->`) or the subscript operator (`[]`). This is because
|
|
|
|
|
// both operators can be overloaded in C++, and could result in ambiguity in
|
|
|
|
|
// how the expression is handled. Additionally, `*` and `&` are not supported.
|
|
|
|
|
const bool try_variable_path =
|
|
|
|
|
expr.find_first_of("*&->[]") == StringRef::npos;
|
|
|
|
|
if (frame && try_variable_path) {
|
|
|
|
|
VariableSP var_sp;
|
|
|
|
|
Status status;
|
|
|
|
|
auto valobj_sp = frame->GetValueForVariableExpressionPath(
|
|
|
|
|
expr, eval_options.GetUseDynamic(),
|
|
|
|
|
StackFrame::eExpressionPathOptionsAllowDirectIVarAccess, var_sp,
|
|
|
|
|
status);
|
|
|
|
|
if (valobj_sp && status.Success() && valobj_sp->GetError().Success()) {
|
[lldb] Delay removal of persistent results
Follow up to "Suppress persistent result when running po" (D144044).
This change delays removal of the persistent result until after `Dump` has been called.
In doing so, the persistent result is available for the purpose of getting its object
description.
In the original change, the persistent result removal happens indirectly, by setting
`EvaluateExpressionOptions::SetSuppressPersistentResult`. In practice this has worked,
however this exposed a latent bug in swift-lldb. The subtlety, and the bug, depend on
when the persisteted result variable is removed.
When the result is removed via `SetSuppressPersistentResult`, it happens within the call
to `Target::EvaluateExpression`. That is, by the time the call returns, the persistent
result is already removed.
The issue occurs shortly thereafter, when `ValueObject::Dump` is called, it cannot make
use of the persistent result variable (instead it uses the `ValueObjectConstResult`). In
swift-lldb, this causes an additional expression evaluation to happen. It first tries an
expression that reference `$R0` etc, but that always fails because `$R0` is removed. The
fallback to this failure does work most of the time, but there's at least one bug
involving imported Clang types.
Differential Revision: https://reviews.llvm.org/D150619
2023-05-15 14:36:17 -07:00
|
|
|
if (!suppress_result) {
|
2023-03-08 13:42:11 -08:00
|
|
|
if (auto persisted_valobj = valobj_sp->Persist())
|
|
|
|
|
valobj_sp = persisted_valobj;
|
|
|
|
|
}
|
2023-02-16 15:39:09 -08:00
|
|
|
|
2022-12-19 15:33:56 -08:00
|
|
|
if (verbosity == eDWIMPrintVerbosityFull) {
|
|
|
|
|
StringRef flags;
|
|
|
|
|
if (args.HasArgs())
|
|
|
|
|
flags = args.GetArgString();
|
2024-11-02 08:52:32 -07:00
|
|
|
result.AppendNoteWithFormatv("ran `frame variable {0}{1}`", flags,
|
|
|
|
|
expr);
|
2022-12-19 15:33:56 -08:00
|
|
|
}
|
2023-02-16 15:39:09 -08:00
|
|
|
|
2024-03-18 14:34:08 -07:00
|
|
|
dump_val_object(*valobj_sp);
|
2023-10-30 10:21:00 -10:00
|
|
|
return;
|
[lldb] Introduce dwim-print command
Implements `dwim-print`, a printing command that chooses the most direct,
efficient, and resilient means of printing a given expression.
DWIM is an acronym for Do What I Mean. From Wikipedia, DWIM is described as:
> attempt to anticipate what users intend to do, correcting trivial errors
> automatically rather than blindly executing users' explicit but
> potentially incorrect input
The `dwim-print` command serves as a single print command for users who don't
yet know, or prefer not to know, the various lldb commands that can be used to
print, and when to use them.
This initial implementation is the base foundation for `dwim-print`. It accepts
no flags, only an expression. If the expression is the name of a variable in
the frame, then effectively `frame variable` is used to get, and print, its
value. Otherwise, printing falls back to using `expression` evaluation. In this
initial version, frame variable paths will be handled with `expression`.
Following this, there are a number of improvements that can be made. Some
improvements include supporting `frame variable` expressions or registers.
To provide transparency, especially as the `dwim-print` command evolves, a new
setting is also introduced: `dwim-print-verbosity`. This setting instructs
`dwim-print` to optionally print a message showing the effective command being
run. For example `dwim-print var.meth()` can print a message such as: "note:
ran `expression var.meth()`".
See https://discourse.llvm.org/t/dwim-print-command/66078 for the proposal and
discussion.
Differential Revision: https://reviews.llvm.org/D138315
2022-11-17 17:11:30 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-15 16:09:24 -07:00
|
|
|
// Second, try `expr` as a persistent variable.
|
|
|
|
|
if (expr.starts_with("$"))
|
|
|
|
|
if (auto *state = target.GetPersistentExpressionStateForLanguage(language))
|
|
|
|
|
if (auto var_sp = state->GetVariable(expr))
|
|
|
|
|
if (auto valobj_sp = var_sp->GetValueObject()) {
|
2024-03-18 14:34:08 -07:00
|
|
|
dump_val_object(*valobj_sp);
|
2024-03-15 16:09:24 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Third, and lastly, try `expr` as a source expression to evaluate.
|
[lldb] Introduce dwim-print command
Implements `dwim-print`, a printing command that chooses the most direct,
efficient, and resilient means of printing a given expression.
DWIM is an acronym for Do What I Mean. From Wikipedia, DWIM is described as:
> attempt to anticipate what users intend to do, correcting trivial errors
> automatically rather than blindly executing users' explicit but
> potentially incorrect input
The `dwim-print` command serves as a single print command for users who don't
yet know, or prefer not to know, the various lldb commands that can be used to
print, and when to use them.
This initial implementation is the base foundation for `dwim-print`. It accepts
no flags, only an expression. If the expression is the name of a variable in
the frame, then effectively `frame variable` is used to get, and print, its
value. Otherwise, printing falls back to using `expression` evaluation. In this
initial version, frame variable paths will be handled with `expression`.
Following this, there are a number of improvements that can be made. Some
improvements include supporting `frame variable` expressions or registers.
To provide transparency, especially as the `dwim-print` command evolves, a new
setting is also introduced: `dwim-print-verbosity`. This setting instructs
`dwim-print` to optionally print a message showing the effective command being
run. For example `dwim-print var.meth()` can print a message such as: "note:
ran `expression var.meth()`".
See https://discourse.llvm.org/t/dwim-print-command/66078 for the proposal and
discussion.
Differential Revision: https://reviews.llvm.org/D138315
2022-11-17 17:11:30 -08:00
|
|
|
{
|
2022-11-29 16:35:36 -08:00
|
|
|
auto *exe_scope = m_exe_ctx.GetBestExecutionContextScope();
|
[lldb] Introduce dwim-print command
Implements `dwim-print`, a printing command that chooses the most direct,
efficient, and resilient means of printing a given expression.
DWIM is an acronym for Do What I Mean. From Wikipedia, DWIM is described as:
> attempt to anticipate what users intend to do, correcting trivial errors
> automatically rather than blindly executing users' explicit but
> potentially incorrect input
The `dwim-print` command serves as a single print command for users who don't
yet know, or prefer not to know, the various lldb commands that can be used to
print, and when to use them.
This initial implementation is the base foundation for `dwim-print`. It accepts
no flags, only an expression. If the expression is the name of a variable in
the frame, then effectively `frame variable` is used to get, and print, its
value. Otherwise, printing falls back to using `expression` evaluation. In this
initial version, frame variable paths will be handled with `expression`.
Following this, there are a number of improvements that can be made. Some
improvements include supporting `frame variable` expressions or registers.
To provide transparency, especially as the `dwim-print` command evolves, a new
setting is also introduced: `dwim-print-verbosity`. This setting instructs
`dwim-print` to optionally print a message showing the effective command being
run. For example `dwim-print var.meth()` can print a message such as: "note:
ran `expression var.meth()`".
See https://discourse.llvm.org/t/dwim-print-command/66078 for the proposal and
discussion.
Differential Revision: https://reviews.llvm.org/D138315
2022-11-17 17:11:30 -08:00
|
|
|
ValueObjectSP valobj_sp;
|
2023-10-13 07:06:50 -10:00
|
|
|
std::string fixed_expression;
|
|
|
|
|
|
|
|
|
|
ExpressionResults expr_result = target.EvaluateExpression(
|
|
|
|
|
expr, exe_scope, valobj_sp, eval_options, &fixed_expression);
|
|
|
|
|
|
2025-02-19 15:17:35 -08:00
|
|
|
if (valobj_sp)
|
|
|
|
|
result.GetValueObjectList().Append(valobj_sp);
|
|
|
|
|
|
2024-10-11 09:08:52 -07:00
|
|
|
// Record the position of the expression in the command.
|
|
|
|
|
std::optional<uint16_t> indent;
|
|
|
|
|
if (fixed_expression.empty()) {
|
2024-10-14 16:29:26 -07:00
|
|
|
size_t pos = m_original_command.rfind(expr);
|
2024-10-11 09:08:52 -07:00
|
|
|
if (pos != llvm::StringRef::npos)
|
|
|
|
|
indent = pos;
|
|
|
|
|
}
|
|
|
|
|
// Previously the indent was set up for diagnosing command line
|
|
|
|
|
// parsing errors. Now point it to the expression.
|
|
|
|
|
result.SetDiagnosticIndent(indent);
|
|
|
|
|
|
2023-10-13 07:06:50 -10:00
|
|
|
// Only mention Fix-Its if the expression evaluator applied them.
|
|
|
|
|
// Compiler errors refer to the final expression after applying Fix-It(s).
|
|
|
|
|
if (!fixed_expression.empty() && target.GetEnableNotifyAboutFixIts()) {
|
|
|
|
|
Stream &error_stream = result.GetErrorStream();
|
|
|
|
|
error_stream << " Evaluated this expression after applying Fix-It(s):\n";
|
|
|
|
|
error_stream << " " << fixed_expression << "\n";
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-20 12:50:26 -07:00
|
|
|
// If the expression failed, return an error.
|
|
|
|
|
if (expr_result != eExpressionCompleted) {
|
[lldb] Introduce dwim-print command
Implements `dwim-print`, a printing command that chooses the most direct,
efficient, and resilient means of printing a given expression.
DWIM is an acronym for Do What I Mean. From Wikipedia, DWIM is described as:
> attempt to anticipate what users intend to do, correcting trivial errors
> automatically rather than blindly executing users' explicit but
> potentially incorrect input
The `dwim-print` command serves as a single print command for users who don't
yet know, or prefer not to know, the various lldb commands that can be used to
print, and when to use them.
This initial implementation is the base foundation for `dwim-print`. It accepts
no flags, only an expression. If the expression is the name of a variable in
the frame, then effectively `frame variable` is used to get, and print, its
value. Otherwise, printing falls back to using `expression` evaluation. In this
initial version, frame variable paths will be handled with `expression`.
Following this, there are a number of improvements that can be made. Some
improvements include supporting `frame variable` expressions or registers.
To provide transparency, especially as the `dwim-print` command evolves, a new
setting is also introduced: `dwim-print-verbosity`. This setting instructs
`dwim-print` to optionally print a message showing the effective command being
run. For example `dwim-print var.meth()` can print a message such as: "note:
ran `expression var.meth()`".
See https://discourse.llvm.org/t/dwim-print-command/66078 for the proposal and
discussion.
Differential Revision: https://reviews.llvm.org/D138315
2022-11-17 17:11:30 -08:00
|
|
|
if (valobj_sp)
|
2024-10-02 09:11:47 -07:00
|
|
|
result.SetError(valobj_sp->GetError().Clone());
|
[lldb] Introduce dwim-print command
Implements `dwim-print`, a printing command that chooses the most direct,
efficient, and resilient means of printing a given expression.
DWIM is an acronym for Do What I Mean. From Wikipedia, DWIM is described as:
> attempt to anticipate what users intend to do, correcting trivial errors
> automatically rather than blindly executing users' explicit but
> potentially incorrect input
The `dwim-print` command serves as a single print command for users who don't
yet know, or prefer not to know, the various lldb commands that can be used to
print, and when to use them.
This initial implementation is the base foundation for `dwim-print`. It accepts
no flags, only an expression. If the expression is the name of a variable in
the frame, then effectively `frame variable` is used to get, and print, its
value. Otherwise, printing falls back to using `expression` evaluation. In this
initial version, frame variable paths will be handled with `expression`.
Following this, there are a number of improvements that can be made. Some
improvements include supporting `frame variable` expressions or registers.
To provide transparency, especially as the `dwim-print` command evolves, a new
setting is also introduced: `dwim-print-verbosity`. This setting instructs
`dwim-print` to optionally print a message showing the effective command being
run. For example `dwim-print var.meth()` can print a message such as: "note:
ran `expression var.meth()`".
See https://discourse.llvm.org/t/dwim-print-command/66078 for the proposal and
discussion.
Differential Revision: https://reviews.llvm.org/D138315
2022-11-17 17:11:30 -08:00
|
|
|
else
|
|
|
|
|
result.AppendErrorWithFormatv(
|
|
|
|
|
"unknown error evaluating expression `{0}`", expr);
|
2024-06-20 12:50:26 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (verbosity != eDWIMPrintVerbosityNone) {
|
|
|
|
|
StringRef flags;
|
|
|
|
|
if (args.HasArgs())
|
|
|
|
|
flags = args.GetArgStringWithDelimiter();
|
2024-11-02 08:52:32 -07:00
|
|
|
result.AppendNoteWithFormatv("ran `expression {0}{1}`", flags, expr);
|
[lldb] Introduce dwim-print command
Implements `dwim-print`, a printing command that chooses the most direct,
efficient, and resilient means of printing a given expression.
DWIM is an acronym for Do What I Mean. From Wikipedia, DWIM is described as:
> attempt to anticipate what users intend to do, correcting trivial errors
> automatically rather than blindly executing users' explicit but
> potentially incorrect input
The `dwim-print` command serves as a single print command for users who don't
yet know, or prefer not to know, the various lldb commands that can be used to
print, and when to use them.
This initial implementation is the base foundation for `dwim-print`. It accepts
no flags, only an expression. If the expression is the name of a variable in
the frame, then effectively `frame variable` is used to get, and print, its
value. Otherwise, printing falls back to using `expression` evaluation. In this
initial version, frame variable paths will be handled with `expression`.
Following this, there are a number of improvements that can be made. Some
improvements include supporting `frame variable` expressions or registers.
To provide transparency, especially as the `dwim-print` command evolves, a new
setting is also introduced: `dwim-print-verbosity`. This setting instructs
`dwim-print` to optionally print a message showing the effective command being
run. For example `dwim-print var.meth()` can print a message such as: "note:
ran `expression var.meth()`".
See https://discourse.llvm.org/t/dwim-print-command/66078 for the proposal and
discussion.
Differential Revision: https://reviews.llvm.org/D138315
2022-11-17 17:11:30 -08:00
|
|
|
}
|
2024-06-20 12:50:26 -07:00
|
|
|
|
|
|
|
|
if (valobj_sp->GetError().GetError() != UserExpression::kNoResult)
|
|
|
|
|
dump_val_object(*valobj_sp);
|
|
|
|
|
else
|
2024-11-01 13:39:14 -07:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
2024-06-20 12:50:26 -07:00
|
|
|
|
|
|
|
|
if (suppress_result)
|
|
|
|
|
if (auto result_var_sp =
|
|
|
|
|
target.GetPersistentVariable(valobj_sp->GetName())) {
|
|
|
|
|
auto language = valobj_sp->GetPreferredDisplayLanguage();
|
|
|
|
|
if (auto *persistent_state =
|
|
|
|
|
target.GetPersistentExpressionStateForLanguage(language))
|
|
|
|
|
persistent_state->RemovePersistentVariable(result_var_sp);
|
|
|
|
|
}
|
[lldb] Introduce dwim-print command
Implements `dwim-print`, a printing command that chooses the most direct,
efficient, and resilient means of printing a given expression.
DWIM is an acronym for Do What I Mean. From Wikipedia, DWIM is described as:
> attempt to anticipate what users intend to do, correcting trivial errors
> automatically rather than blindly executing users' explicit but
> potentially incorrect input
The `dwim-print` command serves as a single print command for users who don't
yet know, or prefer not to know, the various lldb commands that can be used to
print, and when to use them.
This initial implementation is the base foundation for `dwim-print`. It accepts
no flags, only an expression. If the expression is the name of a variable in
the frame, then effectively `frame variable` is used to get, and print, its
value. Otherwise, printing falls back to using `expression` evaluation. In this
initial version, frame variable paths will be handled with `expression`.
Following this, there are a number of improvements that can be made. Some
improvements include supporting `frame variable` expressions or registers.
To provide transparency, especially as the `dwim-print` command evolves, a new
setting is also introduced: `dwim-print-verbosity`. This setting instructs
`dwim-print` to optionally print a message showing the effective command being
run. For example `dwim-print var.meth()` can print a message such as: "note:
ran `expression var.meth()`".
See https://discourse.llvm.org/t/dwim-print-command/66078 for the proposal and
discussion.
Differential Revision: https://reviews.llvm.org/D138315
2022-11-17 17:11:30 -08:00
|
|
|
}
|
|
|
|
|
}
|