Update prebuilt Clang to r365631c1 from Android.
The version we had was segfaulting.
Bug: 132420445
Change-Id: Icb45a6fe0b4e2166f7895e669df1157cec9fb4e0
diff --git a/linux-x64/clang/include/lldb/Expression/DWARFExpression.h b/linux-x64/clang/include/lldb/Expression/DWARFExpression.h
new file mode 100644
index 0000000..21830a5
--- /dev/null
+++ b/linux-x64/clang/include/lldb/Expression/DWARFExpression.h
@@ -0,0 +1,322 @@
+//===-- DWARFExpression.h ---------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_DWARFExpression_h_
+#define liblldb_DWARFExpression_h_
+
+#include "lldb/Core/Address.h"
+#include "lldb/Core/Disassembler.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/Scalar.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/lldb-private.h"
+#include <functional>
+
+class DWARFUnit;
+
+namespace lldb_private {
+
+/// \class DWARFExpression DWARFExpression.h
+/// "lldb/Expression/DWARFExpression.h" Encapsulates a DWARF location
+/// expression and interprets it.
+///
+/// DWARF location expressions are used in two ways by LLDB. The first
+/// use is to find entities specified in the debug information, since their
+/// locations are specified in precisely this language. The second is to
+/// interpret expressions without having to run the target in cases where the
+/// overhead from copying JIT-compiled code into the target is too high or
+/// where the target cannot be run. This class encapsulates a single DWARF
+/// location expression or a location list and interprets it.
+class DWARFExpression {
+public:
+ enum LocationListFormat : uint8_t {
+ NonLocationList, // Not a location list
+ RegularLocationList, // Location list format used in non-split dwarf files
+ SplitDwarfLocationList, // Location list format used in pre-DWARF v5 split
+ // dwarf files (.debug_loc.dwo)
+ LocLists, // Location list format used in DWARF v5
+ // (.debug_loclists/.debug_loclists.dwo).
+ };
+
+ DWARFExpression();
+
+ /// Constructor
+ ///
+ /// \param[in] data
+ /// A data extractor configured to read the DWARF location expression's
+ /// bytecode.
+ ///
+ /// \param[in] data_offset
+ /// The offset of the location expression in the extractor.
+ ///
+ /// \param[in] data_length
+ /// The byte length of the location expression.
+ DWARFExpression(lldb::ModuleSP module, const DataExtractor &data,
+ const DWARFUnit *dwarf_cu, lldb::offset_t data_offset,
+ lldb::offset_t data_length);
+
+ /// Destructor
+ virtual ~DWARFExpression();
+
+ /// Print the description of the expression to a stream
+ ///
+ /// \param[in] s
+ /// The stream to print to.
+ ///
+ /// \param[in] level
+ /// The level of verbosity to use.
+ ///
+ /// \param[in] location_list_base_addr
+ /// If this is a location list based expression, this is the
+ /// address of the object that owns it. NOTE: this value is
+ /// different from the DWARF version of the location list base
+ /// address which is compile unit relative. This base address
+ /// is the address of the object that owns the location list.
+ ///
+ /// \param[in] abi
+ /// An optional ABI plug-in that can be used to resolve register
+ /// names.
+ void GetDescription(Stream *s, lldb::DescriptionLevel level,
+ lldb::addr_t location_list_base_addr, ABI *abi) const;
+
+ /// Return true if the location expression contains data
+ bool IsValid() const;
+
+ /// Return true if a location list was provided
+ bool IsLocationList() const;
+
+ /// Search for a load address in the location list
+ ///
+ /// \param[in] process
+ /// The process to use when resolving the load address
+ ///
+ /// \param[in] addr
+ /// The address to resolve
+ ///
+ /// \return
+ /// True if IsLocationList() is true and the address was found;
+ /// false otherwise.
+ // bool
+ // LocationListContainsLoadAddress (Process* process, const Address &addr)
+ // const;
+ //
+ bool LocationListContainsAddress(lldb::addr_t loclist_base_addr,
+ lldb::addr_t addr) const;
+
+ /// If a location is not a location list, return true if the location
+ /// contains a DW_OP_addr () opcode in the stream that matches \a file_addr.
+ /// If file_addr is LLDB_INVALID_ADDRESS, the this function will return true
+ /// if the variable there is any DW_OP_addr in a location that (yet still is
+ /// NOT a location list). This helps us detect if a variable is a global or
+ /// static variable since there is no other indication from DWARF debug
+ /// info.
+ ///
+ /// \param[in] op_addr_idx
+ /// The DW_OP_addr index to retrieve in case there is more than
+ /// one DW_OP_addr opcode in the location byte stream.
+ ///
+ /// \param[out] error
+ /// If the location stream contains unknown DW_OP opcodes or the
+ /// data is missing, \a error will be set to \b true.
+ ///
+ /// \return
+ /// LLDB_INVALID_ADDRESS if the location doesn't contain a
+ /// DW_OP_addr for \a op_addr_idx, otherwise a valid file address
+ lldb::addr_t GetLocation_DW_OP_addr(uint32_t op_addr_idx, bool &error) const;
+
+ bool Update_DW_OP_addr(lldb::addr_t file_addr);
+
+ void UpdateValue(uint64_t const_value, lldb::offset_t const_value_byte_size,
+ uint8_t addr_byte_size);
+
+ void SetModule(const lldb::ModuleSP &module) { m_module_wp = module; }
+
+ bool ContainsThreadLocalStorage() const;
+
+ bool LinkThreadLocalStorage(
+ lldb::ModuleSP new_module_sp,
+ std::function<lldb::addr_t(lldb::addr_t file_addr)> const
+ &link_address_callback);
+
+ /// Tells the expression that it refers to a location list.
+ ///
+ /// \param[in] slide
+ /// This value should be a slide that is applied to any values
+ /// in the location list data so the values become zero based
+ /// offsets into the object that owns the location list. We need
+ /// to make location lists relative to the objects that own them
+ /// so we can relink addresses on the fly.
+ void SetLocationListSlide(lldb::addr_t slide);
+
+ /// Return the call-frame-info style register kind
+ int GetRegisterKind();
+
+ /// Set the call-frame-info style register kind
+ ///
+ /// \param[in] reg_kind
+ /// The register kind.
+ void SetRegisterKind(lldb::RegisterKind reg_kind);
+
+ /// Wrapper for the static evaluate function that accepts an
+ /// ExecutionContextScope instead of an ExecutionContext and uses member
+ /// variables to populate many operands
+ bool Evaluate(ExecutionContextScope *exe_scope,
+ lldb::addr_t loclist_base_load_addr,
+ const Value *initial_value_ptr, const Value *object_address_ptr,
+ Value &result, Status *error_ptr) const;
+
+ /// Wrapper for the static evaluate function that uses member variables to
+ /// populate many operands
+ bool Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx,
+ lldb::addr_t loclist_base_load_addr,
+ const Value *initial_value_ptr, const Value *object_address_ptr,
+ Value &result, Status *error_ptr) const;
+
+ /// Evaluate a DWARF location expression in a particular context
+ ///
+ /// \param[in] exe_ctx
+ /// The execution context in which to evaluate the location
+ /// expression. The location expression may access the target's
+ /// memory, especially if it comes from the expression parser.
+ ///
+ /// \param[in] opcode_ctx
+ /// The module which defined the expression.
+ ///
+ /// \param[in] opcodes
+ /// This is a static method so the opcodes need to be provided
+ /// explicitly.
+ ///
+ /// \param[in] expr_locals
+ /// If the location expression was produced by the expression parser,
+ /// the list of local variables referenced by the DWARF expression.
+ /// This list should already have been populated during parsing;
+ /// the DWARF expression refers to variables by index. Can be NULL if
+ /// the location expression uses no locals.
+ ///
+ /// \param[in] decl_map
+ /// If the location expression was produced by the expression parser,
+ /// the list of external variables referenced by the location
+ /// expression. Can be NULL if the location expression uses no
+ /// external variables.
+ ///
+ /// \param[in] reg_ctx
+ /// An optional parameter which provides a RegisterContext for use
+ /// when evaluating the expression (i.e. for fetching register values).
+ /// Normally this will come from the ExecutionContext's StackFrame but
+ /// in the case where an expression needs to be evaluated while building
+ /// the stack frame list, this short-cut is available.
+ ///
+ /// \param[in] offset
+ /// The offset of the location expression in the data extractor.
+ ///
+ /// \param[in] length
+ /// The length in bytes of the location expression.
+ ///
+ /// \param[in] reg_set
+ /// The call-frame-info style register kind.
+ ///
+ /// \param[in] initial_value_ptr
+ /// A value to put on top of the interpreter stack before evaluating
+ /// the expression, if the expression is parametrized. Can be NULL.
+ ///
+ /// \param[in] result
+ /// A value into which the result of evaluating the expression is
+ /// to be placed.
+ ///
+ /// \param[in] error_ptr
+ /// If non-NULL, used to report errors in expression evaluation.
+ ///
+ /// \return
+ /// True on success; false otherwise. If error_ptr is non-NULL,
+ /// details of the failure are provided through it.
+ static bool Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx,
+ lldb::ModuleSP opcode_ctx, const DataExtractor &opcodes,
+ const DWARFUnit *dwarf_cu, const lldb::offset_t offset,
+ const lldb::offset_t length,
+ const lldb::RegisterKind reg_set,
+ const Value *initial_value_ptr,
+ const Value *object_address_ptr, Value &result,
+ Status *error_ptr);
+
+ bool GetExpressionData(DataExtractor &data) const {
+ data = m_data;
+ return data.GetByteSize() > 0;
+ }
+
+ bool DumpLocationForAddress(Stream *s, lldb::DescriptionLevel level,
+ lldb::addr_t loclist_base_load_addr,
+ lldb::addr_t address, ABI *abi);
+
+ static size_t LocationListSize(const DWARFUnit *dwarf_cu,
+ const DataExtractor &debug_loc_data,
+ lldb::offset_t offset);
+
+ static bool PrintDWARFExpression(Stream &s, const DataExtractor &data,
+ int address_size, int dwarf_ref_size,
+ bool location_expression);
+
+ static void PrintDWARFLocationList(Stream &s, const DWARFUnit *cu,
+ const DataExtractor &debug_loc_data,
+ lldb::offset_t offset);
+
+ bool MatchesOperand(StackFrame &frame, const Instruction::Operand &op);
+
+private:
+ /// Pretty-prints the location expression to a stream
+ ///
+ /// \param[in] stream
+ /// The stream to use for pretty-printing.
+ ///
+ /// \param[in] offset
+ /// The offset into the data buffer of the opcodes to be printed.
+ ///
+ /// \param[in] length
+ /// The length in bytes of the opcodes to be printed.
+ ///
+ /// \param[in] level
+ /// The level of detail to use in pretty-printing.
+ ///
+ /// \param[in] abi
+ /// An optional ABI plug-in that can be used to resolve register
+ /// names.
+ void DumpLocation(Stream *s, lldb::offset_t offset, lldb::offset_t length,
+ lldb::DescriptionLevel level, ABI *abi) const;
+
+ bool GetLocation(lldb::addr_t base_addr, lldb::addr_t pc,
+ lldb::offset_t &offset, lldb::offset_t &len);
+
+ static bool AddressRangeForLocationListEntry(
+ const DWARFUnit *dwarf_cu, const DataExtractor &debug_loc_data,
+ lldb::offset_t *offset_ptr, lldb::addr_t &low_pc, lldb::addr_t &high_pc);
+
+ bool GetOpAndEndOffsets(StackFrame &frame, lldb::offset_t &op_offset,
+ lldb::offset_t &end_offset);
+
+ /// Module which defined this expression.
+ lldb::ModuleWP m_module_wp;
+
+ /// A data extractor capable of reading opcode bytes
+ DataExtractor m_data;
+
+ /// The DWARF compile unit this expression belongs to. It is used to evaluate
+ /// values indexing into the .debug_addr section (e.g. DW_OP_GNU_addr_index,
+ /// DW_OP_GNU_const_index)
+ const DWARFUnit *m_dwarf_cu;
+
+ /// One of the defines that starts with LLDB_REGKIND_
+ lldb::RegisterKind m_reg_kind;
+
+ /// A value used to slide the location list offsets so that m_c they are
+ /// relative to the object that owns the location list (the function for
+ /// frame base and variable location lists)
+ lldb::addr_t m_loclist_slide;
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_DWARFExpression_h_
diff --git a/linux-x64/clang/include/lldb/Expression/DiagnosticManager.h b/linux-x64/clang/include/lldb/Expression/DiagnosticManager.h
new file mode 100644
index 0000000..7e3e2bb
--- /dev/null
+++ b/linux-x64/clang/include/lldb/Expression/DiagnosticManager.h
@@ -0,0 +1,165 @@
+//===-- DiagnosticManager.h -------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef lldb_DiagnosticManager_h
+#define lldb_DiagnosticManager_h
+
+#include "lldb/lldb-defines.h"
+#include "lldb/lldb-types.h"
+
+#include "llvm/ADT/StringRef.h"
+
+#include <string>
+#include <vector>
+
+namespace lldb_private {
+
+enum DiagnosticOrigin {
+ eDiagnosticOriginUnknown = 0,
+ eDiagnosticOriginLLDB,
+ eDiagnosticOriginClang,
+ eDiagnosticOriginGo,
+ eDiagnosticOriginSwift,
+ eDiagnosticOriginLLVM
+};
+
+enum DiagnosticSeverity {
+ eDiagnosticSeverityError,
+ eDiagnosticSeverityWarning,
+ eDiagnosticSeverityRemark
+};
+
+const uint32_t LLDB_INVALID_COMPILER_ID = UINT32_MAX;
+
+class Diagnostic {
+ friend class DiagnosticManager;
+
+public:
+ DiagnosticOrigin getKind() const { return m_origin; }
+
+ static bool classof(const Diagnostic *diag) {
+ DiagnosticOrigin kind = diag->getKind();
+ switch (kind) {
+ case eDiagnosticOriginUnknown:
+ case eDiagnosticOriginLLDB:
+ case eDiagnosticOriginGo:
+ case eDiagnosticOriginLLVM:
+ return true;
+ case eDiagnosticOriginClang:
+ case eDiagnosticOriginSwift:
+ return false;
+ }
+ }
+
+ Diagnostic(llvm::StringRef message, DiagnosticSeverity severity,
+ DiagnosticOrigin origin, uint32_t compiler_id)
+ : m_message(message), m_severity(severity), m_origin(origin),
+ m_compiler_id(compiler_id) {}
+
+ Diagnostic(const Diagnostic &rhs)
+ : m_message(rhs.m_message), m_severity(rhs.m_severity),
+ m_origin(rhs.m_origin), m_compiler_id(rhs.m_compiler_id) {}
+
+ virtual ~Diagnostic() = default;
+
+ virtual bool HasFixIts() const { return false; }
+
+ DiagnosticSeverity GetSeverity() const { return m_severity; }
+
+ uint32_t GetCompilerID() const { return m_compiler_id; }
+
+ llvm::StringRef GetMessage() const { return m_message; }
+
+ void AppendMessage(llvm::StringRef message,
+ bool precede_with_newline = true) {
+ if (precede_with_newline)
+ m_message.push_back('\n');
+ m_message.append(message);
+ }
+
+protected:
+ std::string m_message;
+ DiagnosticSeverity m_severity;
+ DiagnosticOrigin m_origin;
+ uint32_t m_compiler_id; // Compiler-specific diagnostic ID
+};
+
+typedef std::vector<Diagnostic *> DiagnosticList;
+
+class DiagnosticManager {
+public:
+ void Clear() {
+ m_diagnostics.clear();
+ m_fixed_expression.clear();
+ }
+
+ // The diagnostic manager holds a list of diagnostics, which are owned by the
+ // manager.
+ const DiagnosticList &Diagnostics() { return m_diagnostics; }
+
+ ~DiagnosticManager() {
+ for (Diagnostic *diag : m_diagnostics) {
+ delete diag;
+ }
+ }
+
+ bool HasFixIts() {
+ for (Diagnostic *diag : m_diagnostics) {
+ if (diag->HasFixIts())
+ return true;
+ }
+ return false;
+ }
+
+ void AddDiagnostic(llvm::StringRef message, DiagnosticSeverity severity,
+ DiagnosticOrigin origin,
+ uint32_t compiler_id = LLDB_INVALID_COMPILER_ID) {
+ m_diagnostics.push_back(
+ new Diagnostic(message, severity, origin, compiler_id));
+ }
+
+ void AddDiagnostic(Diagnostic *diagnostic) {
+ m_diagnostics.push_back(diagnostic);
+ }
+
+ void CopyDiagnostics(DiagnosticManager &otherDiagnostics);
+
+ size_t Printf(DiagnosticSeverity severity, const char *format, ...)
+ __attribute__((format(printf, 3, 4)));
+ size_t PutString(DiagnosticSeverity severity, llvm::StringRef str);
+
+ void AppendMessageToDiagnostic(llvm::StringRef str) {
+ if (!m_diagnostics.empty()) {
+ m_diagnostics.back()->AppendMessage(str);
+ }
+ }
+
+ // Returns a string containing errors in this format:
+ //
+ // "error: error text\n
+ // warning: warning text\n
+ // remark text\n"
+ std::string GetString(char separator = '\n');
+
+ void Dump(Log *log);
+
+ const std::string &GetFixedExpression() { return m_fixed_expression; }
+
+ // Moves fixed_expression to the internal storage.
+ void SetFixedExpression(std::string fixed_expression) {
+ m_fixed_expression = std::move(fixed_expression);
+ fixed_expression.clear();
+ }
+
+protected:
+ DiagnosticList m_diagnostics;
+ std::string m_fixed_expression;
+};
+}
+
+#endif /* lldb_DiagnosticManager_h */
diff --git a/linux-x64/clang/include/lldb/Expression/Expression.h b/linux-x64/clang/include/lldb/Expression/Expression.h
new file mode 100644
index 0000000..2f0183c
--- /dev/null
+++ b/linux-x64/clang/include/lldb/Expression/Expression.h
@@ -0,0 +1,114 @@
+//===-- Expression.h --------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_Expression_h_
+#define liblldb_Expression_h_
+
+#include <map>
+#include <string>
+#include <vector>
+
+
+#include "lldb/Expression/ExpressionTypeSystemHelper.h"
+#include "lldb/lldb-forward.h"
+#include "lldb/lldb-private.h"
+
+namespace lldb_private {
+
+class RecordingMemoryManager;
+
+/// \class Expression Expression.h "lldb/Expression/Expression.h" Encapsulates
+/// a single expression for use in lldb
+///
+/// LLDB uses expressions for various purposes, notably to call functions
+/// and as a backend for the expr command. Expression encapsulates the
+/// objects needed to parse and interpret or JIT an expression. It uses the
+/// expression parser appropriate to the language of the expression to produce
+/// LLVM IR from the expression.
+class Expression {
+public:
+ /// Discriminator for LLVM-style RTTI (dyn_cast<> et al.)
+ enum ExpressionKind {
+ eKindFunctionCaller,
+ eKindClangFunctionCaller,
+ eKindUserExpression,
+ eKindLLVMUserExpression,
+ eKindClangUserExpression,
+ eKindUtilityFunction,
+ eKindClangUtilityFunction,
+ };
+
+ enum ResultType { eResultTypeAny, eResultTypeId };
+
+ Expression(Target &target, ExpressionKind kind);
+
+ Expression(ExecutionContextScope &exe_scope, ExpressionKind kind);
+
+ /// Destructor
+ virtual ~Expression() {}
+
+ /// Return the string that the parser should parse. Must be a full
+ /// translation unit.
+ virtual const char *Text() = 0;
+
+ /// Return the function name that should be used for executing the
+ /// expression. Text() should contain the definition of this function.
+ virtual const char *FunctionName() = 0;
+
+ /// Return the language that should be used when parsing. To use the
+ /// default, return eLanguageTypeUnknown.
+ virtual lldb::LanguageType Language() { return lldb::eLanguageTypeUnknown; }
+
+ /// Return the desired result type of the function, or eResultTypeAny if
+ /// indifferent.
+ virtual ResultType DesiredResultType() { return eResultTypeAny; }
+
+ /// Flags
+
+ /// Return true if validation code should be inserted into the expression.
+ virtual bool NeedsValidation() = 0;
+
+ /// Return true if external variables in the expression should be resolved.
+ virtual bool NeedsVariableResolution() = 0;
+
+ virtual EvaluateExpressionOptions *GetOptions() { return nullptr; };
+
+ /// Return the address of the function's JIT-compiled code, or
+ /// LLDB_INVALID_ADDRESS if the function is not JIT compiled
+ lldb::addr_t StartAddress() { return m_jit_start_addr; }
+
+ /// Called to notify the expression that it is about to be executed.
+ virtual void WillStartExecuting() {}
+
+ /// Called to notify the expression that its execution has finished.
+ virtual void DidFinishExecuting() {}
+
+ virtual ExpressionTypeSystemHelper *GetTypeSystemHelper() { return nullptr; }
+
+ /// LLVM-style RTTI support.
+ ExpressionKind getKind() const { return m_kind; }
+
+private:
+ /// LLVM-style RTTI support.
+ const ExpressionKind m_kind;
+protected:
+ lldb::TargetWP m_target_wp; /// Expression's always have to have a target...
+ lldb::ProcessWP m_jit_process_wp; /// An expression might have a process, but
+ /// it doesn't need to (e.g. calculator
+ /// mode.)
+ lldb::addr_t m_jit_start_addr; ///< The address of the JITted function within
+ ///the JIT allocation. LLDB_INVALID_ADDRESS if
+ ///invalid.
+ lldb::addr_t m_jit_end_addr; ///< The address of the JITted function within
+ ///the JIT allocation. LLDB_INVALID_ADDRESS if
+ ///invalid.
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_Expression_h_
diff --git a/linux-x64/clang/include/lldb/Expression/ExpressionParser.h b/linux-x64/clang/include/lldb/Expression/ExpressionParser.h
new file mode 100644
index 0000000..59f7c15
--- /dev/null
+++ b/linux-x64/clang/include/lldb/Expression/ExpressionParser.h
@@ -0,0 +1,147 @@
+//===-- ExpressionParser.h --------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_ExpressionParser_h_
+#define liblldb_ExpressionParser_h_
+
+#include "lldb/Utility/CompletionRequest.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/lldb-private-enumerations.h"
+#include "lldb/lldb-public.h"
+
+namespace lldb_private {
+
+class IRExecutionUnit;
+
+/// \class ExpressionParser ExpressionParser.h
+/// "lldb/Expression/ExpressionParser.h" Encapsulates an instance of a
+/// compiler that can parse expressions.
+///
+/// ExpressionParser is the base class for llvm based Expression parsers.
+class ExpressionParser {
+public:
+ /// Constructor
+ ///
+ /// Initializes class variables.
+ ///
+ /// \param[in] exe_scope,
+ /// If non-NULL, an execution context scope that can help to
+ /// correctly create an expression with a valid process for
+ /// optional tuning Objective-C runtime support. Can be NULL.
+ ///
+ /// \param[in] expr
+ /// The expression to be parsed.
+ ExpressionParser(ExecutionContextScope *exe_scope, Expression &expr,
+ bool generate_debug_info)
+ : m_expr(expr), m_generate_debug_info(generate_debug_info) {}
+
+ /// Destructor
+ virtual ~ExpressionParser(){};
+
+ /// Attempts to find possible command line completions for the given
+ /// expression.
+ ///
+ /// \param[out] request
+ /// The completion request to fill out. The completion should be a string
+ /// that would complete the current token at the cursor position.
+ /// Note that the string in the list replaces the current token
+ /// in the command line.
+ ///
+ /// \param[in] line
+ /// The line with the completion cursor inside the expression as a string.
+ /// The first line in the expression has the number 0.
+ ///
+ /// \param[in] pos
+ /// The character position in the line with the completion cursor.
+ /// If the value is 0, then the cursor is on top of the first character
+ /// in the line (i.e. the user has requested completion from the start of
+ /// the expression).
+ ///
+ /// \param[in] typed_pos
+ /// The cursor position in the line as typed by the user. If the user
+ /// expression has not been transformed in some form (e.g. wrapping it
+ /// in a function body for C languages), then this is equal to the
+ /// 'pos' parameter. The semantics of this value are otherwise equal to
+ /// 'pos' (e.g. a value of 0 means the cursor is at start of the
+ /// expression).
+ ///
+ /// \return
+ /// True if we added any completion results to the output;
+ /// false otherwise.
+ virtual bool Complete(CompletionRequest &request, unsigned line, unsigned pos,
+ unsigned typed_pos) = 0;
+
+ /// Parse a single expression and convert it to IR using Clang. Don't wrap
+ /// the expression in anything at all.
+ ///
+ /// \param[in] diagnostic_manager
+ /// The diagnostic manager in which to store the errors and warnings.
+ ///
+ /// \return
+ /// The number of errors encountered during parsing. 0 means
+ /// success.
+ virtual unsigned Parse(DiagnosticManager &diagnostic_manager) = 0;
+
+ /// Try to use the FixIts in the diagnostic_manager to rewrite the
+ /// expression. If successful, the rewritten expression is stored in the
+ /// diagnostic_manager, get it out with GetFixedExpression.
+ ///
+ /// \param[in] diagnostic_manager
+ /// The diagnostic manager containing fixit's to apply.
+ ///
+ /// \return
+ /// \b true if the rewrite was successful, \b false otherwise.
+ virtual bool RewriteExpression(DiagnosticManager &diagnostic_manager) {
+ return false;
+ }
+
+ /// Ready an already-parsed expression for execution, possibly evaluating it
+ /// statically.
+ ///
+ /// \param[out] func_addr
+ /// The address to which the function has been written.
+ ///
+ /// \param[out] func_end
+ /// The end of the function's allocated memory region. (func_addr
+ /// and func_end do not delimit an allocated region; the allocated
+ /// region may begin before func_addr.)
+ ///
+ /// \param[in] execution_unit_sp
+ /// After parsing, ownership of the execution unit for
+ /// for the expression is handed to this shared pointer.
+ ///
+ /// \param[in] exe_ctx
+ /// The execution context to write the function into.
+ ///
+ /// \param[out] can_interpret
+ /// Set to true if the expression could be interpreted statically;
+ /// untouched otherwise.
+ ///
+ /// \param[in] execution_policy
+ /// Determines whether the expression must be JIT-compiled, must be
+ /// evaluated statically, or whether this decision may be made
+ /// opportunistically.
+ ///
+ /// \return
+ /// An error code indicating the success or failure of the operation.
+ /// Test with Success().
+ virtual 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) = 0;
+
+ bool GetGenerateDebugInfo() const { return m_generate_debug_info; }
+
+protected:
+ Expression &m_expr; ///< The expression to be parsed
+ bool m_generate_debug_info;
+};
+}
+
+#endif // liblldb_ExpressionParser_h_
diff --git a/linux-x64/clang/include/lldb/Expression/ExpressionSourceCode.h b/linux-x64/clang/include/lldb/Expression/ExpressionSourceCode.h
new file mode 100644
index 0000000..d0d01b5
--- /dev/null
+++ b/linux-x64/clang/include/lldb/Expression/ExpressionSourceCode.h
@@ -0,0 +1,38 @@
+//===-- ExpressionSourceCode.h ----------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_ExpressionSourceCode_h
+#define liblldb_ExpressionSourceCode_h
+
+#include "lldb/lldb-enumerations.h"
+#include "llvm/ADT/ArrayRef.h"
+
+#include <string>
+
+namespace lldb_private {
+
+class ExpressionSourceCode {
+public:
+ bool NeedsWrapping() const { return m_wrap; }
+
+ const char *GetName() const { return m_name.c_str(); }
+
+protected:
+ ExpressionSourceCode(const char *name, const char *prefix, const char *body,
+ bool wrap)
+ : m_name(name), m_prefix(prefix), m_body(body), m_wrap(wrap) {}
+
+ std::string m_name;
+ std::string m_prefix;
+ std::string m_body;
+ bool m_wrap;
+};
+
+} // namespace lldb_private
+
+#endif
diff --git a/linux-x64/clang/include/lldb/Expression/ExpressionTypeSystemHelper.h b/linux-x64/clang/include/lldb/Expression/ExpressionTypeSystemHelper.h
new file mode 100644
index 0000000..9c64553
--- /dev/null
+++ b/linux-x64/clang/include/lldb/Expression/ExpressionTypeSystemHelper.h
@@ -0,0 +1,47 @@
+//===-- ExpressionTypeSystemHelper.h ---------------------------------*- C++
+//-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef ExpressionTypeSystemHelper_h
+#define ExpressionTypeSystemHelper_h
+
+#include "llvm/Support/Casting.h"
+
+namespace lldb_private {
+
+/// \class ExpressionTypeSystemHelper ExpressionTypeSystemHelper.h
+/// "lldb/Expression/ExpressionTypeSystemHelper.h"
+/// A helper object that the Expression can pass to its ExpressionParser
+/// to provide generic information that
+/// any type of expression will need to supply. It's only job is to support
+/// dyn_cast so that the expression parser can cast it back to the requisite
+/// specific type.
+///
+
+class ExpressionTypeSystemHelper {
+public:
+ enum LLVMCastKind {
+ eKindClangHelper,
+ eKindSwiftHelper,
+ eKindGoHelper,
+ kNumKinds
+ };
+
+ LLVMCastKind getKind() const { return m_kind; }
+
+ ExpressionTypeSystemHelper(LLVMCastKind kind) : m_kind(kind) {}
+
+ ~ExpressionTypeSystemHelper() {}
+
+protected:
+ LLVMCastKind m_kind;
+};
+
+} // namespace lldb_private
+
+#endif /* ExpressionTypeSystemHelper_h */
diff --git a/linux-x64/clang/include/lldb/Expression/ExpressionVariable.h b/linux-x64/clang/include/lldb/Expression/ExpressionVariable.h
new file mode 100644
index 0000000..08c9872
--- /dev/null
+++ b/linux-x64/clang/include/lldb/Expression/ExpressionVariable.h
@@ -0,0 +1,256 @@
+//===-- ExpressionVariable.h ------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_ExpressionVariable_h_
+#define liblldb_ExpressionVariable_h_
+
+#include <memory>
+#include <vector>
+
+#include "llvm/ADT/DenseMap.h"
+
+#include "lldb/Core/ValueObject.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/lldb-public.h"
+
+namespace lldb_private {
+
+class ExpressionVariable
+ : public std::enable_shared_from_this<ExpressionVariable> {
+public:
+ // See TypeSystem.h for how to add subclasses to this.
+ enum LLVMCastKind { eKindClang, eKindSwift, eKindGo, kNumKinds };
+
+ LLVMCastKind getKind() const { return m_kind; }
+
+ ExpressionVariable(LLVMCastKind kind) : m_flags(0), m_kind(kind) {}
+
+ virtual ~ExpressionVariable();
+
+ size_t GetByteSize() { return m_frozen_sp->GetByteSize(); }
+
+ ConstString GetName() { return m_frozen_sp->GetName(); }
+
+ lldb::ValueObjectSP GetValueObject() { return m_frozen_sp; }
+
+ uint8_t *GetValueBytes();
+
+ void ValueUpdated() { m_frozen_sp->ValueUpdated(); }
+
+ RegisterInfo *GetRegisterInfo() {
+ return m_frozen_sp->GetValue().GetRegisterInfo();
+ }
+
+ void SetRegisterInfo(const RegisterInfo *reg_info) {
+ return m_frozen_sp->GetValue().SetContext(
+ Value::eContextTypeRegisterInfo, const_cast<RegisterInfo *>(reg_info));
+ }
+
+ CompilerType GetCompilerType() { return m_frozen_sp->GetCompilerType(); }
+
+ void SetCompilerType(const CompilerType &compiler_type) {
+ m_frozen_sp->GetValue().SetCompilerType(compiler_type);
+ }
+
+ void SetName(ConstString name) { m_frozen_sp->SetName(name); }
+
+ // this function is used to copy the address-of m_live_sp into m_frozen_sp
+ // this is necessary because the results of certain cast and pointer-
+ // arithmetic operations (such as those described in bugzilla issues 11588
+ // and 11618) generate frozen objects that do not have a valid address-of,
+ // which can be troublesome when using synthetic children providers.
+ // Transferring the address-of the live object solves these issues and
+ // provides the expected user-level behavior
+ void TransferAddress(bool force = false) {
+ if (m_live_sp.get() == nullptr)
+ return;
+
+ if (m_frozen_sp.get() == nullptr)
+ return;
+
+ if (force || (m_frozen_sp->GetLiveAddress() == LLDB_INVALID_ADDRESS))
+ m_frozen_sp->SetLiveAddress(m_live_sp->GetLiveAddress());
+ }
+
+ enum Flags {
+ EVNone = 0,
+ EVIsLLDBAllocated = 1 << 0, ///< This variable is resident in a location
+ ///specifically allocated for it by LLDB in the
+ ///target process
+ EVIsProgramReference = 1 << 1, ///< This variable is a reference to a
+ ///(possibly invalid) area managed by the
+ ///target program
+ EVNeedsAllocation = 1 << 2, ///< Space for this variable has yet to be
+ ///allocated in the target process
+ EVIsFreezeDried = 1 << 3, ///< This variable's authoritative version is in
+ ///m_frozen_sp (for example, for
+ ///statically-computed results)
+ EVNeedsFreezeDry =
+ 1 << 4, ///< Copy from m_live_sp to m_frozen_sp during dematerialization
+ EVKeepInTarget = 1 << 5, ///< Keep the allocation after the expression is
+ ///complete rather than freeze drying its contents
+ ///and freeing it
+ EVTypeIsReference = 1 << 6, ///< The original type of this variable is a
+ ///reference, so materialize the value rather
+ ///than the location
+ EVUnknownType = 1 << 7, ///< This is a symbol of unknown type, and the type
+ ///must be resolved after parsing is complete
+ EVBareRegister = 1 << 8 ///< This variable is a direct reference to $pc or
+ ///some other entity.
+ };
+
+ typedef uint16_t FlagType;
+
+ FlagType m_flags; // takes elements of Flags
+
+ // these should be private
+ lldb::ValueObjectSP m_frozen_sp;
+ lldb::ValueObjectSP m_live_sp;
+ LLVMCastKind m_kind;
+};
+
+/// \class ExpressionVariableList ExpressionVariable.h
+/// "lldb/Expression/ExpressionVariable.h"
+/// A list of variable references.
+///
+/// This class stores variables internally, acting as the permanent store.
+class ExpressionVariableList {
+public:
+ /// Implementation of methods in ExpressionVariableListBase
+ size_t GetSize() { return m_variables.size(); }
+
+ lldb::ExpressionVariableSP GetVariableAtIndex(size_t index) {
+ lldb::ExpressionVariableSP var_sp;
+ if (index < m_variables.size())
+ var_sp = m_variables[index];
+ return var_sp;
+ }
+
+ size_t AddVariable(const lldb::ExpressionVariableSP &var_sp) {
+ m_variables.push_back(var_sp);
+ return m_variables.size() - 1;
+ }
+
+ lldb::ExpressionVariableSP
+ AddNewlyConstructedVariable(ExpressionVariable *var) {
+ lldb::ExpressionVariableSP var_sp(var);
+ m_variables.push_back(var_sp);
+ return m_variables.back();
+ }
+
+ bool ContainsVariable(const lldb::ExpressionVariableSP &var_sp) {
+ const size_t size = m_variables.size();
+ for (size_t index = 0; index < size; ++index) {
+ if (m_variables[index].get() == var_sp.get())
+ return true;
+ }
+ return false;
+ }
+
+ /// Finds a variable by name in the list.
+ ///
+ /// \param[in] name
+ /// The name of the requested variable.
+ ///
+ /// \return
+ /// The variable requested, or nullptr if that variable is not in the
+ /// list.
+ lldb::ExpressionVariableSP GetVariable(ConstString name) {
+ lldb::ExpressionVariableSP var_sp;
+ for (size_t index = 0, size = GetSize(); index < size; ++index) {
+ var_sp = GetVariableAtIndex(index);
+ if (var_sp->GetName() == name)
+ return var_sp;
+ }
+ var_sp.reset();
+ return var_sp;
+ }
+
+ lldb::ExpressionVariableSP GetVariable(llvm::StringRef name) {
+ if (name.empty())
+ return nullptr;
+
+ for (size_t index = 0, size = GetSize(); index < size; ++index) {
+ auto var_sp = GetVariableAtIndex(index);
+ llvm::StringRef var_name_str = var_sp->GetName().GetStringRef();
+ if (var_name_str == name)
+ return var_sp;
+ }
+ return nullptr;
+ }
+
+ void RemoveVariable(lldb::ExpressionVariableSP var_sp) {
+ for (std::vector<lldb::ExpressionVariableSP>::iterator
+ vi = m_variables.begin(),
+ ve = m_variables.end();
+ vi != ve; ++vi) {
+ if (vi->get() == var_sp.get()) {
+ m_variables.erase(vi);
+ return;
+ }
+ }
+ }
+
+ void Clear() { m_variables.clear(); }
+
+private:
+ std::vector<lldb::ExpressionVariableSP> m_variables;
+};
+
+class PersistentExpressionState : public ExpressionVariableList {
+public:
+ // See TypeSystem.h for how to add subclasses to this.
+ enum LLVMCastKind { eKindClang, eKindSwift, eKindGo, kNumKinds };
+
+ LLVMCastKind getKind() const { return m_kind; }
+
+ PersistentExpressionState(LLVMCastKind kind) : m_kind(kind) {}
+
+ virtual ~PersistentExpressionState();
+
+ virtual lldb::ExpressionVariableSP
+ CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp) = 0;
+
+ virtual lldb::ExpressionVariableSP
+ CreatePersistentVariable(ExecutionContextScope *exe_scope,
+ ConstString name, const CompilerType &type,
+ lldb::ByteOrder byte_order,
+ uint32_t addr_byte_size) = 0;
+
+ /// Return a new persistent variable name with the specified prefix.
+ ConstString GetNextPersistentVariableName(Target &target,
+ llvm::StringRef prefix);
+
+ virtual llvm::StringRef
+ GetPersistentVariablePrefix(bool is_error = false) const = 0;
+
+ virtual void
+ RemovePersistentVariable(lldb::ExpressionVariableSP variable) = 0;
+
+ virtual llvm::Optional<CompilerType>
+ GetCompilerTypeFromPersistentDecl(ConstString type_name) = 0;
+
+ virtual lldb::addr_t LookupSymbol(ConstString name);
+
+ void RegisterExecutionUnit(lldb::IRExecutionUnitSP &execution_unit_sp);
+
+private:
+ LLVMCastKind m_kind;
+
+ typedef std::set<lldb::IRExecutionUnitSP> ExecutionUnitSet;
+ ExecutionUnitSet
+ m_execution_units; ///< The execution units that contain valuable symbols.
+
+ typedef llvm::DenseMap<const char *, lldb::addr_t> SymbolMap;
+ SymbolMap
+ m_symbol_map; ///< The addresses of the symbols in m_execution_units.
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_ExpressionVariable_h_
diff --git a/linux-x64/clang/include/lldb/Expression/FunctionCaller.h b/linux-x64/clang/include/lldb/Expression/FunctionCaller.h
new file mode 100644
index 0000000..ea9d020
--- /dev/null
+++ b/linux-x64/clang/include/lldb/Expression/FunctionCaller.h
@@ -0,0 +1,350 @@
+//===-- FunctionCaller.h ----------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_FunctionCaller_h_
+#define liblldb_FunctionCaller_h_
+
+#include <list>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "lldb/Core/Address.h"
+#include "lldb/Core/Value.h"
+#include "lldb/Expression/Expression.h"
+#include "lldb/Expression/ExpressionParser.h"
+#include "lldb/Symbol/CompilerType.h"
+
+namespace lldb_private {
+
+/// \class FunctionCaller FunctionCaller.h "lldb/Expression/FunctionCaller.h"
+/// Encapsulates a function that can be called.
+///
+/// A given FunctionCaller object can handle a single function signature.
+/// Once constructed, it can set up any number of concurrent calls to
+/// functions with that signature.
+///
+/// It performs the call by synthesizing a structure that contains the pointer
+/// to the function and the arguments that should be passed to that function,
+/// and producing a special-purpose JIT-compiled function that accepts a void*
+/// pointing to this struct as its only argument and calls the function in the
+/// struct with the written arguments. This method lets Clang handle the
+/// vagaries of function calling conventions.
+///
+/// The simplest use of the FunctionCaller is to construct it with a function
+/// representative of the signature you want to use, then call
+/// ExecuteFunction(ExecutionContext &, Stream &, Value &).
+///
+/// If you need to reuse the arguments for several calls, you can call
+/// InsertFunction() followed by WriteFunctionArguments(), which will return
+/// the location of the args struct for the wrapper function in args_addr_ref.
+///
+/// If you need to call the function on the thread plan stack, you can also
+/// call InsertFunction() followed by GetThreadPlanToCallFunction().
+///
+/// Any of the methods that take arg_addr_ptr or arg_addr_ref can be passed a
+/// pointer set to LLDB_INVALID_ADDRESS and new structure will be allocated
+/// and its address returned in that variable.
+///
+/// Any of the methods that take arg_addr_ptr can be passed nullptr, and the
+/// argument space will be managed for you.
+class FunctionCaller : public Expression {
+public:
+ /// LLVM-style RTTI support.
+ static bool classof(const Expression *E) {
+ return E->getKind() == eKindFunctionCaller;
+ }
+
+ /// Constructor
+ ///
+ /// \param[in] exe_scope
+ /// An execution context scope that gets us at least a target and
+ /// process.
+ ///
+ /// \param[in] ast_context
+ /// The AST context to evaluate argument types in.
+ ///
+ /// \param[in] return_qualtype
+ /// An opaque Clang QualType for the function result. Should be
+ /// defined in ast_context.
+ ///
+ /// \param[in] function_address
+ /// The address of the function to call.
+ ///
+ /// \param[in] arg_value_list
+ /// The default values to use when calling this function. Can
+ /// be overridden using WriteFunctionArguments().
+ FunctionCaller(ExecutionContextScope &exe_scope,
+ const CompilerType &return_type,
+ const Address &function_address,
+ const ValueList &arg_value_list, const char *name);
+
+ /// Destructor
+ ~FunctionCaller() override;
+
+ /// Compile the wrapper function
+ ///
+ /// \param[in] thread_to_use_sp
+ /// Compilation might end up calling functions. Pass in the thread you
+ /// want the compilation to use. If you pass in an empty ThreadSP it will
+ /// use the currently selected thread.
+ ///
+ /// \param[in] diagnostic_manager
+ /// The diagnostic manager to report parser errors to.
+ ///
+ /// \return
+ /// The number of errors.
+ virtual unsigned CompileFunction(lldb::ThreadSP thread_to_use_sp,
+ DiagnosticManager &diagnostic_manager) = 0;
+
+ /// Insert the default function wrapper and its default argument struct
+ ///
+ /// \param[in] exe_ctx
+ /// The execution context to insert the function and its arguments
+ /// into.
+ ///
+ /// \param[in,out] args_addr_ref
+ /// The address of the structure to write the arguments into. May
+ /// be LLDB_INVALID_ADDRESS; if it is, a new structure is allocated
+ /// and args_addr_ref is pointed to it.
+ ///
+ /// \param[in] diagnostic_manager
+ /// The diagnostic manager to report errors to.
+ ///
+ /// \return
+ /// True on success; false otherwise.
+ bool InsertFunction(ExecutionContext &exe_ctx, lldb::addr_t &args_addr_ref,
+ DiagnosticManager &diagnostic_manager);
+
+ /// Insert the default function wrapper (using the JIT)
+ ///
+ /// \param[in] exe_ctx
+ /// The execution context to insert the function and its arguments
+ /// into.
+ ///
+ /// \param[in] diagnostic_manager
+ /// The diagnostic manager to report errors to.
+ ///
+ /// \return
+ /// True on success; false otherwise.
+ bool WriteFunctionWrapper(ExecutionContext &exe_ctx,
+ DiagnosticManager &diagnostic_manager);
+
+ /// Insert the default function argument struct
+ ///
+ /// \param[in] exe_ctx
+ /// The execution context to insert the function and its arguments
+ /// into.
+ ///
+ /// \param[in,out] args_addr_ref
+ /// The address of the structure to write the arguments into. May
+ /// be LLDB_INVALID_ADDRESS; if it is, a new structure is allocated
+ /// and args_addr_ref is pointed to it.
+ ///
+ /// \param[in] diagnostic_manager
+ /// The diagnostic manager to report errors to.
+ ///
+ /// \return
+ /// True on success; false otherwise.
+ bool WriteFunctionArguments(ExecutionContext &exe_ctx,
+ lldb::addr_t &args_addr_ref,
+ DiagnosticManager &diagnostic_manager);
+
+ /// Insert an argument struct with a non-default function address and non-
+ /// default argument values
+ ///
+ /// \param[in] exe_ctx
+ /// The execution context to insert the function and its arguments
+ /// into.
+ ///
+ /// \param[in,out] args_addr_ref
+ /// The address of the structure to write the arguments into. May
+ /// be LLDB_INVALID_ADDRESS; if it is, a new structure is allocated
+ /// and args_addr_ref is pointed at it.
+ ///
+ /// \param[in] arg_values
+ /// The values of the function's arguments.
+ ///
+ /// \param[in] diagnostic_manager
+ /// The diagnostic manager to report errors to.
+ ///
+ /// \return
+ /// True on success; false otherwise.
+ bool WriteFunctionArguments(ExecutionContext &exe_ctx,
+ lldb::addr_t &args_addr_ref,
+ ValueList &arg_values,
+ DiagnosticManager &diagnostic_manager);
+
+ /// Run the function this FunctionCaller was created with.
+ ///
+ /// This is the full version.
+ ///
+ /// \param[in] exe_ctx
+ /// The thread & process in which this function will run.
+ ///
+ /// \param[in] args_addr_ptr
+ /// If nullptr, the function will take care of allocating & deallocating
+ /// the wrapper
+ /// args structure. Otherwise, if set to LLDB_INVALID_ADDRESS, a new
+ /// structure
+ /// will be allocated, filled and the address returned to you. You are
+ /// responsible
+ /// for deallocating it. And if passed in with a value other than
+ /// LLDB_INVALID_ADDRESS,
+ /// this should point to an already allocated structure with the values
+ /// already written.
+ ///
+ /// \param[in] diagnostic_manager
+ /// The diagnostic manager to report errors to.
+ ///
+ /// \param[in] options
+ /// The options for this expression execution.
+ ///
+ /// \param[out] results
+ /// The result value will be put here after running the function.
+ ///
+ /// \return
+ /// Returns one of the ExpressionResults enum indicating function call
+ /// status.
+ lldb::ExpressionResults
+ ExecuteFunction(ExecutionContext &exe_ctx, lldb::addr_t *args_addr_ptr,
+ const EvaluateExpressionOptions &options,
+ DiagnosticManager &diagnostic_manager, Value &results);
+
+ /// Get a thread plan to run the function this FunctionCaller was created
+ /// with.
+ ///
+ /// \param[in] exe_ctx
+ /// The execution context to insert the function and its arguments
+ /// into.
+ ///
+ /// \param[in] func_addr
+ /// The address of the function in the target process.
+ ///
+ /// \param[in] args_addr
+ /// The address of the argument struct.
+ ///
+ /// \param[in] diagnostic_manager
+ /// The diagnostic manager to report errors to.
+ ///
+ /// \param[in] stop_others
+ /// True if other threads should pause during execution.
+ ///
+ /// \param[in] unwind_on_error
+ /// True if the thread plan may simply be discarded if an error occurs.
+ ///
+ /// \return
+ /// A ThreadPlan shared pointer for executing the function.
+ lldb::ThreadPlanSP
+ GetThreadPlanToCallFunction(ExecutionContext &exe_ctx, lldb::addr_t args_addr,
+ const EvaluateExpressionOptions &options,
+ DiagnosticManager &diagnostic_manager);
+
+ /// Get the result of the function from its struct
+ ///
+ /// \param[in] exe_ctx
+ /// The execution context to retrieve the result from.
+ ///
+ /// \param[in] args_addr
+ /// The address of the argument struct.
+ ///
+ /// \param[out] ret_value
+ /// The value returned by the function.
+ ///
+ /// \return
+ /// True on success; false otherwise.
+ bool FetchFunctionResults(ExecutionContext &exe_ctx, lldb::addr_t args_addr,
+ Value &ret_value);
+
+ /// Deallocate the arguments structure
+ ///
+ /// \param[in] exe_ctx
+ /// The execution context to insert the function and its arguments
+ /// into.
+ ///
+ /// \param[in] args_addr
+ /// The address of the argument struct.
+ void DeallocateFunctionResults(ExecutionContext &exe_ctx,
+ lldb::addr_t args_addr);
+
+ /// Interface for ClangExpression
+
+ /// Return the string that the parser should parse. Must be a full
+ /// translation unit.
+ const char *Text() override { return m_wrapper_function_text.c_str(); }
+
+ /// Return the function name that should be used for executing the
+ /// expression. Text() should contain the definition of this function.
+ const char *FunctionName() override {
+ return m_wrapper_function_name.c_str();
+ }
+
+ /// Return the object that the parser should use when registering local
+ /// variables. May be nullptr if the Expression doesn't care.
+ ExpressionVariableList *LocalVariables() { return nullptr; }
+
+ /// Return true if validation code should be inserted into the expression.
+ bool NeedsValidation() override { return false; }
+
+ /// Return true if external variables in the expression should be resolved.
+ bool NeedsVariableResolution() override { return false; }
+
+ ValueList GetArgumentValues() const { return m_arg_values; }
+
+protected:
+ // Note: the parser needs to be destructed before the execution unit, so
+ // declare the execution unit first.
+ std::shared_ptr<IRExecutionUnit> m_execution_unit_sp;
+ std::unique_ptr<ExpressionParser>
+ m_parser; ///< The parser responsible for compiling the function.
+ ///< This will get made in CompileFunction, so it is
+ ///< safe to access it after that.
+
+ lldb::ModuleWP m_jit_module_wp;
+ std::string
+ m_name; ///< The name of this clang function - for debugging purposes.
+
+ Function *m_function_ptr; ///< The function we're going to call. May be
+ ///nullptr if we don't have debug info for the
+ ///function.
+ Address m_function_addr; ///< If we don't have the FunctionSP, we at least
+ ///need the address & return type.
+ CompilerType m_function_return_type; ///< The opaque clang qual type for the
+ ///function return type.
+
+ std::string m_wrapper_function_name; ///< The name of the wrapper function.
+ std::string
+ m_wrapper_function_text; ///< The contents of the wrapper function.
+ std::string m_wrapper_struct_name; ///< The name of the struct that contains
+ ///the target function address, arguments,
+ ///and result.
+ std::list<lldb::addr_t> m_wrapper_args_addrs; ///< The addresses of the
+ ///arguments to the wrapper
+ ///function.
+
+ bool m_struct_valid; ///< True if the ASTStructExtractor has populated the
+ ///variables below.
+
+ /// These values are populated by the ASTStructExtractor
+ size_t m_struct_size; ///< The size of the argument struct, in bytes.
+ std::vector<uint64_t>
+ m_member_offsets; ///< The offset of each member in the struct, in bytes.
+ uint64_t m_return_size; ///< The size of the result variable, in bytes.
+ uint64_t m_return_offset; ///< The offset of the result variable in the
+ ///struct, in bytes.
+
+ ValueList m_arg_values; ///< The default values of the arguments.
+
+ bool m_compiled; ///< True if the wrapper function has already been parsed.
+ bool
+ m_JITted; ///< True if the wrapper function has already been JIT-compiled.
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_FunctionCaller_h_
diff --git a/linux-x64/clang/include/lldb/Expression/IRDynamicChecks.h b/linux-x64/clang/include/lldb/Expression/IRDynamicChecks.h
new file mode 100644
index 0000000..26f1cdb
--- /dev/null
+++ b/linux-x64/clang/include/lldb/Expression/IRDynamicChecks.h
@@ -0,0 +1,146 @@
+//===-- IRDynamicChecks.h ---------------------------------------------*- C++
+//-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_IRDynamicChecks_h_
+#define liblldb_IRDynamicChecks_h_
+
+#include "lldb/lldb-types.h"
+#include "llvm/Pass.h"
+
+namespace llvm {
+class BasicBlock;
+class CallInst;
+class Constant;
+class Function;
+class Instruction;
+class Module;
+class DataLayout;
+class Value;
+}
+
+namespace lldb_private {
+
+class ClangExpressionDeclMap;
+class ExecutionContext;
+class Stream;
+
+/// \class DynamicCheckerFunctions IRDynamicChecks.h
+/// "lldb/Expression/IRDynamicChecks.h" Encapsulates dynamic check functions
+/// used by expressions.
+///
+/// Each of the utility functions encapsulated in this class is responsible
+/// for validating some data that an expression is about to use. Examples
+/// are:
+///
+/// a = *b; // check that b is a valid pointer [b init]; // check that b
+/// is a valid object to send "init" to
+///
+/// The class installs each checker function into the target process and makes
+/// it available to IRDynamicChecks to use.
+class DynamicCheckerFunctions {
+public:
+ /// Constructor
+ DynamicCheckerFunctions();
+
+ /// Destructor
+ ~DynamicCheckerFunctions();
+
+ /// Install the utility functions into a process. This binds the instance
+ /// of DynamicCheckerFunctions to that process.
+ ///
+ /// \param[in] diagnostic_manager
+ /// A diagnostic manager to report errors to.
+ ///
+ /// \param[in] exe_ctx
+ /// The execution context to install the functions into.
+ ///
+ /// \return
+ /// True on success; false on failure, or if the functions have
+ /// already been installed.
+ bool Install(DiagnosticManager &diagnostic_manager,
+ ExecutionContext &exe_ctx);
+
+ bool DoCheckersExplainStop(lldb::addr_t addr, Stream &message);
+
+ std::unique_ptr<UtilityFunction> m_valid_pointer_check;
+ std::unique_ptr<UtilityFunction> m_objc_object_check;
+};
+
+/// \class IRDynamicChecks IRDynamicChecks.h
+/// "lldb/Expression/IRDynamicChecks.h" Adds dynamic checks to a user-entered
+/// expression to reduce its likelihood of crashing
+///
+/// When an IR function is executed in the target process, it may cause
+/// crashes or hangs by dereferencing NULL pointers, trying to call
+/// Objective-C methods on objects that do not respond to them, and so forth.
+///
+/// IRDynamicChecks adds calls to the functions in DynamicCheckerFunctions to
+/// appropriate locations in an expression's IR.
+class IRDynamicChecks : public llvm::ModulePass {
+public:
+ /// Constructor
+ ///
+ /// \param[in] checker_functions
+ /// The checker functions for the target process.
+ ///
+ /// \param[in] func_name
+ /// The name of the function to prepare for execution in the target.
+ ///
+ /// \param[in] decl_map
+ /// The mapping used to look up entities in the target process. In
+ /// this case, used to find objc_msgSend
+ IRDynamicChecks(DynamicCheckerFunctions &checker_functions,
+ const char *func_name = "$__lldb_expr");
+
+ /// Destructor
+ ~IRDynamicChecks() override;
+
+ /// Run this IR transformer on a single module
+ ///
+ /// \param[in] M
+ /// The module to run on. This module is searched for the function
+ /// $__lldb_expr, and that function is passed to the passes one by
+ /// one.
+ ///
+ /// \return
+ /// True on success; false otherwise
+ bool runOnModule(llvm::Module &M) override;
+
+ /// Interface stub
+ void assignPassManager(
+ llvm::PMStack &PMS,
+ llvm::PassManagerType T = llvm::PMT_ModulePassManager) override;
+
+ /// Returns PMT_ModulePassManager
+ llvm::PassManagerType getPotentialPassManagerType() const override;
+
+private:
+ /// A basic block-level pass to find all pointer dereferences and
+ /// validate them before use.
+
+ /// The top-level pass implementation
+ ///
+ /// \param[in] M
+ /// The module currently being processed.
+ ///
+ /// \param[in] BB
+ /// The basic block currently being processed.
+ ///
+ /// \return
+ /// True on success; false otherwise
+ bool FindDataLoads(llvm::Module &M, llvm::BasicBlock &BB);
+
+ std::string m_func_name; ///< The name of the function to add checks to
+ DynamicCheckerFunctions
+ &m_checker_functions; ///< The checker functions for the process
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_IRDynamicChecks_h_
diff --git a/linux-x64/clang/include/lldb/Expression/IRExecutionUnit.h b/linux-x64/clang/include/lldb/Expression/IRExecutionUnit.h
new file mode 100644
index 0000000..beff44d
--- /dev/null
+++ b/linux-x64/clang/include/lldb/Expression/IRExecutionUnit.h
@@ -0,0 +1,408 @@
+//===-- IRExecutionUnit.h ---------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_IRExecutionUnit_h_
+#define liblldb_IRExecutionUnit_h_
+
+#include <atomic>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "llvm/ExecutionEngine/SectionMemoryManager.h"
+#include "llvm/IR/Module.h"
+
+#include "lldb/Expression/IRMemoryMap.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Symbol/SymbolContext.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/lldb-forward.h"
+#include "lldb/lldb-private.h"
+
+namespace llvm {
+
+class Module;
+class ExecutionEngine;
+class ObjectCache;
+
+} // namespace llvm
+
+namespace lldb_private {
+
+class Status;
+
+/// \class IRExecutionUnit IRExecutionUnit.h
+/// "lldb/Expression/IRExecutionUnit.h" Contains the IR and, optionally, JIT-
+/// compiled code for a module.
+///
+/// This class encapsulates the compiled version of an expression, in IR form
+/// (for interpretation purposes) and in raw machine code form (for execution
+/// in the target).
+///
+/// This object wraps an IR module that comes from the expression parser, and
+/// knows how to use the JIT to make it into executable code. It can then be
+/// used as input to the IR interpreter, or the address of the executable code
+/// can be passed to a thread plan to run in the target.
+///
+/// This class creates a subclass of LLVM's SectionMemoryManager, because that
+/// is how the JIT emits code. Because LLDB needs to move JIT-compiled code
+/// into the target process, the IRExecutionUnit knows how to copy the emitted
+/// code into the target process.
+class IRExecutionUnit : public std::enable_shared_from_this<IRExecutionUnit>,
+ public IRMemoryMap,
+ public ObjectFileJITDelegate {
+public:
+ /// Constructor
+ IRExecutionUnit(std::unique_ptr<llvm::LLVMContext> &context_up,
+ std::unique_ptr<llvm::Module> &module_up, ConstString &name,
+ const lldb::TargetSP &target_sp, const SymbolContext &sym_ctx,
+ std::vector<std::string> &cpu_features);
+
+ /// Destructor
+ ~IRExecutionUnit() override;
+
+ ConstString GetFunctionName() { return m_name; }
+
+ llvm::Module *GetModule() { return m_module; }
+
+ llvm::Function *GetFunction() {
+ return ((m_module != nullptr) ? m_module->getFunction(m_name.AsCString())
+ : nullptr);
+ }
+
+ void GetRunnableInfo(Status &error, lldb::addr_t &func_addr,
+ lldb::addr_t &func_end);
+
+ /// Accessors for IRForTarget and other clients that may want binary data
+ /// placed on their behalf. The binary data is owned by the IRExecutionUnit
+ /// unless the client explicitly chooses to free it.
+
+ lldb::addr_t WriteNow(const uint8_t *bytes, size_t size, Status &error);
+
+ void FreeNow(lldb::addr_t allocation);
+
+ /// ObjectFileJITDelegate overrides
+ lldb::ByteOrder GetByteOrder() const override;
+
+ uint32_t GetAddressByteSize() const override;
+
+ void PopulateSymtab(lldb_private::ObjectFile *obj_file,
+ lldb_private::Symtab &symtab) override;
+
+ void PopulateSectionList(lldb_private::ObjectFile *obj_file,
+ lldb_private::SectionList §ion_list) override;
+
+ ArchSpec GetArchitecture() override;
+
+ lldb::ModuleSP GetJITModule();
+
+ lldb::addr_t FindSymbol(ConstString name, bool &missing_weak);
+
+ void GetStaticInitializers(std::vector<lldb::addr_t> &static_initializers);
+
+ /// \class JittedFunction IRExecutionUnit.h
+ /// "lldb/Expression/IRExecutionUnit.h"
+ /// Encapsulates a single function that has been generated by the JIT.
+ ///
+ /// Functions that have been generated by the JIT are first resident in the
+ /// local process, and then placed in the target process. JittedFunction
+ /// represents a function possibly resident in both.
+ struct JittedEntity {
+ ConstString m_name; ///< The function's name
+ lldb::addr_t m_local_addr; ///< The address of the function in LLDB's memory
+ lldb::addr_t
+ m_remote_addr; ///< The address of the function in the target's memory
+
+ /// Constructor
+ ///
+ /// Initializes class variabes.
+ ///
+ /// \param[in] name
+ /// The name of the function.
+ ///
+ /// \param[in] local_addr
+ /// The address of the function in LLDB, or LLDB_INVALID_ADDRESS if
+ /// it is not present in LLDB's memory.
+ ///
+ /// \param[in] remote_addr
+ /// The address of the function in the target, or LLDB_INVALID_ADDRESS
+ /// if it is not present in the target's memory.
+ JittedEntity(const char *name,
+ lldb::addr_t local_addr = LLDB_INVALID_ADDRESS,
+ lldb::addr_t remote_addr = LLDB_INVALID_ADDRESS)
+ : m_name(name), m_local_addr(local_addr), m_remote_addr(remote_addr) {}
+ };
+
+ struct JittedFunction : JittedEntity {
+ bool m_external;
+ JittedFunction(const char *name, bool external,
+ lldb::addr_t local_addr = LLDB_INVALID_ADDRESS,
+ lldb::addr_t remote_addr = LLDB_INVALID_ADDRESS)
+ : JittedEntity(name, local_addr, remote_addr), m_external(external) {}
+ };
+
+ struct JittedGlobalVariable : JittedEntity {
+ JittedGlobalVariable(const char *name,
+ lldb::addr_t local_addr = LLDB_INVALID_ADDRESS,
+ lldb::addr_t remote_addr = LLDB_INVALID_ADDRESS)
+ : JittedEntity(name, local_addr, remote_addr) {}
+ };
+
+ const std::vector<JittedFunction> &GetJittedFunctions() {
+ return m_jitted_functions;
+ }
+
+ const std::vector<JittedGlobalVariable> &GetJittedGlobalVariables() {
+ return m_jitted_global_variables;
+ }
+
+private:
+ /// Look up the object in m_address_map that contains a given address, find
+ /// where it was copied to, and return the remote address at the same offset
+ /// into the copied entity
+ ///
+ /// \param[in] local_address
+ /// The address in the debugger.
+ ///
+ /// \return
+ /// The address in the target process.
+ lldb::addr_t GetRemoteAddressForLocal(lldb::addr_t local_address);
+
+ /// Look up the object in m_address_map that contains a given address, find
+ /// where it was copied to, and return its address range in the target
+ /// process
+ ///
+ /// \param[in] local_address
+ /// The address in the debugger.
+ ///
+ /// \return
+ /// The range of the containing object in the target process.
+ typedef std::pair<lldb::addr_t, uintptr_t> AddrRange;
+ AddrRange GetRemoteRangeForLocal(lldb::addr_t local_address);
+
+ /// Commit all allocations to the process and record where they were stored.
+ ///
+ /// \param[in] process
+ /// The process to allocate memory in.
+ ///
+ /// \return
+ /// True <=> all allocations were performed successfully.
+ /// This method will attempt to free allocated memory if the
+ /// operation fails.
+ bool CommitAllocations(lldb::ProcessSP &process_sp);
+
+ /// Report all committed allocations to the execution engine.
+ ///
+ /// \param[in] engine
+ /// The execution engine to notify.
+ void ReportAllocations(llvm::ExecutionEngine &engine);
+
+ /// Write the contents of all allocations to the process.
+ ///
+ /// \param[in] local_address
+ /// The process containing the allocations.
+ ///
+ /// \return
+ /// True <=> all allocations were performed successfully.
+ bool WriteData(lldb::ProcessSP &process_sp);
+
+ Status DisassembleFunction(Stream &stream, lldb::ProcessSP &process_sp);
+
+ struct SearchSpec;
+
+ void CollectCandidateCNames(std::vector<SearchSpec> &C_specs,
+ ConstString name);
+
+ void CollectCandidateCPlusPlusNames(std::vector<SearchSpec> &CPP_specs,
+ const std::vector<SearchSpec> &C_specs,
+ const SymbolContext &sc);
+
+ void CollectFallbackNames(std::vector<SearchSpec> &fallback_specs,
+ const std::vector<SearchSpec> &C_specs);
+
+ lldb::addr_t FindInSymbols(const std::vector<SearchSpec> &specs,
+ const lldb_private::SymbolContext &sc,
+ bool &symbol_was_missing_weak);
+
+ lldb::addr_t FindInRuntimes(const std::vector<SearchSpec> &specs,
+ const lldb_private::SymbolContext &sc);
+
+ lldb::addr_t FindInUserDefinedSymbols(const std::vector<SearchSpec> &specs,
+ const lldb_private::SymbolContext &sc);
+
+ void ReportSymbolLookupError(ConstString name);
+
+ class MemoryManager : public llvm::SectionMemoryManager {
+ public:
+ MemoryManager(IRExecutionUnit &parent);
+
+ ~MemoryManager() override;
+
+ /// Allocate space for executable code, and add it to the m_spaceBlocks
+ /// map
+ ///
+ /// \param[in] Size
+ /// The size of the area.
+ ///
+ /// \param[in] Alignment
+ /// The required alignment of the area.
+ ///
+ /// \param[in] SectionID
+ /// A unique identifier for the section.
+ ///
+ /// \return
+ /// Allocated space.
+ uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
+ unsigned SectionID,
+ llvm::StringRef SectionName) override;
+
+ /// Allocate space for data, and add it to the m_spaceBlocks map
+ ///
+ /// \param[in] Size
+ /// The size of the area.
+ ///
+ /// \param[in] Alignment
+ /// The required alignment of the area.
+ ///
+ /// \param[in] SectionID
+ /// A unique identifier for the section.
+ ///
+ /// \param[in] IsReadOnly
+ /// Flag indicating the section is read-only.
+ ///
+ /// \return
+ /// Allocated space.
+ uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
+ unsigned SectionID,
+ llvm::StringRef SectionName,
+ bool IsReadOnly) override;
+
+ /// Called when object loading is complete and section page permissions
+ /// can be applied. Currently unimplemented for LLDB.
+ ///
+ /// \param[out] ErrMsg
+ /// The error that prevented the page protection from succeeding.
+ ///
+ /// \return
+ /// True in case of failure, false in case of success.
+ bool finalizeMemory(std::string *ErrMsg) override {
+ // TODO: Ensure that the instruction cache is flushed because
+ // relocations are updated by dy-load. See:
+ // sys::Memory::InvalidateInstructionCache
+ // llvm::SectionMemoryManager
+ return false;
+ }
+
+ void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr,
+ size_t Size) override {}
+
+ uint64_t getSymbolAddress(const std::string &Name) override;
+
+ // Find the address of the symbol Name. If Name is a missing weak symbol
+ // then missing_weak will be true.
+ uint64_t GetSymbolAddressAndPresence(const std::string &Name,
+ bool &missing_weak);
+
+ llvm::JITSymbol findSymbol(const std::string &Name) override;
+
+ void *getPointerToNamedFunction(const std::string &Name,
+ bool AbortOnFailure = true) override;
+
+ private:
+ std::unique_ptr<SectionMemoryManager> m_default_mm_up; ///< The memory
+ /// allocator to use
+ /// in actually
+ /// creating space.
+ /// All calls are
+ /// passed through to
+ /// it.
+ IRExecutionUnit &m_parent; ///< The execution unit this is a proxy for.
+ };
+
+ static const unsigned eSectionIDInvalid = (unsigned)-1;
+
+ /// \class AllocationRecord IRExecutionUnit.h
+ /// "lldb/Expression/IRExecutionUnit.h" Encapsulates a single allocation
+ /// request made by the JIT.
+ ///
+ /// Allocations made by the JIT are first queued up and then applied in bulk
+ /// to the underlying process.
+ enum class AllocationKind { Stub, Code, Data, Global, Bytes };
+
+ static lldb::SectionType
+ GetSectionTypeFromSectionName(const llvm::StringRef &name,
+ AllocationKind alloc_kind);
+
+ struct AllocationRecord {
+ std::string m_name;
+ lldb::addr_t m_process_address;
+ uintptr_t m_host_address;
+ uint32_t m_permissions;
+ lldb::SectionType m_sect_type;
+ size_t m_size;
+ unsigned m_alignment;
+ unsigned m_section_id;
+
+ AllocationRecord(uintptr_t host_address, uint32_t permissions,
+ lldb::SectionType sect_type, size_t size,
+ unsigned alignment, unsigned section_id, const char *name)
+ : m_name(), m_process_address(LLDB_INVALID_ADDRESS),
+ m_host_address(host_address), m_permissions(permissions),
+ m_sect_type(sect_type), m_size(size), m_alignment(alignment),
+ m_section_id(section_id) {
+ if (name && name[0])
+ m_name = name;
+ }
+
+ void dump(Log *log);
+ };
+
+ bool CommitOneAllocation(lldb::ProcessSP &process_sp, Status &error,
+ AllocationRecord &record);
+
+ typedef std::vector<AllocationRecord> RecordVector;
+ RecordVector m_records;
+
+ std::unique_ptr<llvm::LLVMContext> m_context_up;
+ std::unique_ptr<llvm::ExecutionEngine> m_execution_engine_up;
+ std::unique_ptr<llvm::ObjectCache> m_object_cache_up;
+ std::unique_ptr<llvm::Module>
+ m_module_up; ///< Holder for the module until it's been handed off
+ llvm::Module *m_module; ///< Owned by the execution engine
+ std::vector<std::string> m_cpu_features;
+ std::vector<JittedFunction> m_jitted_functions; ///< A vector of all functions
+ ///that have been JITted into
+ ///machine code
+ std::vector<JittedGlobalVariable> m_jitted_global_variables; ///< A vector of
+ ///all functions
+ ///that have been
+ ///JITted into
+ ///machine code
+ const ConstString m_name;
+ SymbolContext m_sym_ctx; ///< Used for symbol lookups
+ std::vector<ConstString> m_failed_lookups;
+
+ std::atomic<bool> m_did_jit;
+
+ lldb::addr_t m_function_load_addr;
+ lldb::addr_t m_function_end_load_addr;
+
+ bool m_strip_underscore = true; ///< True for platforms where global symbols
+ /// have a _ prefix
+ bool m_reported_allocations; ///< True after allocations have been reported.
+ ///It is possible that
+ ///< sections will be allocated when this is true, in which case they weren't
+ ///< depended on by any function. (Top-level code defining a variable, but
+ ///< defining no functions using that variable, would do this.) If this
+ ///< is true, any allocations need to be committed immediately -- no
+ ///< opportunity for relocation.
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_IRExecutionUnit_h_
diff --git a/linux-x64/clang/include/lldb/Expression/IRInterpreter.h b/linux-x64/clang/include/lldb/Expression/IRInterpreter.h
new file mode 100644
index 0000000..6148093
--- /dev/null
+++ b/linux-x64/clang/include/lldb/Expression/IRInterpreter.h
@@ -0,0 +1,55 @@
+//===-- IRInterpreter.h -----------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_IRInterpreter_h_
+#define liblldb_IRInterpreter_h_
+
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/Stream.h"
+#include "lldb/lldb-public.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/Pass.h"
+
+namespace llvm {
+class Function;
+class Module;
+}
+
+namespace lldb_private {
+
+class ClangExpressionDeclMap;
+class IRMemoryMap;
+}
+
+/// \class IRInterpreter IRInterpreter.h "lldb/Expression/IRInterpreter.h"
+/// Attempt to interpret the function's code if it does not require
+/// running the target.
+///
+/// In some cases, the IR for an expression can be evaluated entirely in the
+/// debugger, manipulating variables but not executing any code in the target.
+/// The IRInterpreter attempts to do this.
+class IRInterpreter {
+public:
+ static bool CanInterpret(llvm::Module &module, llvm::Function &function,
+ lldb_private::Status &error,
+ const bool support_function_calls);
+
+ static bool Interpret(llvm::Module &module, llvm::Function &function,
+ llvm::ArrayRef<lldb::addr_t> args,
+ lldb_private::IRExecutionUnit &execution_unit,
+ lldb_private::Status &error,
+ lldb::addr_t stack_frame_bottom,
+ lldb::addr_t stack_frame_top,
+ lldb_private::ExecutionContext &exe_ctx);
+
+private:
+ static bool supportsFunction(llvm::Function &llvm_function,
+ lldb_private::Status &err);
+};
+
+#endif
diff --git a/linux-x64/clang/include/lldb/Expression/IRMemoryMap.h b/linux-x64/clang/include/lldb/Expression/IRMemoryMap.h
new file mode 100644
index 0000000..d6a17a9
--- /dev/null
+++ b/linux-x64/clang/include/lldb/Expression/IRMemoryMap.h
@@ -0,0 +1,136 @@
+//===-- IRMemoryMap.h -------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef lldb_IRMemoryMap_h_
+#define lldb_IRMemoryMap_h_
+
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/UserID.h"
+#include "lldb/lldb-public.h"
+
+#include <map>
+
+namespace lldb_private {
+
+/// \class IRMemoryMap IRMemoryMap.h "lldb/Expression/IRMemoryMap.h"
+/// Encapsulates memory that may exist in the process but must
+/// also be available in the host process.
+///
+/// This class encapsulates a group of memory objects that must be readable or
+/// writable from the host process regardless of whether the process exists.
+/// This allows the IR interpreter as well as JITted code to access the same
+/// memory. All allocations made by this class are represented as disjoint
+/// intervals.
+///
+/// Point queries against this group of memory objects can be made by the
+/// address in the tar at which they reside. If the inferior does not exist,
+/// allocations still get made-up addresses. If an inferior appears at some
+/// point, then those addresses need to be re-mapped.
+class IRMemoryMap {
+public:
+ IRMemoryMap(lldb::TargetSP target_sp);
+ ~IRMemoryMap();
+
+ enum AllocationPolicy : uint8_t {
+ eAllocationPolicyInvalid =
+ 0, ///< It is an error for an allocation to have this policy.
+ eAllocationPolicyHostOnly, ///< This allocation was created in the host and
+ ///will never make it into the process.
+ ///< It is an error to create other types of allocations while such
+ ///allocations exist.
+ eAllocationPolicyMirror, ///< The intent is that this allocation exist both
+ ///in the host and the process and have
+ ///< the same content in both.
+ eAllocationPolicyProcessOnly ///< The intent is that this allocation exist
+ ///only in the process.
+ };
+
+ lldb::addr_t Malloc(size_t size, uint8_t alignment, uint32_t permissions,
+ AllocationPolicy policy, bool zero_memory, Status &error);
+ void Leak(lldb::addr_t process_address, Status &error);
+ void Free(lldb::addr_t process_address, Status &error);
+
+ void WriteMemory(lldb::addr_t process_address, const uint8_t *bytes,
+ size_t size, Status &error);
+ void WriteScalarToMemory(lldb::addr_t process_address, Scalar &scalar,
+ size_t size, Status &error);
+ void WritePointerToMemory(lldb::addr_t process_address, lldb::addr_t address,
+ Status &error);
+ void ReadMemory(uint8_t *bytes, lldb::addr_t process_address, size_t size,
+ Status &error);
+ void ReadScalarFromMemory(Scalar &scalar, lldb::addr_t process_address,
+ size_t size, Status &error);
+ void ReadPointerFromMemory(lldb::addr_t *address,
+ lldb::addr_t process_address, Status &error);
+ bool GetAllocSize(lldb::addr_t address, size_t &size);
+ void GetMemoryData(DataExtractor &extractor, lldb::addr_t process_address,
+ size_t size, Status &error);
+
+ lldb::ByteOrder GetByteOrder();
+ uint32_t GetAddressByteSize();
+
+ // This function can return NULL.
+ ExecutionContextScope *GetBestExecutionContextScope() const;
+
+ lldb::TargetSP GetTarget() { return m_target_wp.lock(); }
+
+protected:
+ // This function should only be used if you know you are using the JIT. Any
+ // other cases should use GetBestExecutionContextScope().
+
+ lldb::ProcessWP &GetProcessWP() { return m_process_wp; }
+
+private:
+ struct Allocation {
+ lldb::addr_t
+ m_process_alloc; ///< The (unaligned) base for the remote allocation.
+ lldb::addr_t
+ m_process_start; ///< The base address of the allocation in the process.
+ size_t m_size; ///< The size of the requested allocation.
+ DataBufferHeap m_data;
+
+ /// Flags. Keep these grouped together to avoid structure padding.
+ AllocationPolicy m_policy;
+ bool m_leak;
+ uint8_t m_permissions; ///< The access permissions on the memory in the
+ /// process. In the host, the memory is always
+ /// read/write.
+ uint8_t m_alignment; ///< The alignment of the requested allocation.
+
+ public:
+ Allocation(lldb::addr_t process_alloc, lldb::addr_t process_start,
+ size_t size, uint32_t permissions, uint8_t alignment,
+ AllocationPolicy m_policy);
+
+ DISALLOW_COPY_AND_ASSIGN(Allocation);
+ };
+
+ static_assert(sizeof(Allocation) <=
+ (4 * sizeof(lldb::addr_t)) + sizeof(DataBufferHeap),
+ "IRMemoryMap::Allocation is larger than expected");
+
+ lldb::ProcessWP m_process_wp;
+ lldb::TargetWP m_target_wp;
+ typedef std::map<lldb::addr_t, Allocation> AllocationMap;
+ AllocationMap m_allocations;
+
+ lldb::addr_t FindSpace(size_t size);
+ bool ContainsHostOnlyAllocations();
+ AllocationMap::iterator FindAllocation(lldb::addr_t addr, size_t size);
+
+ // Returns true if the given allocation intersects any allocation in the
+ // memory map.
+ bool IntersectsAllocation(lldb::addr_t addr, size_t size) const;
+
+ // Returns true if the two given allocations intersect each other.
+ static bool AllocationsIntersect(lldb::addr_t addr1, size_t size1,
+ lldb::addr_t addr2, size_t size2);
+};
+}
+
+#endif
diff --git a/linux-x64/clang/include/lldb/Expression/LLVMUserExpression.h b/linux-x64/clang/include/lldb/Expression/LLVMUserExpression.h
new file mode 100644
index 0000000..c2af723
--- /dev/null
+++ b/linux-x64/clang/include/lldb/Expression/LLVMUserExpression.h
@@ -0,0 +1,134 @@
+//===-- LLVMUserExpression.h ------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_LLVMUserExpression_h
+#define liblldb_LLVMUserExpression_h
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "llvm/IR/LegacyPassManager.h"
+
+#include "lldb/Expression/UserExpression.h"
+
+namespace lldb_private {
+
+/// \class LLVMUserExpression LLVMUserExpression.h
+/// "lldb/Expression/LLVMUserExpression.h" Encapsulates a one-time expression
+/// for use in lldb.
+///
+/// LLDB uses expressions for various purposes, notably to call functions
+/// and as a backend for the expr command. LLVMUserExpression is a virtual
+/// base class that encapsulates the objects needed to parse and JIT an
+/// expression. The actual parsing part will be provided by the specific
+/// implementations of LLVMUserExpression - which will be vended through the
+/// appropriate TypeSystem.
+class LLVMUserExpression : public UserExpression {
+public:
+ /// LLVM-style RTTI support.
+ static bool classof(const Expression *E) {
+ return E->getKind() == eKindLLVMUserExpression;
+ }
+
+ // The IRPasses struct is filled in by a runtime after an expression is
+ // compiled and can be used to to run fixups/analysis passes as required.
+ // EarlyPasses are run on the generated module before lldb runs its own IR
+ // fixups and inserts instrumentation code/pointer checks. LatePasses are run
+ // after the module has been processed by llvm, before the module is
+ // assembled and run in the ThreadPlan.
+ struct IRPasses {
+ IRPasses() : EarlyPasses(nullptr), LatePasses(nullptr){};
+ std::shared_ptr<llvm::legacy::PassManager> EarlyPasses;
+ std::shared_ptr<llvm::legacy::PassManager> LatePasses;
+ };
+
+ LLVMUserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr,
+ llvm::StringRef prefix, lldb::LanguageType language,
+ ResultType desired_type,
+ const EvaluateExpressionOptions &options,
+ ExpressionKind kind);
+ ~LLVMUserExpression() override;
+
+ bool FinalizeJITExecution(
+ DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx,
+ lldb::ExpressionVariableSP &result,
+ lldb::addr_t function_stack_bottom = LLDB_INVALID_ADDRESS,
+ lldb::addr_t function_stack_top = LLDB_INVALID_ADDRESS) override;
+
+ bool CanInterpret() override { return m_can_interpret; }
+
+ /// Return the string that the parser should parse. Must be a full
+ /// translation unit.
+ const char *Text() override { return m_transformed_text.c_str(); }
+
+ lldb::ModuleSP GetJITModule() override;
+
+protected:
+ lldb::ExpressionResults
+ DoExecute(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx,
+ const EvaluateExpressionOptions &options,
+ lldb::UserExpressionSP &shared_ptr_to_me,
+ lldb::ExpressionVariableSP &result) override;
+
+ virtual void ScanContext(ExecutionContext &exe_ctx,
+ lldb_private::Status &err) = 0;
+
+ bool PrepareToExecuteJITExpression(DiagnosticManager &diagnostic_manager,
+ ExecutionContext &exe_ctx,
+ lldb::addr_t &struct_address);
+
+ virtual bool AddArguments(ExecutionContext &exe_ctx,
+ std::vector<lldb::addr_t> &args,
+ lldb::addr_t struct_address,
+ DiagnosticManager &diagnostic_manager) = 0;
+
+ lldb::addr_t
+ m_stack_frame_bottom; ///< The bottom of the allocated stack frame.
+ lldb::addr_t m_stack_frame_top; ///< The top of the allocated stack frame.
+
+ bool m_allow_cxx; ///< True if the language allows C++.
+ bool m_allow_objc; ///< True if the language allows Objective-C.
+ std::string
+ m_transformed_text; ///< The text of the expression, as send to the parser
+
+ std::shared_ptr<IRExecutionUnit>
+ m_execution_unit_sp; ///< The execution unit the expression is stored in.
+ std::unique_ptr<Materializer> m_materializer_up; ///< The materializer to use
+ /// when running the
+ /// expression.
+ lldb::ModuleWP m_jit_module_wp;
+ bool m_enforce_valid_object; ///< True if the expression parser should enforce
+ ///the presence of a valid class pointer
+ /// in order to generate the expression as a method.
+ bool m_in_cplusplus_method; ///< True if the expression is compiled as a C++
+ ///member function (true if it was parsed
+ /// when exe_ctx was in a C++ method).
+ bool m_in_objectivec_method; ///< True if the expression is compiled as an
+ ///Objective-C method (true if it was parsed
+ /// when exe_ctx was in an Objective-C method).
+ bool m_in_static_method; ///< True if the expression is compiled as a static
+ ///(or class) method (currently true if it
+ /// was parsed when exe_ctx was in an Objective-C class method).
+ bool m_needs_object_ptr; ///< True if "this" or "self" must be looked up and
+ ///passed in. False if the expression
+ /// doesn't really use them and they can be NULL.
+ bool m_const_object; ///< True if "this" is const.
+ Target *m_target; ///< The target for storing persistent data like types and
+ ///variables.
+
+ bool m_can_interpret; ///< True if the expression could be evaluated
+ ///statically; false otherwise.
+ lldb::addr_t m_materialized_address; ///< The address at which the arguments
+ ///to the expression have been
+ ///materialized.
+ Materializer::DematerializerSP m_dematerializer_sp; ///< The dematerializer.
+};
+
+} // namespace lldb_private
+#endif
diff --git a/linux-x64/clang/include/lldb/Expression/Materializer.h b/linux-x64/clang/include/lldb/Expression/Materializer.h
new file mode 100644
index 0000000..603b4e0
--- /dev/null
+++ b/linux-x64/clang/include/lldb/Expression/Materializer.h
@@ -0,0 +1,139 @@
+//===-- Materializer.h ------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_Materializer_h
+#define liblldb_Materializer_h
+
+#include <memory>
+#include <vector>
+
+#include "lldb/Expression/IRMemoryMap.h"
+#include "lldb/Symbol/TaggedASTType.h"
+#include "lldb/Target/StackFrame.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/lldb-private-types.h"
+
+namespace lldb_private {
+
+class Materializer {
+public:
+ Materializer();
+ ~Materializer();
+
+ class Dematerializer {
+ public:
+ Dematerializer()
+ : m_materializer(nullptr), m_map(nullptr),
+ m_process_address(LLDB_INVALID_ADDRESS) {}
+
+ ~Dematerializer() { Wipe(); }
+
+ void Dematerialize(Status &err, lldb::addr_t frame_top,
+ lldb::addr_t frame_bottom);
+
+ void Wipe();
+
+ bool IsValid() {
+ return m_materializer && m_map &&
+ (m_process_address != LLDB_INVALID_ADDRESS);
+ }
+
+ private:
+ friend class Materializer;
+
+ Dematerializer(Materializer &materializer, lldb::StackFrameSP &frame_sp,
+ IRMemoryMap &map, lldb::addr_t process_address)
+ : m_materializer(&materializer), m_map(&map),
+ m_process_address(process_address) {
+ if (frame_sp) {
+ m_thread_wp = frame_sp->GetThread();
+ m_stack_id = frame_sp->GetStackID();
+ }
+ }
+
+ Materializer *m_materializer;
+ lldb::ThreadWP m_thread_wp;
+ StackID m_stack_id;
+ IRMemoryMap *m_map;
+ lldb::addr_t m_process_address;
+ };
+
+ typedef std::shared_ptr<Dematerializer> DematerializerSP;
+ typedef std::weak_ptr<Dematerializer> DematerializerWP;
+
+ DematerializerSP Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
+ lldb::addr_t process_address, Status &err);
+
+ class PersistentVariableDelegate {
+ public:
+ virtual ~PersistentVariableDelegate();
+ virtual ConstString GetName() = 0;
+ virtual void DidDematerialize(lldb::ExpressionVariableSP &variable) = 0;
+ };
+
+ uint32_t
+ AddPersistentVariable(lldb::ExpressionVariableSP &persistent_variable_sp,
+ PersistentVariableDelegate *delegate, Status &err);
+ uint32_t AddVariable(lldb::VariableSP &variable_sp, Status &err);
+ uint32_t AddResultVariable(const CompilerType &type, bool is_lvalue,
+ bool keep_in_memory,
+ PersistentVariableDelegate *delegate, Status &err);
+ uint32_t AddSymbol(const Symbol &symbol_sp, Status &err);
+ uint32_t AddRegister(const RegisterInfo ®ister_info, Status &err);
+
+ uint32_t GetStructAlignment() { return m_struct_alignment; }
+
+ uint32_t GetStructByteSize() { return m_current_offset; }
+
+ class Entity {
+ public:
+ Entity() : m_alignment(1), m_size(0), m_offset(0) {}
+
+ virtual ~Entity() = default;
+
+ virtual void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
+ lldb::addr_t process_address, Status &err) = 0;
+ virtual void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
+ lldb::addr_t process_address,
+ lldb::addr_t frame_top,
+ lldb::addr_t frame_bottom, Status &err) = 0;
+ virtual void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,
+ Log *log) = 0;
+ virtual void Wipe(IRMemoryMap &map, lldb::addr_t process_address) = 0;
+
+ uint32_t GetAlignment() { return m_alignment; }
+
+ uint32_t GetSize() { return m_size; }
+
+ uint32_t GetOffset() { return m_offset; }
+
+ void SetOffset(uint32_t offset) { m_offset = offset; }
+
+ protected:
+ void SetSizeAndAlignmentFromType(CompilerType &type);
+
+ uint32_t m_alignment;
+ uint32_t m_size;
+ uint32_t m_offset;
+ };
+
+private:
+ uint32_t AddStructMember(Entity &entity);
+
+ typedef std::unique_ptr<Entity> EntityUP;
+ typedef std::vector<EntityUP> EntityVector;
+
+ DematerializerWP m_dematerializer_wp;
+ EntityVector m_entities;
+ uint32_t m_current_offset;
+ uint32_t m_struct_alignment;
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_Materializer_h
diff --git a/linux-x64/clang/include/lldb/Expression/REPL.h b/linux-x64/clang/include/lldb/Expression/REPL.h
new file mode 100644
index 0000000..850d2f6
--- /dev/null
+++ b/linux-x64/clang/include/lldb/Expression/REPL.h
@@ -0,0 +1,163 @@
+//===-- REPL.h --------------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef lldb_REPL_h
+#define lldb_REPL_h
+
+#include <string>
+
+#include "lldb/Core/IOHandler.h"
+#include "lldb/Interpreter/OptionGroupFormat.h"
+#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
+#include "lldb/Target/Target.h"
+
+namespace lldb_private {
+
+class REPL : public IOHandlerDelegate {
+public:
+ // See TypeSystem.h for how to add subclasses to this.
+ enum LLVMCastKind { eKindClang, eKindSwift, eKindGo, kNumKinds };
+
+ LLVMCastKind getKind() const { return m_kind; }
+
+ REPL(LLVMCastKind kind, Target &target);
+
+ ~REPL() override;
+
+ /// Get a REPL with an existing target (or, failing that, a debugger to use),
+ /// and (optional) extra arguments for the compiler.
+ ///
+ /// \param[out] error
+ /// If this language is supported but the REPL couldn't be created, this
+ /// error is populated with the reason.
+ ///
+ /// \param[in] language
+ /// The language to create a REPL for.
+ ///
+ /// \param[in] debugger
+ /// If provided, and target is nullptr, the debugger to use when setting
+ /// up a top-level REPL.
+ ///
+ /// \param[in] target
+ /// If provided, the target to put the REPL inside.
+ ///
+ /// \param[in] repl_options
+ /// If provided, additional options for the compiler when parsing REPL
+ /// expressions.
+ ///
+ /// \return
+ /// The range of the containing object in the target process.
+ static lldb::REPLSP Create(Status &Status, lldb::LanguageType language,
+ Debugger *debugger, Target *target,
+ const char *repl_options);
+
+ void SetFormatOptions(const OptionGroupFormat &options) {
+ m_format_options = options;
+ }
+
+ void
+ SetValueObjectDisplayOptions(const OptionGroupValueObjectDisplay &options) {
+ m_varobj_options = options;
+ }
+
+ void SetEvaluateOptions(const EvaluateExpressionOptions &options) {
+ m_expr_options = options;
+ }
+
+ void SetCompilerOptions(const char *options) {
+ if (options)
+ m_compiler_options = options;
+ }
+
+ lldb::IOHandlerSP GetIOHandler();
+
+ Status RunLoop();
+
+ // IOHandler::Delegate functions
+ void IOHandlerActivated(IOHandler &io_handler, bool interactive) override;
+
+ bool IOHandlerInterrupt(IOHandler &io_handler) override;
+
+ void IOHandlerInputInterrupted(IOHandler &io_handler,
+ std::string &line) override;
+
+ const char *IOHandlerGetFixIndentationCharacters() override;
+
+ ConstString IOHandlerGetControlSequence(char ch) override;
+
+ const char *IOHandlerGetCommandPrefix() override;
+
+ const char *IOHandlerGetHelpPrologue() override;
+
+ bool IOHandlerIsInputComplete(IOHandler &io_handler,
+ StringList &lines) override;
+
+ int IOHandlerFixIndentation(IOHandler &io_handler, const StringList &lines,
+ int cursor_position) override;
+
+ void IOHandlerInputComplete(IOHandler &io_handler,
+ std::string &line) override;
+
+ int IOHandlerComplete(IOHandler &io_handler, const char *current_line,
+ const char *cursor, const char *last_char,
+ int skip_first_n_matches, int max_matches,
+ StringList &matches, StringList &descriptions) override;
+
+protected:
+ static int CalculateActualIndentation(const StringList &lines);
+
+ // Subclasses should override these functions to implement a functional REPL.
+
+ virtual Status DoInitialization() = 0;
+
+ virtual ConstString GetSourceFileBasename() = 0;
+
+ virtual const char *GetAutoIndentCharacters() = 0;
+
+ virtual bool SourceIsComplete(const std::string &source) = 0;
+
+ virtual lldb::offset_t GetDesiredIndentation(
+ const StringList &lines, int cursor_position,
+ int tab_size) = 0; // LLDB_INVALID_OFFSET means no change
+
+ virtual lldb::LanguageType GetLanguage() = 0;
+
+ virtual bool PrintOneVariable(Debugger &debugger,
+ lldb::StreamFileSP &output_sp,
+ lldb::ValueObjectSP &valobj_sp,
+ ExpressionVariable *var = nullptr) = 0;
+
+ virtual int CompleteCode(const std::string ¤t_code,
+ StringList &matches) = 0;
+
+ OptionGroupFormat m_format_options = OptionGroupFormat(lldb::eFormatDefault);
+ OptionGroupValueObjectDisplay m_varobj_options;
+ EvaluateExpressionOptions m_expr_options;
+ std::string m_compiler_options;
+
+ bool m_enable_auto_indent = true;
+ std::string m_indent_str; // Use this string for each level of indentation
+ std::string m_current_indent_str;
+ uint32_t m_current_indent_level = 0;
+
+ std::string m_repl_source_path;
+ bool m_dedicated_repl_mode = false;
+
+ StringList m_code; // All accumulated REPL statements are saved here
+
+ Target &m_target;
+ lldb::IOHandlerSP m_io_handler_sp;
+ LLVMCastKind m_kind;
+
+private:
+ std::string GetSourcePath();
+};
+
+} // namespace lldb_private
+
+#endif // lldb_REPL_h
diff --git a/linux-x64/clang/include/lldb/Expression/UserExpression.h b/linux-x64/clang/include/lldb/Expression/UserExpression.h
new file mode 100644
index 0000000..b1d52f8
--- /dev/null
+++ b/linux-x64/clang/include/lldb/Expression/UserExpression.h
@@ -0,0 +1,315 @@
+//===-- UserExpression.h ----------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_UserExpression_h_
+#define liblldb_UserExpression_h_
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "lldb/Core/Address.h"
+#include "lldb/Expression/Expression.h"
+#include "lldb/Expression/Materializer.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/Target.h"
+#include "lldb/lldb-forward.h"
+#include "lldb/lldb-private.h"
+
+namespace lldb_private {
+
+/// \class UserExpression UserExpression.h "lldb/Expression/UserExpression.h"
+/// Encapsulates a one-time expression for use in lldb.
+///
+/// LLDB uses expressions for various purposes, notably to call functions
+/// and as a backend for the expr command. UserExpression is a virtual base
+/// class that encapsulates the objects needed to parse and interpret or
+/// JIT an expression. The actual parsing part will be provided by the specific
+/// implementations of UserExpression - which will be vended through the
+/// appropriate TypeSystem.
+class UserExpression : public Expression {
+public:
+ /// LLVM-style RTTI support.
+ static bool classof(const Expression *E) {
+ return E->getKind() == eKindUserExpression;
+ }
+
+ enum { kDefaultTimeout = 500000u };
+
+ /// Constructor
+ ///
+ /// \param[in] expr
+ /// The expression to parse.
+ ///
+ /// \param[in] expr_prefix
+ /// If non-nullptr, a C string containing translation-unit level
+ /// definitions to be included when the expression is parsed.
+ ///
+ /// \param[in] language
+ /// If not eLanguageTypeUnknown, a language to use when parsing
+ /// the expression. Currently restricted to those languages
+ /// supported by Clang.
+ ///
+ /// \param[in] desired_type
+ /// If not eResultTypeAny, the type to use for the expression
+ /// result.
+ UserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr,
+ llvm::StringRef prefix, lldb::LanguageType language,
+ ResultType desired_type,
+ const EvaluateExpressionOptions &options,
+ ExpressionKind kind);
+
+ /// Destructor
+ ~UserExpression() override;
+
+ /// Parse the expression
+ ///
+ /// \param[in] diagnostic_manager
+ /// A diagnostic manager to report parse errors and warnings to.
+ ///
+ /// \param[in] exe_ctx
+ /// The execution context to use when looking up entities that
+ /// are needed for parsing (locations of functions, types of
+ /// variables, persistent variables, etc.)
+ ///
+ /// \param[in] execution_policy
+ /// Determines whether interpretation is possible or mandatory.
+ ///
+ /// \param[in] keep_result_in_memory
+ /// True if the resulting persistent variable should reside in
+ /// target memory, if applicable.
+ ///
+ /// \return
+ /// True on success (no errors); false otherwise.
+ virtual bool Parse(DiagnosticManager &diagnostic_manager,
+ ExecutionContext &exe_ctx,
+ lldb_private::ExecutionPolicy execution_policy,
+ bool keep_result_in_memory, bool generate_debug_info) = 0;
+
+ /// Attempts to find possible command line completions for the given
+ /// (possible incomplete) user expression.
+ ///
+ /// \param[in] exe_ctx
+ /// The execution context to use when looking up entities that
+ /// are needed for parsing and completing (locations of functions, types
+ /// of variables, persistent variables, etc.)
+ ///
+ /// \param[out] request
+ /// The completion request to fill out. The completion should be a string
+ /// that would complete the current token at the cursor position.
+ /// Note that the string in the list replaces the current token
+ /// in the command line.
+ ///
+ /// \param[in] complete_pos
+ /// The position of the cursor inside the user expression string.
+ /// The completion process starts on the token that the cursor is in.
+ ///
+ /// \return
+ /// True if we added any completion results to the output;
+ /// false otherwise.
+ virtual bool Complete(ExecutionContext &exe_ctx, CompletionRequest &request,
+ unsigned complete_pos) {
+ return false;
+ }
+
+ virtual bool CanInterpret() = 0;
+
+ bool MatchesContext(ExecutionContext &exe_ctx);
+
+ /// Execute the parsed expression by callinng the derived class's DoExecute
+ /// method.
+ ///
+ /// \param[in] diagnostic_manager
+ /// A diagnostic manager to report errors to.
+ ///
+ /// \param[in] exe_ctx
+ /// The execution context to use when looking up entities that
+ /// are needed for parsing (locations of variables, etc.)
+ ///
+ /// \param[in] options
+ /// Expression evaluation options.
+ ///
+ /// \param[in] shared_ptr_to_me
+ /// This is a shared pointer to this UserExpression. This is
+ /// needed because Execute can push a thread plan that will hold onto
+ /// the UserExpression for an unbounded period of time. So you
+ /// need to give the thread plan a reference to this object that can
+ /// keep it alive.
+ ///
+ /// \param[in] result
+ /// A pointer to direct at the persistent variable in which the
+ /// expression's result is stored.
+ ///
+ /// \return
+ /// A Process::Execution results value.
+ lldb::ExpressionResults Execute(DiagnosticManager &diagnostic_manager,
+ ExecutionContext &exe_ctx,
+ const EvaluateExpressionOptions &options,
+ lldb::UserExpressionSP &shared_ptr_to_me,
+ lldb::ExpressionVariableSP &result);
+
+ /// Apply the side effects of the function to program state.
+ ///
+ /// \param[in] diagnostic_manager
+ /// A diagnostic manager to report errors to.
+ ///
+ /// \param[in] exe_ctx
+ /// The execution context to use when looking up entities that
+ /// are needed for parsing (locations of variables, etc.)
+ ///
+ /// \param[in] result
+ /// A pointer to direct at the persistent variable in which the
+ /// expression's result is stored.
+ ///
+ /// \param[in] function_stack_pointer
+ /// A pointer to the base of the function's stack frame. This
+ /// is used to determine whether the expression result resides in
+ /// memory that will still be valid, or whether it needs to be
+ /// treated as homeless for the purpose of future expressions.
+ ///
+ /// \return
+ /// A Process::Execution results value.
+ virtual bool FinalizeJITExecution(
+ DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx,
+ lldb::ExpressionVariableSP &result,
+ lldb::addr_t function_stack_bottom = LLDB_INVALID_ADDRESS,
+ lldb::addr_t function_stack_top = LLDB_INVALID_ADDRESS) = 0;
+
+ /// Return the string that the parser should parse.
+ const char *Text() override { return m_expr_text.c_str(); }
+
+ /// Return the string that the user typed.
+ const char *GetUserText() { return m_expr_text.c_str(); }
+
+ /// Return the function name that should be used for executing the
+ /// expression. Text() should contain the definition of this function.
+ const char *FunctionName() override { return "$__lldb_expr"; }
+
+ /// Return the language that should be used when parsing. To use the
+ /// default, return eLanguageTypeUnknown.
+ lldb::LanguageType Language() override { return m_language; }
+
+ /// Return the desired result type of the function, or eResultTypeAny if
+ /// indifferent.
+ ResultType DesiredResultType() override { return m_desired_type; }
+
+ /// Return true if validation code should be inserted into the expression.
+ bool NeedsValidation() override { return true; }
+
+ /// Return true if external variables in the expression should be resolved.
+ bool NeedsVariableResolution() override { return true; }
+
+ EvaluateExpressionOptions *GetOptions() override { return &m_options; }
+
+ virtual lldb::ExpressionVariableSP
+ GetResultAfterDematerialization(ExecutionContextScope *exe_scope) {
+ return lldb::ExpressionVariableSP();
+ }
+
+ virtual lldb::ModuleSP GetJITModule() { return lldb::ModuleSP(); }
+
+ /// Evaluate one expression in the scratch context of the target passed in
+ /// the exe_ctx and return its result.
+ ///
+ /// \param[in] exe_ctx
+ /// The execution context to use when evaluating the expression.
+ ///
+ /// \param[in] options
+ /// Expression evaluation options. N.B. The language in the
+ /// evaluation options will be used to determine the language used for
+ /// expression evaluation.
+ ///
+ /// \param[in] expr_cstr
+ /// A C string containing the expression to be evaluated.
+ ///
+ /// \param[in] expr_prefix
+ /// If non-nullptr, a C string containing translation-unit level
+ /// definitions to be included when the expression is parsed.
+ ///
+ /// \param[in,out] result_valobj_sp
+ /// If execution is successful, the result valobj is placed here.
+ ///
+ /// \param[out] error
+ /// Filled in with an error in case the expression evaluation
+ /// fails to parse, run, or evaluated.
+ ///
+ /// \param[out] fixed_expression
+ /// If non-nullptr, the fixed expression is copied into the provided
+ /// string.
+ ///
+ /// \param[out] jit_module_sp_ptr
+ /// If non-nullptr, used to persist the generated IR module.
+ ///
+ /// \param[in] ctx_obj
+ /// If specified, then the expression will be evaluated in the context of
+ /// this object. It means that the context object's address will be
+ /// treated as `this` for the expression (the expression will be
+ /// evaluated as if it was inside of a method of the context object's
+ /// class, and its `this` parameter were pointing to the context object).
+ /// The parameter makes sense for class and union types only.
+ /// Currently there is a limitation: the context object must be located
+ /// in the debuggee process' memory (and have the load address).
+ ///
+ /// \result
+ /// A Process::ExpressionResults value. eExpressionCompleted for
+ /// success.
+ static lldb::ExpressionResults
+ Evaluate(ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options,
+ llvm::StringRef expr_cstr, llvm::StringRef expr_prefix,
+ lldb::ValueObjectSP &result_valobj_sp, Status &error,
+ std::string *fixed_expression = nullptr,
+ lldb::ModuleSP *jit_module_sp_ptr = nullptr,
+ ValueObject *ctx_obj = nullptr);
+
+ static const Status::ValueType kNoResult =
+ 0x1001; ///< ValueObject::GetError() returns this if there is no result
+ /// from the expression.
+
+ const char *GetFixedText() {
+ if (m_fixed_text.empty())
+ return nullptr;
+ return m_fixed_text.c_str();
+ }
+
+protected:
+ virtual lldb::ExpressionResults
+ DoExecute(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx,
+ const EvaluateExpressionOptions &options,
+ lldb::UserExpressionSP &shared_ptr_to_me,
+ lldb::ExpressionVariableSP &result) = 0;
+
+ static lldb::addr_t GetObjectPointer(lldb::StackFrameSP frame_sp,
+ ConstString &object_name, Status &err);
+
+ /// Populate m_in_cplusplus_method and m_in_objectivec_method based on the
+ /// environment.
+
+ void InstallContext(ExecutionContext &exe_ctx);
+
+ bool LockAndCheckContext(ExecutionContext &exe_ctx, lldb::TargetSP &target_sp,
+ lldb::ProcessSP &process_sp,
+ lldb::StackFrameSP &frame_sp);
+
+ Address m_address; ///< The address the process is stopped in.
+ std::string m_expr_text; ///< The text of the expression, as typed by the user
+ std::string m_expr_prefix; ///< The text of the translation-level definitions,
+ ///as provided by the user
+ std::string m_fixed_text; ///< The text of the expression with fix-its applied
+ ///- this won't be set if the fixed text doesn't
+ ///parse.
+ lldb::LanguageType m_language; ///< The language to use when parsing
+ ///(eLanguageTypeUnknown means use defaults)
+ ResultType m_desired_type; ///< The type to coerce the expression's result to.
+ ///If eResultTypeAny, inferred from the expression.
+ EvaluateExpressionOptions
+ m_options; ///< Additional options provided by the user.
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_UserExpression_h_
diff --git a/linux-x64/clang/include/lldb/Expression/UtilityFunction.h b/linux-x64/clang/include/lldb/Expression/UtilityFunction.h
new file mode 100644
index 0000000..26da081
--- /dev/null
+++ b/linux-x64/clang/include/lldb/Expression/UtilityFunction.h
@@ -0,0 +1,120 @@
+//===-- UtilityFunction.h ----------------------------------------*- C++
+//-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_UtilityFunction_h_
+#define liblldb_UtilityFunction_h_
+
+#include <memory>
+#include <string>
+
+#include "lldb/Expression/Expression.h"
+#include "lldb/lldb-forward.h"
+#include "lldb/lldb-private.h"
+
+namespace lldb_private {
+
+/// \class UtilityFunction UtilityFunction.h
+/// "lldb/Expression/UtilityFunction.h" Encapsulates a bit of source code that
+/// provides a function that is callable
+///
+/// LLDB uses expressions for various purposes, notably to call functions
+/// and as a backend for the expr command. UtilityFunction encapsulates a
+/// self-contained function meant to be used from other code. Utility
+/// functions can perform error-checking for ClangUserExpressions,
+class UtilityFunction : public Expression {
+public:
+ /// LLVM-style RTTI support.
+ static bool classof(const Expression *E) {
+ return E->getKind() == eKindUtilityFunction;
+ }
+
+ /// Constructor
+ ///
+ /// \param[in] text
+ /// The text of the function. Must be a full translation unit.
+ ///
+ /// \param[in] name
+ /// The name of the function, as used in the text.
+ UtilityFunction(ExecutionContextScope &exe_scope, const char *text,
+ const char *name, ExpressionKind kind);
+
+ ~UtilityFunction() override;
+
+ /// Install the utility function into a process
+ ///
+ /// \param[in] diagnostic_manager
+ /// A diagnostic manager to print parse errors and warnings to.
+ ///
+ /// \param[in] exe_ctx
+ /// The execution context to install the utility function to.
+ ///
+ /// \return
+ /// True on success (no errors); false otherwise.
+ virtual bool Install(DiagnosticManager &diagnostic_manager,
+ ExecutionContext &exe_ctx) = 0;
+
+ /// Check whether the given PC is inside the function
+ ///
+ /// Especially useful if the function dereferences nullptr to indicate a
+ /// failed assert.
+ ///
+ /// \param[in] pc
+ /// The program counter to check.
+ ///
+ /// \return
+ /// True if the program counter falls within the function's bounds;
+ /// false if not (or the function is not JIT compiled)
+ bool ContainsAddress(lldb::addr_t address) {
+ // nothing is both >= LLDB_INVALID_ADDRESS and < LLDB_INVALID_ADDRESS, so
+ // this always returns false if the function is not JIT compiled yet
+ return (address >= m_jit_start_addr && address < m_jit_end_addr);
+ }
+
+ /// Return the string that the parser should parse. Must be a full
+ /// translation unit.
+ const char *Text() override { return m_function_text.c_str(); }
+
+ /// Return the function name that should be used for executing the
+ /// expression. Text() should contain the definition of this function.
+ const char *FunctionName() override { return m_function_name.c_str(); }
+
+ /// Return the object that the parser should use when registering local
+ /// variables. May be nullptr if the Expression doesn't care.
+ ExpressionVariableList *LocalVariables() { return nullptr; }
+
+ /// Return true if validation code should be inserted into the expression.
+ bool NeedsValidation() override { return false; }
+
+ /// Return true if external variables in the expression should be resolved.
+ bool NeedsVariableResolution() override { return false; }
+
+ // This makes the function caller function. Pass in the ThreadSP if you have
+ // one available, compilation can end up calling code (e.g. to look up
+ // indirect functions) and we don't want this to wander onto another thread.
+ FunctionCaller *MakeFunctionCaller(const CompilerType &return_type,
+ const ValueList &arg_value_list,
+ lldb::ThreadSP compilation_thread,
+ Status &error);
+
+ // This one retrieves the function caller that is already made. If you
+ // haven't made it yet, this returns nullptr
+ FunctionCaller *GetFunctionCaller() { return m_caller_up.get(); }
+
+protected:
+ std::shared_ptr<IRExecutionUnit> m_execution_unit_sp;
+ lldb::ModuleWP m_jit_module_wp;
+ std::string m_function_text; ///< The text of the function. Must be a
+ ///well-formed translation unit.
+ std::string m_function_name; ///< The name of the function.
+ std::unique_ptr<FunctionCaller> m_caller_up;
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_UtilityFunction_h_