LLDB mainline
DILEval.h
Go to the documentation of this file.
1//===-- DILEval.h -----------------------------------------------*- C++ -*-===//
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
9#ifndef LLDB_VALUEOBJECT_DILEVAL_H
10#define LLDB_VALUEOBJECT_DILEVAL_H
11
14#include "llvm/ADT/StringRef.h"
15#include "llvm/Support/Error.h"
16#include <memory>
17#include <vector>
18
19namespace lldb_private::dil {
20
21/// Given the name of an identifier (variable name, member name, type name,
22/// etc.), find the ValueObject for that name (if it exists), excluding global
23/// variables, and create and return an IdentifierInfo object containing all
24/// the relevant information about that object (for DIL parsing and
25/// evaluating).
26lldb::ValueObjectSP LookupIdentifier(llvm::StringRef name_ref,
27 std::shared_ptr<StackFrame> frame_sp,
28 lldb::DynamicValueType use_dynamic);
29
30/// Given the name of an identifier, check to see if it matches the name of a
31/// global variable. If so, find the ValueObject for that global variable, and
32/// create and return an IdentifierInfo object containing all the relevant
33/// information about it.
34lldb::ValueObjectSP LookupGlobalIdentifier(llvm::StringRef name_ref,
35 std::shared_ptr<StackFrame> frame_sp,
36 lldb::TargetSP target_sp,
37 lldb::DynamicValueType use_dynamic);
38
39/// Given the name of an identifier, attempt to find an enumeration value.
40/// If found, return a ValueObject with a const scalar value of the enum.
41lldb::ValueObjectSP LookupEnumValue(llvm::StringRef name_ref,
42 ExecutionContextScope &ctx_scope);
43
45public:
46 Interpreter(lldb::TargetSP target, llvm::StringRef expr,
47 std::shared_ptr<StackFrame> frame_sp,
48 lldb::DynamicValueType use_dynamic, uint32_t options);
49
50 /// Evaluate an ASTNode.
51 /// \returns A non-null lldb::ValueObjectSP or an Error.
52 llvm::Expected<lldb::ValueObjectSP> Evaluate(const ASTNode &node);
53
54private:
55 /// Evaluate an ASTNode. If the result is a reference, it is also
56 /// dereferenced using ValueObject::Dereference.
57 /// \returns A non-null lldb::ValueObjectSP or an Error.
58 llvm::Expected<lldb::ValueObjectSP>
60 llvm::Expected<lldb::ValueObjectSP>
61 Visit(const IdentifierNode &node) override;
62 llvm::Expected<lldb::ValueObjectSP> Visit(const MemberOfNode &node) override;
63 llvm::Expected<lldb::ValueObjectSP> Visit(const UnaryOpNode &node) override;
64 llvm::Expected<lldb::ValueObjectSP> Visit(const BinaryOpNode &node) override;
65 llvm::Expected<lldb::ValueObjectSP>
66 Visit(const ArraySubscriptNode &node) override;
67 llvm::Expected<lldb::ValueObjectSP>
68 Visit(const BitFieldExtractionNode &node) override;
69 llvm::Expected<lldb::ValueObjectSP>
70 Visit(const IntegerLiteralNode &node) override;
71 llvm::Expected<lldb::ValueObjectSP>
72 Visit(const FloatLiteralNode &node) override;
73 llvm::Expected<lldb::ValueObjectSP>
74 Visit(const BooleanLiteralNode &node) override;
75 llvm::Expected<lldb::ValueObjectSP> Visit(const CastNode &node) override;
76
77 /// Perform usual unary conversions on a value. At the moment this
78 /// includes array-to-pointer and integral promotion for eligible types.
79 llvm::Expected<lldb::ValueObjectSP>
80 UnaryConversion(lldb::ValueObjectSP valobj, uint32_t location);
81
82 /// If `lhs_type` is unsigned and `rhs_type` is signed, check whether it
83 /// can represent all of the values of `lhs_type`.
84 /// If not, then promote `rhs_type` to the unsigned version of its type.
85 /// This expects that Rank(lhs_type) < Rank(rhs_type).
86 /// \returns Unchanged `rhs_type` or promoted unsigned version.
87 llvm::Expected<CompilerType> PromoteSignedInteger(CompilerType &lhs_type,
88 CompilerType &rhs_type);
89
90 /// Perform an arithmetic conversion on two values from an arithmetic
91 /// operation.
92 /// \returns The result type of an arithmetic operation.
93 llvm::Expected<CompilerType> ArithmeticConversion(lldb::ValueObjectSP &lhs,
95 uint32_t location);
96 /// Add or subtract the offset to the pointer according to the pointee type
97 /// byte size.
98 /// \returns A new `ValueObject` with a new pointer value.
99 llvm::Expected<lldb::ValueObjectSP> PointerOffset(lldb::ValueObjectSP ptr,
100 lldb::ValueObjectSP offset,
101 BinaryOpKind operation,
102 uint32_t location);
103 llvm::Expected<lldb::ValueObjectSP> EvaluateScalarOp(BinaryOpKind kind,
106 CompilerType result_type,
107 uint32_t location);
108 llvm::Expected<lldb::ValueObjectSP>
110 lldb::ValueObjectSP rhs, uint32_t location);
111 llvm::Expected<lldb::ValueObjectSP>
113 uint32_t location);
114 llvm::Expected<lldb::ValueObjectSP>
116 uint32_t location);
117 llvm::Expected<lldb::ValueObjectSP>
119 uint32_t location);
120 llvm::Expected<lldb::ValueObjectSP>
122 uint32_t location);
123 llvm::Expected<lldb::ValueObjectSP>
125 uint32_t location);
126 llvm::Expected<CompilerType>
128 std::shared_ptr<ExecutionContextScope> ctx,
129 const IntegerLiteralNode &literal);
130
131 /// A helper function for VerifyCastType (below). This performs
132 /// arithmetic-specific checks. It should only be called if the target_type
133 /// is a scalar type.
134 llvm::Expected<CastKind> VerifyArithmeticCast(CompilerType source_type,
135 CompilerType target_type,
136 int location);
137
138 /// As a preparation for type casting, compare the requested 'target' type
139 /// of the cast with the type of the operand to be cast. If the cast is
140 /// allowed, return the appropriate CastKind for the cast; otherwise return
141 /// an error.
142 llvm::Expected<CastKind> VerifyCastType(lldb::ValueObjectSP operand,
143 CompilerType source_type,
144 CompilerType target_type,
145 int location);
146
147 // Used by the interpreter to create objects, perform casts, etc.
149 llvm::StringRef m_expr;
151 std::shared_ptr<StackFrame> m_exe_ctx_scope;
155 // TODO: Remove 'maybe_unused' when next PR, using this, gets submitted.
156 [[maybe_unused]] bool m_allow_var_updates;
157 bool m_allow_globals = true;
158};
159
160} // namespace lldb_private::dil
161
162#endif // LLDB_VALUEOBJECT_DILEVAL_H
Generic representation of a type in a programming language.
The rest of the classes in this file, except for the Visitor class at the very end,...
Definition DILAST.h:79
std::shared_ptr< StackFrame > m_exe_ctx_scope
Definition DILEval.h:151
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryRemainder(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:813
llvm::Expected< lldb::ValueObjectSP > Evaluate(const ASTNode &node)
Evaluate an ASTNode.
Definition DILEval.cpp:421
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryAddition(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:648
llvm::Expected< lldb::ValueObjectSP > EvaluateAndDereference(const ASTNode &node)
Evaluate an ASTNode.
Definition DILEval.cpp:434
llvm::Expected< lldb::ValueObjectSP > PointerOffset(lldb::ValueObjectSP ptr, lldb::ValueObjectSP offset, BinaryOpKind operation, uint32_t location)
Add or subtract the offset to the pointer according to the pointee type byte size.
Definition DILEval.cpp:569
llvm::Expected< lldb::ValueObjectSP > EvaluateScalarOp(BinaryOpKind kind, lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, CompilerType result_type, uint32_t location)
Definition DILEval.cpp:606
llvm::Expected< CompilerType > PromoteSignedInteger(CompilerType &lhs_type, CompilerType &rhs_type)
If lhs_type is unsigned and rhs_type is signed, check whether it can represent all of the values of l...
Definition DILEval.cpp:176
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryShift(BinaryOpKind kind, lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:841
llvm::Expected< lldb::ValueObjectSP > EvaluateBinarySubtraction(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:686
llvm::Expected< lldb::ValueObjectSP > UnaryConversion(lldb::ValueObjectSP valobj, uint32_t location)
Perform usual unary conversions on a value.
Definition DILEval.cpp:60
llvm::Expected< lldb::ValueObjectSP > Visit(const IdentifierNode &node) override
Definition DILEval.cpp:450
lldb::ValueObjectSP m_scope
Definition DILEval.h:150
llvm::Expected< CompilerType > PickIntegerType(lldb::TypeSystemSP type_system, std::shared_ptr< ExecutionContextScope > ctx, const IntegerLiteralNode &literal)
Definition DILEval.cpp:1220
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryDivision(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:785
Interpreter(lldb::TargetSP target, llvm::StringRef expr, std::shared_ptr< StackFrame > frame_sp, lldb::DynamicValueType use_dynamic, uint32_t options)
Definition DILEval.cpp:400
lldb::DynamicValueType m_use_dynamic
Definition DILEval.h:152
llvm::Expected< CompilerType > ArithmeticConversion(lldb::ValueObjectSP &lhs, lldb::ValueObjectSP &rhs, uint32_t location)
Perform an arithmetic conversion on two values from an arithmetic operation.
Definition DILEval.cpp:205
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryMultiplication(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:763
llvm::Expected< CastKind > VerifyCastType(lldb::ValueObjectSP operand, CompilerType source_type, CompilerType target_type, int location)
As a preparation for type casting, compare the requested 'target' type of the cast with the type of t...
Definition DILEval.cpp:1387
llvm::Expected< CastKind > VerifyArithmeticCast(CompilerType source_type, CompilerType target_type, int location)
A helper function for VerifyCastType (below).
Definition DILEval.cpp:1320
This class contains one Visit method for each specialized type of DIL AST node.
Definition DILAST.h:324
BinaryOpKind
The binary operators recognized by DIL.
Definition DILAST.h:44
lldb::ValueObjectSP LookupEnumValue(llvm::StringRef name_ref, ExecutionContextScope &ctx_scope)
Given the name of an identifier, attempt to find an enumeration value.
Definition DILEval.cpp:375
lldb::ValueObjectSP LookupGlobalIdentifier(llvm::StringRef name_ref, std::shared_ptr< StackFrame > frame_sp, lldb::TargetSP target_sp, lldb::DynamicValueType use_dynamic)
Given the name of an identifier, check to see if it matches the name of a global variable.
Definition DILEval.cpp:286
lldb::ValueObjectSP LookupIdentifier(llvm::StringRef name_ref, std::shared_ptr< StackFrame > frame_sp, lldb::DynamicValueType use_dynamic)
Given the name of an identifier (variable name, member name, type name, etc.), find the ValueObject f...
Definition DILEval.cpp:327
std::shared_ptr< lldb_private::TypeSystem > TypeSystemSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::Target > TargetSP