Add all deserialization fatal output to the pretty stack trace

Rather than outputting diagnostics and to stderr, output all the extra
information added when deserialization fatally fails to the pretty stack
trace instead. Since the pretty stack trace is added to crash logs, this
should avoid the dance of requesting the compiler output

  - Moves the previous "**** DESERIALIZATION FAILURE ..." output to the
    last pretty stack trace line

  - Removes the module and compiler version notes added to the fatal
    diagnostic

  - Adds a new effective compiler version line for all frontend failure.
    Somewhat duplicates the line from the driver, but adds in the
    effective version

  - Adds a new line for the full misc version of the module that failed.
    May double up with previous "While reading from ..." lines that are
    added in various deserialization methods, but better to have it
    twice than not at all
This commit is contained in:
Ben Barham
2021-06-02 16:12:55 +10:00
parent dd543e630b
commit 599ba8bdbd
12 changed files with 123 additions and 125 deletions

View File

@@ -14,19 +14,17 @@
#include "ModuleFileCoreTableInfo.h"
#include "BCReadingExtras.h"
#include "DeserializationErrors.h"
#include "swift/Basic/LangOptions.h"
#include "swift/Strings.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/OnDiskHashTable.h"
#include "llvm/Support/PrettyStackTrace.h"
using namespace swift;
using namespace swift::serialization;
using namespace llvm::support;
using llvm::Expected;
StringRef swift::getNameOfModule(const ModuleFileSharedCore *MF) {
return MF->getName();
}
static bool checkModuleSignature(llvm::BitstreamCursor &cursor,
ArrayRef<unsigned char> signature) {
for (unsigned char byte : signature) {
@@ -472,13 +470,31 @@ std::string ModuleFileSharedCore::Dependency::getPrettyPrintedPath() const {
return output;
}
void ModuleFileSharedCore::fatal(llvm::Error error) {
logAllUnhandledErrors(std::move(error), llvm::errs(),
"\n*** DESERIALIZATION FAILURE (please include this "
"section in any bug report) ***\n");
void ModuleFileSharedCore::fatal(llvm::Error error) const {
llvm::SmallString<0> errorStr;
llvm::raw_svector_ostream out(errorStr);
out << "*** DESERIALIZATION FAILURE ***\n";
outputDiagnosticInfo(out);
out << "\n";
if (error) {
handleAllErrors(std::move(error), [&](const llvm::ErrorInfoBase &ei) {
ei.log(out);
out << "\n";
});
}
llvm::PrettyStackTraceString trace(errorStr.c_str());
abort();
}
void ModuleFileSharedCore::outputDiagnosticInfo(llvm::raw_ostream &os) const {
os << "module '" << Name << "' with full misc version '" << MiscVersion
<< "'";
if (Bits.IsAllowModuleWithCompilerErrorsEnabled)
os << " (built with -experimental-allow-module-with-compiler-errors)";
}
ModuleFileSharedCore::~ModuleFileSharedCore() { }
std::unique_ptr<ModuleFileSharedCore::SerializedDeclTable>