From 9839fa79eaf134d045b693d40d2a4ce991bf988c Mon Sep 17 00:00:00 2001 From: taynpg Date: Wed, 16 Apr 2025 22:19:49 +0800 Subject: [PATCH] =?UTF-8?q?add=EF=BC=9A=E6=B7=BB=E5=8A=A0crash=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=EF=BC=88-DGRAB=5FCRASH=3DON=EF=BC=89=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .clang-tidy | 135 ------------------------------------------ .clangd | 9 --- .gitmodules | 3 + .vscode/settings.json | 26 ++++---- CMakeLists.txt | 6 ++ client/CMakeLists.txt | 4 ++ client/main.cpp | 21 ++++++- crashelper | 1 + server/CMakeLists.txt | 3 + server/main.cpp | 26 +++++--- 10 files changed, 66 insertions(+), 168 deletions(-) delete mode 100644 .clang-tidy delete mode 100644 .clangd create mode 160000 crashelper diff --git a/.clang-tidy b/.clang-tidy deleted file mode 100644 index 1f932b1..0000000 --- a/.clang-tidy +++ /dev/null @@ -1,135 +0,0 @@ -Checks: "-*, - - clang-*, - - google-build-explicit-make-pair, - google-build-namespaces, - google-default-arguments, - google-explicit-constructor, - google-readability-avoid-underscore-in-googletest-name, - google-runtime-int, - google-runtime-operator, - - - -readability-non-const-parameter, - readability-avoid-const-params-in-decls, - readability-const-return-type, - readability-container-size-empty, - -readability-convert-member-functions-to-static, - readability-delete-null-pointer, - readability-deleted-default, - readability-make-member-function-const, - readability-misplaced-array-index, - readability-qualified-auto, - readability-redundant-control-flow, - readability-redundant-function-ptr-dereference, - readability-redundant-smartptr-get, - readability-redundant-string-cstr, - readability-static-definition-in-anonymous-namespace, - readability-string-compare, - readability-uniqueptr-delete-release, - readability-redundant-member-init, - readability-simplify-subscript-expr, - readability-simplify-boolean-expr, - readability-inconsistent-declaration-parameter-name, - - cert-dcl21-cpp, - cert-dcl50-cpp, - # 不要使用 system() - -cert-env33-c, - cert-err34-c, - cert-err52-cpp, - cert-flp30-c, - cert-mem57-cpp, - cert-msc50-cpp, - cert-oop58-cpp, - - modernize-avoid-bind, - modernize-deprecated-headers, - modernize-loop-convert, - modernize-make-shared, - modernize-make-unique, - -modernize-pass-by-value, - modernize-raw-string-literal, - modernize-redundant-void-arg, - modernize-replace-auto-ptr, - modernize-shrink-to-fit, - modernize-use-bool-literals, - modernize-use-emplace, - modernize-use-equals-delete, - modernize-use-nullptr, - modernize-use-override, - - cppcoreguidelines-pro-type-reinterpret-cast, - -cppcoreguidelines-narrowing-conversions, - cppcoreguidelines-pro-type-member-init, - - misc-unconventional-assign-operator, - -misc-unused-parameters, - misc-throw-by-value-catch-by-reference, - misc-misplaced-const, - misc-redundant-expression, - misc-static-assert, - misc-uniqueptr-reset-release, - -misc-unused-alias-decls, - -misc-unused-using-decls, - - bugprone-undelegated-constructor, - bugprone-macro-parentheses, - bugprone-macro-repeated-side-effects, - bugprone-forward-declaration-namespace, - bugprone-bool-pointer-implicit-conversion, - bugprone-misplaced-widening-cast, - bugprone-argument-comment, - bugprone-bad-signal-to-kill-thread, - bugprone-copy-constructor-init, - bugprone-dangling-handle, - bugprone-fold-init-type, - bugprone-inaccurate-erase, - bugprone-incorrect-roundings, - bugprone-integer-division, - bugprone-misplaced-operator-in-strlen-in-alloc, - bugprone-misplaced-pointer-arithmetic-in-alloc, - bugprone-move-forwarding-reference, - bugprone-multiple-statement-macro, - bugprone-parent-virtual-call, - bugprone-posix-return, - bugprone-reserved-identifier, - bugprone-signed-char-misuse, - bugprone-sizeof-container, - bugprone-sizeof-expression, - bugprone-string-constructor, - bugprone-string-integer-assignment, - bugprone-string-literal-with-embedded-nul, - bugprone-suspicious-enum-usage, - bugprone-suspicious-include, - bugprone-suspicious-memset-usage, - bugprone-suspicious-missing-comma, - bugprone-suspicious-string-compare, - bugprone-swapped-arguments, - bugprone-terminating-continue, - bugprone-throw-keyword-missing, - bugprone-too-small-loop-variable, - bugprone-undefined-memory-manipulation, - bugprone-unhandled-self-assignment, - bugprone-unused-raii, - bugprone-unused-return-value, - bugprone-use-after-move, - bugprone-virtual-near-miss, - - hicpp-exception-baseclass, - hicpp-ignored-remove-result, - hicpp-no-assembler, - -hicpp-signed-bitwise, - - performance-faster-string-find, - performance-for-range-copy, - performance-implicit-conversion-in-loop, - performance-inefficient-algorithm, - performance-inefficient-vector-operation, - performance-move-constructor-init, - performance-no-automatic-move, - -performance-trivially-destructible, - performance-unnecessary-copy-initialization' - -WarningsAsErrors: "*" diff --git a/.clangd b/.clangd deleted file mode 100644 index 41d163f..0000000 --- a/.clangd +++ /dev/null @@ -1,9 +0,0 @@ -Hover: - ShowAKA: true -Diagnostics: - UnusedIncludes: None # 禁用未使用头文件提示 - Suppress: - - anon_type_definition # 禁用匿名的typedef提示 - - unused-variable # 禁用未使用变量提示 - - unused-function # 禁用未使用函数提示 - - unused-includes # 禁用未使用的头文件提示 \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index 03ec1af..303ab6a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,3 +6,6 @@ path = filecomplete url = https://www.sinxmiao.cn/taynpg/filecomplete branch = main +[submodule "crashelper"] + path = crashelper + url = https://www.sinxmiao.cn/taynpg/crashelper diff --git a/.vscode/settings.json b/.vscode/settings.json index d6f28a8..7525efd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,8 @@ { "files.autoSave": "onFocusChange", - "editor.fontSize": 14, + "editor.fontSize": 13, + "editor.fontFamily": "'Monaspace Krypton Light', 'Monaspace Krypton Light', 'Monaspace Krypton Light'", + "terminal.integrated.fontFamily": "Monaspace Krypton Light", "cmake.configureOnOpen": true, "cmake.debugConfig": { "console": "integratedTerminal", @@ -19,6 +21,10 @@ "9999" ] }, + "cmake.configureArgs": [ + "-Wno-dev", + "-DGRAB_CRASH=ON" + ], "cmake.configureSettings": { //"CMAKE_TOOLCHAIN_FILE": "${env:VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" }, @@ -31,17 +37,9 @@ "zh-hant": true, "zh-hans": true }, - "C_Cpp.intelliSenseEngine": "disabled", - "clangd.arguments": [ - "--header-insertion=never", - "--all-scopes-completion", - "--completion-style=detailed", - "-j=4", - "--clang-tidy", - "--pch-storage=memory", - "--compile-commands-dir=build", - "--background-index", - "--ranking-model=heuristics", - "--function-arg-placeholders=false" - ], + "files.associations": { + ".clang-tidy": "yaml", + "filesystem": "cpp", + "regex": "cpp" + } } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index dd4ea31..4685d16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,12 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}/ ) +if (DEFINED GRAB_CRASH) +message(STATUS "GRAB_CRASH ${GRAB_CRASH}") +add_subdirectory(crashelper/crashelper) +add_definitions(-DGRAB_CRASH) +endif() + add_definitions(-DFMT_HEADER_ONLY) include_directories(3rd) include_directories(.) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 9d17b45..301487c 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -24,6 +24,10 @@ if(DEFINED USE_BOOST) target_link_directories(tsc PRIVATE ${MBOOST_LIB_DIR}) target_link_libraries(tsc PRIVATE ${MBOOST_LIBS}) endif() +if (DEFINED GRAB_CRASH) +message(STATUS "tsc link crashelper") +target_link_libraries(tsc PRIVATE crashelper) +endif() if(UNIX) execute_process( COMMAND uname -a diff --git a/client/main.cpp b/client/main.cpp index 251f324..24d00f3 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -16,11 +16,21 @@ #endif #endif +#if defined(GRAB_CRASH) +#ifdef USE_BOOST +#include +namespace fs = boost::filesystem; +#else +#include +namespace fs = std::filesystem; +#endif +#include +#endif + std::shared_ptr g_Config = nullptr; int parse_cmd(int argc, char** argv, CmdParam& param) { - std::string intro( - fmt::format("tsc cmd introduce, version: {}\nopensource: {}", VERSION_NUM, VERSION_URL)); + std::string intro(fmt::format("tsc cmd introduce, version: {}\nopensource: {}", VERSION_NUM, VERSION_URL)); CLI::App app(intro); app.add_option("-u, --use", param.use_config, "使用服务器地址组(值为使用--show中显示的序号)"); @@ -156,6 +166,13 @@ bool exec_cmd(CmdParam& param, bool& run) int main(int argc, char* argv[]) { +#if defined(GRAB_CRASH) + auto config_dir = COfPath::get_config_dir("transm", true); + auto err = fs::path(config_dir).append("errs").string(); + backward::SetDumpFileSavePath(err); + backward::SetDumpLogSavePath(err); + CRASHELPER_MARK_ENTRY(); +#endif #ifdef _WIN32 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); diff --git a/crashelper b/crashelper new file mode 160000 index 0000000..eed787c --- /dev/null +++ b/crashelper @@ -0,0 +1 @@ +Subproject commit eed787c1bfc1ed1585843923673e27354be7c0bd diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index f3b327e..adcaebc 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -23,6 +23,9 @@ endif() if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_SYSTEM_NAME MATCHES "Windows") target_link_libraries(tss PRIVATE ws2_32 wsock32) endif() +if (DEFINED GRAB_CRASH) +target_link_libraries(tss PRIVATE crashelper) +endif() if(UNIX) execute_process( COMMAND uname -a diff --git a/server/main.cpp b/server/main.cpp index ef18d54..0c1ec5f 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -3,6 +3,7 @@ #include "server.h" #include "version.h" +#include #ifdef _WIN32 #include @@ -13,17 +14,26 @@ #endif #endif -void signal_handler(int signal) -{ - if (signal == SIGINT) { - fc_recovery_color(); - exit(signal); - } -} +#if defined(GRAB_CRASH) +#ifdef USE_BOOST +#include +namespace fs = boost::filesystem; +#else +#include +namespace fs = std::filesystem; +#endif +#include +#endif int main(int argc, char* argv[]) { - std::signal(SIGINT, signal_handler); +#if defined(GRAB_CRASH) + auto config_dir = COfPath::get_config_dir("transm", true); + auto err = fs::path(config_dir).append("errs").string(); + backward::SetDumpFileSavePath(err); + backward::SetDumpLogSavePath(err); + CRASHELPER_MARK_ENTRY(); +#endif #ifdef _WIN32 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);