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()) {
44 err.SetErrorString("can't run static initializers without a thread");
45 return err;
46 }
47
48 std::vector<addr_t> static_initializers;
49
50 execution_unit_sp->GetStaticInitializers(static_initializers);
51
52 for (addr_t static_initializer : static_initializers) {
54
55 ThreadPlanSP call_static_initializer(new ThreadPlanCallFunction(
56 exe_ctx.GetThreadRef(), Address(static_initializer), CompilerType(),
57 llvm::ArrayRef<addr_t>(), options));
58
59 DiagnosticManager execution_errors;
60 ExpressionResults results =
61 exe_ctx.GetThreadRef().GetProcess()->RunThreadPlan(
62 exe_ctx, call_static_initializer, options, execution_errors);
63
64 if (results != eExpressionCompleted) {
65 err.SetErrorStringWithFormat("couldn't run static initializer: %s",
66 execution_errors.GetString().c_str());
67 return err;
68 }
69 }
70
71 return err;
72}
A section + offset based address class.
Definition: Address.h:62
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
std::string GetString(char separator='\n')
"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:44
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Set the current error string to a formatted error string.
Definition: Status.cpp:246
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:232
bool Success() const
Test for success condition.
Definition: Status.cpp:278
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:449
std::shared_ptr< lldb_private::IRExecutionUnit > IRExecutionUnitSP
Definition: lldb-forward.h:361
ExpressionResults
The results of expression evaluation.
@ eExpressionCompleted
uint64_t addr_t
Definition: lldb-types.h:80