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#include "llvm/Support/FormatProviders.h"
17
19#include "lldb/lldb-forward.h"
20#include "lldb/lldb-private.h"
21
22namespace lldb_private {
23
24/// \class Expression Expression.h "lldb/Expression/Expression.h" Encapsulates
25/// a single expression for use in lldb
26///
27/// LLDB uses expressions for various purposes, notably to call functions
28/// and as a backend for the expr command. Expression encapsulates the
29/// objects needed to parse and interpret or JIT an expression. It uses the
30/// expression parser appropriate to the language of the expression to produce
31/// LLVM IR from the expression.
33public:
35
36 Expression(Target &target);
37
39
40 /// Destructor
41 virtual ~Expression() = default;
42
43 /// Return the string that the parser should parse. Must be a full
44 /// translation unit.
45 virtual const char *Text() = 0;
46
47 /// Return the function name that should be used for executing the
48 /// expression. Text() should contain the definition of this function.
49 virtual const char *FunctionName() = 0;
50
51 /// Return the language that should be used when parsing.
52 virtual SourceLanguage Language() const { return {}; }
53
54 /// Return the Materializer that the parser should use when registering
55 /// external values.
56 virtual Materializer *GetMaterializer() { return nullptr; }
57
58 /// Return the desired result type of the function, or eResultTypeAny if
59 /// indifferent.
60 virtual ResultType DesiredResultType() const { return eResultTypeAny; }
61
62 /// Flags
63
64 /// Return true if validation code should be inserted into the expression.
65 virtual bool NeedsValidation() = 0;
66
67 /// Return true if external variables in the expression should be resolved.
68 virtual bool NeedsVariableResolution() = 0;
69
70 virtual EvaluateExpressionOptions *GetOptions() { return nullptr; };
71
72 /// Return the address of the function's JIT-compiled code, or
73 /// LLDB_INVALID_ADDRESS if the function is not JIT compiled
75
76 /// Called to notify the expression that it is about to be executed.
77 virtual void WillStartExecuting() {}
78
79 /// Called to notify the expression that its execution has finished.
80 virtual void DidFinishExecuting() {}
81
82 virtual ExpressionTypeSystemHelper *GetTypeSystemHelper() { return nullptr; }
83
84 // LLVM RTTI support
85 virtual bool isA(const void *ClassID) const = 0;
86
87protected:
88 lldb::TargetWP m_target_wp; /// Expression's always have to have a target...
89 lldb::ProcessWP m_jit_process_wp; /// An expression might have a process, but
90 /// it doesn't need to (e.g. calculator
91 /// mode.)
92 lldb::addr_t m_jit_start_addr; ///< The address of the JITted function within
93 ///the JIT allocation. LLDB_INVALID_ADDRESS if
94 ///invalid.
95 lldb::addr_t m_jit_end_addr; ///< The address of the JITted function within
96 ///the JIT allocation. LLDB_INVALID_ADDRESS if
97 ///invalid.
98};
99
100/// Holds parsed information about a function call label that
101/// LLDB attaches as an AsmLabel to function AST nodes it parses
102/// from debug-info.
103///
104/// The format being:
105///
106/// <prefix>:<discriminator>:<module uid>:<symbol uid>:<name>
107///
108/// The label string needs to stay valid for the entire lifetime
109/// of this object.
111 /// Arbitrary string which language plugins can interpret for their
112 /// own needs.
113 llvm::StringRef discriminator;
114
115 /// Unique identifier of the lldb_private::Module
116 /// which contains the symbol identified by \c symbol_id.
118
119 /// Unique identifier of the function symbol on which to
120 /// perform the function call. For example, for DWARF this would
121 /// be the DIE UID.
123
124 /// Name to use when searching for the function symbol in
125 /// \c module_id. For most function calls this will be a
126 /// mangled name. In cases where a mangled name can't be used,
127 /// this will be the function name.
128 ///
129 /// NOTE: kept as last element so we don't have to worry about
130 /// ':' in the mangled name when parsing the label.
131 llvm::StringRef lookup_name;
132
133 /// Decodes the specified function \c label into a \c FunctionCallLabel.
134 static llvm::Expected<FunctionCallLabel> fromString(llvm::StringRef label);
135
136 /// Encode this FunctionCallLabel into its string representation.
137 ///
138 /// The representation roundtrips through \c fromString:
139 /// \code{.cpp}
140 /// llvm::StringRef encoded = "$__lldb_func:blah:0x0:0x0:_Z3foov";
141 /// FunctionCallLabel label = *fromString(label);
142 ///
143 /// assert (label.toString() == encoded);
144 /// assert (*fromString(label.toString()) == label);
145 /// \endcode
146 std::string toString() const;
147};
148
149/// LLDB attaches this prefix to mangled names of functions that get called
150/// from JITted expressions.
151inline constexpr llvm::StringRef FunctionCallLabelPrefix = "$__lldb_func";
152
153} // namespace lldb_private
154
155namespace llvm {
156template <> struct format_provider<lldb_private::FunctionCallLabel> {
157 static void format(const lldb_private::FunctionCallLabel &label,
158 raw_ostream &OS, StringRef Style);
159};
160} // namespace llvm
161
162#endif // LLDB_EXPRESSION_EXPRESSION_H
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
"lldb/Expression/ExpressionTypeSystemHelper.h" A helper object that the Expression can pass to its Ex...
virtual bool NeedsValidation()=0
Flags.
virtual const char * Text()=0
Return the string that the parser should parse.
lldb::addr_t m_jit_end_addr
The address of the JITted function within the JIT allocation.
Definition Expression.h:95
virtual SourceLanguage Language() const
Return the language that should be used when parsing.
Definition Expression.h:52
lldb::ProcessWP m_jit_process_wp
Expression's always have to have a target...
Definition Expression.h:89
lldb::addr_t m_jit_start_addr
An expression might have a process, but it doesn't need to (e.g.
Definition Expression.h:92
lldb::TargetWP m_target_wp
Definition Expression.h:88
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:74
virtual void DidFinishExecuting()
Called to notify the expression that its execution has finished.
Definition Expression.h:80
virtual EvaluateExpressionOptions * GetOptions()
Definition Expression.h:70
virtual ResultType DesiredResultType() const
Return the desired result type of the function, or eResultTypeAny if indifferent.
Definition Expression.h:60
virtual bool isA(const void *ClassID) const =0
virtual bool NeedsVariableResolution()=0
Return true if external variables in the expression should be resolved.
virtual ExpressionTypeSystemHelper * GetTypeSystemHelper()
Definition Expression.h:82
virtual const char * FunctionName()=0
Return the function name that should be used for executing the expression.
virtual Materializer * GetMaterializer()
Return the Materializer that the parser should use when registering external values.
Definition Expression.h:56
virtual void WillStartExecuting()
Called to notify the expression that it is about to be executed.
Definition Expression.h:77
Expression(Target &target)
virtual ~Expression()=default
Destructor.
A class that represents a running process on the host machine.
constexpr llvm::StringRef FunctionCallLabelPrefix
LLDB attaches this prefix to mangled names of functions that get called from JITted expressions.
Definition Expression.h:151
std::weak_ptr< lldb_private::Process > ProcessWP
uint64_t user_id_t
Definition lldb-types.h:82
uint64_t addr_t
Definition lldb-types.h:80
std::weak_ptr< lldb_private::Target > TargetWP
Holds parsed information about a function call label that LLDB attaches as an AsmLabel to function AS...
Definition Expression.h:110
lldb::user_id_t symbol_id
Unique identifier of the function symbol on which to perform the function call.
Definition Expression.h:122
std::string toString() const
Encode this FunctionCallLabel into its string representation.
llvm::StringRef discriminator
Arbitrary string which language plugins can interpret for their own needs.
Definition Expression.h:113
llvm::StringRef lookup_name
Name to use when searching for the function symbol in module_id.
Definition Expression.h:131
static llvm::Expected< FunctionCallLabel > fromString(llvm::StringRef label)
Decodes the specified function label into a FunctionCallLabel.
lldb::user_id_t module_id
Unique identifier of the lldb_private::Module which contains the symbol identified by symbol_id.
Definition Expression.h:117
A type-erased pair of llvm::dwarf::SourceLanguageName and version.
static void format(const lldb_private::FunctionCallLabel &label, raw_ostream &OS, StringRef Style)