Skip to content

Commit

Permalink
Add libdwarf backend for stack traces
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed May 8, 2021
1 parent 5aae470 commit 43f3ef1
Show file tree
Hide file tree
Showing 7 changed files with 661 additions and 157 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ To build from a released tarball:
make
sudo make install

To use a specific version of LLVM add `--with-llvm=/path/to/llvm-config` to
the configure command. LLVM 7, 8, and 9 have all been tested.
To use a specific version of LLVM add `--with-llvm=/path/to/llvm-config`
to the configure command. LLVM 7, 8, 9, 10, 11 and 12 have all been
tested.

NVC also depends GNU Flex to generate the lexical analyser.
NVC also depends on Flex to generate the lexical analyser.

[GtkWave](http://gtkwave.sourceforge.net/) can be used to view simulation
waveforms. Version 3.3.79 or later is required for the default FST format.
Expand All @@ -64,8 +65,8 @@ waveforms. Version 3.3.79 or later is required for the default FST format.
On a Debian derivative the following should be sufficient to install all
required dependencies:

sudo apt-get install build-essential automake autoconf autoconf-archive flex \
check llvm-dev pkg-config zlib1g-dev
sudo apt-get install build-essential automake autoconf \
flex check llvm-dev pkg-config zlib1g-dev libdw-dev

#### macOS

Expand Down Expand Up @@ -103,7 +104,7 @@ standard installation instructions above.

Install the dependencies with `pkg_add`:

pkg_add automake autoconf libexecinfo llvm check libexecinfo
pkg_add automake autoconf libdwarf llvm check libexecinfo

Pass `CC` and `CXX` explicitly to configure to ensure Clang is used
instead of an old version of GCC.
Expand Down
58 changes: 40 additions & 18 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ AC_INIT([nvc], [1.6-devel],
[nvc])
AC_PREREQ([2.63])

AC_CANONICAL_HOST
AC_CANONICAL_TARGET

dnl Automake 1.11 does not support the serial-tests option
dnl Remove this when 1.11 no longer in common use
m4_define([serial_tests], [
Expand All @@ -21,8 +24,6 @@ AM_SILENT_RULES([yes])

AC_CONFIG_MACRO_DIR([m4])

AC_CANONICAL_HOST

AC_PROG_CC
AC_PROG_CC_C99
AC_PROG_CXX
Expand All @@ -35,7 +36,7 @@ AC_EXEEXT
AC_C_INLINE
AC_C_RESTRICT

AC_CHECK_HEADERS([execinfo.h sys/ptrace.h sys/prctl.h])
AC_CHECK_HEADERS([sys/ptrace.h sys/prctl.h])

AC_CHECK_MEMBERS([struct stat.st_mtimespec.tv_nsec])
AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec])
Expand All @@ -54,15 +55,9 @@ AC_SUBST(PIC_FLAG)

AX_GCC_FUNC_ATTRIBUTE([returns_nonnull])

AX_PROG_FLEX([], [AC_MSG_ERROR(GNU Flex not found)])
AX_PROG_FLEX([], [AC_MSG_ERROR(Flex not found)])

case $host_os in
openbsd*|freebsd*)
# Need to link libexecinfo explicitly
AC_SEARCH_LIBS([backtrace_symbols], [execinfo], [],
[AC_MSG_ERROR(libexecinfo not found)], [])
;;

*cygwin*|msys*|mingw32*)
# LLVM on Windows needs libffi and curses
AX_WITH_CURSES
Expand Down Expand Up @@ -156,19 +151,46 @@ fi

AX_LLVM_C([engine passes ipo linker native])

PKG_CHECK_EXISTS([check],
[PKG_CHECK_MODULES([CHECK], [check >= 0.9.4], [], [])],
[AC_MSG_WARN(libcheck not found - unit tests will not run)])
PKG_CHECK_MODULES([CHECK], [check >= 0.9.4], [],
[AC_MSG_WARN(libcheck not found - unit tests will not run)])

