diff options
| author | Davide Italiano <davide@freebsd.org> | 2018-03-13 01:40:00 +0000 |
|---|---|---|
| committer | Davide Italiano <davide@freebsd.org> | 2018-03-13 01:40:00 +0000 |
| commit | d5bbaa6688dd51023170eaeae261b026e54bd2f2 (patch) | |
| tree | 7e3fb3eb6f1c0e1c52192e8794b58514e38c2c32 | |
| parent | 80058e30cc3abb7240eaa4541aab5ae55af94935 (diff) | |
| download | bcm5719-llvm-d5bbaa6688dd51023170eaeae261b026e54bd2f2.tar.gz bcm5719-llvm-d5bbaa6688dd51023170eaeae261b026e54bd2f2.zip | |
[ExpressionParser] Fix crash when evaluating invalid expresssions.
Typical example, illformed comparisons (operator== where LHS and
RHS are not compatible). If a symbol matched `operator==` in any
of the object files lldb inserted a generic function declaration
in the ASTContext on which Sema operates. Maintaining the AST
context invariants is fairly tricky and sometimes resulted in
crashes inside clang (or assertions hit).
The real reason why this feature exists in the first place is
that of allowing users to do something like:
(lldb) call printf("patatino")
even if the debug informations for printf() is not available.
Eventually, we might reconsider this feature in its
entirety, but for now we can't remove it as it would break
a bunch of users. Instead, try to limit it to non-C++ symbols,
where getting the invariants right is hopefully easier.
Now you can't do in lldb anymore
(lldb) call _Zsomethingsomething(1,2,3)
but that doesn't seem to be such a big loss.
<rdar://problem/35645893>
llvm-svn: 327356
| -rw-r--r-- | lldb/lit/Expr/Inputs/basic.cpp | 12 | ||||
| -rw-r--r-- | lldb/lit/Expr/TestCallCppSym.test | 6 | ||||
| -rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp | 9 |
3 files changed, 27 insertions, 0 deletions
diff --git a/lldb/lit/Expr/Inputs/basic.cpp b/lldb/lit/Expr/Inputs/basic.cpp new file mode 100644 index 00000000000..80a79379a2e --- /dev/null +++ b/lldb/lit/Expr/Inputs/basic.cpp @@ -0,0 +1,12 @@ +class Patatino { +private: + long tinky; + +public: + Patatino(long tinky) { this->tinky = tinky; } +}; + +int main(void) { + Patatino *a = new Patatino(26); + return 0; +} diff --git a/lldb/lit/Expr/TestCallCppSym.test b/lldb/lit/Expr/TestCallCppSym.test new file mode 100644 index 00000000000..ac48c6f5160 --- /dev/null +++ b/lldb/lit/Expr/TestCallCppSym.test @@ -0,0 +1,6 @@ +# 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' diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp index 07ff2e97aac..093be6c898a 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp @@ -2072,6 +2072,15 @@ void ClangExpressionDeclMap::AddOneFunction(NameSearchContext &context, 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(); |

