1
0
mirror of https://github.com/winscp/winscp.git synced 2026-10-24 02:28:55 +03:00

Moving abnormal program termination handling to reduce interface

Source commit: 528cf0238d2af829fcc8481bd2452e1ba2ef7832
This commit is contained in:
Martin Prikryl
2026-10-16 09:02:13 +00:00
parent ec328f18f1
commit 53f8213112
4 changed files with 31 additions and 27 deletions

View File

@@ -9,31 +9,12 @@ USEFORM("forms\ScpExplorer.cpp", ScpExplorerForm);
//---------------------------------------------------------------------------
#include <ProgParams.h>
#include <PuttyTools.h>
#include <signal.h>
//---------------------------------------------------------------------------
void __fastcall AppLogImpl(UnicodeString S)
{
AppLog(S);
}
//---------------------------------------------------------------------------
NORETURN void TerminateHandler()
{
AppLog(L"Terminate handler");
abort();
}
//---------------------------------------------------------------------------
void AbortSignalHandler(int Signal)
{
AppLogFmt(L"Abort signal handler [%d]", (Signal));
UnicodeString Message = MainInstructions(L"Abnormal program termination");
std::unique_ptr<TStrings> MoreMessages(new TStringList());
UnicodeString ReportErrorText = Trim(FMTLOAD(REPORT_ERROR, (EmptyStr)));
MoreMessages->Add(ReportErrorText);
std::unique_ptr<TStrings> StackTrace(GetAbortStackTrace());
AppendStackTrace(MoreMessages.get(), StackTrace.get());
MoreMessageDialog(Message, MoreMessages.get(), qtError, qaOK | qaReport, EmptyStr);
}
//---------------------------------------------------------------------------
int WINAPI wWinMain(HINSTANCE, HINSTANCE, wchar_t *, int)
{
int Result = 0;
@@ -78,8 +59,7 @@ int WINAPI wWinMain(HINSTANCE, HINSTANCE, wchar_t *, int)
InitializeSystemSettings();
AddStartupSequence(L"S");
std::set_terminate(TerminateHandler);
signal(SIGABRT, AbortSignalHandler);
RegisterTerminateHandlers();
try
{

View File

@@ -39,10 +39,7 @@ class TOptions;
TOptions * __fastcall GetGlobalOptions();
void __fastcall ShowExtendedException(Exception * E);
void AppendStackTrace(TStrings * MoreMessages, TStrings * StackTrace);
bool AppendExceptionStackTrace(Exception * E, TStrings *& MoreMessages);
TStrings * GetCurrentStackTrace();
TStrings * GetAbortStackTrace();
void __fastcall IgnoreException(const std::type_info & ExceptionType);
UnicodeString GetExceptionDebugInfo(Exception * E);

View File

@@ -3,6 +3,7 @@
#pragma hdrstop
#include <shlwapi.h>
#include <signal.h>
#include <Queue.h>
#include <Glyphs.h>
@@ -675,7 +676,7 @@ UnicodeString GetExceptionDebugInfo(Exception * E)
return Result;
}
//---------------------------------------------------------------------------
void AppendStackTrace(TStrings * MoreMessages, TStrings * StackTrace)
static void AppendStackTrace(TStrings * MoreMessages, TStrings * StackTrace)
{
if (!MoreMessages->Text.IsEmpty())
{
@@ -785,7 +786,7 @@ static void FilterStackTrace(TStrings * StackTrace)
}
}
//---------------------------------------------------------------------------
TStrings * GetCurrentStackTrace()
static TStrings * GetCurrentStackTrace()
{
std::unique_ptr<TJclStackInfoList> StackInfoList(JclCreateStackList(false, 0, Caller(0, false)));
std::unique_ptr<TStrings> Result(StackInfoListToStrings(StackInfoList.get()));
@@ -830,7 +831,7 @@ bool IsValidCallSite64(ULONG_PTR CodeAddr)
}
#endif
//---------------------------------------------------------------------------
TStrings * GetAbortStackTrace()
static TStrings * GetAbortStackTrace()
{
// In 64-bit when abort handlers is called, the stack is already unwind, so we canot use JclCreateStackList,
// instread we walk stale raw stack data.
@@ -880,6 +881,30 @@ TStrings * GetAbortStackTrace()
#endif
}
//---------------------------------------------------------------------------
NORETURN static void TerminateHandler()
{
AppLog(L"Terminate handler");
abort();
}
//---------------------------------------------------------------------------
static void AbortSignalHandler(int Signal)
{
AppLogFmt(L"Abort signal handler [%d]", (Signal));
UnicodeString Message = MainInstructions(L"Abnormal program termination");
std::unique_ptr<TStrings> MoreMessages(new TStringList());
UnicodeString ReportErrorText = Trim(FMTLOAD(REPORT_ERROR, (EmptyStr)));
MoreMessages->Add(ReportErrorText);
std::unique_ptr<TStrings> StackTrace(GetAbortStackTrace());
AppendStackTrace(MoreMessages.get(), StackTrace.get());
MoreMessageDialog(Message, MoreMessages.get(), qtError, qaOK | qaReport, EmptyStr);
}
//---------------------------------------------------------------------------
void RegisterTerminateHandlers()
{
std::set_terminate(TerminateHandler);
signal(SIGABRT, AbortSignalHandler);
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void * __fastcall BusyStart()
{

View File

@@ -147,6 +147,8 @@ unsigned int __fastcall FatalExceptionMessageDialog(
Exception * E, TQueryType Type, const UnicodeString & MessageFormat, unsigned int Answers,
const UnicodeString & HelpKeyword, const TMessageParams * Params);
void RegisterTerminateHandlers();
// forms\Custom.cpp
TSessionData * __fastcall DoSaveSession(TSessionData * SessionData,
TSessionData * OriginalSession, bool ForceDialog,