LLDB  mainline
Expression.h
Go to the documentation of this file.
1 //===-- Expression.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_EXPRESSION_EXPRESSION_H
10 #define LLDB_EXPRESSION_EXPRESSION_H
11 
12 #include <map>
13 #include <string>
14 #include <vector>
15 
16 
18 #include "lldb/lldb-forward.h"
19 #include "lldb/lldb-private.h"
20 
21 namespace lldb_private {
22 
23 class RecordingMemoryManager;
24 
25 /// \class Expression Expression.h "lldb/Expression/Expression.h" Encapsulates
26 /// a single expression for use in lldb
27 ///
28 /// LLDB uses expressions for various purposes, notably to call functions
29 /// and as a backend for the expr command. Expression encapsulates the
30 /// objects needed to parse and interpret or JIT an expression. It uses the
31 /// expression parser appropriate to the language of the expression to produce
32 /// LLVM IR from the expression.
33 class Expression {
34 public:
36 
37  Expression(Target &target);
38 
40 
41  /// Destructor
42  virtual ~Expression() = default;
43 
44  /// Return the string that the parser should parse. Must be a full
45  /// translation unit.
46  virtual const char *Text() = 0;
47 
48  /// Return the function name that should be used for executing the
49  /// expression. Text() should contain the definition of this function.
50  virtual const char *FunctionName() = 0;
51 
52  /// Return the language that should be used when parsing. To use the
53  /// default, return eLanguageTypeUnknown.
54  virtual lldb::LanguageType Language() const {
56  }
57 
58  /// Return the Materializer that the parser should use when registering
59  /// external values.
60  virtual Materializer *GetMaterializer() { return nullptr; }
61 
62  /// Return the desired result type of the function, or eResultTypeAny if
63  /// indifferent.
65 
66  /// Flags
67 
68  /// Return true if validation code should be inserted into the expression.
69  virtual bool NeedsValidation() = 0;
70 
71  /// Return true if external variables in the expression should be resolved.
72  virtual bool NeedsVariableResolution() = 0;
73 
74  virtual EvaluateExpressionOptions *GetOptions() { return nullptr; };
75 
76  /// Return the address of the function's JIT-compiled code, or
77  /// LLDB_INVALID_ADDRESS if the function is not JIT compiled
79 
80  /// Called to notify the expression that it is about to be executed.
81  virtual void WillStartExecuting() {}
82 
83  /// Called to notify the expression that its execution has finished.
84  virtual void DidFinishExecuting() {}
85 
86  virtual ExpressionTypeSystemHelper *GetTypeSystemHelper() { return nullptr; }
87 
88  // LLVM RTTI support
89  virtual bool isA(const void *ClassID) const = 0;
90 
91 protected:
92  lldb::TargetWP m_target_wp; /// Expression's always have to have a target...
93  lldb::ProcessWP m_jit_process_wp; /// An expression might have a process, but
94  /// it doesn't need to (e.g. calculator
95  /// mode.)
96  lldb::addr_t m_jit_start_addr; ///< The address of the JITted function within
97  ///the JIT allocation. LLDB_INVALID_ADDRESS if
98  ///invalid.
99  lldb::addr_t m_jit_end_addr; ///< The address of the JITted function within
100  ///the JIT allocation. LLDB_INVALID_ADDRESS if
101  ///invalid.
102 };
103 
104 } // namespace lldb_private
105 
106 #endif // LLDB_EXPRESSION_EXPRESSION_H
lldb_private::Expression::FunctionName
virtual const char * FunctionName()=0
Return the function name that should be used for executing the expression.
lldb_private::Expression::WillStartExecuting
virtual void WillStartExecuting()
Called to notify the expression that it is about to be executed.
Definition: Expression.h:81
lldb_private::Expression::GetTypeSystemHelper
virtual ExpressionTypeSystemHelper * GetTypeSystemHelper()
Definition: Expression.h:86
lldb_private::Expression::m_jit_process_wp
lldb::ProcessWP m_jit_process_wp
Expression's always have to have a target...
Definition: Expression.h:93
lldb_private::Expression::NeedsVariableResolution
virtual bool NeedsVariableResolution()=0
Return true if external variables in the expression should be resolved.
lldb_private::Expression::GetOptions
virtual EvaluateExpressionOptions * GetOptions()
Definition: Expression.h:74
lldb_private::EvaluateExpressionOptions
Definition: Target.h:262
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:436
lldb_private::Expression::m_jit_start_addr
lldb::addr_t m_jit_start_addr
An expression might have a process, but it doesn't need to (e.g.
Definition: Expression.h:96
ExpressionTypeSystemHelper.h
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::Target
Definition: Target.h:454
lldb_private::ExpressionTypeSystemHelper
Definition: ExpressionTypeSystemHelper.h:26
lldb_private::Expression::isA
virtual bool isA(const void *ClassID) const =0
lldb_private::Expression::ResultType
ResultType
Definition: Expression.h:35
lldb_private::ExecutionContextScope
Definition: ExecutionContextScope.h:32
lldb_private::Expression::NeedsValidation
virtual bool NeedsValidation()=0
Flags.
lldb_private::Expression::m_jit_end_addr
lldb::addr_t m_jit_end_addr
The address of the JITted function within the JIT allocation.
Definition: Expression.h:99
lldb_private::Expression::DesiredResultType
virtual ResultType DesiredResultType()
Return the desired result type of the function, or eResultTypeAny if indifferent.
Definition: Expression.h:64
lldb_private::Expression::Language
virtual lldb::LanguageType Language() const
Return the language that should be used when parsing.
Definition: Expression.h:54
lldb_private::Expression::Expression
Expression(Target &target)
Definition: Expression.cpp:15
lldb_private::Expression::GetMaterializer
virtual Materializer * GetMaterializer()
Return the Materializer that the parser should use when registering external values.
Definition: Expression.h:60
lldb_private::Materializer
Definition: Materializer.h:23
lldb_private::Expression::m_target_wp
lldb::TargetWP m_target_wp
Definition: Expression.h:92
lldb-private.h
lldb::eLanguageTypeUnknown
@ eLanguageTypeUnknown
Unknown or invalid language value.
Definition: lldb-enumerations.h:437
lldb_private::Expression::StartAddress
lldb::addr_t StartAddress()
Return the address of the function's JIT-compiled code, or LLDB_INVALID_ADDRESS if the function is no...
Definition: Expression.h:78
lldb_private::Expression::~Expression
virtual ~Expression()=default
Destructor.
lldb_private::Expression::eResultTypeAny
@ eResultTypeAny
Definition: Expression.h:35
lldb-forward.h
lldb_private::Expression::DidFinishExecuting
virtual void DidFinishExecuting()
Called to notify the expression that its execution has finished.
Definition: Expression.h:84
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::Expression::Text
virtual const char * Text()=0
Return the string that the parser should parse.
lldb_private::Expression
Definition: Expression.h:33
lldb_private::Expression::eResultTypeId
@ eResultTypeId
Definition: Expression.h:35