Merge branch 'develop' of https://github.com/pvpgn/pvpgn-server into develop

This commit is contained in:
RElesgoe 2018-05-16 19:26:25 -07:00
commit 64386a81b7
9 changed files with 150 additions and 69 deletions

View file

@ -46,6 +46,23 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
message(FATAL_ERROR "Visual Studio 2015 or higher required")
endif()
# DEBUG compiler flags:
# /Zi create debugging information PDB file
# /Od disable optimizations
# /Oy- do not suppress frame pointers (recommended for debugging)
# /MTd use statically linked, thread-safe, debug CRT libs (Magic Builder set this flag when build)
#
# RELEASE compiler flags:
# /MT use statically linked, thread-safe CRT libs (Magic Builder set this flag when build)
# /GS- no Buffer Security Check
#
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Zi /Od /Oy-")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
# Explaining of linker flags and why enable pdb with debug info for Release build is on:
# https://www.wintellect.com/correctly-creating-native-c-release-build-pdbs
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
endif()
subdirs(src conf man files)

View file

@ -22,7 +22,7 @@ environment:
db_id: 5
configuration:
- Debug
# - Debug
- Release
matrix:
@ -39,14 +39,16 @@ install:
- cmd: mkdir c:\builder\source\
- cmd: xcopy /E /R /K /Y /Q "c:\pvpgn" "c:\builder\source\"
- cmd: cd c:\builder\
- cmd: mkdir bkp
- cmd: mkdir bin
- cmd: mkdir pdb
before_build:
- cmd: set APPVEYOR_REPO_COMMIT_SHORT=%APPVEYOR_REPO_COMMIT:~0,7%
# read version string from version.h to %PVPGN_VERSION% and append commit string inside that file
- cmd: module\tools\pvpgn_version.bat %APPVEYOR_REPO_COMMIT_SHORT%
- cmd: set COMPLETE_BUILD_VERSION=pvpgn-%APPVEYOR_REPO_BRANCH%-%PVPGN_VERSION%-%APPVEYOR_REPO_COMMIT_SHORT%
- ps: $env:PVPGN_ZIP=$env:COMPLETE_BUILD_VERSION + "_" + $env:DB + $(If ($env:CONFIGURATION -eq "Debug") {"_debug"} Else {""}) + ".zip"
- ps: $env:PVPGN_ZIP=$env:COMPLETE_BUILD_VERSION + "_" + $env:DB + $(If ($env:CONFIGURATION -ne "Release") {"_" + ($env:CONFIGURATION).ToLower()} Else {""}) + ".zip"
- ps: $env:PVPGN_PDB_ZIP=$env:COMPLETE_BUILD_VERSION + "_" + $env:DB + $(If ($env:CONFIGURATION -ne "Release") {"_" + ($env:CONFIGURATION).ToLower()} Else {".pdb"}) + ".zip"
build_script:
@ -59,15 +61,22 @@ build_script:
# 5. with or without lua
# 6. Release or Debug
# gui
- cmd: build_pvpgn.bat auto auto 2 %DB_ID% y %CONFIGURATION%
- cmd: copy /Y %CONFIGURATION%\* bkp\* # backup gui exe/pdb files
- cmd: move /Y %CONFIGURATION%\*.pdb pdb\ # move pdb files
- cmd: copy /Y %CONFIGURATION%\* bin\ # backup binary files
# console
- cmd: build_pvpgn.bat auto auto 1 %DB_ID% y %CONFIGURATION%
- cmd: move /Y bkp\* %CONFIGURATION% # move back after build console versions
- cmd: move /Y %CONFIGURATION%\*.pdb pdb\ # move pdb files
- cmd: move /Y bin\* %CONFIGURATION% # move back binaries after build console version
# create zip artifacts
- cmd: 7z.exe a %PVPGN_ZIP% .\%CONFIGURATION%\*
- cmd: 7z.exe a %PVPGN_PDB_ZIP% .\pdb\*
deploy_script:
- ps: |
Push-AppveyorArtifact $env:PVPGN_ZIP
Push-AppveyorArtifact $env:PVPGN_PDB_ZIP
# check the latest build executable for exists
test:

View file

