Skip to content

Commit

Permalink
Use backward-cpp for a stack trace if we crash
Browse files Browse the repository at this point in the history
  • Loading branch information
mickelson committed Mar 3, 2022
1 parent d2daac4 commit 9c5de04
Show file tree
Hide file tree
Showing 5 changed files with 4,569 additions and 14 deletions.
1 change: 1 addition & 0 deletions Compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ distributions. Other distributions should have similar packages available.
- Xinerama (for multiple monitor support).
- libarchive (for .7z, .rar, .tar.gz and .tar.bz2 archive support).
- Libcurl (for network info/artwork scraping).
- Libdw, libbfd or libdwarf (for a pretty stack trace if we crash).

2. Extract the Attract-Mode source to your system.

Expand Down
63 changes: 49 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
#FE_HWACCEL_VAAPI=1
#FE_HWACCEL_VDPAU=1
#
# Uncomment the next line to build attract.debug file with debug symbols
#ENABLE_DEBUG_SYMBOLS=1
#
###############################

#FE_DEBUG=1
Expand All @@ -70,22 +73,24 @@ CC=gcc
CXX=g++
CFLAGS=$(EXTRA_CFLAGS)
STRIP=strip
OBJCOPY=objcopy
PKG_CONFIG=pkg-config
AR=ar
ARFLAGS=rc
RM=rm -f
MD=mkdir -p
WINDRES=windres

ifndef OPTIMIZE
OPTIMIZE=2
endif
-include attract.mk

OPTIMIZE ?= 2

ifndef VERBOSE
SILENT=@
SILENT = @
CC_MSG = @echo Compiling $@...
AR_MSG = @echo Archiving $@...
EXE_MSG = @echo Creating executable: $@
DEBUG_MSG = @echo Writing debug symbols: $@.debug
endif

ifneq ($(origin TOOLCHAIN),undefined)
Expand All @@ -100,19 +105,19 @@ override PKG_CONFIG := $(TOOLCHAIN)-$(PKG_CONFIG)
override WINDRES := $(TOOLCHAIN)-$(WINDRES)
endif

prefix=/usr/local
datarootdir=$(prefix)/share
datadir=$(datarootdir)
exec_prefix=$(prefix)
bindir=$(exec_prefix)/bin
prefix ?= /usr/local
datarootdir ?= $(prefix)/share
datadir ?= $(datarootdir)
exec_prefix ?= $(prefix)
bindir ?= $(exec_prefix)/bin

DATA_PATH:=$(datadir)/attract/
EXE_BASE=attract
EXE_EXT=
OBJ_DIR=obj
SRC_DIR=src
EXTLIBS_DIR=extlibs
FE_FLAGS=
FE_FLAGS :=

_DEP =\
fe_base.hpp \
Expand Down Expand Up @@ -305,8 +310,9 @@ endif
# Now process the various settings...
#
ifeq ($(FE_DEBUG),1)
CFLAGS += -g -Wall
CFLAGS += -Wall
FE_FLAGS += -DFE_DEBUG
ENABLE_DEBUG_SYMBOLS=1
else
CFLAGS += -O$(OPTIMIZE) -DNDEBUG
endif
Expand Down Expand Up @@ -397,6 +403,30 @@ ifeq ($(USE_LIBCURL),1)
_OBJ += fe_net.o
endif

ifeq ($(ENABLE_DEBUG_SYMBOLS),1)
CFLAGS += -g
#
# libs for pretty output from backward-cpp
#
ifeq ($(shell $(PKG_CONFIG) --exists libdw && echo "1" || echo "0"), 1)
TEMP_LIBS += libdw
CFLAGS +=-DBACKWARD_HAS_DW=1
_OBJ += backward.o
else
ifeq ($(shell $(PKG_CONFIG) --exists libbfd && echo "1" || echo "0"), 1)
TEMP_LIBS += libbfd
CFLAGS +=-g -DBACKWARD_HAS_BFD=1
_OBJ += backward.o
else
ifeq ($(shell $(PKG_CONFIG) --exists libdwarf && echo "1" || echo "0"), 1)
TEMP_LIBS += libdwarf
CFLAGS += -DBACKWARD_HAS_DWARF=1
_OBJ += backward.o
endif
endif
endif
endif

