[Lldb-commits] [lldb] r267833 - Fixed a bug where const this would cause parser errors about $__lldb_expr.

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 28 01:24:50 PDT 2016


Hi,

this commit broke the build due to a missing declaration of the
APIntWithTypeAndValue. Since this function is not called anywhere, i
suspect some work in progress may have gotten committed with the
actual fix. I'm not sure which one is which, so I reverted the whole
patch. Could you please take a look and resumbit the relevant parts?

pl

On 28 April 2016 at 02:36, Sean Callanan via lldb-commits
<lldb-commits at lists.llvm.org> wrote:
> Author: spyffe
> Date: Wed Apr 27 20:36:21 2016
> New Revision: 267833
>
> URL: http://llvm.org/viewvc/llvm-project?rev=267833&view=rev
> Log:
> Fixed a bug where const this would cause parser errors about $__lldb_expr.
>
> In templated const functions, trying to run an expression would produce the
> error
>
> error: out-of-line definition of '$__lldb_expr' does not match any declaration in 'foo'
> member declaration does not match because it is const qualified
> error: 1 error parsing expression
>
> which is no good.  It turned out we don't actually need to worry about "const,"
> we just need to be consistent about the declaration of the expression and the
> FunctionDecl we inject into the class for "this."
>
> Also added a test case.
>
> <rdar://problem/24985958>
>
> Added:
>     lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/const_this/
>     lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/const_this/Makefile
>     lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/const_this/TestConstThis.py
>     lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/const_this/main.cpp
> Modified:
>     lldb/trunk/source/Core/Scalar.cpp
>     lldb/trunk/source/Expression/ExpressionSourceCode.cpp
>     lldb/trunk/source/Expression/LLVMUserExpression.cpp
>     lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
>     lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
>
> Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/const_this/Makefile
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/const_this/Makefile?rev=267833&view=auto
> ==============================================================================
> --- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/const_this/Makefile (added)
> +++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/const_this/Makefile Wed Apr 27 20:36:21 2016
> @@ -0,0 +1,8 @@
> +LEVEL = ../../../make
> +CXX_SOURCES := main.cpp
> +CXXFLAGS += -std=c++11
> +include $(LEVEL)/Makefile.rules
> +
> +cleanup:
> +       rm -f Makefile *.d
> +
>
> Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/const_this/TestConstThis.py
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/const_this/TestConstThis.py?rev=267833&view=auto
> ==============================================================================
> --- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/const_this/TestConstThis.py (added)
> +++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/const_this/TestConstThis.py Wed Apr 27 20:36:21 2016
> @@ -0,0 +1,4 @@
> +from lldbsuite.test import lldbinline
> +from lldbsuite.test import decorators
> +
> +lldbinline.MakeInlineTest(__file__, globals(), [decorators.expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24764")] )
>
> Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/const_this/main.cpp
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/const_this/main.cpp?rev=267833&view=auto
> ==============================================================================
> --- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/const_this/main.cpp (added)
> +++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/const_this/main.cpp Wed Apr 27 20:36:21 2016
> @@ -0,0 +1,23 @@
> +//===-- main.cpp ------------------------------------------------*- C++ -*-===//
> +//
> +//                     The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +
> +#include <stdio.h>
> +
> +class foo {
> +public:
> +  template <class T> T func(T x) const {
> +    return x+2; //% self.expect("expr 2+3", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["5"])
> +  }
> +};
> +
> +int i;
> +
> +int main() {
> +  return foo().func(i);
> +}
>
> Modified: lldb/trunk/source/Core/Scalar.cpp
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Scalar.cpp?rev=267833&r1=267832&r2=267833&view=diff
> ==============================================================================
> --- lldb/trunk/source/Core/Scalar.cpp (original)
> +++ lldb/trunk/source/Core/Scalar.cpp Wed Apr 27 20:36:21 2016
> @@ -78,6 +78,74 @@ PromoteToMaxType
>      return Scalar::e_void;
>  }
>
> +llvm::APInt
> +Scalar::APIntWithTypeAndValue(Scalar::Type type, uint64_t raw_value)
> +{
> +    //  APInt(unsigned numBits, uint64_t val, bool isSigned = false)
> +    unsigned num_bits = 1;
> +    bool is_signed = false;
> +
> +    switch (type)
> +    {
> +        case Scalar::e_void:
> +            break;
> +        case Scalar::e_sint:
> +            is_signed = true;
> +            num_bits = sizeof(sint_t) * 8;
> +            break;
> +        case Scalar::e_uint:
> +            is_signed = false;
> +            num_bits = sizeof(uint_t) * 8;
> +            break;
> +        case Scalar::e_slong:
> +            is_signed = true;
> +            num_bits = sizeof(slong_t) * 8;
> +            break;
> +        case Scalar::e_ulong:
> +            is_signed = false;
> +            num_bits = sizeof(ulong_t) * 8;
> +            break;
> +        case Scalar::e_slonglong:
> +            is_signed = true;
> +            num_bits = sizeof(slonglong_t) * 8;
> +            break;
> +        case Scalar::e_ulonglong:
> +            is_signed = false;
> +            num_bits = sizeof(ulonglong_t) * 8;
> +            break;
> +        case Scalar::e_sint128:
> +            is_signed = true;
> +            num_bits = 128;
> +            break;
> +        case Scalar::e_uint128:
> +            is_signed = false;
> +            num_bits = 128;
> +            break;
> +        case Scalar::e_sint256:
> +            is_signed = true;
> +            num_bits = 256;
> +            break;
> +        case Scalar::e_uint256:
> +            is_signed = false;
> +            num_bits = 256;
> +            break;
> +        case Scalar::e_float:
> +            is_signed = false;
> +            num_bits = sizeof(float_t) * 8;
> +            break;
> +        case Scalar::e_double:
> +            is_signed = false;
> +            num_bits = sizeof(double_t) * 8;
> +            break;
> +        case Scalar::e_long_double:
> +            is_signed = false;
> +            num_bits = sizeof(long_double_t) * 8;
> +            break;
> +    }
> +
> +    return llvm::APInt(num_bits, raw_value, is_signed);
> +}
> +
>  Scalar::Scalar() :
>      m_type(e_void),
>      m_float((float)0)
>
> Modified: lldb/trunk/source/Expression/ExpressionSourceCode.cpp
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ExpressionSourceCode.cpp?rev=267833&r1=267832&r2=267833&view=diff
> ==============================================================================
> --- lldb/trunk/source/Expression/ExpressionSourceCode.cpp (original)
> +++ lldb/trunk/source/Expression/ExpressionSourceCode.cpp Wed Apr 27 20:36:21 2016
> @@ -195,7 +195,7 @@ AddLocalVariableDecls(const lldb::Variab
>      }
>  }
>
> -bool ExpressionSourceCode::GetText (std::string &text, lldb::LanguageType wrapping_language, bool const_object, bool static_method, ExecutionContext &exe_ctx) const
> +bool ExpressionSourceCode::GetText (std::string &text, lldb::LanguageType wrapping_language, bool static_method, ExecutionContext &exe_ctx) const
>  {
>      const char *target_specific_defines = "typedef signed char BOOL;\n";
>      std::string module_macros;
> @@ -337,13 +337,12 @@ bool ExpressionSourceCode::GetText (std:
>              break;
>          case lldb::eLanguageTypeC_plus_plus:
>              wrap_stream.Printf("void                                   \n"
> -                               "$__lldb_class::%s(void *$__lldb_arg) %s\n"
> +                               "$__lldb_class::%s(void *$__lldb_arg)   \n"
>                                 "{                                      \n"
>                                 "    %s;                                \n"
>                                 "%s"
>                                 "}                                      \n",
>                                 m_name.c_str(),
> -                               (const_object ? "const" : ""),
>                                 lldb_local_var_decls.GetData(),
>                                 tagged_body.c_str());
>              break;
>
> Modified: lldb/trunk/source/Expression/LLVMUserExpression.cpp
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/LLVMUserExpression.cpp?rev=267833&r1=267832&r2=267833&view=diff
> ==============================================================================
> --- lldb/trunk/source/Expression/LLVMUserExpression.cpp (original)
> +++ lldb/trunk/source/Expression/LLVMUserExpression.cpp Wed Apr 27 20:36:21 2016
> @@ -59,7 +59,6 @@ LLVMUserExpression::LLVMUserExpression(E
>        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)
>
> Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp?rev=267833&r1=267832&r2=267833&view=diff
> ==============================================================================
> --- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp (original)
> +++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp Wed Apr 27 20:36:21 2016
> @@ -2212,10 +2212,10 @@ ClangExpressionDeclMap::AddThisType(Name
>  {
>      CompilerType copied_clang_type = GuardedCopyType(ut);
>
> +    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
> +
>      if (!copied_clang_type)
>      {
> -        Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
> -
>          if (log)
>              log->Printf("ClangExpressionDeclMap::AddThisType - Couldn't import the type");
>
> @@ -2232,7 +2232,7 @@ ClangExpressionDeclMap::AddThisType(Name
>                                                                          &void_ptr_clang_type,
>                                                                          1,
>                                                                          false,
> -                                                                        copied_clang_type.GetTypeQualifiers());
> +                                                                        0);
>
>          const bool is_virtual = false;
>          const bool is_static = false;
> @@ -2241,7 +2241,7 @@ ClangExpressionDeclMap::AddThisType(Name
>          const bool is_attr_used = true;
>          const bool is_artificial = false;
>
> -        ClangASTContext::GetASTContext(m_ast_context)->
> +        CXXMethodDecl *method_decl = ClangASTContext::GetASTContext(m_ast_context)->
>              AddMethodToCXXRecordType (copied_clang_type.GetOpaqueQualType(),
>                                        "$__lldb_expr",
>                                        method_type,
> @@ -2252,6 +2252,16 @@ ClangExpressionDeclMap::AddThisType(Name
>                                        is_explicit,
>                                        is_attr_used,
>                                        is_artificial);
> +
> +        if (log)
> +        {
> +            ASTDumper method_ast_dumper((clang::Decl*)method_decl);
> +            ASTDumper type_ast_dumper(copied_clang_type);
> +
> +            log->Printf("  CEDM::AddThisType Added function $__lldb_expr (description %s) for this type %s",
> +                        method_ast_dumper.GetCString(),
> +                        type_ast_dumper.GetCString());
> +        }
>      }
>
>      if (!copied_clang_type.IsValid())
>
> Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp?rev=267833&r1=267832&r2=267833&view=diff
> ==============================================================================
> --- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp (original)
> +++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp Wed Apr 27 20:36:21 2016
> @@ -417,7 +417,7 @@ ClangUserExpression::Parse(DiagnosticMan
>          else
>              lang_type = lldb::eLanguageTypeC;
>
> -        if (!source_code->GetText(m_transformed_text, lang_type, m_const_object, m_in_static_method, exe_ctx))
> +        if (!source_code->GetText(m_transformed_text, lang_type, m_in_static_method, exe_ctx))
>          {
>              diagnostic_manager.PutCString(eDiagnosticSeverityError, "couldn't construct expression body");
>              return false;
>
>
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


More information about the lldb-commits mailing list