Skip to content

Commit 764aa9f

Browse files
QroxZhilkinSerg
authored andcommitted
Use libbacktrace to generate readable backtrace on Windows (CleverRaven#36615)
* 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
1 parent 238ab4b commit 764aa9f

8 files changed

+262
-232
lines changed

CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ option(TILES "Build graphical tileset version." "OFF")
1515
option(CURSES "Build curses version." "ON")
1616
option(SOUND "Support for in-game sounds & music." "OFF")
1717
option(BACKTRACE "Support for printing stack backtraces on crash" "ON")
18+
option(LIBBACKTRACE "Print backtrace with libbacktrace." "OFF")
1819
option(USE_HOME_DIR "Use user's home directory for save files." "ON")
1920
option(LOCALIZE "Support for language localizations. Also enable UTF support." "ON")
2021
option(LANGUAGES "Compile localization files for specified languages." "")
@@ -323,6 +324,9 @@ ENDIF(SOUND)
323324

324325
IF(BACKTRACE)
325326
ADD_DEFINITIONS(-DBACKTRACE)
327+
IF(LIBBACKTRACE)
328+
ADD_DEFINITIONS(-DLIBBACKTRACE)
329+
ENDIF(LIBBACKTRACE)
326330
ENDIF(BACKTRACE)
327331

328332
# Ok. Now create build and install recipes

LICENSE.txt

+32
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,35 @@ CATCH unit-test framework (tests/catch/catch.hpp) is licensed under the Boost So
99
PLF List and PLF Colony (src/list.h, src/colony.h) are licensed under the zLib license (https://www.zlib.net/zlib_license.html).
1010

1111
getpost (tools/json_tools/format/getpost.h) is licensed under the MIT license, see file for text of license.
12+
13+
libbacktrace is licensed under a BSD license (https://github.com/ianlancetaylor/libbacktrace/blob/master/LICENSE). The full license text is as follows:
14+
15+
# Copyright (C) 2012-2016 Free Software Foundation, Inc.
16+
17+
# Redistribution and use in source and binary forms, with or without
18+
# modification, are permitted provided that the following conditions are
19+
# met:
20+
21+
# (1) Redistributions of source code must retain the above copyright
22+
# notice, this list of conditions and the following disclaimer.
23+
24+
# (2) Redistributions in binary form must reproduce the above copyright
25+
# notice, this list of conditions and the following disclaimer in
26+
# the documentation and/or other materials provided with the
27+
# distribution.
28+
29+
# (3) The name of the author may not be used to
30+
# endorse or promote products derived from this software without
31+
# specific prior written permission.
32+
33+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
34+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
35+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36+
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
37+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
38+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
39+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
41+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
42+
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43+
# POSSIBILITY OF SUCH DAMAGE.

Makefile

+18-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
# make LOCALIZE=0
4141
# Disable backtrace support, not available on all platforms
4242
# make BACKTRACE=0
43+
# Use libbacktrace. Only has effect if BACKTRACE=1. (currently only for MinGW builds)
44+
# make LIBBACKTRACE=1
4345
# Compile localization files for specified languages
4446
# make localization LANGUAGES="<lang_id_1>[ lang_id_2][ ...]"
4547
# (for example: make LANGUAGES="zh_CN zh_TW" for Chinese)
@@ -171,6 +173,14 @@ ifndef BACKTRACE
171173
BACKTRACE = 1
172174
endif
173175
endif
176+
ifdef BACKTRACE
177+
# Also enable libbacktrace on cross-compilation to Windows
178+
ifndef LIBBACKTRACE
179+
ifneq (,$(findstring mingw32,$(CROSS)))
180+
LIBBACKTRACE = 1
181+
endif
182+
endif
183+
endif
174184

175185
ifeq ($(RUNTESTS), 1)
176186
TESTS = tests
@@ -185,7 +195,7 @@ W32ODIR = $(BUILD_PREFIX)objwin
185195
W32ODIRTILES = $(W32ODIR)/tiles
186196

187197
ifdef AUTO_BUILD_PREFIX
188-
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-)
198+
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-)
189199
export BUILD_PREFIX
190200
endif
191201

@@ -340,7 +350,7 @@ endif
340350
CXXFLAGS += $(WARNINGS) $(DEBUG) $(DEBUGSYMS) $(PROFILE) $(OTHERS) -MMD -MP
341351
TOOL_CXXFLAGS = -DCATA_IN_TOOL
342352

343-
BINDIST_EXTRAS += README.md data doc
353+
BINDIST_EXTRAS += README.md data doc LICENSE.txt
344354
BINDIST = $(BUILD_PREFIX)cataclysmdda-$(VERSION).tar.gz
345355
W32BINDIST = $(BUILD_PREFIX)cataclysmdda-$(VERSION).zip
346356
BINDIST_CMD = tar --transform=s@^$(BINDIST_DIR)@cataclysmdda-$(VERSION)@ -czvf $(BINDIST) $(BINDIST_DIR)
@@ -666,11 +676,17 @@ ifeq ($(TARGETSYSTEM),WINDOWS)
666676
LDFLAGS += -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lversion
667677
ifeq ($(BACKTRACE),1)
668678
LDFLAGS += -ldbghelp
679+
ifeq ($(LIBBACKTRACE),1)
680+
LDFLAGS += -lbacktrace
681+
endif
669682
endif
670683
endif
671684

672685
ifeq ($(BACKTRACE),1)
673686
DEFINES += -DBACKTRACE
687+
ifeq ($(LIBBACKTRACE),1)
688+
DEFINES += -DLIBBACKTRACE
689+
endif
674690
endif
675691

676692
ifeq ($(LOCALIZE),1)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
52811183c904305ddfa28d4b2236cc14da5293cd4d038d02b57d53dc18701502 *libbacktrace-i686-w64-mingw32.tar.gz

build-scripts/requirements.sh

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ if [ -n "${MXE_TARGET}" ]; then
5353
# Need to overwrite CXX to make the Makefile $CROSS logic work right.
5454
export CXX="$COMPILER"
5555
export CCACHE=1
56+
57+
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
58+
if ! shasum -a 256 -c ./build-scripts/libbacktrace-i686-w64-mingw32-sha256; then
59+
echo "Checksum failed for libbacktrace-i686-w64-mingw32.tar.gz"
60+
exit 1
61+
fi
62+
sudo tar -xzf libbacktrace-i686-w64-mingw32.tar.gz --exclude=LICENSE -C ${MXE_DIR}/../${PLATFORM}
5663
fi
5764

5865
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then

src/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ IF(TILES)
123123
target_link_libraries(libcataclysm-tiles version.lib)
124124
IF (BACKTRACE)
125125
target_link_libraries(libcataclysm-tiles dbghelp.lib)
126+
IF(LIBBACKTRACE)
127+
target_link_libraries(libcataclysm-tiles backtrace)
128+
ENDIF(LIBBACKTRACE)
126129
ENDIF(BACKTRACE)
127130
ENDIF(WIN32)
128131

@@ -185,6 +188,9 @@ IF(CURSES)
185188
target_link_libraries(libcataclysm version.lib)
186189
IF (BACKTRACE)
187190
target_link_libraries(libcataclysm dbghelp.lib)
191+
IF(LIBBACKTRACE)
192+
target_link_libraries(libcataclysm backtrace)
193+
ENDIF(LIBBACKTRACE)
188194
ENDIF(BACKTRACE)
189195
ENDIF(WIN32)
190196

0 commit comments

Comments
 (0)