ifeq ($(NO_MOVIE),1)
FE_FLAGS += -DNO_MOVIE
ifeq ($(WINDOWS_STATIC),1)
Expand Down Expand Up @@ -497,8 +527,13 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.mm $(DEP) | $(OBJ_DIR)

$(EXE): $(OBJ) $(EXPAT) $(SQUIRREL) $(AUDIO)
$(EXE_MSG)
$(SILENT)$(CXX) -o $@ $^ $(CFLAGS) $(FE_FLAGS) $(LIBS)
ifneq ($(FE_DEBUG),1)
$(CXX) -o $@ $^ $(CFLAGS) $(FE_FLAGS) $(LIBS)
ifeq ($(ENABLE_DEBUG_SYMBOLS),1)
$(DEBUG_MSG)
$(SILENT)$(OBJCOPY) --only-keep-debug $@ [email protected]
$(SILENT)$(STRIP) --strip-debug --strip-unneeded $@
$(SILENT)$(OBJCOPY) [email protected] $@
else
$(SILENT)$(STRIP) $@
endif

Expand Down Expand Up @@ -777,4 +812,4 @@ smallclean:
-$(RM) $(OBJ_DIR)/*.o *~ core

clean:
-$(RM) $(OBJ_DIR)/*.o $(EXPAT_OBJ_DIR)/*.o $(SQUIRREL_OBJ_DIR)/*.o $(SQSTDLIB_OBJ_DIR)/*.o $(AUDIO_OBJ_DIR)/*.o $(NOWIDE_OBJ_DIR)/*.o $(GSBASE_OBJ_DIR)/*.o $(GAMESWF_OBJ_DIR)/*.o $(GAMESWF_OBJ_DIR)/gameswf_as_classes/*.o $(OBJ_DIR)/*.a $(OBJ_DIR)/*.res *~ core
-$(RM) $(OBJ_DIR)/*.o $(EXPAT_OBJ_DIR)/*.o $(SQUIRREL_OBJ_DIR)/*.o $(SQSTDLIB_OBJ_DIR)/*.o $(AUDIO_OBJ_DIR)/*.o $(NOWIDE_OBJ_DIR)/*.o $(GSBASE_OBJ_DIR)/*.o $(GAMESWF_OBJ_DIR)/*.o $(GAMESWF_OBJ_DIR)/gameswf_as_classes/*.o $(OBJ_DIR)/*.a $(OBJ_DIR)/*.res *~ core attract attract.debug
42 changes: 42 additions & 0 deletions src/backward.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Pick your poison.
//
// On GNU/Linux, you have few choices to get the most out of your stack trace.
//
// By default you get:
// - object filename
// - function name
//
// In order to add:
// - source filename
// - line and column numbers
// - source code snippet (assuming the file is accessible)

// Install one of the following libraries then uncomment one of the macro (or
// better, add the detection of the lib and the macro definition in your build
// system)

// - apt-get install libdw-dev ...
// - g++/clang++ -ldw ...
// #define BACKWARD_HAS_DW 1

// - apt-get install binutils-dev ...
// - g++/clang++ -lbfd ...
// #define BACKWARD_HAS_BFD 1

// - apt-get install libdwarf-dev ...
// - g++/clang++ -ldwarf ...
// #define BACKWARD_HAS_DWARF 1

// Regardless of the library you choose to read the debug information,
// for potentially more detailed stack traces you can use libunwind
// - apt-get install libunwind-dev
// - g++/clang++ -lunwind
// #define BACKWARD_HAS_LIBUNWIND 1

#include "backward.hpp"

namespace backward {

backward::SignalHandling sh;

} // namespace backward
Loading

0 comments on commit 9c5de04

Please sign in to comment.