debug_backend=
AC_CHECK_HEADER([unwind.h],
AC_SEARCH_LIBS([_Unwind_Backtrace], [c++abi],
[
# libc++-abi needs to link -lpthread on OpenBSD
if test "$ac_cv_search__Unwind_Backtrace" = "-lc++abi"; then
[AX_PTHREAD([LIBS="$PTHREAD_LIBS $LIBS"],
[AC_MSG_ERROR([pthread not found])])]
fi
],
[AC_MSG_ERROR(cannot find library for _Unwind_Backtrace)],
[-lpthread])

[PKG_CHECK_MODULES([libdw], [libdw >= 0.159],
[AC_DEFINE_UNQUOTED([HAVE_LIBDW], [1], [Have libdw for stack traces])
debug_backend=libdw],
[true])
AC_CHECK_HEADER([libdwarf/libdwarf.h],
[AC_SEARCH_LIBS([elf_version], [elf], [], [AC_MSG_ERROR(cannot find libelf)])
AC_SEARCH_LIBS([dwarf_init], [dwarf],
[AC_DEFINE_UNQUOTED([HAVE_LIBDWARF], [1], [Have libdwarf for stack traces])
debug_backend=libdwarf],
[AC_MSG_WARN(cannot link against libdwarf)], [])])])

case $host_os in
linux*)
PKG_CHECK_EXISTS([libdw],
[PKG_CHECK_MODULES([libdw], [libdw >= 0.159], [], [])
AC_DEFINE_UNQUOTED([HAVE_LIBDW], [1], [Have libdw for stack traces])],
[AC_MSG_NOTICE(libdw not found - using basic stack traces)])
*cygwin*|msys*|mingw32*)
debug_backend=win32
;;
esac

if test -z "$debug_backend"; then
AX_EXECINFO
AC_MSG_NOTICE(libdw or libdwarf not found - using basic stack traces)
debug_backend=execinfo
fi

AX_DEFINE_DIR([DATADIR], [datadir/nvc], [Installation data directory])
AX_DEFINE_DIR([LIBDIR], [libdir], [Installation library directory])
AX_DEFINE_DIR([TESTDIR], [srcdir/test], [Location of testcases])
Expand Down
67 changes: 67 additions & 0 deletions m4/ax_execinfo.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# ===========================================================================
# https://www.gnu.org/software/autoconf-archive/ax_execinfo.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_EXECINFO([ACTION-IF-EXECINFO-H-IS-FOUND], [ACTION-IF-EXECINFO-H-IS-NOT-FOUND], [ADDITIONAL-TYPES-LIST])
#
# DESCRIPTION
#
# Checks for execinfo.h header and if the len parameter/return type can be
# found from a list, also define backtrace_size_t to that type.
#
# By default the list of types to try contains int and size_t, but should
# some yet undiscovered system use e.g. unsigned, the 3rd argument can be
# used for extensions. I'd like to hear of further suggestions.
#
# Executes ACTION-IF-EXECINFO-H-IS-FOUND when present and the execinfo.h
# header is found or ACTION-IF-EXECINFO-H-IS-NOT-FOUND in case the header
# seems unavailable.
#
# Also adds -lexecinfo to LIBS on BSD if needed.
#
# LICENSE
#
# Copyright (c) 2014 Thomas Jahns <jahns@dkrz.de>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 2

AC_DEFUN([AX_EXECINFO],
[AC_CHECK_HEADERS([execinfo.h])
AS_IF([test x"$ac_cv_header_execinfo_h" = xyes],
[AC_CACHE_CHECK([size parameter type for backtrace()],
[ax_cv_proto_backtrace_type],
[AC_LANG_PUSH([C])
for ax_cv_proto_backtrace_type in size_t int m4_ifnblank([$3],[$3 ])none; do
AS_IF([test "${ax_cv_proto_backtrace_type}" = none],
[ax_cv_proto_backtrace_type= ; break])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
#include <execinfo.h>
extern
${ax_cv_proto_backtrace_type} backtrace(void **addrlist, ${ax_cv_proto_backtrace_type} len);
char **backtrace_symbols(void *const *buffer, ${ax_cv_proto_backtrace_type} size);
])],
[break])
done
AC_LANG_POP([C])])])
AS_IF([test x${ax_cv_proto_backtrace_type} != x],
[AC_DEFINE_UNQUOTED([backtrace_size_t], [$ax_cv_proto_backtrace_type],
[Defined to return type of backtrace().])])
AC_SEARCH_LIBS([backtrace],[execinfo])
AS_IF([test x"${ax_cv_proto_backtrace_type}" != x -a x"$ac_cv_header_execinfo_h" = xyes -a x"$ac_cv_search_backtrace" != xno],
[AC_DEFINE([HAVE_BACKTRACE],[1],
[Defined if backtrace() could be fully identified.])
]m4_ifnblank([$1],[$1
]),m4_ifnblank([$2],[$2
]))])
dnl
dnl Local Variables:
dnl mode: autoconf
dnl End:
dnl
Loading

0 comments on commit 43f3ef1

Please sign in to comment.