Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(port): various debug.cpp improvements #3101

Merged
merged 20 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
sound: 0
lua: 0
test-stage: 1
libbacktrace: 1
title: GCC 12, Ubuntu, Curses
native: linux64
- compiler: g++-12
Expand All @@ -51,9 +52,10 @@ jobs:
sound: 1
lua: 1
test-stage: 1
title: GCC 11, Ubuntu, Tiles, Sound, Lua
libbacktrace: 1
title: GCC 12, Ubuntu, Tiles, Sound, Lua
native: linux64
- compiler: g++-11
- compiler: g++-12
os: ubuntu-22.04
cmake: 0
tiles: 1
Expand Down Expand Up @@ -95,6 +97,7 @@ jobs:
TEST_STAGE: ${{ matrix.test-stage }}
LANGUAGES: ${{ matrix.languages }}
EXTRA_TEST_OPTS:
LIBBACKTRACE: ${{ matrix.libbacktrace }}
NATIVE: ${{ matrix.native }}
RELEASE: 1
SKIP: ${{ needs.skip-duplicates.outputs.should_skip == 'true' }}
Expand Down
36 changes: 23 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ set(CATA_CLANG_TIDY_INCLUDE_DIR "" CACHE STRING "Path to internal clang-tidy hea
set(CATA_CHECK_CLANG_TIDY "" CACHE STRING "Path to check_clang_tidy.py for plugin tests")
set(GIT_BINARY "" CACHE STRING "Git binary name or path.")
set(PREFIX "" CACHE STRING "Location of Data & GFX directories")
set(LINKER "" CACHE STRING "Custom Linker to use")

include(CTest)

Expand All @@ -52,6 +53,10 @@ MESSAGE(STATUS "${PROJECT} build environment -- \n")

MESSAGE(STATUS "Build realm is : ${CMAKE_SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_PROCESSOR}")

IF(LINKER)
add_link_options("-fuse-ld=${LINKER}")
ENDIF()

IF(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
ENDIF(NOT CMAKE_BUILD_TYPE)
Expand All @@ -62,7 +67,7 @@ if (NOT ${GIT_VERSION} MATCHES GIT-NOTFOUND)
string(REPLACE "-NOTFOUND" "" GIT_VERSION ${GIT_VERSION})
FILE(WRITE ${CMAKE_SOURCE_DIR}/src/version.h
"// NOLINT(cata-header-guard)\n\#define VERSION \"${GIT_VERSION}\"\n")
MESSAGE(STATUS "${PROJECT_NAME} build version is : ${GIT_VERSION}\n")
MESSAGE(STATUS "${PROJECT_NAME} build version is : ${GIT_VERSION}\n")
ADD_DEFINITIONS(-DGIT_VERSION)
ELSE (NOT ${GIT_VERSION} MATCHES GIT-NOTFOUND)
MESSAGE("")
Expand Down Expand Up @@ -196,22 +201,27 @@ ELSE (CMAKE_BUILD_TYPE STREQUAL Debug)
ADD_DEFINITIONS(-DDATA_DIR_PREFIX)
ENDIF (PREFIX AND NOT WIN32)
ENDIF (CMAKE_BUILD_TYPE STREQUAL Debug)
MESSAGE(STATUS "GIT_BINARY : ${GIT_EXECUTABLE}")
MESSAGE(STATUS "DYNAMIC_LINKING : ${DYNAMIC_LINKING}")

MESSAGE(STATUS "TILES : ${TILES}")
MESSAGE(STATUS "CURSES : ${CURSES}")
MESSAGE(STATUS "SOUND : ${SOUND}")
MESSAGE(STATUS "LUA : ${LUA}")
MESSAGE(STATUS "BACKTRACE : ${BACKTRACE}")
MESSAGE(STATUS "USE_HOME_DIR : ${USE_HOME_DIR}\n")
MESSAGE(STATUS "GIT_BINARY : ${GIT_EXECUTABLE}")
MESSAGE(STATUS "DYNAMIC_LINKING : ${DYNAMIC_LINKING}")

MESSAGE(STATUS "UNITY_BUILD : ${USE_UNITY_BUILD}")
MESSAGE(STATUS "PCH_HEADER : ${USE_PCH_HEADER}")
MESSAGE(STATUS "TILES : ${TILES}")
MESSAGE(STATUS "CURSES : ${CURSES}")
MESSAGE(STATUS "SOUND : ${SOUND}")
MESSAGE(STATUS "LUA : ${LUA}")
MESSAGE(STATUS "BACKTRACE : ${BACKTRACE}")
MESSAGE(STATUS "LIBBACKTRACE : ${LIBBACKTRACE}")
MESSAGE(STATUS "USE_HOME_DIR : ${USE_HOME_DIR}\n")

MESSAGE(STATUS "LANGUAGES : ${LANGUAGES}\n")
MESSAGE(STATUS "UNITY_BUILD : ${USE_UNITY_BUILD}")
MESSAGE(STATUS "PCH_HEADER : ${USE_PCH_HEADER}")
MESSAGE(STATUS "LANGUAGES : ${LANGUAGES}\n")

IF(LINKER)
MESSAGE(STATUS "LINKER : ${LINKER}\n")
ENDIF()

MESSAGE(STATUS "See INSTALL file for details and more info --\n")
MESSAGE(STATUS "See INSTALL file for details and more info --\n")

IF(MSVC)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
Expand Down
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
# make TILES=1 SOUND=1
# Disable backtrace support, not available on all platforms
# make BACKTRACE=0
# Use libbacktrace. Only has effect if BACKTRACE=1. (currently only for MinGW builds)
# Use libbacktrace. Only has effect if BACKTRACE=1. (currently only for MinGW and Linux builds)
# make LIBBACKTRACE=1
# Compile localization files for specified languages
# make localization LANGUAGES="<lang_id_1>[ lang_id_2][ ...]"
Expand Down Expand Up @@ -399,7 +399,11 @@ ifeq ($(RELEASE), 1)
OTHERS += $(RELEASE_FLAGS)
DEBUG =
ifndef DEBUG_SYMBOLS
DEBUGSYMS =
ifeq ($(LIBBACKTRACE), 1)
DEBUGSYMS = -g1
else
DEBUGSYMS =
endif
endif
DEFINES += -DRELEASE
# Check for astyle or JSON regressions on release builds.
Expand Down Expand Up @@ -763,16 +767,14 @@ 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
LDFLAGS += -lbacktrace
endif
endif

Expand Down Expand Up @@ -827,7 +829,7 @@ ifeq ($(LUA), 1)
DEFINES += -DLUA
LUA_OBJS = $(sort $(LUA_SOURCES:$(LUA_SRC_DIR)/%.c=$(ODIRLUA)/%.o))
else
LUA_OBJS =
LUA_OBJS =
endif

ifdef LANGUAGES
Expand Down
3 changes: 2 additions & 1 deletion build-scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ then
-DCMAKE_BUILD_TYPE="$build_type" \
-DTILES=${TILES:-0} \
-DSOUND=${SOUND:-0} \
-DLIBBACKTRACE=${LIBBACKTRACE:-0} \
"${cmake_extra_opts[@]}" \
..
if [ -n "$CATA_CLANG_TIDY" ]
Expand Down Expand Up @@ -149,7 +150,7 @@ else
else
export BACKTRACE=1
fi
make -j "$num_jobs" RELEASE=1 CCACHE=1 CROSS="$CROSS_COMPILATION" LANGUAGES="all" LINTJSON=0
make -j "$num_jobs" RELEASE=1 CCACHE=1 CROSS="$CROSS_COMPILATION" LANGUAGES="all" LINTJSON=0 LIBBACKTRACE="$LIBBACKTRACE"

export UBSAN_OPTIONS=print_stacktrace=1
if [ "$OS" == "macos-12" ]
Expand Down
11 changes: 11 additions & 0 deletions build-scripts/requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ set -x
echo "::add-matcher::build-scripts/problem-matchers/catch2.json"
echo "::add-matcher::build-scripts/problem-matchers/debugmsg.json"

if [[ "$LIBBACKTRACE" == "1" ]]; then
git clone https://github.com/ianlancetaylor/libbacktrace.git
(
cd libbacktrace
git checkout 4d2dd0b172f2c9192f83ba93425f868f2a13c553
./configure
make -j$(nproc)
sudo make install
)
fi

if [ -n "$CATA_CLANG_TIDY" ]; then
pip install --user wheel --upgrade
pip install --user 'lit==0.11.1' 'click==7.1.2'
Expand Down
42 changes: 32 additions & 10 deletions doc/COMPILING/COMPILING-CMAKE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ For official way to build CataclysmBN See:

# Contents

* [Prerequisites](#prerequisites)
* [Build Environment](#build-environment)
* [UNIX Environment](#unix-environment)
* [Windows Environment](#windows-environment-msys2)
* [CMake Build](#cmake-build)
* [MinGW,MSYS,MSYS2](#cmake-build-for-msys2-mingw)
* [MSBuild, VisualStudio](#cmake-build-for-visual-studio--msbuild)
* [Build Options](#build-options)
* [CMake specific options](#cmake-specific-options)
* [CataclysmBN specific options])(#cataclysmbn-specific-options)
- [Disclaimer](#disclaimer)
- [Contents](#contents)
- [Prerequisites](#prerequisites)
- [Build Environment](#build-environment)
- [UNIX Environment](#unix-environment)
- [Windows Environment (MSYS2)](#windows-environment-msys2)
- [CMake Build](#cmake-build)
- [CMake Build for MSYS2 (MinGW)](#cmake-build-for-msys2-mingw)
- [CMake Build for Visual Studio / MSBuild](#cmake-build-for-visual-studio--msbuild)
- [Build Options](#build-options)
- [CMake specific options](#cmake-specific-options)
- [CataclysmBN specific options](#cataclysmbn-specific-options)

# Prerequisites

Expand Down Expand Up @@ -321,6 +323,26 @@ Run the game. Should work.

Use dynamic linking. Or use static to remove MinGW dependency instead.

* CUSTOM LINKER=`<str>`

Choose custom linkers such as [gold], [lld] or [mold].

- Choose ld if you don't use libbacktrace.
- Choose mold if use libbacktrace. It's the fastest linker, outperforming gold by 24x.

[gold]: https://en.wikipedia.org/wiki/Gold_(linker)
[lld]: https://lld.llvm.org
[mold]: https://github.com/rui314/mold

* BACKTRACE=`<boolean>`

On crash, print a backtrace to the console. Defaults to `ON` for debug builds.

* LIBBACKTRACE=`<boolean>`

Print backtrace with [libbacktrace]. This allows lld and mold to print backtrace, and is generally much faster.

[libbacktrace]: https://github.com/ianlancetaylor/libbacktrace

* GIT_BINARY=`<str>`

Expand Down
2 changes: 1 addition & 1 deletion src/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ LOCAL_SHARED_LIBRARIES := libhidapi SDL2 SDL2_mixer SDL2_image SDL2_ttf mpg123

LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog

LOCAL_CFLAGS += -DTILES=1 -DSDL_SOUND=1 -DLUA=1 -DCATA_NO_CPP11_STRING_CONVERSIONS=1 -Wextra -Wall -fsigned-char -ffast-math
LOCAL_CFLAGS += -DTILES=1 -DSDL_SOUND=1 -DLUA=1 -DBACKTRACE=1 -Wextra -Wall -fsigned-char -ffast-math

LOCAL_LDFLAGS += $(LOCAL_CFLAGS)

Expand Down
16 changes: 8 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ IF(TILES)

IF(BACKTRACE)
target_link_libraries(cataclysm-tiles-common dbghelp.lib)

IF(LIBBACKTRACE)
target_link_libraries(cataclysm-tiles-common backtrace)
ENDIF(LIBBACKTRACE)
ENDIF(BACKTRACE)
ENDIF(WIN32)

IF(LIBBACKTRACE)
target_link_libraries(cataclysm-tiles-common backtrace)
ENDIF(LIBBACKTRACE)

IF(RELEASE)
install(TARGETS cataclysm-tiles DESTINATION ${BIN_PREFIX})
ENDIF(RELEASE)
Expand Down Expand Up @@ -205,13 +205,13 @@ IF(CURSES)

IF(BACKTRACE)
target_link_libraries(cataclysm-common dbghelp.lib)

IF(LIBBACKTRACE)
target_link_libraries(cataclysm-common backtrace)
ENDIF(LIBBACKTRACE)
ENDIF(BACKTRACE)
ENDIF(WIN32)

IF(LIBBACKTRACE)
target_link_libraries(cataclysm-common backtrace)
ENDIF(LIBBACKTRACE)

IF(RELEASE)
install(TARGETS cataclysm DESTINATION ${BIN_PREFIX})
ENDIF(RELEASE)
Expand Down
17 changes: 17 additions & 0 deletions src/crash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ extern "C" {
#endif
const std::string crash_log_file = PATH_INFO::crash();
std::ostringstream log_text;
#if defined(__ANDROID__)
// At this point, Android JVM is already doomed
// No further UI interaction (including the SDL message box)
// Show a dialogue at next launch
log_text << "VERSION: " << getVersionString()
<< '\n' << type << ' ' << msg;
#else
log_text << "The program has crashed."
<< "\nSee the log file for a stack trace."
<< "\nCRASH LOG FILE: " << crash_log_file
Expand All @@ -66,6 +73,7 @@ extern "C" {
log_text.str().c_str(), nullptr ) != 0 ) {
log_text << "Error creating SDL message box: " << SDL_GetError() << '\n';
}
#endif
#endif
log_text << "\nSTACK TRACE:\n";
debug_write_backtrace( log_text );
Expand All @@ -75,6 +83,15 @@ extern "C" {
fwrite( log_text.str().data(), 1, log_text.str().size(), file );
fclose( file );
}
#if defined(__ANDROID__)
// Create a placeholder dummy file "config/crash.log.prompt"
// to let the app show a dialog box at next start
file = fopen( ( crash_log_file + ".prompt" ).c_str(), "w" );
if( file ) {
fwrite( "0", 1, 1, file );
fclose( file );
}
#endif
}

static void signal_handler( int sig )
Expand Down
Loading