Skip to content

Commit

Permalink
Refactor stacktrace
Browse files Browse the repository at this point in the history
It now first collects all the information into the StacktraceItem
struct, and then uses the information from there to nicely format the
stacktrace, or to return it to the user.

We only use the unwind capability and removed execinfo.
  • Loading branch information
certik committed Aug 27, 2020
1 parent b1082fe commit 121bc71
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 206 deletions.
11 changes: 1 addition & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ if (MSVC)
endif()

# Stacktrace
set(WITH_EXECINFO no
CACHE BOOL "Build with execinfo support (requires glibc)")
set(WITH_UNWIND no
CACHE BOOL "Build with unwind support")
set(WITH_BFD no
Expand All @@ -149,9 +147,7 @@ set(WITH_LINKH no
set(WITH_STACKTRACE no
CACHE BOOL "Build with stacktrace support (requires binutils-dev)")
if (WITH_STACKTRACE)
if (NOT (WITH_EXECINFO OR WITH_UNWIND))
set(WITH_UNWIND yes)
endif ()
set(WITH_UNWIND yes)
set(WITH_BFD yes)
set(WITH_LINKH yes)
set(HAVE_LFORTRAN_STACKTRACE yes)
Expand All @@ -164,10 +160,6 @@ if (WITH_LINKH)
find_package(LINKH REQUIRED)
set(HAVE_LFORTRAN_LINK yes)
endif()
if (WITH_EXECINFO)
find_package(EXECINFO REQUIRED)
set(HAVE_LFORTRAN_EXECINFO yes)
endif()
if (WITH_UNWIND)
set(HAVE_LFORTRAN_UNWIND yes)
endif()
Expand All @@ -194,7 +186,6 @@ message("WITH_LFORTRAN_ASSERT: ${WITH_LFORTRAN_ASSERT}")
message("LFORTRAN_STATIC_BIN: ${LFORTRAN_STATIC_BIN}")
message("WITH_STACKTRACE: ${WITH_STACKTRACE}")
message("WITH_UNWIND: ${WITH_UNWIND}")
message("WITH_EXECINFO: ${WITH_EXECINFO}")
message("WITH_BFD: ${WITH_BFD}")
message("WITH_LINKH: ${WITH_LINKH}")
message("HAVE_LFORTRAN_DEMANGLE: ${HAVE_LFORTRAN_DEMANGLE}")
Expand Down
19 changes: 0 additions & 19 deletions cmake/FindEXECINFO.cmake

This file was deleted.

1 change: 0 additions & 1 deletion src/lfortran/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#cmakedefine HAVE_LFORTRAN_STACKTRACE
#cmakedefine HAVE_LFORTRAN_BFD
#cmakedefine HAVE_LFORTRAN_LINK
#cmakedefine HAVE_LFORTRAN_EXECINFO
#cmakedefine HAVE_LFORTRAN_UNWIND

/* Define if cxxabi.h is present */
Expand Down
22 changes: 9 additions & 13 deletions src/lfortran/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,16 @@ typedef enum {
namespace LFortran
{

const int stacktrace_depth = 4;

class LFortranException : public std::exception
{
std::string m_msg;
lfortran_exceptions_t ec;
std::string m_stacktrace;

public:
LFortranException(const std::string &msg, lfortran_exceptions_t error,
#if defined(HAVE_LFORTRAN_STACKTRACE)
int stacktrace_depth
#else
int /* stacktrace_depth */
#endif
)
LFortranException(const std::string &msg, lfortran_exceptions_t error)
: m_msg{msg}, ec{error}
{
#if defined(HAVE_LFORTRAN_STACKTRACE)
Expand All @@ -57,7 +53,7 @@ class LFortranException : public std::exception
#endif
}
LFortranException(const std::string &msg)
: LFortranException(msg, LFORTRAN_EXCEPTION, 2)
: LFortranException(msg, LFORTRAN_EXCEPTION)
{
}
const char *what() const throw()
Expand Down Expand Up @@ -104,7 +100,7 @@ class TokenizerError : public LFortranException
public:
TokenizerError(const std::string &msg, const Location &loc,
const std::string &token)
: LFortranException(msg, LFORTRAN_TOKENIZER_ERROR, 2), loc{loc},
: LFortranException(msg, LFORTRAN_TOKENIZER_ERROR), loc{loc},
token{token}
{
}
Expand All @@ -117,7 +113,7 @@ class ParserError : public LFortranException
int token;
public:
ParserError(const std::string &msg, const Location &loc, const int token)
: LFortranException(msg, LFORTRAN_PARSER_ERROR, 2), loc{loc}, token{token}
: LFortranException(msg, LFORTRAN_PARSER_ERROR), loc{loc}, token{token}
{
}
};
Expand All @@ -128,7 +124,7 @@ class SemanticError : public LFortranException
Location loc;
public:
SemanticError(const std::string &msg, const Location &loc)
: LFortranException(msg, LFORTRAN_SEMANTIC_ERROR, 2), loc{loc}
: LFortranException(msg, LFORTRAN_SEMANTIC_ERROR), loc{loc}
{
}
};
Expand All @@ -137,7 +133,7 @@ class CodeGenError : public LFortranException
{
public:
CodeGenError(const std::string &msg)
: LFortranException(msg, LFORTRAN_CODEGEN_ERROR, 2)
: LFortranException(msg, LFORTRAN_CODEGEN_ERROR)
{
}
};
Expand All @@ -146,7 +142,7 @@ class AssertFailed : public LFortranException
{
public:
AssertFailed(const std::string &msg)
: LFortranException(msg, LFORTRAN_ASSERT_FAILED, 2)
: LFortranException(msg, LFORTRAN_ASSERT_FAILED)
{
}
};
Expand Down
Loading

0 comments on commit 121bc71

Please sign in to comment.