From 55ae07fd5831af32e47f75e41cd814fc3f83333d Mon Sep 17 00:00:00 2001 From: wingsummer <1326224942@qq.com> Date: Wed, 12 Feb 2025 23:13:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Linux=20=E7=9A=84?= =?UTF-8?q?=E5=B4=A9=E6=BA=83=E6=8A=A5=E5=91=8A=E4=BD=BF=E7=94=A8=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TestPlugin/lang/TestPlugin_zh_CN.ts | 45 +++++------ TestPlugin/testplugin.cpp | 34 ++++++++- TestPlugin/testplugin.h | 4 + lang/zh_CN/winghex_zh_CN.ts | 114 ++++++++++++++-------------- lang/zh_TW/winghex_zh_TW.ts | 114 ++++++++++++++-------------- src/class/crashhandler.cpp | 9 +++ src/control/editorview.cpp | 1 - src/plugin/pluginsystem.cpp | 1 - 8 files changed, 180 insertions(+), 142 deletions(-) diff --git a/TestPlugin/lang/TestPlugin_zh_CN.ts b/TestPlugin/lang/TestPlugin_zh_CN.ts index 04a86bb..dfb4c98 100644 --- a/TestPlugin/lang/TestPlugin_zh_CN.ts +++ b/TestPlugin/lang/TestPlugin_zh_CN.ts @@ -296,59 +296,60 @@ TestPlugin - + Test 测试 - - - + + + TestPlugin 测试插件 - + Button - 按钮 - - + Click 点击 - + A Test Plugin for WingHexExplorer2. 一个用来测试羽云十六进制编辑器2的插件 - - + - - - - - - - - - - + + + + + + + + + + + + InvalidParamsCount 无效参数个数 - - + + InvalidParam 非法参数 - + AllocArrayFailed 分配数组失败 diff --git a/TestPlugin/testplugin.cpp b/TestPlugin/testplugin.cpp index 52f190c..a49cbdf 100644 --- a/TestPlugin/testplugin.cpp +++ b/TestPlugin/testplugin.cpp @@ -166,6 +166,15 @@ TestPlugin::TestPlugin() : WingHex::IWingPlugin() { info.ret = MetaType::Bool; _scriptInfo.insert(QStringLiteral("pluginMetaTestEnabled"), info); } + + { + WingHex::IWingPlugin::ScriptFnInfo info; + info.fn = std::bind( + QOverload::of(&TestPlugin::testCrash), this, + std::placeholders::_1); + info.ret = MetaType::Void; + _scriptInfo.insert(QStringLiteral("testCrash"), info); + } } TestPlugin::~TestPlugin() { destoryTestShareMem(); } @@ -437,10 +446,10 @@ TestPlugin::colorTable(const QList ¶ms) { } auto invoked = - emit invokeService(QStringLiteral("WingAngelAPI"), "vector2AsArray", - WINGAPI_RETURN_ARG(void *, array), - WINGAPI_ARG(MetaType, MetaType::Color), - WINGAPI_ARG(QVector, colors)); + invokeService(QStringLiteral("WingAngelAPI"), "vector2AsArray", + WINGAPI_RETURN_ARG(void *, array), + WINGAPI_ARG(MetaType, MetaType::Color), + WINGAPI_ARG(QVector, colors)); if (invoked) { if (array) { qDeleteAll(colors); @@ -496,6 +505,14 @@ QVariant TestPlugin::pluginMetaTestEnabled(const QVariantList ¶ms) { return pluginMetaTestEnabled(); } +QVariant TestPlugin::testCrash(const QVariantList ¶ms) { + if (!params.isEmpty()) { + return getScriptCallError(-1, tr("InvalidParamsCount")); + } + testCrash(); + return {}; +} + void TestPlugin::test_a() { emit debug(__FUNCTION__); } void TestPlugin::test_b(const QString &b) { @@ -604,6 +621,15 @@ void TestPlugin::setPluginMetaTestEnabled(bool b) { bool TestPlugin::pluginMetaTestEnabled() { return ENABLE_META; } +void TestPlugin::testCrash() { + // if you want to reproduce nullptr deferenced, + // you can use this example. 'volatile' is important in release mode + // volatile int *a = nullptr; + // (*a)++; + + abort(); +} + QHash TestPlugin::registeredScriptFns() const { return _scriptInfo; diff --git a/TestPlugin/testplugin.h b/TestPlugin/testplugin.h index a2d0eab..15f4307 100644 --- a/TestPlugin/testplugin.h +++ b/TestPlugin/testplugin.h @@ -91,6 +91,8 @@ private: QVariant setPluginMetaTestEnabled(const QVariantList ¶ms); QVariant pluginMetaTestEnabled(const QVariantList ¶ms); + QVariant testCrash(const QVariantList ¶ms); + private: void test_a(); void test_b(const QString &b); @@ -110,6 +112,8 @@ private: void setPluginMetaTestEnabled(bool b); bool pluginMetaTestEnabled(); + void testCrash(); + private: QDialog *_tform = nullptr; QMenu *_tmenu = nullptr; diff --git a/lang/zh_CN/winghex_zh_CN.ts b/lang/zh_CN/winghex_zh_CN.ts index d922d89..aaad219 100644 --- a/lang/zh_CN/winghex_zh_CN.ts +++ b/lang/zh_CN/winghex_zh_CN.ts @@ -332,67 +332,67 @@ EditorView - + Cut 剪切 - + CutHex 剪切(十六进制) - + Copy 复制 - + CopyHex 复制(十六进制) - + Paste 粘贴 - + PasteHex 粘贴(十六进制) - + Delete 删除 - + Find 查找 - + Goto 跳转 - + Fill 填充 - + MetaData 标注 - + BookMark 书签 - + Untitled 未命名 @@ -2216,210 +2216,210 @@ PluginSystem - + LoadingPlugin 加载插件中: - + InvalidPluginBrokenInfo 加载插件失败:损坏的插件数据 - + AppClosingCanceled: 程序关闭被取消: - + - PluginID: - 插件 ID: - + FoundDrvPluginCount 总计发现设备拓展插件数目: - + RegisterScriptFnUnSupportedTypes: 因脚本函数含有未支持的类型而注册失败: - - + + RegisterScriptFnInvalidSig: 因脚本函数签名非法而注册失败: - - + + RegisterScriptFnConflitSig: 因脚本函数签名冲突而注册失败: - + InvalidEnumName: 非法枚举名: - + InvalidEnumValue: 非法枚举值: - + InvalidMarcosRegister: 非法宏注册: - + ErrLoadPluginSign 插件加载失败:非法插件签名! - + ErrLoadPluginSDKVersion 插件加载失败:非法插件 SDK 版本! - + ErrLoadPluginNoName 插件加载失败:非法插件名称! - + ErrLoadInitPlugin 插件加载失败:初始化插件失败! - + PluginName : 插件名: - + PluginAuthor : 插件作者: - + PluginWidgetRegister 注册插件对象中…… - + ErrLoadExtPluginSign 设备拓展插件加载失败:非法插件签名! - + ErrLoadExtPluginSDKVersion 设备拓展插件加载失败:非法插件 SDK 版本! - + ExtPluginAuthor : 设备拓展插件作者: - + ExtPluginWidgetRegister 设备拓展注册插件对象中…… - + ErrLoadInitExtPlugin 设备拓展插件加载失败:初始化插件失败! - + ChooseFile 选择文件 - - + + Error 错误 - + FileNotExist 文件不存在! - + FilePermission 因文件权限无法继续! - + EmptyNameDockWidget: 空的贴边组件名: - + InvalidNameDockWidget: 无效贴边组件名: - + InvalidNullDockWidget: 无效空贴边组件: - + [EvilCall] 【恶意调用】 - + Not allowed operation in non-UI thread 该操作在非 UI 线程非法 - + UnsafePluginDir 不安全的插件目录,请将插件目录设置为仅管理员账户可写 - + InvalidPluginID 加载插件失败:非法插件标识符 - + InvalidDupPlugin 加载插件失败:重复的插件标识符 - + FoundPluginCount 总计发现插件数目: - + PluginLoadingFailedSummary 有依赖插件加载失败总结 - + - Dependencies: - 依赖: - + PUID: 插件唯一标志符: - + Version: 版本: - + PluginLoadingFinished 加载插件完毕! diff --git a/lang/zh_TW/winghex_zh_TW.ts b/lang/zh_TW/winghex_zh_TW.ts index 639baea..f7e64f6 100644 --- a/lang/zh_TW/winghex_zh_TW.ts +++ b/lang/zh_TW/winghex_zh_TW.ts @@ -332,67 +332,67 @@ EditorView - + Cut 剪切 - + CutHex 剪切(十六進制) - + Copy 複製 - + CopyHex 複製(十六進制) - + Paste 粘貼 - + PasteHex 粘貼(十六進制) - + Delete 刪除 - + Find 查找 - + Goto 跳轉 - + Fill 填充 - + MetaData 標注 - + BookMark 書簽 - + Untitled 未命名 @@ -2216,210 +2216,210 @@ PluginSystem - + LoadingPlugin 加載插件中: - + InvalidPluginBrokenInfo 加載插件失敗:損壞的插件數據 - + AppClosingCanceled: 程式關閉被取消: - + - PluginID: - 插件 ID: - + FoundDrvPluginCount 總計發現設備拓展插件數目: - + RegisterScriptFnUnSupportedTypes: 因腳本函數含有未支持的類型而註冊失敗: - - + + RegisterScriptFnInvalidSig: 因腳本函數簽名非法而註冊失敗: - - + + RegisterScriptFnConflitSig: 因腳本函數簽名衝突而註冊失敗: - + InvalidEnumName: 非法枚舉名: - + InvalidEnumValue: 非法枚舉值: - + InvalidMarcosRegister: 非法宏註冊: - + ErrLoadPluginSign 插件加載失敗:非法插件簽名! - + ErrLoadPluginSDKVersion 插件加載失敗:非法插件 SDK 版本! - + ErrLoadPluginNoName 插件加載失敗:非法插件名稱! - + ErrLoadInitPlugin 插件加載失敗:初始化插件失敗! - + PluginName : 插件名: - + PluginAuthor : 插件作者: - + PluginWidgetRegister 註冊插件對象中…… - + ErrLoadExtPluginSign 設備拓展插件加載失敗:非法插件簽名! - + ErrLoadExtPluginSDKVersion 設備拓展插件加載失敗:非法插件 SDK 版本! - + ExtPluginAuthor : 設備拓展插件作者: - + ExtPluginWidgetRegister 設備拓展註冊插件對象中…… - + ErrLoadInitExtPlugin 設備拓展插件加載失敗:初始化插件失敗! - + ChooseFile 選擇檔 - - + + Error 錯誤 - + FileNotExist 檔不存在! - + FilePermission 因檔許可權無法繼續! - + EmptyNameDockWidget: 空的貼邊組件名: - + InvalidNameDockWidget: 無效貼邊組件名: - + InvalidNullDockWidget: 無效空貼邊組件: - + [EvilCall] 【惡意調用】 - + Not allowed operation in non-UI thread 該操作在非 UI 線程非法 - + UnsafePluginDir 不安全的插件目錄,請將插件目錄設置為僅管理員帳戶可寫 - + InvalidPluginID 加載插件失敗:非法插件識別字 - + InvalidDupPlugin 加載插件失敗:重複的插件識別字 - + FoundPluginCount 總計發現插件數目: - + PluginLoadingFailedSummary 有依賴插件加載失敗總結 - + - Dependencies: - 依賴: - + PUID: 插件唯一標誌符: - + Version: 版本: - + PluginLoadingFinished 加載插件完畢! diff --git a/src/class/crashhandler.cpp b/src/class/crashhandler.cpp index 05a163a..af5d269 100644 --- a/src/class/crashhandler.cpp +++ b/src/class/crashhandler.cpp @@ -39,7 +39,10 @@ void CrashHandler::init() { ::SetUnhandledExceptionFilter(ExceptionFilter); #else ::signal(SIGSEGV, signalHandler); + ::signal(SIGILL, signalHandler); ::signal(SIGABRT, signalHandler); + ::signal(SIGFPE, signalHandler); + ::signal(SIGBUS, signalHandler); #endif } @@ -58,6 +61,7 @@ void CrashHandler::reportCrashAndExit() { ss << Qt::endl; + // we should keep this exception free auto &plgsys = PluginSystem::instance(); ss << QStringLiteral("Plugin System:") << Qt::endl; ss << QStringLiteral("* Loading: ") << plgsys.currentLoadingPlugin() @@ -122,5 +126,10 @@ void CrashHandler::reportCrashAndExit() { r.setInfomation(buffer); r.exec(); +#ifdef Q_OS_LINUX + // because abort() will also trigger it + ::signal(SIGABRT, nullptr); +#endif + abort(); } diff --git a/src/control/editorview.cpp b/src/control/editorview.cpp index 60f4980..1b4cf72 100644 --- a/src/control/editorview.cpp +++ b/src/control/editorview.cpp @@ -32,7 +32,6 @@ #include #ifdef Q_OS_LINUX -#include "class/scopeguard.h" #include #endif diff --git a/src/plugin/pluginsystem.cpp b/src/plugin/pluginsystem.cpp index d611b0c..3846679 100644 --- a/src/plugin/pluginsystem.cpp +++ b/src/plugin/pluginsystem.cpp @@ -38,7 +38,6 @@ #include #include #include -#include PluginSystem::PluginSystem(QObject *parent) : QObject(parent) {}