@ -88,6 +88,9 @@
#include "handle_apireg.h"
#include "i18n.h"
#include "userlog.h"
#ifdef WIN32
#include "win32/windump.h"
#endif
#include "common/setup_after.h"
#ifdef WITH_LUA
@ -530,6 +533,11 @@ extern int app_main(int argc, char ** argv)
extern int main(int argc, char ** argv)
#endif
{
#ifdef WIN32
// create a dump file whenever the gateway crashes
SetUnhandledExceptionFilter(unhandled_handler);
#endif
try {
int a;
char *pidfile;

View file

@ -37,6 +37,9 @@
#ifdef WIN32_GUI
# include "win32/winmain.h"
#endif
#ifdef WIN32
# include "win32/windump.h"
#endif
#include "compat/stdfileno.h"
#include "compat/pgetpid.h"
@ -253,6 +256,11 @@ extern int main(int argc, char ** argv)
{
int pid;
#ifdef WIN32
// create a dump file whenever the gateway crashes
SetUnhandledExceptionFilter(unhandled_handler);
#endif
eventlog_set(stderr);
if (!((pid = config_init(argc, argv)) == 0)) {
// if (pid==1) pid=0;

View file

@ -38,6 +38,9 @@
#ifdef WIN32_GUI
# include "win32/winmain.h"
#endif
#ifdef WIN32
# include "win32/windump.h"
#endif
#include "compat/stdfileno.h"
#include "compat/pgetpid.h"
@ -233,6 +236,11 @@ extern int main(int argc, char ** argv)
int pid;
char * pidfile;
#ifdef WIN32
// create a dump file whenever the gateway crashes
SetUnhandledExceptionFilter(unhandled_handler);
#endif
eventlog_set(stderr);
pid = config_init(argc, argv);
if (!(pid == 0)) {

View file

@ -1,5 +1,5 @@
set(WIN32_SOURCES
service.cpp service.h console_output.h console_output.cpp dirent.h
service.cpp service.h console_output.h console_output.cpp dirent.h windump.cpp windump.h
)
add_library(win32 ${WIN32_SOURCES})

71
src/win32/windump.cpp Normal file
View file

@ -0,0 +1,71 @@
/*
* Copyright (C) 2018 HarpyWar (harpywar@gmail.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef WIN32
#include <windows.h>
#include <Dbghelp.h>
void make_minidump(struct _EXCEPTION_POINTERS* e)
{
auto hDbgHelp = LoadLibraryA("dbghelp");
if (hDbgHelp == nullptr)
return;
auto pMiniDumpWriteDump = (decltype(&MiniDumpWriteDump))GetProcAddress(hDbgHelp, "MiniDumpWriteDump");
if (pMiniDumpWriteDump == nullptr)
return;
char name[MAX_PATH];
{
auto nameEnd = name + GetModuleFileNameA(GetModuleHandleA(0), name, MAX_PATH);
SYSTEMTIME t;
GetSystemTime(&t);
wsprintfA(nameEnd - strlen(".exe"),
"_%4d%02d%02d_%02d%02d%02d.dmp",
t.wYear, t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond);
}
auto hFile = CreateFileA(name, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (hFile == INVALID_HANDLE_VALUE)
return;
MINIDUMP_EXCEPTION_INFORMATION exceptionInfo;
exceptionInfo.ThreadId = GetCurrentThreadId();
exceptionInfo.ExceptionPointers = e;
exceptionInfo.ClientPointers = FALSE;
auto dumped = pMiniDumpWriteDump(
GetCurrentProcess(),
GetCurrentProcessId(),
hFile,
MINIDUMP_TYPE(MiniDumpWithIndirectlyReferencedMemory | MiniDumpScanMemory),
e ? &exceptionInfo : nullptr,
nullptr,
nullptr);
CloseHandle(hFile);
return;
}
LONG WINAPI unhandled_handler(struct _EXCEPTION_POINTERS* e)
{
make_minidump(e);
return EXCEPTION_CONTINUE_SEARCH;
}
#endif

23
src/win32/windump.h Normal file
View file

@ -0,0 +1,23 @@
/*
* Copyright (C) 2018 HarpyWar (harpywar@gmail.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef WIN32
#include "windows.h""
LONG WINAPI unhandled_handler(struct _EXCEPTION_POINTERS* e);
#endif

View file

@ -31,9 +31,6 @@
#include <windows.h>
#if _DEBUG
#include <dbghelp.h>
#endif
#include <windowsx.h>
#include <winuser.h>
#include <process.h>
@ -873,72 +870,12 @@ namespace pvpgn
}
#if _DEBUG
void make_minidump(EXCEPTION_POINTERS* e)
{
HMODULE hDbgHelp = LoadLibraryW(L"dbghelp.dll");
if (hDbgHelp == nullptr)
return;
auto pMiniDumpWriteDump = reinterpret_cast<decltype(&MiniDumpWriteDump)>(GetProcAddress(hDbgHelp, "MiniDumpWriteDump"));
if (pMiniDumpWriteDump == nullptr)
{
FreeLibrary(hDbgHelp);
return;
}
wchar_t name[MAX_PATH] = {};
{
auto nameEnd = name + GetModuleFileNameW(GetModuleHandleW(nullptr), name, MAX_PATH);
SYSTEMTIME t;
GetSystemTime(&t);
wsprintfW(nameEnd - std::wcslen(L".exe"), L"_%4d%02d%02d_%02d%02d%02d.dmp", t.wYear, t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond);
}
auto hFile = CreateFileW(name, GENERIC_WRITE, FILE_SHARE_READ, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (hFile == INVALID_HANDLE_VALUE)
{
FreeLibrary(hDbgHelp);
return;
}
MINIDUMP_EXCEPTION_INFORMATION exceptionInfo = {};
exceptionInfo.ThreadId = GetCurrentThreadId();
exceptionInfo.ExceptionPointers = e;
exceptionInfo.ClientPointers = FALSE;
auto dumped = pMiniDumpWriteDump(
GetCurrentProcess(),
GetCurrentProcessId(),
hFile,
MINIDUMP_TYPE(MiniDumpWithIndirectlyReferencedMemory | MiniDumpScanMemory),
e ? &exceptionInfo : nullptr,
nullptr,
nullptr);
CloseHandle(hFile);
FreeLibrary(hDbgHelp);
return;
}
LONG CALLBACK unhandled_handler(EXCEPTION_POINTERS* e)
{
make_minidump(e);
return EXCEPTION_CONTINUE_SEARCH;
}
#endif
using namespace pvpgn;
using namespace pvpgn::bnetd;
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE reserved, LPSTR lpCmdLine, int nCmdShow)
{
#if _DEBUG
SetUnhandledExceptionFilter(unhandled_handler);
#endif
Console console;
if (cmdline_load(__argc, __argv) != 1)