LLDB mainline
ExpressionParser.cpp
Go to the documentation of this file.
1//===-- ExpressionParser.cpp ----------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
14
15using namespace lldb;
16using namespace lldb_private;
17
19 addr_t &func_addr, addr_t &func_end,
20 std::shared_ptr<IRExecutionUnit> &execution_unit_sp,
21 ExecutionContext &exe_ctx, bool &can_interpret,
22 ExecutionPolicy execution_policy) {
23 Status status =
24 DoPrepareForExecution(func_addr, func_end, execution_unit_sp, exe_ctx,
25 can_interpret, execution_policy);
26 if (status.Success() && exe_ctx.GetProcessPtr() && exe_ctx.HasThreadScope())
27 status = RunStaticInitializers(execution_unit_sp, exe_ctx);
28
29 return status;
30}
31
34 ExecutionContext &exe_ctx) {
35 Status err;
36
37 if (!execution_unit_sp.get()) {
39 "can't run static initializers for a NULL execution unit");
40 return err;
41 }
42
43 if (!exe_ctx.HasThreadScope()) {
45 "can't run static initializers without a thread");
46 return err;
47 }
48
49 std::vector<addr_t> static_initializers;
50
51 execution_unit_sp->GetStaticInitializers(static_initializers);
52
53 for (addr_t static_initializer : static_initializers) {
55
56 ThreadPlanSP call_static_initializer(new ThreadPlanCallFunction(
57 exe_ctx.GetThreadRef(), Address(static_initializer), CompilerType(),
58 llvm::ArrayRef<addr_t>(), options));
59
60 DiagnosticManager execution_errors;
61 ExpressionResults results =
62 exe_ctx.GetThreadRef().GetProcess()->RunThreadPlan(
63 exe_ctx, call_static_initializer, options, execution_errors);
64
65 if (results != eExpressionCompleted) {
66 err = Status::FromError(execution_errors.GetAsError(
67 lldb::eExpressionSetupError, "couldn't run static initializer:"));
68 return err;
69 }
70 }
71
72 return err;
73}
A section + offset based address class.
Definition: Address.h:62
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
llvm::Error GetAsError(lldb::ExpressionResults result, llvm::Twine message={}) const
Returns an ExpressionError with arg as error code.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
bool HasThreadScope() const
Returns true the ExecutionContext object contains a valid target, process, and thread.
Process * GetProcessPtr() const
Returns a pointer to the process object.
Thread & GetThreadRef() const
Returns a reference to the thread object.
Status RunStaticInitializers(lldb::IRExecutionUnitSP &execution_unit_sp, ExecutionContext &exe_ctx)
Run all static initializers for an execution unit.
virtual Status DoPrepareForExecution(lldb::addr_t &func_addr, lldb::addr_t &func_end, std::shared_ptr< IRExecutionUnit > &execution_unit_sp, ExecutionContext &exe_ctx, bool &can_interpret, lldb_private::ExecutionPolicy execution_policy)=0
Status PrepareForExecution(lldb::addr_t &func_addr, lldb::addr_t &func_end, std::shared_ptr< IRExecutionUnit > &execution_unit_sp, ExecutionContext &exe_ctx, bool &can_interpret, lldb_private::ExecutionPolicy execution_policy)
Ready an already-parsed expression for execution, possibly evaluating it statically.
An error handling class.
Definition: Status.h:115
static Status FromErrorString(const char *str)
Definition: Status.h:138
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition: Status.cpp:137
bool Success() const
Test for success condition.
Definition: Status.cpp:280
lldb::ProcessSP GetProcess() const
Definition: Thread.h:157
A class that represents a running process on the host machine.
ExecutionPolicy
Expression execution policies.
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
Definition: lldb-forward.h:453
std::shared_ptr< lldb_private::IRExecutionUnit > IRExecutionUnitSP
Definition: lldb-forward.h:363
ExpressionResults
The results of expression evaluation.
@ eExpressionCompleted
@ eExpressionSetupError
uint64_t addr_t
Definition: lldb-types.h:80