mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Add flag to dump the raw SemIR in the event of a crash. (#6558)
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "common/check.h"
|
||||
#include "common/map.h"
|
||||
#include "common/pretty_stack_trace_function.h"
|
||||
#include "toolchain/check/check_unit.h"
|
||||
#include "toolchain/check/context.h"
|
||||
#include "toolchain/check/cpp/import.h"
|
||||
@@ -417,6 +418,27 @@ auto CheckParseTrees(
|
||||
&unit, tree_and_subtrees_getters.Get(unit.sem_ir->check_ir_id()));
|
||||
}));
|
||||
|
||||
// Dump the raw SemIR in the event of a crash. We dump it to a separate file
|
||||
// to keep the stack trace manageable.
|
||||
PrettyStackTraceFunction sem_ir_dumper([&](llvm::raw_ostream& output) {
|
||||
if (!options.sem_ir_crash_dump.empty()) {
|
||||
output << "Dumping raw SemIR to " << options.sem_ir_crash_dump << "\n";
|
||||
std::error_code error_code;
|
||||
llvm::raw_fd_ostream sem_ir_dump(options.sem_ir_crash_dump, error_code);
|
||||
if (error_code) {
|
||||
output << "Raw SemIR dump failed: " << error_code.category().name()
|
||||
<< ":" << error_code.value() << ": " << error_code.message()
|
||||
<< "\n";
|
||||
} else {
|
||||
for (const auto& unit_info : unit_infos) {
|
||||
if (unit_info.is_checked && unit_info.unit->sem_ir != nullptr) {
|
||||
unit_info.unit->sem_ir->Print(sem_ir_dump);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Map<ImportKey, UnitAndImports*> api_map =
|
||||
BuildApiMapAndDiagnosePackaging(unit_infos);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user