[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- UserExpression.cpp ------------------------------------------------===//
|
2015-09-16 05:13:50 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-09-16 05:13:50 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2021-05-26 18:19:37 +08:00
|
|
|
#include <cstdio>
|
2015-09-16 05:13:50 +08:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "lldb/Core/Module.h"
|
|
|
|
#include "lldb/Core/StreamFile.h"
|
|
|
|
#include "lldb/Core/ValueObjectConstResult.h"
|
2016-03-19 08:03:59 +08:00
|
|
|
#include "lldb/Expression/DiagnosticManager.h"
|
2019-05-08 07:11:05 +08:00
|
|
|
#include "lldb/Expression/ExpressionVariable.h"
|
2015-09-16 05:13:50 +08:00
|
|
|
#include "lldb/Expression/IRExecutionUnit.h"
|
|
|
|
#include "lldb/Expression/IRInterpreter.h"
|
|
|
|
#include "lldb/Expression/Materializer.h"
|
|
|
|
#include "lldb/Expression/UserExpression.h"
|
|
|
|
#include "lldb/Host/HostInfo.h"
|
|
|
|
#include "lldb/Symbol/Block.h"
|
|
|
|
#include "lldb/Symbol/Function.h"
|
|
|
|
#include "lldb/Symbol/ObjectFile.h"
|
|
|
|
#include "lldb/Symbol/SymbolVendor.h"
|
|
|
|
#include "lldb/Symbol/Type.h"
|
2015-10-01 03:57:57 +08:00
|
|
|
#include "lldb/Symbol/TypeSystem.h"
|
2015-09-16 05:13:50 +08:00
|
|
|
#include "lldb/Symbol/VariableList.h"
|
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/StackFrame.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
|
|
|
#include "lldb/Target/ThreadPlan.h"
|
|
|
|
#include "lldb/Target/ThreadPlanCallUserExpression.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/ConstString.h"
|
2022-02-03 20:26:10 +08:00
|
|
|
#include "lldb/Utility/LLDBLog.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/StreamString.h"
|
2015-09-16 05:13:50 +08:00
|
|
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2019-11-12 17:04:32 +08:00
|
|
|
char UserExpression::ID;
|
|
|
|
|
2015-11-03 10:11:24 +08:00
|
|
|
UserExpression::UserExpression(ExecutionContextScope &exe_scope,
|
2016-11-08 12:52:16 +08:00
|
|
|
llvm::StringRef expr, llvm::StringRef prefix,
|
2015-11-03 10:11:24 +08:00
|
|
|
lldb::LanguageType language,
|
|
|
|
ResultType desired_type,
|
2019-11-12 17:04:32 +08:00
|
|
|
const EvaluateExpressionOptions &options)
|
2020-01-29 03:23:46 +08:00
|
|
|
: Expression(exe_scope), m_expr_text(std::string(expr)),
|
|
|
|
m_expr_prefix(std::string(prefix)), m_language(language),
|
|
|
|
m_desired_type(desired_type), m_options(options) {}
|
2015-09-16 05:13:50 +08:00
|
|
|
|
2021-07-03 02:27:37 +08:00
|
|
|
UserExpression::~UserExpression() = default;
|
2015-09-16 05:13:50 +08:00
|
|
|
|
|
|
|
void UserExpression::InstallContext(ExecutionContext &exe_ctx) {
|
|
|
|
m_jit_process_wp = exe_ctx.GetProcessSP();
|
|
|
|
|
|
|
|
lldb::StackFrameSP frame_sp = exe_ctx.GetFrameSP();
|
|
|
|
|
|
|
|
if (frame_sp)
|
|
|
|
m_address = frame_sp->GetFrameCodeAddress();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UserExpression::LockAndCheckContext(ExecutionContext &exe_ctx,
|
|
|
|
lldb::TargetSP &target_sp,
|
|
|
|
lldb::ProcessSP &process_sp,
|
|
|
|
lldb::StackFrameSP &frame_sp) {
|
|
|
|
lldb::ProcessSP expected_process_sp = m_jit_process_wp.lock();
|
|
|
|
process_sp = exe_ctx.GetProcessSP();
|
|
|
|
|
|
|
|
if (process_sp != expected_process_sp)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
process_sp = exe_ctx.GetProcessSP();
|
|
|
|
target_sp = exe_ctx.GetTargetSP();
|
|
|
|
frame_sp = exe_ctx.GetFrameSP();
|
|
|
|
|
|
|
|
if (m_address.IsValid()) {
|
|
|
|
if (!frame_sp)
|
|
|
|
return false;
|
2020-01-04 08:49:51 +08:00
|
|
|
return (Address::CompareLoadAddress(m_address,
|
|
|
|
frame_sp->GetFrameCodeAddress(),
|
|
|
|
target_sp.get()) == 0);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-09-16 05:13:50 +08:00
|
|
|
|
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-09-16 05:13:50 +08:00
|
|
|
|
|
|
|
bool UserExpression::MatchesContext(ExecutionContext &exe_ctx) {
|
|
|
|
lldb::TargetSP target_sp;
|
|
|
|
lldb::ProcessSP process_sp;
|
|
|
|
lldb::StackFrameSP frame_sp;
|
|
|
|
|
|
|
|
return LockAndCheckContext(exe_ctx, target_sp, process_sp, frame_sp);
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::addr_t UserExpression::GetObjectPointer(lldb::StackFrameSP frame_sp,
|
|
|
|
ConstString &object_name,
|
2017-05-12 12:51:55 +08:00
|
|
|
Status &err) {
|
2015-09-16 05:13:50 +08:00
|
|
|
err.Clear();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-16 05:13:50 +08:00
|
|
|
if (!frame_sp) {
|
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"Couldn't load '%s' because the context is incomplete",
|
|
|
|
object_name.AsCString());
|
|
|
|
return LLDB_INVALID_ADDRESS;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-09-16 05:13:50 +08:00
|
|
|
lldb::VariableSP var_sp;
|
|
|
|
lldb::ValueObjectSP valobj_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-16 05:13:50 +08:00
|
|
|
valobj_sp = frame_sp->GetValueForVariableExpressionPath(
|
2020-02-11 16:05:37 +08:00
|
|
|
object_name.GetStringRef(), lldb::eNoDynamicValues,
|
2015-09-16 05:13:50 +08:00
|
|
|
StackFrame::eExpressionPathOptionCheckPtrVsMember |
|
|
|
|
StackFrame::eExpressionPathOptionsNoFragileObjcIvar |
|
|
|
|
StackFrame::eExpressionPathOptionsNoSyntheticChildren |
|
|
|
|
StackFrame::eExpressionPathOptionsNoSyntheticArrayRange,
|
2016-03-19 08:03:59 +08:00
|
|
|
var_sp, err);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-16 05:13:50 +08:00
|
|
|
if (!err.Success() || !valobj_sp.get())
|
|
|
|
return LLDB_INVALID_ADDRESS;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-16 05:13:50 +08:00
|
|
|
lldb::addr_t ret = valobj_sp->GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-16 05:13:50 +08:00
|
|
|
if (ret == LLDB_INVALID_ADDRESS) {
|
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"Couldn't load '%s' because its value couldn't be evaluated",
|
|
|
|
object_name.AsCString());
|
|
|
|
return LLDB_INVALID_ADDRESS;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-09-16 05:13:50 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-01-31 15:16:12 +08:00
|
|
|
lldb::ExpressionResults
|
|
|
|
UserExpression::Evaluate(ExecutionContext &exe_ctx,
|
|
|
|
const EvaluateExpressionOptions &options,
|
|
|
|
llvm::StringRef expr, llvm::StringRef prefix,
|
|
|
|
lldb::ValueObjectSP &result_valobj_sp, Status &error,
|
|
|
|
std::string *fixed_expression, ValueObject *ctx_obj) {
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log(GetLog(LLDBLog::Expressions | LLDBLog::Step));
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-02-05 17:14:36 +08:00
|
|
|
if (ctx_obj) {
|
|
|
|
static unsigned const ctx_type_mask =
|
|
|
|
lldb::TypeFlags::eTypeIsClass | lldb::TypeFlags::eTypeIsStructUnion;
|
|
|
|
if (!(ctx_obj->GetTypeInfo() & ctx_type_mask)) {
|
|
|
|
LLDB_LOG(log, "== [UserExpression::Evaluate] Passed a context object of "
|
|
|
|
"an invalid type, can't run expressions.");
|
|
|
|
error.SetErrorString("a context object of an invalid type passed");
|
|
|
|
return lldb::eExpressionSetupError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-16 05:13:50 +08:00
|
|
|
lldb_private::ExecutionPolicy execution_policy = options.GetExecutionPolicy();
|
2015-10-08 06:01:12 +08:00
|
|
|
lldb::LanguageType language = options.GetLanguage();
|
2015-09-16 05:13:50 +08:00
|
|
|
const ResultType desired_type = options.DoesCoerceToId()
|
|
|
|
? UserExpression::eResultTypeId
|
|
|
|
: UserExpression::eResultTypeAny;
|
|
|
|
lldb::ExpressionResults execution_results = lldb::eExpressionSetupError;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-16 05:13:50 +08:00
|
|
|
Target *target = exe_ctx.GetTargetPtr();
|
|
|
|
if (!target) {
|
2020-03-04 08:31:25 +08:00
|
|
|
LLDB_LOG(log, "== [UserExpression::Evaluate] Passed a NULL target, can't "
|
|
|
|
"run expressions.");
|
2016-11-08 06:47:01 +08:00
|
|
|
error.SetErrorString("expression passed a null target");
|
2015-09-16 05:13:50 +08:00
|
|
|
return lldb::eExpressionSetupError;
|
|
|
|
}
|
|
|
|
|
|
|
|
Process *process = exe_ctx.GetProcessPtr();
|
|
|
|
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
if (process == nullptr || process->GetState() != lldb::eStateStopped) {
|
2015-09-16 05:13:50 +08:00
|
|
|
if (execution_policy == eExecutionPolicyAlways) {
|
2020-03-04 08:31:25 +08:00
|
|
|
LLDB_LOG(log, "== [UserExpression::Evaluate] Expression may not run, but "
|
|
|
|
"is not constant ==");
|
2015-09-16 05:13:50 +08:00
|
|
|
|
|
|
|
error.SetErrorString("expression needed to run but couldn't");
|
|
|
|
|
|
|
|
return execution_results;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2021-02-12 00:00:17 +08:00
|
|
|
// Explicitly force the IR interpreter to evaluate the expression when the
|
|
|
|
// there is no process that supports running the expression for us. Don't
|
|
|
|
// change the execution policy if we have the special top-level policy that
|
|
|
|
// doesn't contain any expression and there is nothing to interpret.
|
|
|
|
if (execution_policy != eExecutionPolicyTopLevel &&
|
|
|
|
(process == nullptr || !process->CanJIT()))
|
2015-09-16 05:13:50 +08:00
|
|
|
execution_policy = eExecutionPolicyNever;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-03-22 03:21:13 +08:00
|
|
|
// We need to set the expression execution thread here, turns out parse can
|
2018-05-01 00:49:04 +08:00
|
|
|
// call functions in the process of looking up symbols, which will escape the
|
|
|
|
// context set by exe_ctx passed to Execute.
|
2016-03-22 03:21:13 +08:00
|
|
|
lldb::ThreadSP thread_sp = exe_ctx.GetThreadSP();
|
|
|
|
ThreadList::ExpressionExecutionThreadPusher execution_thread_pusher(
|
|
|
|
thread_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-11-08 12:52:16 +08:00
|
|
|
llvm::StringRef full_prefix;
|
|
|
|
llvm::StringRef option_prefix(options.GetPrefix());
|
2015-09-16 05:13:50 +08:00
|
|
|
std::string full_prefix_storage;
|
2016-11-08 12:52:16 +08:00
|
|
|
if (!prefix.empty() && !option_prefix.empty()) {
|
2020-01-29 03:23:46 +08:00
|
|
|
full_prefix_storage = std::string(prefix);
|
|
|
|
full_prefix_storage.append(std::string(option_prefix));
|
2016-11-08 12:52:16 +08:00
|
|
|
full_prefix = full_prefix_storage;
|
|
|
|
} else if (!prefix.empty())
|
|
|
|
full_prefix = prefix;
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2016-04-13 01:17:35 +08:00
|
|
|
full_prefix = option_prefix;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// If the language was not specified in the expression command, set it to the
|
|
|
|
// language in the target's properties if specified, else default to the
|
|
|
|
// langage for the frame.
|
2015-09-16 05:13:50 +08:00
|
|
|
if (language == lldb::eLanguageTypeUnknown) {
|
2015-10-08 06:01:12 +08:00
|
|
|
if (target->GetLanguage() != lldb::eLanguageTypeUnknown)
|
|
|
|
language = target->GetLanguage();
|
2015-09-16 05:13:50 +08:00
|
|
|
else if (StackFrame *frame = exe_ctx.GetFramePtr())
|
|
|
|
language = frame->GetLanguage();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-09-16 05:13:50 +08:00
|
|
|
lldb::UserExpressionSP user_expression_sp(
|
2016-11-08 12:52:16 +08:00
|
|
|
target->GetUserExpressionForLanguage(expr, full_prefix, language,
|
2019-02-05 17:14:36 +08:00
|
|
|
desired_type, options, ctx_obj,
|
|
|
|
error));
|
2015-09-16 05:13:50 +08:00
|
|
|
if (error.Fail()) {
|
2020-03-04 08:31:25 +08:00
|
|
|
LLDB_LOG(log, "== [UserExpression::Evaluate] Getting expression: {0} ==",
|
|
|
|
error.AsCString());
|
2015-09-16 05:13:50 +08:00
|
|
|
return lldb::eExpressionSetupError;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2020-03-04 08:31:25 +08:00
|
|
|
LLDB_LOG(log, "== [UserExpression::Evaluate] Parsing expression {0} ==",
|
|
|
|
expr.str());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-16 05:13:50 +08:00
|
|
|
const bool keep_expression_in_memory = true;
|
|
|
|
const bool generate_debug_info = options.GetGenerateDebugInfo();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-08 06:01:12 +08:00
|
|
|
if (options.InvokeCancelCallback(lldb::eExpressionEvaluationParse)) {
|
|
|
|
error.SetErrorString("expression interrupted by callback before parse");
|
2016-03-19 08:03:59 +08:00
|
|
|
result_valobj_sp = ValueObjectConstResult::Create(
|
2015-10-08 06:01:12 +08:00
|
|
|
exe_ctx.GetBestExecutionContextScope(), error);
|
|
|
|
return lldb::eExpressionInterrupted;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2016-03-19 08:03:59 +08:00
|
|
|
DiagnosticManager diagnostic_manager;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-08 06:01:12 +08:00
|
|
|
bool parse_success =
|
|
|
|
user_expression_sp->Parse(diagnostic_manager, exe_ctx, execution_policy,
|
2016-03-30 06:00:08 +08:00
|
|
|
keep_expression_in_memory, generate_debug_info);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-08 06:01:12 +08:00
|
|
|
// Calculate the fixed expression always, since we need it for errors.
|
|
|
|
std::string tmp_fixed_expression;
|
|
|
|
if (fixed_expression == nullptr)
|
2016-03-30 06:00:08 +08:00
|
|
|
fixed_expression = &tmp_fixed_expression;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2021-12-16 06:48:30 +08:00
|
|
|
*fixed_expression = user_expression_sp->GetFixedText().str();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-08 06:01:12 +08:00
|
|
|
// If there is a fixed expression, try to parse it:
|
2016-03-30 06:00:08 +08:00
|
|
|
if (!parse_success) {
|
2020-03-20 00:40:53 +08:00
|
|
|
// Delete the expression that failed to parse before attempting to parse
|
|
|
|
// the next expression.
|
|
|
|
user_expression_sp.reset();
|
|
|
|
|
2015-10-08 06:01:12 +08:00
|
|
|
execution_results = lldb::eExpressionParseError;
|
2021-12-16 06:54:03 +08:00
|
|
|
if (!fixed_expression->empty() && options.GetAutoApplyFixIts()) {
|
2020-04-06 17:08:12 +08:00
|
|
|
const uint64_t max_fix_retries = options.GetRetriesWithFixIts();
|
|
|
|
for (uint64_t i = 0; i < max_fix_retries; ++i) {
|
|
|
|
// Try parsing the fixed expression.
|
|
|
|
lldb::UserExpressionSP fixed_expression_sp(
|
|
|
|
target->GetUserExpressionForLanguage(
|
|
|
|
fixed_expression->c_str(), full_prefix, language, desired_type,
|
|
|
|
options, ctx_obj, error));
|
|
|
|
DiagnosticManager fixed_diagnostic_manager;
|
|
|
|
parse_success = fixed_expression_sp->Parse(
|
|
|
|
fixed_diagnostic_manager, exe_ctx, execution_policy,
|
|
|
|
keep_expression_in_memory, generate_debug_info);
|
|
|
|
if (parse_success) {
|
|
|
|
diagnostic_manager.Clear();
|
|
|
|
user_expression_sp = fixed_expression_sp;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
// The fixed expression also didn't parse. Let's check for any new
|
|
|
|
// Fix-Its we could try.
|
2021-12-16 06:48:30 +08:00
|
|
|
if (!fixed_expression_sp->GetFixedText().empty()) {
|
|
|
|
*fixed_expression = fixed_expression_sp->GetFixedText().str();
|
2020-04-06 17:08:12 +08:00
|
|
|
} else {
|
|
|
|
// Fixed expression didn't compile without a fixit, don't retry and
|
|
|
|
// don't tell the user about it.
|
|
|
|
fixed_expression->clear();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-10-08 06:01:12 +08:00
|
|
|
}
|
|
|
|
|
2015-09-16 05:13:50 +08:00
|
|
|
if (!parse_success) {
|
2021-04-28 01:38:51 +08:00
|
|
|
std::string msg;
|
|
|
|
{
|
|
|
|
llvm::raw_string_ostream os(msg);
|
|
|
|
os << "expression failed to parse:\n";
|
|
|
|
if (!diagnostic_manager.Diagnostics().empty())
|
|
|
|
os << diagnostic_manager.GetString();
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2021-04-28 01:38:51 +08:00
|
|
|
os << "unknown error";
|
|
|
|
if (target->GetEnableNotifyAboutFixIts() && fixed_expression &&
|
|
|
|
!fixed_expression->empty())
|
|
|
|
os << "\nfixed expression suggested:\n " << *fixed_expression;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2021-04-28 01:38:51 +08:00
|
|
|
error.SetExpressionError(execution_results, msg.c_str());
|
2015-09-16 05:13:50 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2016-03-30 06:00:08 +08:00
|
|
|
if (parse_success) {
|
2015-09-16 05:13:50 +08:00
|
|
|
lldb::ExpressionVariableSP expr_result;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-16 05:13:50 +08:00
|
|
|
if (execution_policy == eExecutionPolicyNever &&
|
|
|
|
!user_expression_sp->CanInterpret()) {
|
2020-03-04 08:31:25 +08:00
|
|
|
LLDB_LOG(log, "== [UserExpression::Evaluate] Expression may not run, but "
|
|
|
|
"is not constant ==");
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-03-30 06:00:08 +08:00
|
|
|
if (!diagnostic_manager.Diagnostics().size())
|
2016-03-19 08:03:59 +08:00
|
|
|
error.SetExpressionError(lldb::eExpressionSetupError,
|
|
|
|
"expression needed to run but couldn't");
|
2016-03-29 05:10:36 +08:00
|
|
|
} else if (execution_policy == eExecutionPolicyTopLevel) {
|
2018-10-18 11:10:43 +08:00
|
|
|
error.SetError(UserExpression::kNoResult, lldb::eErrorTypeGeneric);
|
2016-03-29 05:10:36 +08:00
|
|
|
return lldb::eExpressionCompleted;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2015-09-16 05:13:50 +08:00
|
|
|
if (options.InvokeCancelCallback(lldb::eExpressionEvaluationExecution)) {
|
2016-03-30 06:00:08 +08:00
|
|
|
error.SetExpressionError(
|
2015-09-16 05:13:50 +08:00
|
|
|
lldb::eExpressionInterrupted,
|
|
|
|
"expression interrupted by callback before execution");
|
|
|
|
result_valobj_sp = ValueObjectConstResult::Create(
|
|
|
|
exe_ctx.GetBestExecutionContextScope(), error);
|
|
|
|
return lldb::eExpressionInterrupted;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-09-16 05:13:50 +08:00
|
|
|
|
|
|
|
diagnostic_manager.Clear();
|
|
|
|
|
2020-03-04 08:31:25 +08:00
|
|
|
LLDB_LOG(log, "== [UserExpression::Evaluate] Executing expression ==");
|
2015-09-16 05:13:50 +08:00
|
|
|
|
2016-03-19 08:03:59 +08:00
|
|
|
execution_results =
|
|
|
|
user_expression_sp->Execute(diagnostic_manager, exe_ctx, options,
|
2015-09-16 05:13:50 +08:00
|
|
|
user_expression_sp, expr_result);
|
|
|
|
|
2016-03-30 06:00:08 +08:00
|
|
|
if (execution_results != lldb::eExpressionCompleted) {
|
2020-03-04 08:31:25 +08:00
|
|
|
LLDB_LOG(log, "== [UserExpression::Evaluate] Execution completed "
|
|
|
|
"abnormally ==");
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-03-30 06:00:08 +08:00
|
|
|
if (!diagnostic_manager.Diagnostics().size())
|
|
|
|
error.SetExpressionError(
|
2016-03-19 08:03:59 +08:00
|
|
|
execution_results, "expression failed to execute, unknown error");
|
2015-09-16 05:13:50 +08:00
|
|
|
else
|
|
|
|
error.SetExpressionError(execution_results,
|
|
|
|
diagnostic_manager.GetString().c_str());
|
|
|
|
} else {
|
|
|
|
if (expr_result) {
|
|
|
|
result_valobj_sp = expr_result->GetValueObject();
|
2020-11-13 04:11:47 +08:00
|
|
|
result_valobj_sp->SetPreferredDisplayLanguage(language);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-03-04 08:31:25 +08:00
|
|
|
LLDB_LOG(log,
|
|
|
|
"== [UserExpression::Evaluate] Execution completed "
|
2021-02-11 23:05:14 +08:00
|
|
|
"normally with result {0} ==",
|
2020-03-04 08:31:25 +08:00
|
|
|
result_valobj_sp->GetValueAsCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2020-03-04 08:31:25 +08:00
|
|
|
LLDB_LOG(log, "== [UserExpression::Evaluate] Execution completed "
|
|
|
|
"normally with no result ==");
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-10-18 11:10:43 +08:00
|
|
|
error.SetError(UserExpression::kNoResult, lldb::eErrorTypeGeneric);
|
2015-09-16 05:13:50 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-09-16 05:13:50 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-09-16 05:13:50 +08:00
|
|
|
|
|
|
|
if (options.InvokeCancelCallback(lldb::eExpressionEvaluationComplete)) {
|
|
|
|
error.SetExpressionError(
|
|
|
|
lldb::eExpressionInterrupted,
|
|
|
|
"expression interrupted by callback after complete");
|
|
|
|
return lldb::eExpressionInterrupted;
|
|
|
|
}
|
|
|
|
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
if (result_valobj_sp.get() == nullptr) {
|
2015-09-16 05:13:50 +08:00
|
|
|
result_valobj_sp = ValueObjectConstResult::Create(
|
|
|
|
exe_ctx.GetBestExecutionContextScope(), error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return execution_results;
|
|
|
|
}
|
2016-04-13 01:17:35 +08:00
|
|
|
|
|
|
|
lldb::ExpressionResults
|
|
|
|
UserExpression::Execute(DiagnosticManager &diagnostic_manager,
|
|
|
|
ExecutionContext &exe_ctx,
|
|
|
|
const EvaluateExpressionOptions &options,
|
|
|
|
lldb::UserExpressionSP &shared_ptr_to_me,
|
|
|
|
lldb::ExpressionVariableSP &result_var) {
|
|
|
|
lldb::ExpressionResults expr_result = DoExecute(
|
|
|
|
diagnostic_manager, exe_ctx, options, shared_ptr_to_me, result_var);
|
|
|
|
Target *target = exe_ctx.GetTargetPtr();
|
|
|
|
if (options.GetResultIsInternal() && result_var && target) {
|
2020-01-09 06:18:47 +08:00
|
|
|
if (auto *persistent_state =
|
|
|
|
target->GetPersistentExpressionStateForLanguage(m_language))
|
|
|
|
persistent_state->RemovePersistentVariable(result_var);
|
2016-04-13 01:17:35 +08:00
|
|
|
}
|
|
|
|
return expr_result;
|
|
|
|
}
|