Skip to content

Commit

Permalink
[cxxmodules] Print stacktrace before aborting on a missing exception.
Browse files Browse the repository at this point in the history
We will probably see an increasing amount of these failures with
C++ modules as we now deserialize all declarations instead of just
the PCH ones. To safe us a lot of debugging time on where to push
the needed transaction, let's directly print the stack trace here
in the rare case that we crash here.
  • Loading branch information
Teemperor committed Sep 12, 2017
1 parent 2ebbb74 commit 964acb8
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions interpreter/cling/lib/Interpreter/DeclCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "cling/Interpreter/Transaction.h"
#include "cling/Utils/AST.h"

#include "llvm/Support/Signals.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
Expand Down Expand Up @@ -57,6 +58,15 @@ namespace {
return true;
return false;
}

/// \brief Asserts that the given transaction is not null, otherwise prints a
/// stack trace to stderr and aborts execution.
static void assertHasTransaction(const cling::Transaction* T) {
if (!T) {
llvm::sys::PrintStackTrace(llvm::errs());
llvm_unreachable("Missing transaction during deserialization!");
}
}
}

namespace cling {
Expand All @@ -67,7 +77,7 @@ namespace cling {

void MacroDirective(const clang::Token& MacroNameTok,
const clang::MacroDirective* MD) {
assert(m_Parent->m_CurTransaction && "Missing transction");
assertHasTransaction(m_Parent->m_CurTransaction);
Transaction::MacroDirectiveInfo MDE(MacroNameTok.getIdentifierInfo(), MD);
m_Parent->m_CurTransaction->append(MDE);
}
Expand Down Expand Up @@ -101,7 +111,7 @@ namespace cling {

bool DeclCollector::comesFromASTReader(DeclGroupRef DGR) const {
assert(!DGR.isNull() && "DeclGroupRef is Null!");
assert(m_CurTransaction && "No current transaction when deserializing");
assertHasTransaction(m_CurTransaction);
if (m_CurTransaction->getCompilationOpts().CodeGenerationForModule)
return true;

Expand Down Expand Up @@ -183,7 +193,7 @@ namespace cling {
if (DGR.isNull())
return true;

assert(m_CurTransaction && "Missing transction");
assertHasTransaction(m_CurTransaction);
Transaction::DelayCallInfo DCI(DGR, Transaction::kCCIHandleTopLevelDecl);
m_CurTransaction->append(DCI);
if (!m_Consumer
Expand Down Expand Up @@ -222,7 +232,7 @@ namespace cling {
}

void DeclCollector::HandleInterestingDecl(DeclGroupRef DGR) {
assert(m_CurTransaction && "Missing transction");
assertHasTransaction(m_CurTransaction);
Transaction::DelayCallInfo DCI(DGR, Transaction::kCCIHandleInterestingDecl);
m_CurTransaction->append(DCI);
if (m_Consumer
Expand All @@ -231,7 +241,7 @@ namespace cling {
}

void DeclCollector::HandleTagDeclDefinition(TagDecl* TD) {
assert(m_CurTransaction && "Missing transction");
assertHasTransaction(m_CurTransaction);
Transaction::DelayCallInfo DCI(DeclGroupRef(TD),
Transaction::kCCIHandleTagDeclDefinition);
m_CurTransaction->append(DCI);
Expand All @@ -242,7 +252,7 @@ namespace cling {
}

void DeclCollector::HandleInvalidTagDeclDefinition(clang::TagDecl *TD){
assert(m_CurTransaction && "Missing transction");
assertHasTransaction(m_CurTransaction);
Transaction::DelayCallInfo DCI(DeclGroupRef(TD),
Transaction::kCCIHandleTagDeclDefinition);
m_CurTransaction->append(DCI);
Expand All @@ -254,7 +264,7 @@ namespace cling {
}

void DeclCollector::HandleVTable(CXXRecordDecl* RD) {
assert(m_CurTransaction && "Missing transction");
assertHasTransaction(m_CurTransaction);
Transaction::DelayCallInfo DCI(DeclGroupRef(RD),
Transaction::kCCIHandleVTable);
m_CurTransaction->append(DCI);
Expand All @@ -272,7 +282,7 @@ namespace cling {
}

void DeclCollector::CompleteTentativeDefinition(VarDecl* VD) {
assert(m_CurTransaction && "Missing transction");
assertHasTransaction(m_CurTransaction);
// C has tentative definitions which we might need to deal with when running
// in C mode.
Transaction::DelayCallInfo DCI(DeclGroupRef(VD),
Expand All @@ -290,7 +300,7 @@ namespace cling {
}

void DeclCollector::HandleCXXImplicitFunctionInstantiation(FunctionDecl *D) {
assert(m_CurTransaction && "Missing transction");
assertHasTransaction(m_CurTransaction);
Transaction::DelayCallInfo DCI(DeclGroupRef(D),
Transaction::kCCIHandleCXXImplicitFunctionInstantiation);
m_CurTransaction->append(DCI);
Expand All @@ -301,7 +311,7 @@ namespace cling {
}

void DeclCollector::HandleCXXStaticMemberVarInstantiation(VarDecl *D) {
assert(m_CurTransaction && "Missing transction");
assertHasTransaction(m_CurTransaction);
Transaction::DelayCallInfo DCI(DeclGroupRef(D),
Transaction::kCCIHandleCXXStaticMemberVarInstantiation);
m_CurTransaction->append(DCI);
Expand Down

0 comments on commit 964acb8

Please sign in to comment.