Skip to content

Commit

Permalink
Add check for SIGABRT
Browse files Browse the repository at this point in the history
  • Loading branch information
nkchuykin committed Jun 20, 2022
1 parent 9ae5a8e commit 56b777d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion project/src/transpiler/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ void SegfaultSigaction(int /*unused*/, siginfo_t *si, void * /*unused*/) {
exit(0);
}

void SiAbrtSigaction(int /*unused*/, siginfo_t *si, void * /*unused*/) {
llvm::errs() << "exception: SIGABRT with code " << si->si_code
<< " while tool run\n";
ofstream out(filename);
out << "+package c2eo.src." << package_name << "\n\n";
out << "+alias c2eo.stdio.printf\n\n";
out << "[args...] > global\n";
out << " printf \"SIGABRT at address " << si->si_addr
<< " while tool run\" > @\n";
out.close();
exit(0);
}

int main(int argc, const char **argv) {
if (argc < 3) {
llvm::errs() << "exception: incorrect command line format. Necessary: c2eo "
Expand Down Expand Up @@ -87,8 +100,15 @@ int main(int argc, const char **argv) {
sigemptyset(&sa.sa_mask);
sa.sa_sigaction = SegfaultSigaction;
sa.sa_flags = SA_SIGINFO;

sigaction(SIGSEGV, &sa, nullptr);

struct sigaction sab {};
memset(&sab, 0, sizeof(struct sigaction));
sigemptyset(&sab.sa_mask);
sab.sa_sigaction = SiAbrtSigaction;
sab.sa_flags = SA_SIGINFO;
sigaction(SIGABRT, &sab, nullptr);

auto result = tool.run(newFrontendActionFactory(&finder).get());
if (result != 0) {
cerr << "An error in clang occurred\n";
Expand Down
2 changes: 1 addition & 1 deletion project/src/transpiler/memory_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class MemoryManager {

bool Empty();

size_t GetFreeSpacePointer() const;
[[nodiscard]] size_t GetFreeSpacePointer() const;

const Variable &GetVarById(const clang::VarDecl *id) const;

Expand Down

0 comments on commit 56b777d

Please sign in to comment.