[Lldb-commits] [lldb] r251820 - Create an expression parser for Go.

Ryan Brown via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 2 12:55:26 PST 2015


Oops, thanks.

-- Ryan Brown

On Mon, Nov 2, 2015 at 12:53 PM, Zachary Turner <zturner at google.com> wrote:

> Hi Ryan, my change to the test system seems to have crossed paths with
> this CL.  tests don't go in lldb/test anymore, they go in
> lldb/packages/Python/lldbsuite/test.  Right now these are the only tests
> still in the wrong location, so they aren't getting run.  You will need to
> move them over to the new location.
>
> On Mon, Nov 2, 2015 at 11:33 AM Ryan Brown via lldb-commits <
> lldb-commits at lists.llvm.org> wrote:
>
>> Author: ribrdb
>> Date: Mon Nov  2 13:30:40 2015
>> New Revision: 251820
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=251820&view=rev
>> Log:
>> Create an expression parser for Go.
>>
>> The Go interpreter doesn't JIT or use LLVM, so this also
>> moves all the JIT related code from UserExpression to a new class
>> LLVMUserExpression.
>>
>> Differential Revision: http://reviews.llvm.org/D13073
>>
>> Fix merge
>>
>> Added:
>>     lldb/trunk/include/lldb/Expression/LLVMUserExpression.h
>>     lldb/trunk/source/Expression/LLVMUserExpression.cpp
>>     lldb/trunk/source/Plugins/ExpressionParser/Go/
>>     lldb/trunk/source/Plugins/ExpressionParser/Go/CMakeLists.txt
>>     lldb/trunk/source/Plugins/ExpressionParser/Go/GoAST.h
>>     lldb/trunk/source/Plugins/ExpressionParser/Go/GoLexer.cpp
>>     lldb/trunk/source/Plugins/ExpressionParser/Go/GoLexer.h
>>     lldb/trunk/source/Plugins/ExpressionParser/Go/GoParser.cpp
>>     lldb/trunk/source/Plugins/ExpressionParser/Go/GoParser.h
>>     lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
>>     lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.h
>>     lldb/trunk/source/Plugins/ExpressionParser/Go/Makefile
>>     lldb/trunk/source/Plugins/ExpressionParser/Go/gen_go_ast.py
>>     lldb/trunk/test/lang/go/expressions/
>>     lldb/trunk/test/lang/go/expressions/TestExpressions.py
>>     lldb/trunk/test/lang/go/expressions/main.go
>>     lldb/trunk/unittests/Expression/
>>     lldb/trunk/unittests/Expression/CMakeLists.txt
>>     lldb/trunk/unittests/Expression/GoParserTest.cpp
>> Modified:
>>     lldb/trunk/.clang-format
>>     lldb/trunk/cmake/LLDBDependencies.cmake
>>     lldb/trunk/include/lldb/Expression/UserExpression.h
>>     lldb/trunk/include/lldb/Symbol/GoASTContext.h
>>     lldb/trunk/lldb.xcodeproj/project.pbxproj
>>     lldb/trunk/source/API/SBFrame.cpp
>>     lldb/trunk/source/Expression/CMakeLists.txt
>>     lldb/trunk/source/Expression/UserExpression.cpp
>>     lldb/trunk/source/Plugins/ExpressionParser/CMakeLists.txt
>>
>> lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
>>     lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
>>     lldb/trunk/source/Symbol/GoASTContext.cpp
>>     lldb/trunk/unittests/CMakeLists.txt
>>
>> Modified: lldb/trunk/.clang-format
>> URL:
>> http://llvm.org/viewvc/llvm-project/lldb/trunk/.clang-format?rev=251820&r1=251819&r2=251820&view=diff
>>
>> ==============================================================================
>> --- lldb/trunk/.clang-format (original)
>> +++ lldb/trunk/.clang-format Mon Nov  2 13:30:40 2015
>> @@ -4,5 +4,5 @@ ColumnLimit:     120
>>  BreakBeforeBraces: Allman
>>  AlwaysBreakAfterDefinitionReturnType: true
>>  AllowShortFunctionsOnASingleLine: Inline
>> -BreakConstructorInitializersBeforeComma: true
>> +ConstructorInitializerAllOnOneLineOrOnePerLine: true
>>  IndentCaseLabels: true
>>
>> Modified: lldb/trunk/cmake/LLDBDependencies.cmake
>> URL:
>> http://llvm.org/viewvc/llvm-project/lldb/trunk/cmake/LLDBDependencies.cmake?rev=251820&r1=251819&r2=251820&view=diff
>>
>> ==============================================================================
>> --- lldb/trunk/cmake/LLDBDependencies.cmake (original)
>> +++ lldb/trunk/cmake/LLDBDependencies.cmake Mon Nov  2 13:30:40 2015
>> @@ -74,6 +74,7 @@ set( LLDB_USED_LIBS
>>    lldbPluginProcessElfCore
>>    lldbPluginJITLoaderGDB
>>    lldbPluginExpressionParserClang
>> +  lldbPluginExpressionParserGo
>>    )
>>
>>  # Windows-only libraries
>>
>> Added: lldb/trunk/include/lldb/Expression/LLVMUserExpression.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/LLVMUserExpression.h?rev=251820&view=auto
>>
>> ==============================================================================
>> --- lldb/trunk/include/lldb/Expression/LLVMUserExpression.h (added)
>> +++ lldb/trunk/include/lldb/Expression/LLVMUserExpression.h Mon Nov  2
>> 13:30:40 2015
>> @@ -0,0 +1,108 @@
>> +//===-- LLVMUserExpression.h ------------------------------------*- C++
>> -*-===//
>> +//
>> +//                     The LLVM Compiler Infrastructure
>> +//
>> +// This file is distributed under the University of Illinois Open Source
>> +// License. See LICENSE.TXT for details.
>> +//
>>
>> +//===----------------------------------------------------------------------===//
>> +
>> +#ifndef liblldb_LLVMUserExpression_h
>> +#define liblldb_LLVMUserExpression_h
>> +
>> +// C Includes
>> +// C++ Includes
>> +#include <string>
>> +#include <map>
>> +#include <vector>
>> +
>> +// Project includes
>> +#include "lldb/Expression/UserExpression.h"
>> +
>> +namespace lldb_private
>> +{
>> +
>> +//----------------------------------------------------------------------
>> +/// @class LLVMUserExpression LLVMUserExpression.h
>> "lldb/Expression/LLVMUserExpression.h"
>> +/// @brief 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:
>> +    LLVMUserExpression(ExecutionContextScope &exe_scope, const char
>> *expr, const char *expr_prefix,
>> +                       lldb::LanguageType language, ResultType
>> desired_type);
>> +    ~LLVMUserExpression() override;
>> +
>> +    lldb::ExpressionResults Execute(Stream &error_stream,
>> ExecutionContext &exe_ctx,
>> +                                    const EvaluateExpressionOptions
>> &options, lldb::UserExpressionSP &shared_ptr_to_me,
>> +                                    lldb::ExpressionVariableSP &result)
>> override;
>> +
>> +    bool FinalizeJITExecution(Stream &error_stream, 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:
>> +    virtual void ScanContext(ExecutionContext &exe_ctx,
>> lldb_private::Error &err) = 0;
>> +
>> +    bool PrepareToExecuteJITExpression(Stream &error_stream,
>> ExecutionContext &exe_ctx, lldb::addr_t &struct_address);
>> +    virtual bool
>> +    AddInitialArguments(ExecutionContext &exe_ctx,
>> std::vector<lldb::addr_t> &args, Stream &error_stream)
>> +    {
>> +        return true;
>> +    }
>> +
>> +    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_ap;      ///< 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
>>
>> Modified: lldb/trunk/include/lldb/Expression/UserExpression.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/UserExpression.h?rev=251820&r1=251819&r2=251820&view=diff
>>
>> ==============================================================================
>> --- lldb/trunk/include/lldb/Expression/UserExpression.h (original)
>> +++ lldb/trunk/include/lldb/Expression/UserExpression.h Mon Nov  2
>> 13:30:40 2015
>> @@ -102,11 +102,7 @@ public:
>>             bool keep_result_in_memory,
>>             bool generate_debug_info) = 0;
>>
>> -    bool
>> -    CanInterpret ()
>> -    {
>> -        return m_can_interpret;
>> -    }
>> +    virtual bool CanInterpret() = 0;
>>
>>      bool
>>      MatchesContext (ExecutionContext &exe_ctx);
>> @@ -138,12 +134,10 @@ public:
>>      /// @return
>>      ///     A Process::Execution results value.
>>      //------------------------------------------------------------------
>> -    lldb::ExpressionResults
>> -    Execute (Stream &error_stream,
>> -             ExecutionContext &exe_ctx,
>> -             const EvaluateExpressionOptions& options,
>> -             lldb::UserExpressionSP &shared_ptr_to_me,
>> -             lldb::ExpressionVariableSP &result);
>> +    virtual lldb::ExpressionResults Execute(Stream &error_stream,
>> ExecutionContext &exe_ctx,
>> +                                            const
>> EvaluateExpressionOptions &options,
>> +                                            lldb::UserExpressionSP
>> &shared_ptr_to_me,
>> +                                            lldb::ExpressionVariableSP
>> &result) = 0;
>>
>>      //------------------------------------------------------------------
>>      /// Apply the side effects of the function to program state.
>> @@ -168,21 +162,18 @@ public:
>>      /// @return
>>      ///     A Process::Execution results value.
>>      //------------------------------------------------------------------
>> -    bool
>> -    FinalizeJITExecution (Stream &error_stream,
>> -                          ExecutionContext &exe_ctx,
>> -                          lldb::ExpressionVariableSP &result,
>> -                          lldb::addr_t function_stack_bottom =
>> LLDB_INVALID_ADDRESS,
>> -                          lldb::addr_t function_stack_top =
>> LLDB_INVALID_ADDRESS);
>> +    virtual bool FinalizeJITExecution(Stream &error_stream,
>> 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.  Must be a full
>> -    /// translation unit.
>> +    /// Return the string that the parser should parse.
>>      //------------------------------------------------------------------
>>      const char *
>>      Text() override
>>      {
>> -        return m_transformed_text.c_str();
>> +        return m_expr_text.c_str();
>>      }
>>
>>      //------------------------------------------------------------------
>> @@ -251,6 +242,12 @@ public:
>>          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.
>> @@ -308,23 +305,6 @@ protected:
>>      /// Populate m_in_cplusplus_method and m_in_objectivec_method based
>> on the environment.
>>      //------------------------------------------------------------------
>>
>> -    virtual void
>> -    ScanContext (ExecutionContext &exe_ctx,
>> -                 lldb_private::Error &err) = 0;
>> -
>> -    bool
>> -    PrepareToExecuteJITExpression (Stream &error_stream,
>> -                                   ExecutionContext &exe_ctx,
>> -                                   lldb::addr_t &struct_address);
>> -
>> -    virtual bool
>> -    AddInitialArguments (ExecutionContext &exe_ctx,
>> -                         std::vector<lldb::addr_t> &args,
>> -                         Stream &error_stream)
>> -    {
>> -        return true;
>> -    }
>> -
>>      void
>>      InstallContext (ExecutionContext &exe_ctx);
>>
>> @@ -335,31 +315,11 @@ protected:
>>                           lldb::StackFrameSP &frame_sp);
>>
>>      Address                                     m_address;
>> ///< The address the process is stopped in.
>> -    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.
>> -
>>      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
>>      lldb::LanguageType                          m_language;
>>  ///< The language to use when parsing (eLanguageTypeUnknown means use
>> defaults)
>> -    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
>>      ResultType                                  m_desired_type;
>>  ///< The type to coerce the expression's result to.  If eResultTypeAny,
>> inferred from the expression.
>>
>> -    std::shared_ptr<IRExecutionUnit>            m_execution_unit_sp;
>> ///< The execution unit the expression is stored in.
>> -    std::unique_ptr<Materializer>               m_materializer_ap;
>> ///< 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 nullptr.
>> -    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
>>
>> Modified: lldb/trunk/include/lldb/Symbol/GoASTContext.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/GoASTContext.h?rev=251820&r1=251819&r2=251820&view=diff
>>
>> ==============================================================================
>> --- lldb/trunk/include/lldb/Symbol/GoASTContext.h (original)
>> +++ lldb/trunk/include/lldb/Symbol/GoASTContext.h Mon Nov  2 13:30:40 2015
>> @@ -254,8 +254,7 @@ class GoASTContext : public TypeSystem
>>
>>      lldb::BasicType GetBasicTypeEnumeration(lldb::opaque_compiler_type_t
>> type) override;
>>
>> -    CompilerType GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding
>> encoding,
>> -                                                     size_t bit_size)
>> override;
>> +    CompilerType GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding
>> encoding, size_t bit_size) override;
>>
>>      uint32_t GetNumFields(lldb::opaque_compiler_type_t type) override;
>>
>> @@ -394,6 +393,15 @@ class GoASTContext : public TypeSystem
>>      const GoASTContext &operator=(const GoASTContext &) = delete;
>>  };
>>
>> -} // namespace lldb_private
>> +class GoASTContextForExpr : public GoASTContext
>> +{
>> +  public:
>> +    GoASTContextForExpr(lldb::TargetSP target) : m_target_wp(target) {}
>> +    UserExpression *GetUserExpression(const char *expr, const char
>> *expr_prefix, lldb::LanguageType language,
>> +                                      Expression::ResultType
>> desired_type) override;
>>
>> +  private:
>> +    lldb::TargetWP m_target_wp;
>> +};
>> +}
>>  #endif // liblldb_GoASTContext_h_
>>
>> Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
>> URL:
>> http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=251820&r1=251819&r2=251820&view=diff
>>
>> ==============================================================================
>> --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
>> +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Mon Nov  2 13:30:40 2015
>> @@ -839,10 +839,14 @@
>>                 9AC703AF117675410086C050 /* SBInstruction.cpp in Sources
>> */ = {isa = PBXBuildFile; fileRef = 9AC703AE117675410086C050 /*
>> SBInstruction.cpp */; };
>>                 9AC703B1117675490086C050 /* SBInstructionList.cpp in
>> Sources */ = {isa = PBXBuildFile; fileRef = 9AC703B0117675490086C050 /*
>> SBInstructionList.cpp */; };
>>                 A36FF33C17D8E94600244D40 /* OptionParser.cpp in Sources
>> */ = {isa = PBXBuildFile; fileRef = A36FF33B17D8E94600244D40 /*
>> OptionParser.cpp */; };
>> +               AE44FB301BB07EB20033EB62 /* GoUserExpression.cpp in
>> Sources */ = {isa = PBXBuildFile; fileRef = AE44FB2C1BB07DD80033EB62 /*
>> GoUserExpression.cpp */; };
>> +               AE44FB311BB07EB80033EB62 /* GoLexer.cpp in Sources */ =
>> {isa = PBXBuildFile; fileRef = AE44FB2A1BB07DD80033EB62 /* GoLexer.cpp */;
>> };
>> +               AE44FB321BB07EBC0033EB62 /* GoParser.cpp in Sources */ =
>> {isa = PBXBuildFile; fileRef = AE44FB2B1BB07DD80033EB62 /* GoParser.cpp */;
>> };
>>                 AE44FB3E1BB485960033EB62 /* GoLanguageRuntime.cpp in
>> Sources */ = {isa = PBXBuildFile; fileRef = AE44FB3D1BB485960033EB62 /*
>> GoLanguageRuntime.cpp */; };
>>                 AE6897281B94F6DE0018845D /* DWARFASTParserGo.cpp in
>> Sources */ = {isa = PBXBuildFile; fileRef = AE6897261B94F6DE0018845D /*
>> DWARFASTParserGo.cpp */; };
>>                 AE7F56291B8FE418001377A8 /* GoASTContext.cpp in Sources
>> */ = {isa = PBXBuildFile; fileRef = AEFFBA7C1AC4835D0087B932 /*
>> GoASTContext.cpp */; };
>>                 AE8F624919EF3E1E00326B21 /* OperatingSystemGo.cpp in
>> Sources */ = {isa = PBXBuildFile; fileRef = AE8F624719EF3E1E00326B21 /*
>> OperatingSystemGo.cpp */; };
>> +               AEB0E4591BD6E9F800B24093 /* LLVMUserExpression.cpp in
>> Sources */ = {isa = PBXBuildFile; fileRef = AEB0E4581BD6E9F800B24093 /*
>> LLVMUserExpression.cpp */; };
>>                 AEEA34051AC88A7400AB639D /* TypeSystem.cpp in Sources */
>> = {isa = PBXBuildFile; fileRef = AEEA34041AC88A7400AB639D /* TypeSystem.cpp
>> */; };
>>                 AF061F87182C97ED00B6A19C /* RegisterContextHistory.cpp in
>> Sources */ = {isa = PBXBuildFile; fileRef = AF061F85182C97ED00B6A19C /*
>> RegisterContextHistory.cpp */; };
>>                 AF0C112818580CD800C4C45B /* QueueItem.cpp in Sources */ =
>> {isa = PBXBuildFile; fileRef = AF0C112718580CD800C4C45B /* QueueItem.cpp
>> */; };
>> @@ -2683,12 +2687,21 @@
>>                 9AF16CC7114086A1007A7B3F /* SBBreakpointLocation.cpp */ =
>> {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType =
>> sourcecode.cpp.cpp; name = SBBreakpointLocation.cpp; path =
>> source/API/SBBreakpointLocation.cpp; sourceTree = "<group>"; };
>>                 A36FF33B17D8E94600244D40 /* OptionParser.cpp */ = {isa =
>> PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp;
>> path = OptionParser.cpp; sourceTree = "<group>"; };
>>                 A36FF33D17D8E98800244D40 /* OptionParser.h */ = {isa =
>> PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h;
>> name = OptionParser.h; path = include/lldb/Host/OptionParser.h; sourceTree
>> = "<group>"; };
>> +               AE44FB261BB07DC60033EB62 /* GoAST.h */ = {isa =
>> PBXFileReference; lastKnownFileType = sourcecode.c.h; name = GoAST.h; path
>> = ExpressionParser/Go/GoAST.h; sourceTree = "<group>"; };
>> +               AE44FB271BB07DC60033EB62 /* GoLexer.h */ = {isa =
>> PBXFileReference; lastKnownFileType = sourcecode.c.h; name = GoLexer.h;
>> path = ExpressionParser/Go/GoLexer.h; sourceTree = "<group>"; };
>> +               AE44FB281BB07DC60033EB62 /* GoParser.h */ = {isa =
>> PBXFileReference; lastKnownFileType = sourcecode.c.h; name = GoParser.h;
>> path = ExpressionParser/Go/GoParser.h; sourceTree = "<group>"; };
>> +               AE44FB291BB07DC60033EB62 /* GoUserExpression.h */ = {isa
>> = PBXFileReference; lastKnownFileType = sourcecode.c.h; name =
>> GoUserExpression.h; path = ExpressionParser/Go/GoUserExpression.h;
>> sourceTree = "<group>"; };
>> +               AE44FB2A1BB07DD80033EB62 /* GoLexer.cpp */ = {isa =
>> PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp;
>> name = GoLexer.cpp; path = ExpressionParser/Go/GoLexer.cpp; sourceTree =
>> "<group>"; };
>> +               AE44FB2B1BB07DD80033EB62 /* GoParser.cpp */ = {isa =
>> PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp;
>> name = GoParser.cpp; path = ExpressionParser/Go/GoParser.cpp; sourceTree =
>> "<group>"; };
>> +               AE44FB2C1BB07DD80033EB62 /* GoUserExpression.cpp */ =
>> {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType =
>> sourcecode.cpp.cpp; name = GoUserExpression.cpp; path =
>> ExpressionParser/Go/GoUserExpression.cpp; sourceTree = "<group>"; };
>>                 AE44FB3C1BB4858A0033EB62 /* GoLanguageRuntime.h */ = {isa
>> = PBXFileReference; lastKnownFileType = sourcecode.c.h; name =
>> GoLanguageRuntime.h; path = Go/GoLanguageRuntime
>> <https://goto.google.com/GoLanguageRuntime>.h; sourceTree = "<group>"; };
>>                 AE44FB3D1BB485960033EB62 /* GoLanguageRuntime.cpp */ =
>> {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType =
>> sourcecode.cpp.cpp; name = GoLanguageRuntime.cpp; path =
>> Go/GoLanguageRuntime <https://goto.google.com/GoLanguageRuntime>.cpp;
>> sourceTree = "<group>"; };
>>                 AE6897261B94F6DE0018845D /* DWARFASTParserGo.cpp */ =
>> {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType =
>> sourcecode.cpp.cpp; path = DWARFASTParserGo.cpp; sourceTree = "<group>"; };
>>                 AE6897271B94F6DE0018845D /* DWARFASTParserGo.h */ = {isa
>> = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h;
>> path = DWARFASTParserGo.h; sourceTree = "<group>"; };
>>                 AE8F624719EF3E1E00326B21 /* OperatingSystemGo.cpp */ =
>> {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType =
>> sourcecode.cpp.cpp; name = OperatingSystemGo.cpp; path =
>> Go/OperatingSystemGo <https://goto.google.com/OperatingSystemGo>.cpp;
>> sourceTree = "<group>"; };
>>                 AE8F624819EF3E1E00326B21 /* OperatingSystemGo.h */ = {isa
>> = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h;
>> name = OperatingSystemGo.h; path = Go/OperatingSystemGo
>> <https://goto.google.com/OperatingSystemGo>.h; sourceTree = "<group>"; };
>> +               AEB0E4581BD6E9F800B24093 /* LLVMUserExpression.cpp */ =
>> {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType =
>> sourcecode.cpp.cpp; name = LLVMUserExpression.cpp; path =
>> source/Expression/LLVMUserExpression.cpp; sourceTree = "<group>"; };
>> +               AEB0E45A1BD6EA1400B24093 /* LLVMUserExpression.h */ =
>> {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name =
>> LLVMUserExpression.h; path = include/lldb/Expression/LLVMUserExpression.h;
>> sourceTree = "<group>"; };
>>                 AEEA33F61AC74FE700AB639D /* TypeSystem.h */ = {isa =
>> PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h;
>> name = TypeSystem.h; path = include/lldb/Symbol/TypeSystem.h; sourceTree =
>> "<group>"; };
>>                 AEEA34041AC88A7400AB639D /* TypeSystem.cpp */ = {isa =
>> PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp;
>> name = TypeSystem.cpp; path = source/Symbol/TypeSystem.cpp; sourceTree =
>> "<group>"; };
>>                 AEEA340F1ACA08A000AB639D /* GoASTContext.h */ = {isa =
>> PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h;
>> name = GoASTContext.h; path = include/lldb/Symbol/GoASTContext.h;
>> sourceTree = "<group>"; };
>> @@ -4528,6 +4541,8 @@
>>                                 4C0083321B9A5DE200D5CF24 /*
>> FunctionCaller.cpp */,
>>                                 4C00832E1B9A58A700D5CF24 /*
>> UserExpression.h */,
>>                                 4C0083331B9A5DE200D5CF24 /*
>> UserExpression.cpp */,
>> +                               AEB0E45A1BD6EA1400B24093 /*
>> LLVMUserExpression.h */,
>> +                               AEB0E4581BD6E9F800B24093 /*
>> LLVMUserExpression.cpp */,
>>                                 4C00833D1B9F9B8400D5CF24 /*
>> UtilityFunction.h */,
>>                                 4C00833F1B9F9BA900D5CF24 /*
>> UtilityFunction.cpp */,
>>                                 49A1CAC11430E21D00306AC9 /*
>> ExpressionSourceCode.h */,
>> @@ -5207,6 +5222,7 @@
>>                         isa = PBXGroup;
>>                         children = (
>>                                 4984BA0C1B97620B008658D4 /* Clang */,
>> +                               AE44FB371BB35A2E0033EB62 /* Go */,
>>                         );
>>                         name = ExpressionParser;
>>                         sourceTree = "<group>";
>> @@ -5580,6 +5596,20 @@
>>                         name = "SysV-mips";
>>                         sourceTree = "<group>";
>>                 };
>> +               AE44FB371BB35A2E0033EB62 /* Go */ = {
>> +                       isa = PBXGroup;
>> +                       children = (
>> +                               AE44FB261BB07DC60033EB62 /* GoAST.h */,
>> +                               AE44FB271BB07DC60033EB62 /* GoLexer.h */,
>> +                               AE44FB2A1BB07DD80033EB62 /* GoLexer.cpp
>> */,
>> +                               AE44FB281BB07DC60033EB62 /* GoParser.h */,
>> +                               AE44FB2B1BB07DD80033EB62 /* GoParser.cpp
>> */,
>> +                               AE44FB291BB07DC60033EB62 /*
>> GoUserExpression.h */,
>> +                               AE44FB2C1BB07DD80033EB62 /*
>> GoUserExpression.cpp */,
>> +                       );
>> +                       name = Go;
>> +                       sourceTree = "<group>";
>> +               };
>>                 AE44FB3B1BB485730033EB62 /* Go */ = {
>>                         isa = PBXGroup;
>>                         children = (
>> @@ -6281,6 +6311,7 @@
>>                                 2689FFDA13353D9D00698AC0 /* lldb.cpp in
>> Sources */,
>>                                 4C0083401B9F9BA900D5CF24 /*
>> UtilityFunction.cpp in Sources */,
>>                                 26474CCD18D0CB5B0073DEBA /*
>> RegisterContextPOSIX_x86.cpp in Sources */,
>> +                               AEB0E4591BD6E9F800B24093 /*
>> LLVMUserExpression.cpp in Sources */,
>>                                 2689FFEF13353DB600698AC0 /*
>> Breakpoint.cpp in Sources */,
>>                                 267A47FB1B1411C40021A5BC /*
>> NativeRegisterContext.cpp in Sources */,
>>                                 2689FFF113353DB600698AC0 /*
>> BreakpointID.cpp in Sources */,
>> @@ -6410,6 +6441,7 @@
>>                                 3F81691A1ABA2419001DA9DF /*
>> NameMatches.cpp in Sources */,
>>                                 94B9E5121BBF20F4000A48DC /* NSString.cpp
>> in Sources */,
>>                                 AF0E22F018A09FB20009B7D1 /*
>> AppleGetItemInfoHandler.cpp in Sources */,
>> +                               AE44FB301BB07EB20033EB62 /*
>> GoUserExpression.cpp in Sources */,
>>                                 2689004E13353E0400698AC0 /* Stream.cpp in
>> Sources */,
>>                                 2689004F13353E0400698AC0 /*
>> StreamFile.cpp in Sources */,
>>                                 2689005013353E0400698AC0 /*
>> StreamString.cpp in Sources */,
>> @@ -6528,6 +6560,7 @@
>>                                 949EEDA31BA76577008C63CF /* Cocoa.cpp in
>> Sources */,
>>                                 3FDFE56C19AF9C44009756A7 /*
>> HostProcessPosix.cpp in Sources */,
>>                                 268900B413353E5000698AC0 /*
>> RegisterContextMacOSXFrameBackchain.cpp in Sources */,
>> +                               AE44FB321BB07EBC0033EB62 /* GoParser.cpp
>> in Sources */,
>>                                 3F8169311ABB7A6D001DA9DF /*
>> SystemInitializer.cpp in Sources */,
>>                                 949EEDB21BA76731008C63CF /*
>> NSIndexPath.cpp in Sources */,
>>                                 3FDFED2D19C257A0009756A7 /*
>> HostProcess.cpp in Sources */,
>> @@ -6689,6 +6722,7 @@
>>                                 26D5E163135BB054006EA0A7 /*
>> OptionGroupPlatform.cpp in Sources */,
>>                                 94CD131A19BA33B400DB7BED /*
>> TypeValidator.cpp in Sources */,
>>                                 26BD407F135D2AE000237D80 /*
>> FileLineResolver.cpp in Sources */,
>> +                               AE44FB311BB07EB80033EB62 /* GoLexer.cpp
>> in Sources */,
>>                                 26A7A035135E6E4200FB369E /*
>> OptionValue.cpp in Sources */,
>>                                 9A22A161135E30370024DDC3 /*
>> EmulateInstructionARM.cpp in Sources */,
>>                                 AFDFDFD119E34D3400EAE509 /*
>> ConnectionFileDescriptorPosix.cpp in Sources */,
>>
>> Modified: lldb/trunk/source/API/SBFrame.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFrame.cpp?rev=251820&r1=251819&r2=251820&view=diff
>>
>> ==============================================================================
>> --- lldb/trunk/source/API/SBFrame.cpp (original)
>> +++ lldb/trunk/source/API/SBFrame.cpp Mon Nov  2 13:30:40 2015
>> @@ -1389,6 +1389,10 @@ SBFrame::EvaluateExpression (const char
>>          lldb::DynamicValueType fetch_dynamic_value =
>> frame->CalculateTarget()->GetPreferDynamicValue();
>>          options.SetFetchDynamicValue (fetch_dynamic_value);
>>          options.SetUnwindOnError (true);
>> +        if (target->GetLanguage() != eLanguageTypeUnknown)
>> +            options.SetLanguage(target->GetLanguage());
>> +        else
>> +            options.SetLanguage(frame->GetLanguage());
>>          return EvaluateExpression (expr, options);
>>      }
>>      return result;
>> @@ -1400,6 +1404,13 @@ SBFrame::EvaluateExpression (const char
>>      SBExpressionOptions options;
>>      options.SetFetchDynamicValue (fetch_dynamic_value);
>>      options.SetUnwindOnError (true);
>> +    ExecutionContext exe_ctx(m_opaque_sp.get());
>> +    StackFrame *frame = exe_ctx.GetFramePtr();
>> +    Target *target = exe_ctx.GetTargetPtr();
>> +    if (target && target->GetLanguage() != eLanguageTypeUnknown)
>> +        options.SetLanguage(target->GetLanguage());
>> +    else if (frame)
>> +        options.SetLanguage(frame->GetLanguage());
>>      return EvaluateExpression (expr, options);
>>  }
>>
>> @@ -1407,8 +1418,15 @@ SBValue
>>  SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType
>> fetch_dynamic_value, bool unwind_on_error)
>>  {
>>      SBExpressionOptions options;
>> +    ExecutionContext exe_ctx(m_opaque_sp.get());
>>      options.SetFetchDynamicValue (fetch_dynamic_value);
>>      options.SetUnwindOnError (unwind_on_error);
>> +    StackFrame *frame = exe_ctx.GetFramePtr();
>> +    Target *target = exe_ctx.GetTargetPtr();
>> +    if (target && target->GetLanguage() != eLanguageTypeUnknown)
>> +        options.SetLanguage(target->GetLanguage());
>> +    else if (frame)
>> +        options.SetLanguage(frame->GetLanguage());
>>      return EvaluateExpression (expr, options);
>>  }
>>
>>
>> Modified: lldb/trunk/source/Expression/CMakeLists.txt
>> URL:
>> http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/CMakeLists.txt?rev=251820&r1=251819&r2=251820&view=diff
>>
>> ==============================================================================
>> --- lldb/trunk/source/Expression/CMakeLists.txt (original)
>> +++ lldb/trunk/source/Expression/CMakeLists.txt Mon Nov  2 13:30:40 2015
>> @@ -8,6 +8,7 @@ add_lldb_library(lldbExpression
>>    IRExecutionUnit.cpp
>>    IRInterpreter.cpp
>>    IRMemoryMap.cpp
>> +  LLVMUserExpression.cpp
>>    Materializer.cpp
>>    REPL.cpp
>>    UserExpression.cpp
>>
>> Added: lldb/trunk/source/Expression/LLVMUserExpression.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/LLVMUserExpression.cpp?rev=251820&view=auto
>>
>> ==============================================================================
>> --- lldb/trunk/source/Expression/LLVMUserExpression.cpp (added)
>> +++ lldb/trunk/source/Expression/LLVMUserExpression.cpp Mon Nov  2
>> 13:30:40 2015
>> @@ -0,0 +1,353 @@
>> +//===-- LLVMUserExpression.cpp ----------------------------------*- C++
>> -*-===//
>> +//
>> +//                     The LLVM Compiler Infrastructure
>> +//
>> +// This file is distributed under the University of Illinois Open Source
>> +// License. See LICENSE.TXT for details.
>> +//
>>
>> +//===----------------------------------------------------------------------===//
>> +
>> +// C Includes
>> +// C++ Includes
>> +
>> +// Project includes
>> +#include "lldb/Expression/LLVMUserExpression.h"
>> +#include "lldb/Core/ConstString.h"
>> +#include "lldb/Core/Log.h"
>> +#include "lldb/Core/Module.h"
>> +#include "lldb/Core/StreamFile.h"
>> +#include "lldb/Core/StreamString.h"
>> +#include "lldb/Core/ValueObjectConstResult.h"
>> +#include "lldb/Expression/ExpressionSourceCode.h"
>> +#include "lldb/Expression/IRExecutionUnit.h"
>> +#include "lldb/Expression/IRInterpreter.h"
>> +#include "lldb/Expression/Materializer.h"
>> +#include "lldb/Host/HostInfo.h"
>> +#include "lldb/Symbol/Block.h"
>> +#include "lldb/Symbol/ClangASTContext.h"
>> +#include "lldb/Symbol/Function.h"
>> +#include "lldb/Symbol/ObjectFile.h"
>> +#include "lldb/Symbol/SymbolVendor.h"
>> +#include "lldb/Symbol/Type.h"
>> +#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
>> +#include "lldb/Symbol/VariableList.h"
>> +#include "lldb/Target/ExecutionContext.h"
>> +#include "lldb/Target/Process.h"
>> +#include "lldb/Target/StackFrame.h"
>> +#include "lldb/Target/Target.h"
>> +#include "lldb/Target/ThreadPlan.h"
>> +#include "lldb/Target/ThreadPlanCallUserExpression.h"
>> +
>> +using namespace lldb_private;
>> +
>> +LLVMUserExpression::LLVMUserExpression(ExecutionContextScope &exe_scope,
>> const char *expr, const char *expr_prefix,
>> +                                       lldb::LanguageType language,
>> ResultType desired_type)
>> +    : UserExpression(exe_scope, expr, expr_prefix, language,
>> desired_type),
>> +      m_stack_frame_bottom(LLDB_INVALID_ADDRESS),
>> +      m_stack_frame_top(LLDB_INVALID_ADDRESS),
>> +      m_transformed_text(),
>> +      m_execution_unit_sp(),
>> +      m_materializer_ap(),
>> +      m_jit_module_wp(),
>> +      m_enforce_valid_object(true),
>> +      m_in_cplusplus_method(false),
>> +      m_in_objectivec_method(false),
>> +      m_in_static_method(false),
>> +      m_needs_object_ptr(false),
>> +      m_const_object(false),
>> +      m_target(NULL),
>> +      m_can_interpret(false),
>> +      m_materialized_address(LLDB_INVALID_ADDRESS)
>> +{
>> +}
>> +
>> +LLVMUserExpression::~LLVMUserExpression()
>> +{
>> +    if (m_target)
>> +    {
>> +        lldb::ModuleSP jit_module_sp(m_jit_module_wp.lock());
>> +        if (jit_module_sp)
>> +            m_target->GetImages().Remove(jit_module_sp);
>> +    }
>> +}
>> +
>> +lldb::ExpressionResults
>> +LLVMUserExpression::Execute(Stream &error_stream, ExecutionContext
>> &exe_ctx, const EvaluateExpressionOptions &options,
>> +                            lldb::UserExpressionSP &shared_ptr_to_me,
>> lldb::ExpressionVariableSP &result)
>> +{
>> +    // The expression log is quite verbose, and if you're just tracking
>> the execution of the
>> +    // expression, it's quite convenient to have these logs come out
>> with the STEP log as well.
>> +    Log
>> *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS |
>> LIBLLDB_LOG_STEP));
>> +
>> +    if (m_jit_start_addr != LLDB_INVALID_ADDRESS || m_can_interpret)
>> +    {
>> +        lldb::addr_t struct_address = LLDB_INVALID_ADDRESS;
>> +
>> +        if (!PrepareToExecuteJITExpression(error_stream, exe_ctx,
>> struct_address))
>> +        {
>> +            error_stream.Printf("Errored out in %s, couldn't
>> PrepareToExecuteJITExpression", __FUNCTION__);
>> +            return lldb::eExpressionSetupError;
>> +        }
>> +
>> +        lldb::addr_t function_stack_bottom = LLDB_INVALID_ADDRESS;
>> +        lldb::addr_t function_stack_top = LLDB_INVALID_ADDRESS;
>> +
>> +        if (m_can_interpret)
>> +        {
>> +            llvm::Module *module = m_execution_unit_sp->GetModule();
>> +            llvm::Function *function =
>> m_execution_unit_sp->GetFunction();
>> +
>> +            if (!module || !function)
>> +            {
>> +                error_stream.Printf("Supposed to interpret, but nothing
>> is there");
>> +                return lldb::eExpressionSetupError;
>> +            }
>> +
>> +            Error interpreter_error;
>> +
>> +            std::vector<lldb::addr_t> args;
>> +
>> +            if (!AddInitialArguments(exe_ctx, args, error_stream))
>> +            {
>> +                error_stream.Printf("Errored out in %s, couldn't
>> AddInitialArguments", __FUNCTION__);
>> +                return lldb::eExpressionSetupError;
>> +            }
>> +
>> +            args.push_back(struct_address);
>> +
>> +            function_stack_bottom = m_stack_frame_bottom;
>> +            function_stack_top = m_stack_frame_top;
>> +
>> +            IRInterpreter::Interpret(*module, *function, args,
>> *m_execution_unit_sp.get(), interpreter_error,
>> +                                     function_stack_bottom,
>> function_stack_top, exe_ctx);
>> +
>> +            if (!interpreter_error.Success())
>> +            {
>> +                error_stream.Printf("Supposed to interpret, but failed:
>> %s", interpreter_error.AsCString());
>> +                return lldb::eExpressionDiscarded;
>> +            }
>> +        }
>> +        else
>> +        {
>> +            if (!exe_ctx.HasThreadScope())
>> +            {
>> +                error_stream.Printf("UserExpression::Execute called with
>> no thread selected.");
>> +                return lldb::eExpressionSetupError;
>> +            }
>> +
>> +            Address wrapper_address(m_jit_start_addr);
>> +
>> +            std::vector<lldb::addr_t> args;
>> +
>> +            if (!AddInitialArguments(exe_ctx, args, error_stream))
>> +            {
>> +                error_stream.Printf("Errored out in %s, couldn't
>> AddInitialArguments", __FUNCTION__);
>> +                return lldb::eExpressionSetupError;
>> +            }
>> +
>> +            args.push_back(struct_address);
>> +
>> +            lldb::ThreadPlanSP call_plan_sp(new
>> ThreadPlanCallUserExpression(exe_ctx.GetThreadRef(), wrapper_address,
>> +
>>      args, options, shared_ptr_to_me));
>> +
>> +            if (!call_plan_sp ||
>> !call_plan_sp->ValidatePlan(&error_stream))
>> +                return lldb::eExpressionSetupError;
>> +
>> +            ThreadPlanCallUserExpression *user_expression_plan =
>> +                static_cast<ThreadPlanCallUserExpression
>> *>(call_plan_sp.get());
>> +
>> +            lldb::addr_t function_stack_pointer =
>> user_expression_plan->GetFunctionStackPointer();
>> +
>> +            function_stack_bottom = function_stack_pointer -
>> HostInfo::GetPageSize();
>> +            function_stack_top = function_stack_pointer;
>> +
>> +            if (log)
>> +                log->Printf("-- [UserExpression::Execute] Execution of
>> expression begins --");
>> +
>> +            if (exe_ctx.GetProcessPtr())
>> +                exe_ctx.GetProcessPtr()->SetRunningUserExpression(true);
>> +
>> +            lldb::ExpressionResults execution_result =
>> +                exe_ctx.GetProcessRef().RunThreadPlan(exe_ctx,
>> call_plan_sp, options, error_stream);
>> +
>> +            if (exe_ctx.GetProcessPtr())
>> +                exe_ctx.GetProcessPtr()->SetRunningUserExpression(false);
>> +
>> +            if (log)
>> +                log->Printf("-- [UserExpression::Execute] Execution of
>> expression completed --");
>> +
>> +            if (execution_result == lldb::eExpressionInterrupted ||
>> execution_result == lldb::eExpressionHitBreakpoint)
>> +            {
>> +                const char *error_desc = NULL;
>> +
>> +                if (call_plan_sp)
>> +                {
>> +                    lldb::StopInfoSP real_stop_info_sp =
>> call_plan_sp->GetRealStopInfo();
>> +                    if (real_stop_info_sp)
>> +                        error_desc = real_stop_info_sp->GetDescription();
>> +                }
>> +                if (error_desc)
>> +                    error_stream.Printf("Execution was interrupted,
>> reason: %s.", error_desc);
>> +                else
>> +                    error_stream.PutCString("Execution was
>> interrupted.");
>> +
>> +                if ((execution_result == lldb::eExpressionInterrupted &&
>> options.DoesUnwindOnError()) ||
>> +                    (execution_result == lldb::eExpressionHitBreakpoint
>> && options.DoesIgnoreBreakpoints()))
>> +                    error_stream.PutCString(
>> +                        "\nThe process has been returned to the state
>> before expression evaluation.");
>> +                else
>> +                {
>> +                    if (execution_result ==
>> lldb::eExpressionHitBreakpoint)
>> +
>> user_expression_plan->TransferExpressionOwnership();
>> +                    error_stream.PutCString(
>> +                        "\nThe process has been left at the point where
>> it was interrupted, "
>> +                        "use \"thread return -x\" to return to the state
>> before expression evaluation.");
>> +                }
>> +
>> +                return execution_result;
>> +            }
>> +            else if (execution_result ==
>> lldb::eExpressionStoppedForDebug)
>> +            {
>> +                error_stream.PutCString(
>> +                    "Execution was halted at the first instruction of
>> the expression "
>> +                    "function because \"debug\" was requested.\n"
>> +                    "Use \"thread return -x\" to return to the state
>> before expression evaluation.");
>> +                return execution_result;
>> +            }
>> +            else if (execution_result != lldb::eExpressionCompleted)
>> +            {
>> +                error_stream.Printf("Couldn't execute function; result
>> was %s\n",
>> +
>> Process::ExecutionResultAsCString(execution_result));
>> +                return execution_result;
>> +            }
>> +        }
>> +
>> +        if (FinalizeJITExecution(error_stream, exe_ctx, result,
>> function_stack_bottom, function_stack_top))
>> +        {
>> +            return lldb::eExpressionCompleted;
>> +        }
>> +        else
>> +        {
>> +            return lldb::eExpressionResultUnavailable;
>> +        }
>> +    }
>> +    else
>> +    {
>> +        error_stream.Printf("Expression can't be run, because there is
>> no JIT compiled function");
>> +        return lldb::eExpressionSetupError;
>> +    }
>> +}
>> +
>> +bool
>> +LLVMUserExpression::FinalizeJITExecution(Stream &error_stream,
>> ExecutionContext &exe_ctx,
>> +                                         lldb::ExpressionVariableSP
>> &result, lldb::addr_t function_stack_bottom,
>> +                                         lldb::addr_t function_stack_top)
>> +{
>> +    Log
>> *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
>> +
>> +    if (log)
>> +        log->Printf("-- [UserExpression::FinalizeJITExecution]
>> Dematerializing after execution --");
>> +
>> +    if (!m_dematerializer_sp)
>> +    {
>> +        error_stream.Printf("Couldn't apply expression side effects : no
>> dematerializer is present");
>> +        return false;
>> +    }
>> +
>> +    Error dematerialize_error;
>> +
>> +    m_dematerializer_sp->Dematerialize(dematerialize_error,
>> function_stack_bottom, function_stack_top);
>> +
>> +    if (!dematerialize_error.Success())
>> +    {
>> +        error_stream.Printf("Couldn't apply expression side effects :
>> %s\n",
>> +                            dematerialize_error.AsCString("unknown
>> error"));
>> +        return false;
>> +    }
>> +
>> +    result =
>> GetResultAfterDematerialization(exe_ctx.GetBestExecutionContextScope());
>> +
>> +    if (result)
>> +        result->TransferAddress();
>> +
>> +    m_dematerializer_sp.reset();
>> +
>> +    return true;
>> +}
>> +
>> +bool
>> +LLVMUserExpression::PrepareToExecuteJITExpression(Stream &error_stream,
>> ExecutionContext &exe_ctx,
>> +                                                  lldb::addr_t
>> &struct_address)
>> +{
>> +    lldb::TargetSP target;
>> +    lldb::ProcessSP process;
>> +    lldb::StackFrameSP frame;
>> +
>> +    if (!LockAndCheckContext(exe_ctx, target, process, frame))
>> +    {
>> +        error_stream.Printf("The context has changed before we could JIT
>> the expression!\n");
>> +        return false;
>> +    }
>> +
>> +    if (m_jit_start_addr != LLDB_INVALID_ADDRESS || m_can_interpret)
>> +    {
>> +        if (m_materialized_address == LLDB_INVALID_ADDRESS)
>> +        {
>> +            Error alloc_error;
>> +
>> +            IRMemoryMap::AllocationPolicy policy =
>> +                m_can_interpret ? IRMemoryMap::eAllocationPolicyHostOnly
>> : IRMemoryMap::eAllocationPolicyMirror;
>> +
>> +            m_materialized_address = m_execution_unit_sp->Malloc(
>> +                m_materializer_ap->GetStructByteSize(),
>> m_materializer_ap->GetStructAlignment(),
>> +                lldb::ePermissionsReadable | lldb::ePermissionsWritable,
>> policy, alloc_error);
>> +
>> +            if (!alloc_error.Success())
>> +            {
>> +                error_stream.Printf("Couldn't allocate space for
>> materialized struct: %s\n", alloc_error.AsCString());
>> +                return false;
>> +            }
>> +        }
>> +
>> +        struct_address = m_materialized_address;
>> +
>> +        if (m_can_interpret && m_stack_frame_bottom ==
>> LLDB_INVALID_ADDRESS)
>> +        {
>> +            Error alloc_error;
>> +
>> +            const size_t stack_frame_size = 512 * 1024;
>> +
>> +            m_stack_frame_bottom =
>> m_execution_unit_sp->Malloc(stack_frame_size, 8,
>> +
>>  lldb::ePermissionsReadable | lldb::ePermissionsWritable,
>> +
>>  IRMemoryMap::eAllocationPolicyHostOnly, alloc_error);
>> +
>> +            m_stack_frame_top = m_stack_frame_bottom + stack_frame_size;
>> +
>> +            if (!alloc_error.Success())
>> +            {
>> +                error_stream.Printf("Couldn't allocate space for the
>> stack frame: %s\n", alloc_error.AsCString());
>> +                return false;
>> +            }
>> +        }
>> +
>> +        Error materialize_error;
>> +
>> +        m_dematerializer_sp =
>> +            m_materializer_ap->Materialize(frame, *m_execution_unit_sp,
>> struct_address, materialize_error);
>> +
>> +        if (!materialize_error.Success())
>> +        {
>> +            error_stream.Printf("Couldn't materialize: %s\n",
>> materialize_error.AsCString());
>> +            return false;
>> +        }
>> +    }
>> +    return true;
>> +}
>> +
>> +lldb::ModuleSP
>> +LLVMUserExpression::GetJITModule()
>> +{
>> +    if (m_execution_unit_sp)
>> +        return m_execution_unit_sp->GetJITModule();
>> +    return lldb::ModuleSP();
>> +}
>>
>> Modified: lldb/trunk/source/Expression/UserExpression.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/UserExpression.cpp?rev=251820&r1=251819&r2=251820&view=diff
>>
>> ==============================================================================
>> --- lldb/trunk/source/Expression/UserExpression.cpp (original)
>> +++ lldb/trunk/source/Expression/UserExpression.cpp Mon Nov  2 13:30:40
>> 2015
>> @@ -45,42 +45,18 @@
>>
>>  using namespace lldb_private;
>>
>> -UserExpression::UserExpression (ExecutionContextScope &exe_scope,
>> -                                const char *expr,
>> -                                const char *expr_prefix,
>> -                                lldb::LanguageType language,
>> -                                ResultType desired_type) :
>> -    Expression (exe_scope),
>> -    m_stack_frame_bottom (LLDB_INVALID_ADDRESS),
>> -    m_stack_frame_top (LLDB_INVALID_ADDRESS),
>> -    m_expr_text (expr),
>> -    m_expr_prefix (expr_prefix ? expr_prefix : ""),
>> -    m_language (language),
>> -    m_transformed_text (),
>> -    m_desired_type (desired_type),
>> -    m_execution_unit_sp(),
>> -    m_materializer_ap(),
>> -    m_jit_module_wp(),
>> -    m_enforce_valid_object (true),
>> -    m_in_cplusplus_method (false),
>> -    m_in_objectivec_method (false),
>> -    m_in_static_method(false),
>> -    m_needs_object_ptr (false),
>> -    m_const_object (false),
>> -    m_target (NULL),
>> -    m_can_interpret (false),
>> -    m_materialized_address (LLDB_INVALID_ADDRESS)
>> +UserExpression::UserExpression(ExecutionContextScope &exe_scope, const
>> char *expr, const char *expr_prefix,
>> +                               lldb::LanguageType language, ResultType
>> desired_type)
>> +    : Expression(exe_scope),
>> +      m_expr_text(expr),
>> +      m_expr_prefix(expr_prefix ? expr_prefix : ""),
>> +      m_language(language),
>> +      m_desired_type(desired_type)
>>  {
>>  }
>>
>>  UserExpression::~UserExpression ()
>>  {
>> -    if (m_target)
>> -    {
>> -        lldb::ModuleSP jit_module_sp (m_jit_module_wp.lock());
>> -        if (jit_module_sp)
>> -            m_target->GetImages().Remove(jit_module_sp);
>> -    }
>>  }
>>
>>  void
>> @@ -170,295 +146,6 @@ UserExpression::GetObjectPointer (lldb::
>>      return ret;
>>  }
>>
>> -bool
>> -UserExpression::PrepareToExecuteJITExpression (Stream &error_stream,
>> -                                                    ExecutionContext
>> &exe_ctx,
>> -                                                    lldb::addr_t
>> &struct_address)
>> -{
>> -    lldb::TargetSP target;
>> -    lldb::ProcessSP process;
>> -    lldb::StackFrameSP frame;
>> -
>> -    if (!LockAndCheckContext(exe_ctx,
>> -                             target,
>> -                             process,
>> -                             frame))
>> -    {
>> -        error_stream.Printf("The context has changed before we could JIT
>> the expression!\n");
>> -        return false;
>> -    }
>> -
>> -    if (m_jit_start_addr != LLDB_INVALID_ADDRESS || m_can_interpret)
>> -    {
>> -        if (m_materialized_address == LLDB_INVALID_ADDRESS)
>> -        {
>> -            Error alloc_error;
>> -
>> -            IRMemoryMap::AllocationPolicy policy = m_can_interpret ?
>> IRMemoryMap::eAllocationPolicyHostOnly :
>> IRMemoryMap::eAllocationPolicyMirror;
>> -
>> -            m_materialized_address =
>> m_execution_unit_sp->Malloc(m_materializer_ap->GetStructByteSize(),
>> -
>>  m_materializer_ap->GetStructAlignment(),
>> -
>>  lldb::ePermissionsReadable | lldb::ePermissionsWritable,
>> -                                                                 policy,
>> -
>>  alloc_error);
>> -
>> -            if (!alloc_error.Success())
>> -            {
>> -                error_stream.Printf("Couldn't allocate space for
>> materialized struct: %s\n", alloc_error.AsCString());
>> -                return false;
>> -            }
>> -        }
>> -
>> -        struct_address = m_materialized_address;
>> -
>> -        if (m_can_interpret && m_stack_frame_bottom ==
>> LLDB_INVALID_ADDRESS)
>> -        {
>> -            Error alloc_error;
>> -
>> -            const size_t stack_frame_size = 512 * 1024;
>> -
>> -            m_stack_frame_bottom =
>> m_execution_unit_sp->Malloc(stack_frame_size,
>> -                                                               8,
>> -
>>  lldb::ePermissionsReadable | lldb::ePermissionsWritable,
>> -
>>  IRMemoryMap::eAllocationPolicyHostOnly,
>> -
>>  alloc_error);
>> -
>> -            m_stack_frame_top = m_stack_frame_bottom + stack_frame_size;
>> -
>> -            if (!alloc_error.Success())
>> -            {
>> -                error_stream.Printf("Couldn't allocate space for the
>> stack frame: %s\n", alloc_error.AsCString());
>> -                return false;
>> -            }
>> -        }
>> -
>> -        Error materialize_error;
>> -
>> -        m_dematerializer_sp = m_materializer_ap->Materialize(frame,
>> *m_execution_unit_sp, struct_address, materialize_error);
>> -
>> -        if (!materialize_error.Success())
>> -        {
>> -            error_stream.Printf("Couldn't materialize: %s\n",
>> materialize_error.AsCString());
>> -            return false;
>> -        }
>> -    }
>> -    return true;
>> -}
>> -
>> -bool
>> -UserExpression::FinalizeJITExecution (Stream &error_stream,
>> -                                           ExecutionContext &exe_ctx,
>> -                                           lldb::ExpressionVariableSP
>> &result,
>> -                                           lldb::addr_t
>> function_stack_bottom,
>> -                                           lldb::addr_t
>> function_stack_top)
>> -{
>> -    Log *log(lldb_private::GetLogIfAllCategoriesSet
>> (LIBLLDB_LOG_EXPRESSIONS));
>> -
>> -    if (log)
>> -        log->Printf("-- [UserExpression::FinalizeJITExecution]
>> Dematerializing after execution --");
>> -
>> -    if (!m_dematerializer_sp)
>> -    {
>> -        error_stream.Printf ("Couldn't apply expression side effects :
>> no dematerializer is present");
>> -        return false;
>> -    }
>> -
>> -    Error dematerialize_error;
>> -
>> -    m_dematerializer_sp->Dematerialize(dematerialize_error,
>> function_stack_bottom, function_stack_top);
>> -
>> -    if (!dematerialize_error.Success())
>> -    {
>> -        error_stream.Printf ("Couldn't apply expression side effects :
>> %s\n", dematerialize_error.AsCString("unknown error"));
>> -        return false;
>> -    }
>> -
>> -    result =
>> GetResultAfterDematerialization(exe_ctx.GetBestExecutionContextScope());
>> -
>> -    if (result)
>> -        result->TransferAddress();
>> -
>> -    m_dematerializer_sp.reset();
>> -
>> -    return true;
>> -}
>> -
>> -lldb::ExpressionResults
>> -UserExpression::Execute (Stream &error_stream,
>> -                              ExecutionContext &exe_ctx,
>> -                              const EvaluateExpressionOptions& options,
>> -                              lldb::UserExpressionSP &shared_ptr_to_me,
>> -                              lldb::ExpressionVariableSP &result)
>> -{
>> -    // The expression log is quite verbose, and if you're just tracking
>> the execution of the
>> -    // expression, it's quite convenient to have these logs come out
>> with the STEP log as well.
>> -    Log *log(lldb_private::GetLogIfAnyCategoriesSet
>> (LIBLLDB_LOG_EXPRESSIONS | LIBLLDB_LOG_STEP));
>> -
>> -    if (m_jit_start_addr != LLDB_INVALID_ADDRESS || m_can_interpret)
>> -    {
>> -        lldb::addr_t struct_address = LLDB_INVALID_ADDRESS;
>> -
>> -        if (!PrepareToExecuteJITExpression (error_stream, exe_ctx,
>> struct_address))
>> -        {
>> -            error_stream.Printf("Errored out in %s, couldn't
>> PrepareToExecuteJITExpression", __FUNCTION__);
>> -            return lldb::eExpressionSetupError;
>> -        }
>> -
>> -        lldb::addr_t function_stack_bottom = LLDB_INVALID_ADDRESS;
>> -        lldb::addr_t function_stack_top = LLDB_INVALID_ADDRESS;
>> -
>> -        if (m_can_interpret)
>> -        {
>> -            llvm::Module *module = m_execution_unit_sp->GetModule();
>> -            llvm::Function *function =
>> m_execution_unit_sp->GetFunction();
>> -
>> -            if (!module || !function)
>> -            {
>> -                error_stream.Printf("Supposed to interpret, but nothing
>> is there");
>> -                return lldb::eExpressionSetupError;
>> -            }
>> -
>> -            Error interpreter_error;
>> -
>> -            std::vector<lldb::addr_t> args;
>> -
>> -            if (!AddInitialArguments(exe_ctx, args, error_stream))
>> -            {
>> -                error_stream.Printf ("Errored out in %s, couldn't
>> AddInitialArguments", __FUNCTION__);
>> -                return lldb::eExpressionSetupError;
>> -            }
>> -
>> -            args.push_back(struct_address);
>> -
>> -            function_stack_bottom = m_stack_frame_bottom;
>> -            function_stack_top = m_stack_frame_top;
>> -
>> -            IRInterpreter::Interpret (*module,
>> -                                      *function,
>> -                                      args,
>> -                                      *m_execution_unit_sp.get(),
>> -                                      interpreter_error,
>> -                                      function_stack_bottom,
>> -                                      function_stack_top,
>> -                                      exe_ctx);
>> -
>> -            if (!interpreter_error.Success())
>> -            {
>> -                error_stream.Printf("Supposed to interpret, but failed:
>> %s", interpreter_error.AsCString());
>> -                return lldb::eExpressionDiscarded;
>> -            }
>> -        }
>> -        else
>> -        {
>> -            if (!exe_ctx.HasThreadScope())
>> -            {
>> -                error_stream.Printf("UserExpression::Execute called with
>> no thread selected.");
>> -                return lldb::eExpressionSetupError;
>> -            }
>> -
>> -            Address wrapper_address (m_jit_start_addr);
>> -
>> -            std::vector<lldb::addr_t> args;
>> -
>> -            if (!AddInitialArguments(exe_ctx, args, error_stream))
>> -            {
>> -                error_stream.Printf ("Errored out in %s, couldn't
>> AddInitialArguments", __FUNCTION__);
>> -                return lldb::eExpressionSetupError;
>> -            }
>> -
>> -            args.push_back(struct_address);
>> -
>> -            lldb::ThreadPlanSP call_plan_sp(new
>> ThreadPlanCallUserExpression (exe_ctx.GetThreadRef(),
>> -
>>       wrapper_address,
>> -
>>       args,
>> -
>>       options,
>> -
>>       shared_ptr_to_me));
>> -
>> -            if (!call_plan_sp || !call_plan_sp->ValidatePlan
>> (&error_stream))
>> -                return lldb::eExpressionSetupError;
>> -
>> -            ThreadPlanCallUserExpression *user_expression_plan =
>> static_cast<ThreadPlanCallUserExpression *>(call_plan_sp.get());
>> -
>> -            lldb::addr_t function_stack_pointer =
>> user_expression_plan->GetFunctionStackPointer();
>> -
>> -            function_stack_bottom = function_stack_pointer -
>> HostInfo::GetPageSize();
>> -            function_stack_top = function_stack_pointer;
>> -
>> -            if (log)
>> -                log->Printf("-- [UserExpression::Execute] Execution of
>> expression begins --");
>> -
>> -            if (exe_ctx.GetProcessPtr())
>> -                exe_ctx.GetProcessPtr()->SetRunningUserExpression(true);
>> -
>> -            lldb::ExpressionResults execution_result =
>> exe_ctx.GetProcessRef().RunThreadPlan (exe_ctx,
>> -
>>                call_plan_sp,
>> -
>>                options,
>> -
>>                error_stream);
>> -
>> -            if (exe_ctx.GetProcessPtr())
>> -                exe_ctx.GetProcessPtr()->SetRunningUserExpression(false);
>> -
>> -            if (log)
>> -
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20151102/8ef3304f/attachment-0001.html>


More information about the lldb-commits mailing list