Skip to content

Commit

Permalink
Use libbacktrace to generate readable backtrace on Windows (#36615)
Browse files Browse the repository at this point in the history
* Use libbacktrace to generate backtrace

* Move dbghelp symbol initialization to debug_write_backtrace

* Use libbacktrace on cross-compilation to Windows

* Download prebuilt libbacktrace before building

* Use square brackets instead of angle brackets

* Add license text of libbacktrace
  • Loading branch information
Qrox authored and ZhilkinSerg committed Jan 6, 2020
1 parent 238ab4b commit 764aa9f
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 232 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ option(TILES "Build graphical tileset version." "OFF")
option(CURSES "Build curses version." "ON")
option(SOUND "Support for in-game sounds & music." "OFF")
option(BACKTRACE "Support for printing stack backtraces on crash" "ON")
option(LIBBACKTRACE "Print backtrace with libbacktrace." "OFF")
option(USE_HOME_DIR "Use user's home directory for save files." "ON")
option(LOCALIZE "Support for language localizations. Also enable UTF support." "ON")
option(LANGUAGES "Compile localization files for specified languages." "")
Expand Down Expand Up @@ -323,6 +324,9 @@ ENDIF(SOUND)

IF(BACKTRACE)
ADD_DEFINITIONS(-DBACKTRACE)
IF(LIBBACKTRACE)
ADD_DEFINITIONS(-DLIBBACKTRACE)
ENDIF(LIBBACKTRACE)
ENDIF(BACKTRACE)

# Ok. Now create build and install recipes
Expand Down
32 changes: 32 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,35 @@ CATCH unit-test framework (tests/catch/catch.hpp) is licensed under the Boost So
PLF List and PLF Colony (src/list.h, src/colony.h) are licensed under the zLib license (https://www.zlib.net/zlib_license.html).

getpost (tools/json_tools/format/getpost.h) is licensed under the MIT license, see file for text of license.

libbacktrace is licensed under a BSD license (https://github.com/ianlancetaylor/libbacktrace/blob/master/LICENSE). The full license text is as follows:

# Copyright (C) 2012-2016 Free Software Foundation, Inc.

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:

# (1) Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.

# (2) Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.

# (3) The name of the author may not be used to
# endorse or promote products derived from this software without
# specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
20 changes: 18 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
# make LOCALIZE=0
# Disable backtrace support, not available on all platforms
# make BACKTRACE=0
# Use libbacktrace. Only has effect if BACKTRACE=1. (currently only for MinGW builds)
# make LIBBACKTRACE=1
# Compile localization files for specified languages
# make localization LANGUAGES="<lang_id_1>[ lang_id_2][ ...]"
# (for example: make LANGUAGES="zh_CN zh_TW" for Chinese)
Expand Down Expand Up @@ -171,6 +173,14 @@ ifndef BACKTRACE
BACKTRACE = 1
endif
endif
ifdef BACKTRACE
# Also enable libbacktrace on cross-compilation to Windows
ifndef LIBBACKTRACE
ifneq (,$(findstring mingw32,$(CROSS)))
LIBBACKTRACE = 1
endif
endif
endif

ifeq ($(RUNTESTS), 1)
TESTS = tests
Expand All @@ -185,7 +195,7 @@ W32ODIR = $(BUILD_PREFIX)objwin
W32ODIRTILES = $(W32ODIR)/tiles

ifdef AUTO_BUILD_PREFIX
BUILD_PREFIX = $(if $(RELEASE),release-)$(if $(DEBUG_SYMBOLS),symbol-)$(if $(TILES),tiles-)$(if $(SOUND),sound-)$(if $(LOCALIZE),local-)$(if $(BACKTRACE),back-)$(if $(SANITIZE),sanitize-)$(if $(MAPSIZE),map-$(MAPSIZE)-)$(if $(USE_XDG_DIR),xdg-)$(if $(USE_HOME_DIR),home-)$(if $(DYNAMIC_LINKING),dynamic-)$(if $(MSYS2),msys2-)
BUILD_PREFIX = $(if $(RELEASE),release-)$(if $(DEBUG_SYMBOLS),symbol-)$(if $(TILES),tiles-)$(if $(SOUND),sound-)$(if $(LOCALIZE),local-)$(if $(BACKTRACE),back-$(if $(LIBBACKTRACE),libbacktrace-))$(if $(SANITIZE),sanitize-)$(if $(MAPSIZE),map-$(MAPSIZE)-)$(if $(USE_XDG_DIR),xdg-)$(if $(USE_HOME_DIR),home-)$(if $(DYNAMIC_LINKING),dynamic-)$(if $(MSYS2),msys2-)
export BUILD_PREFIX
endif

Expand Down Expand Up @@ -340,7 +350,7 @@ endif
CXXFLAGS += $(WARNINGS) $(DEBUG) $(DEBUGSYMS) $(PROFILE) $(OTHERS) -MMD -MP
TOOL_CXXFLAGS = -DCATA_IN_TOOL

BINDIST_EXTRAS += README.md data doc
BINDIST_EXTRAS += README.md data doc LICENSE.txt
BINDIST = $(BUILD_PREFIX)cataclysmdda-$(VERSION).tar.gz
W32BINDIST = $(BUILD_PREFIX)cataclysmdda-$(VERSION).zip
BINDIST_CMD = tar --transform=s@^$(BINDIST_DIR)@cataclysmdda-$(VERSION)@ -czvf $(BINDIST) $(BINDIST_DIR)
Expand Down Expand Up @@ -666,11 +676,17 @@ ifeq ($(TARGETSYSTEM),WINDOWS)
LDFLAGS += -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lversion
ifeq ($(BACKTRACE),1)
LDFLAGS += -ldbghelp
ifeq ($(LIBBACKTRACE),1)
LDFLAGS += -lbacktrace
endif
endif
endif

ifeq ($(BACKTRACE),1)
DEFINES += -DBACKTRACE
ifeq ($(LIBBACKTRACE),1)
DEFINES += -DLIBBACKTRACE
endif
endif

ifeq ($(LOCALIZE),1)
Expand Down
1 change: 1 addition & 0 deletions build-scripts/libbacktrace-i686-w64-mingw32-sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
52811183c904305ddfa28d4b2236cc14da5293cd4d038d02b57d53dc18701502 *libbacktrace-i686-w64-mingw32.tar.gz
7 changes: 7 additions & 0 deletions build-scripts/requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ if [ -n "${MXE_TARGET}" ]; then
# Need to overwrite CXX to make the Makefile $CROSS logic work right.
export CXX="$COMPILER"
export CCACHE=1

curl -L -o libbacktrace-i686-w64-mingw32.tar.gz https://github.com/Qrox/libbacktrace/releases/download/2020-01-03/libbacktrace-i686-w64-mingw32.tar.gz
if ! shasum -a 256 -c ./build-scripts/libbacktrace-i686-w64-mingw32-sha256; then
echo "Checksum failed for libbacktrace-i686-w64-mingw32.tar.gz"
exit 1
fi
sudo tar -xzf libbacktrace-i686-w64-mingw32.tar.gz --exclude=LICENSE -C ${MXE_DIR}/../${PLATFORM}
fi

if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
Expand Down
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ IF(TILES)
target_link_libraries(libcataclysm-tiles version.lib)
IF (BACKTRACE)
target_link_libraries(libcataclysm-tiles dbghelp.lib)
IF(LIBBACKTRACE)
target_link_libraries(libcataclysm-tiles backtrace)
ENDIF(LIBBACKTRACE)
ENDIF(BACKTRACE)
ENDIF(WIN32)

Expand Down Expand Up @@ -185,6 +188,9 @@ IF(CURSES)
target_link_libraries(libcataclysm version.lib)
IF (BACKTRACE)
target_link_libraries(libcataclysm dbghelp.lib)
IF(LIBBACKTRACE)
target_link_libraries(libcataclysm backtrace)
ENDIF(LIBBACKTRACE)
ENDIF(BACKTRACE)
ENDIF(WIN32)

Expand Down
Loading

0 comments on commit 764aa9f

Please sign in to comment.