[Lldb-commits] [lldb] r328025 - [ExpressionParser] Re-implement r327356 in a less disruptive way.

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Mar 21 04:35:20 PDT 2018


It wasn't actually a linux issue, but a logging issue. The reason you
couldn't reproduce this locally is because we don't have logging on by
default (but our bot does, to help figuring out what's wrong when things
break). I haven't tried, but I'm pretty sure the test would break on mac as
well if you ran it with logging enabled (dotest.py --channel "lldb expr").
Right now, I've put a stop-gap fix, but maybe that should be resolved in a
more principled way.

The other issue I fixed was the test's Makefile not working for 32-bit
builds. Generally, when you start writing compiler invocations in the
Makefile by hand, you'll probably get break the test in some configuration.
Most of the effects can be achieved by just setting the appropriate
variables before invoking Makefile.rules. Compiling one part of the binary
without debug info is also possible that way, but historically we haven't
done that for some reason (I should probably go and fix that).



On Tue, 20 Mar 2018 at 22:24, Davide Italiano via lldb-commits <
lldb-commits at lists.llvm.org> wrote:

> This apparently uncovered a crash in the linux build, looking now.
> http://lab.llvm.org:8011/builders/lldb-x86_64-ubuntu-14.04-cmake
>
> Thanks,
>
> --
> Davide
>
> On Tue, Mar 20, 2018 at 12:46 PM, Davide Italiano via lldb-commits
> <lldb-commits at lists.llvm.org> wrote:
> > Author: davide
> > Date: Tue Mar 20 12:46:32 2018
> > New Revision: 328025
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=328025&view=rev
> > Log:
> > [ExpressionParser] Re-implement r327356 in a less disruptive way.
> >
> > Instead of applying the sledgehammer of refusing to insert any
> > C++ symbol in the ASTContext, try to validate the decl if what
> > we have is an operator. There was other code in lldb which was
> > responsible for this, just not really exposed (or used) in this
> > codepath. Also, add a better/more comprehensive test.
> >
> > <rdar://problem/35645893>
> >
> > Added:
> >     lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/
> >
>  lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/Makefile
> >
>  lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/TestOperatorOverload.py
> >
>  lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/a.cpp
> >
>  lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/b.cpp
> > Removed:
> >     lldb/trunk/lit/Expr/Inputs/basic.cpp
> >     lldb/trunk/lit/Expr/TestCallCppSym.test
> > Modified:
> >     lldb/trunk/include/lldb/Symbol/ClangASTContext.h
> >     lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
> >
>  lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
> >     lldb/trunk/source/Symbol/ClangASTContext.cpp
> >
> > Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
> > URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=328025&r1=328024&r2=328025&view=diff
> >
> ==============================================================================
> > --- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
> > +++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Tue Mar 20 12:46:32
> 2018
> > @@ -253,6 +253,9 @@ public:
> >            &type_fields,
> >        bool packed = false);
> >
> > +  static bool IsOperator(const char *name,
> > +                         clang::OverloadedOperatorKind &op_kind);
> > +
> >    //------------------------------------------------------------------
> >    // Structure, Unions, Classes
> >    //------------------------------------------------------------------
> >
> > Removed: lldb/trunk/lit/Expr/Inputs/basic.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Expr/Inputs/basic.cpp?rev=328024&view=auto
> >
> ==============================================================================
> > --- lldb/trunk/lit/Expr/Inputs/basic.cpp (original)
> > +++ lldb/trunk/lit/Expr/Inputs/basic.cpp (removed)
> > @@ -1,12 +0,0 @@
> > -class Patatino {
> > -private:
> > -  long tinky;
> > -
> > -public:
> > -  Patatino(long tinky) { this->tinky = tinky; }
> > -};
> > -
> > -int main(void) {
> > -  Patatino *a = new Patatino(26);
> > -  return 0;
> > -}
> >
> > Removed: lldb/trunk/lit/Expr/TestCallCppSym.test
> > URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Expr/TestCallCppSym.test?rev=328024&view=auto
> >
> ==============================================================================
> > --- lldb/trunk/lit/Expr/TestCallCppSym.test (original)
> > +++ lldb/trunk/lit/Expr/TestCallCppSym.test (removed)
> > @@ -1,6 +0,0 @@
> > -# RUN: %cxx %p/Inputs/basic.cpp -g -o %t && %lldb -b -s %s -- %t 2>&1 |
> FileCheck %s
> > -
> > -breakpoint set --file basic.cpp --line 12
> > -run
> > -call (int)_Znwm(23)
> > -# CHECK: error: use of undeclared identifier '_Znwm'
> >
> > Added:
> lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/Makefile
> > URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/Makefile?rev=328025&view=auto
> >
> ==============================================================================
> > ---
> lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/Makefile
> (added)
> > +++
> lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/Makefile
> Tue Mar 20 12:46:32 2018
> > @@ -0,0 +1,20 @@
> > +LEVEL = ../../../make
> > +
> > +CXX_SOURCES = a.cpp b.cpp
> > +CXXFLAGS_NO_DEBUGINFO = -c
> > +CXXFLAGS_DEBUGINFO = -c -g
> > +
> > +all: main
> > +
> > +main: a.o b.o
> > +       $(CXX) a.o b.o -o main $(LDFLAGS)
> > +
> > +a.o: a.cpp
> > +       $(CXX) $(SRCDIR)/a.cpp $(CXXFLAGS_NO_DEBUGINFO) -o a.o
> > +
> > +b.o: b.cpp
> > +       $(CXX) $(SRCDIR)/b.cpp $(CXXFLAGS_DEBUGINFO) -o b.o
> > +
> > +clean: OBJECTS += a.o b.o main
> > +
> > +include $(LEVEL)/Makefile.rules
> >
> > Added:
> lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/TestOperatorOverload.py
> > URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/TestOperatorOverload.py?rev=328025&view=auto
> >
> ==============================================================================
> > ---
> lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/TestOperatorOverload.py
> (added)
> > +++
> lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/TestOperatorOverload.py
> Tue Mar 20 12:46:32 2018
> > @@ -0,0 +1,22 @@
> > +import lldb
> > +from lldbsuite.test.decorators import *
> > +from lldbsuite.test.lldbtest import *
> > +from lldbsuite.test import lldbutil
> > +
> > +class TestOperatorOverload(TestBase):
> > +  mydir = TestBase.compute_mydir(__file__)
> > +
> > +  def test_overload(self):
> > +    self.build()
> > +    (target, process, thread,
> > +      main_breakpoint) = lldbutil.run_to_source_breakpoint(self,
> > +        "break here", lldb.SBFileSpec("b.cpp"), exe_name = "main")
> > +    frame = thread.GetSelectedFrame()
> > +    value = frame.EvaluateExpression("x == nil")
> > +    self.assertTrue(str(value.GetError())
> > +      .find("comparison between NULL and non-pointer ('Tinky' and
> NULL)")
> > +        != -1)
> > +    self.assertTrue(str(value.GetError())
> > +      .find("invalid operands to binary expression ('Tinky' and
> 'long')")
> > +        != -1)
> > +    self.assertFalse(value.GetError().Success())
> >
> > Added:
> lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/a.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/a.cpp?rev=328025&view=auto
> >
> ==============================================================================
> > ---
> lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/a.cpp
> (added)
> > +++
> lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/a.cpp
> Tue Mar 20 12:46:32 2018
> > @@ -0,0 +1,9 @@
> > +class Patatino {
> > +public:
> > +  double _blah;
> > +  Patatino(int blah) : _blah(blah) {}
> > +};
> > +
> > +bool operator==(const Patatino& a, const Patatino& b) {
> > +  return a._blah < b._blah;
> > +}
> >
> > Added:
> lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/b.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/b.cpp?rev=328025&view=auto
> >
> ==============================================================================
> > ---
> lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/b.cpp
> (added)
> > +++
> lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operator-overload/b.cpp
> Tue Mar 20 12:46:32 2018
> > @@ -0,0 +1,10 @@
> > +class Tinky {
> > +public:
> > +  int _meh;
> > +  Tinky(int meh) : _meh(meh) {}
> > +};
> > +
> > +int main(void) {
> > +  Tinky x(12);
> > +  return 0; // break here
> > +}
> >
> > Modified:
> lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp?rev=328025&r1=328024&r2=328025&view=diff
> >
> ==============================================================================
> > --- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
> (original)
> > +++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
> Tue Mar 20 12:46:32 2018
> > @@ -2156,6 +2156,18 @@ clang::NamedDecl *NameSearchContext::Add
> >        log->Printf("Function type wasn't a FunctionProtoType");
> >    }
> >
> > +  // If this is an operator (e.g. operator new or operator==), only
> insert
> > +  // the declaration we inferred from the symbol if we can provide the
> correct
> > +  // number of arguments. We shouldn't really inject random decl(s) for
> > +  // functions that are analyzed semantically in a special way,
> otherwise we
> > +  // will crash in clang.
> > +  clang::OverloadedOperatorKind op_kind =
> clang::NUM_OVERLOADED_OPERATORS;
> > +  if (func_proto_type &&
> > +      ClangASTContext::IsOperator(decl_name.getAsString().c_str(),
> op_kind)) {
> > +    if (!ClangASTContext::CheckOverloadedOperatorKindParameterCount(
> > +            false, op_kind, func_proto_type->getNumParams()))
> > +      return NULL;
> > +  }
> >    m_decls.push_back(func_decl);
> >
> >    return func_decl;
> >
> > 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=328025&r1=328024&r2=328025&view=diff
> >
> ==============================================================================
> > ---
> lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
> (original)
> > +++
> lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
> Tue Mar 20 12:46:32 2018
> > @@ -2072,15 +2072,6 @@ void ClangExpressionDeclMap::AddOneFunct
> >        return;
> >      }
> >    } else if (symbol) {
> > -    // Don't insert a generic function decl for C++ symbol names.
> > -    // Creating a generic function decl is almost surely going to cause
> troubles
> > -    // as it breaks Clang/Sema invariants and causes crashes in clang
> while
> > -    // we're trying to evaluate the expression.
> > -    // This means users can't call C++ functions by mangled name when
> there
> > -    // are no debug info (as it happens for C symbol, e.g. printf()).
> > -    if (CPlusPlusLanguage::IsCPPMangledName(
> > -            symbol->GetMangled().GetMangledName().GetCString()))
> > -      return;
> >      fun_address = symbol->GetAddress();
> >      function_decl = context.AddGenericFunDecl();
> >      is_indirect_function = symbol->IsIndirect();
> >
> > Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=328025&r1=328024&r2=328025&view=diff
> >
> ==============================================================================
> > --- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
> > +++ lldb/trunk/source/Symbol/ClangASTContext.cpp Tue Mar 20 12:46:32 2018
> > @@ -138,8 +138,8 @@ static ClangASTMap &GetASTMap() {
> >    return *g_map_ptr;
> >  }
> >
> > -static bool IsOperator(const char *name,
> > -                       clang::OverloadedOperatorKind &op_kind) {
> > +bool ClangASTContext::IsOperator(const char *name,
> > +                                 clang::OverloadedOperatorKind
> &op_kind) {
> >    if (name == nullptr || name[0] == '\0')
> >      return false;
> >
> >
> >
> > _______________________________________________
> > lldb-commits mailing list
> > lldb-commits at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180321/7300b970/attachment-0001.html>


More information about the lldb-commits mailing list