[Ttssh2-commit] [9124] 起動時にデバグ用コンソールをオープンできるようにした

アーカイブの一覧に戻る
scmno****@osdn***** scmno****@osdn*****
2021年 1月 16日 (土) 14:19:56 JST


Revision: 9124
          https://osdn.net/projects/ttssh2/scm/svn/commits/9124
Author:   zmatsuo
Date:     2021-01-16 14:19:55 +0900 (Sat, 16 Jan 2021)
Log Message:
-----------
起動時にデバグ用コンソールをオープンできるようにした

- デバグ用 ttdebug.h,cpp を追加
- 例外発生時の処理を ttdebug.cpp に移動

Modified Paths:
--------------
    trunk/teraterm/teraterm/CMakeLists.txt
    trunk/teraterm/teraterm/debug_pp.cpp
    trunk/teraterm/teraterm/teraterm.cpp
    trunk/teraterm/teraterm/ttermpro.v16.vcxproj
    trunk/teraterm/teraterm/ttermpro.v16.vcxproj.filters
    trunk/teraterm/teraterm/ttermpro.v8.vcproj
    trunk/teraterm/teraterm/vtterm.c
    trunk/teraterm/teraterm/vtwin.cpp

Added Paths:
-----------
    trunk/teraterm/teraterm/ttdebug.cpp
    trunk/teraterm/teraterm/ttdebug.h

-------------- next part --------------
Modified: trunk/teraterm/teraterm/CMakeLists.txt
===================================================================
--- trunk/teraterm/teraterm/CMakeLists.txt	2021-01-03 06:35:28 UTC (rev 9123)
+++ trunk/teraterm/teraterm/CMakeLists.txt	2021-01-16 05:19:55 UTC (rev 9124)
@@ -60,6 +60,8 @@
   teraterml.h
   ttdde.c
   ttdde.h
+  ttdebug.cpp
+  ttdebug.h
   ttdialog.c
   ttdialog.h
   ttfileio.c
@@ -259,6 +261,7 @@
 
 target_link_libraries(
   teraterm
+  PRIVATE
   common_static
   ttpcmn
   #ttpfile

Modified: trunk/teraterm/teraterm/debug_pp.cpp
===================================================================
--- trunk/teraterm/teraterm/debug_pp.cpp	2021-01-03 06:35:28 UTC (rev 9123)
+++ trunk/teraterm/teraterm/debug_pp.cpp	2021-01-16 05:19:55 UTC (rev 9124)
@@ -34,7 +34,7 @@
 #include "tt_res.h"
 #include "debug_pp.h"
 #include "../common/tt_res.h"
-#include "unicode_test.h"
+#include "ttdebug.h"
 #include "dlglib.h"
 #include "compat_win.h"
 #include "setting.h"
@@ -93,14 +93,8 @@
 			const char *caption;
 			HWND hWnd = pGetConsoleWindow();
 			if (hWnd == NULL) {
-				FILE *fp;
-				AllocConsole();
-				freopen_s(&fp, "CONOUT$", "w", stdout);
-				freopen_s(&fp, "CONOUT$", "w", stderr);
+				DebugConsoleOpen();
 				caption = "Hide console window";
-				hWnd = pGetConsoleWindow();
-				HMENU hmenu = GetSystemMenu(hWnd, FALSE);
-				RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND);
 			}
 			else {
 				if (::IsWindowVisible(hWnd)) {

Modified: trunk/teraterm/teraterm/teraterm.cpp
===================================================================
--- trunk/teraterm/teraterm/teraterm.cpp	2021-01-03 06:35:28 UTC (rev 9123)
+++ trunk/teraterm/teraterm/teraterm.cpp	2021-01-16 05:19:55 UTC (rev 9124)
@@ -57,6 +57,7 @@
 #include "teraterml.h"
 #include "sendmem.h"
 #include "layer_for_unicode.h"
+#include "ttdebug.h"
 
 #if defined(_DEBUG) && defined(_MSC_VER)
 #define new ::new(_NORMAL_BLOCK, __FILE__, __LINE__)
@@ -110,7 +111,11 @@
 {
 	DLLInit();
 	WinCompatInit();
+	DebugSetException();
 	LoadSpecialFont();
+#if defined(DEBUG_OPEN_CONSOLE_AT_STARTUP)
+	DebugConsoleOpen();
+#endif
 }
 
 // Tera Term main engine

Added: trunk/teraterm/teraterm/ttdebug.cpp
===================================================================
--- trunk/teraterm/teraterm/ttdebug.cpp	                        (rev 0)
+++ trunk/teraterm/teraterm/ttdebug.cpp	2021-01-16 05:19:55 UTC (rev 9124)
@@ -0,0 +1,271 @@
+/*
+ * (C) 2020- TeraTerm Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <windows.h>
+#include <stdio.h>
+#include <imagehlp.h>
+
+#include "compat_win.h"
+
+#include "ttdebug.h"
+
+/**
+ *	\x83R\x83\x93\x83\\x81[\x83\x8B\x83E\x83B\x83\x93\x83h\x83E\x82\xF0\x95\\x8E\xA6\x82\xB7\x82\xE9\x83f\x83o\x83O\x97p
+ *		\x83f\x83o\x83O\x97p\x82ɖ\x84\x82ߍ\x9E\x82\xF1\x82\xBEprintf()\x8Cn\x82\xF0\x95\\x8E\xA6\x82\xB7\x82邱\x82Ƃ\xAA\x82ł\xAB\x82\xE9\x82悤\x82ɂȂ\xE9
+ *
+ *	@retval	\x83R\x83\x93\x83\\x81[\x83\x8B\x82\xCCWindow Handle
+ */
+HWND DebugConsoleOpen(void)
+{
+	FILE *fp;
+	HWND hWnd = pGetConsoleWindow();
+	if (hWnd != NULL) {
+		return hWnd;
+	}
+	AllocConsole();
+	freopen_s(&fp, "CONOUT$", "w", stdout);
+	freopen_s(&fp, "CONOUT$", "w", stderr);
+
+	// \x95‚\xB6\x82\xE9\x83{\x83^\x83\x93\x82𖳌\xF8\x89\xBB
+	hWnd = pGetConsoleWindow();
+	HMENU hmenu = GetSystemMenu(hWnd, FALSE);
+	RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND);
+
+	return hWnd;
+}
+
+//
+// \x97\xE1\x8AO\x83n\x83\x93\x83h\x83\x89\x82̃t\x83b\x83N\x81i\x83X\x83^\x83b\x83N\x83g\x83\x8C\x81[\x83X\x82̃_\x83\x93\x83v\x81j
+//
+// cf. http://svn.collab.net/repos/svn/trunk/subversion/libsvn_subr/win32_crashrpt.c
+// (2007.9.30 yutaka)
+//
+// \x97\xE1\x8AO\x83R\x81[\x83h\x82𕶎\x9A\x97\xF1\x82֕ϊ\xB7\x82\xB7\x82\xE9
+#if !defined(_M_X64)
+static const char *GetExceptionString(DWORD exception)
+{
+#define EXCEPTION(x) case EXCEPTION_##x: return (#x);
+	static char buf[16];
+
+	switch (exception)
+	{
+		EXCEPTION(ACCESS_VIOLATION)
+		EXCEPTION(DATATYPE_MISALIGNMENT)
+		EXCEPTION(BREAKPOINT)
+		EXCEPTION(SINGLE_STEP)
+		EXCEPTION(ARRAY_BOUNDS_EXCEEDED)
+		EXCEPTION(FLT_DENORMAL_OPERAND)
+		EXCEPTION(FLT_DIVIDE_BY_ZERO)
+		EXCEPTION(FLT_INEXACT_RESULT)
+		EXCEPTION(FLT_INVALID_OPERATION)
+		EXCEPTION(FLT_OVERFLOW)
+		EXCEPTION(FLT_STACK_CHECK)
+		EXCEPTION(FLT_UNDERFLOW)
+		EXCEPTION(INT_DIVIDE_BY_ZERO)
+		EXCEPTION(INT_OVERFLOW)
+		EXCEPTION(PRIV_INSTRUCTION)
+		EXCEPTION(IN_PAGE_ERROR)
+		EXCEPTION(ILLEGAL_INSTRUCTION)
+		EXCEPTION(NONCONTINUABLE_EXCEPTION)
+		EXCEPTION(STACK_OVERFLOW)
+		EXCEPTION(INVALID_DISPOSITION)
+		EXCEPTION(GUARD_PAGE)
+		EXCEPTION(INVALID_HANDLE)
+
+	default:
+		_snprintf_s(buf, sizeof(buf), _TRUNCATE, "0x%x", exception);
+		return buf;
+		//return "UNKNOWN_ERROR";
+	}
+#undef EXCEPTION
+}
+
+/* \x97\xE1\x8AO\x94\xAD\x90\xB6\x8E\x9E\x82Ɋ֐\x94\x82̌Ăяo\x82\xB5\x97\x9A\x97\xF0\x82\xF0\x95\\x8E\xA6\x82\xB7\x82\xE9\x81A\x97\xE1\x8AO\x83t\x83B\x83\x8B\x83^\x8A֐\x94 */
+static LONG CALLBACK ApplicationFaultHandler(EXCEPTION_POINTERS *ExInfo)
+{
+	HGLOBAL gptr;
+	STACKFRAME sf;
+	BOOL bResult;
+	PIMAGEHLP_SYMBOL pSym;
+	DWORD Disp;
+	HANDLE hProcess = GetCurrentProcess();
+	HANDLE hThread = GetCurrentThread();
+	IMAGEHLP_MODULE	ih_module;
+	IMAGEHLP_LINE	ih_line;
+	int frame;
+	char msg[3072], buf[256];
+	HMODULE h, h2;
+	char imagehlp_dll[MAX_PATH];
+
+	// Windows98/Me/NT4\x82ł͓\xAE\x82\xA9\x82Ȃ\xA2\x82\xBD\x82߃X\x83L\x83b\x83v\x82\xB7\x82\xE9\x81B(2007.10.9 yutaka)
+	GetSystemDirectory(imagehlp_dll, sizeof(imagehlp_dll));
+	strncat_s(imagehlp_dll, sizeof(imagehlp_dll), "\\imagehlp.dll", _TRUNCATE);
+	h2 = LoadLibrary(imagehlp_dll);
+	if (((h = GetModuleHandle(imagehlp_dll)) == NULL) ||
+		(GetProcAddress(h, "SymGetLineFromAddr") == NULL)) {
+			FreeLibrary(h2);
+			goto error;
+	}
+	FreeLibrary(h2);
+
+	/* \x83V\x83\x93\x83{\x83\x8B\x8F\xEE\x95\xF1\x8Ai\x94[\x97p\x83o\x83b\x83t\x83@\x82̏\x89\x8A\xFA\x89\xBB */
+	gptr = GlobalAlloc(GMEM_FIXED, 10000);
+	if (gptr == NULL) {
+		goto error;
+	}
+	pSym = (PIMAGEHLP_SYMBOL)GlobalLock(gptr);
+	ZeroMemory(pSym, sizeof(IMAGEHLP_SYMBOL));
+	pSym->SizeOfStruct = 10000;
+	pSym->MaxNameLength = 10000 - sizeof(IMAGEHLP_SYMBOL);
+
+	/* \x83X\x83^\x83b\x83N\x83t\x83\x8C\x81[\x83\x80\x82̏\x89\x8A\xFA\x89\xBB */
+	ZeroMemory(&sf, sizeof(sf));
+	sf.AddrPC.Offset = ExInfo->ContextRecord->Eip;
+	sf.AddrStack.Offset = ExInfo->ContextRecord->Esp;
+	sf.AddrFrame.Offset = ExInfo->ContextRecord->Ebp;
+	sf.AddrPC.Mode = AddrModeFlat;
+	sf.AddrStack.Mode = AddrModeFlat;
+	sf.AddrFrame.Mode = AddrModeFlat;
+
+	/* \x83V\x83\x93\x83{\x83\x8B\x83n\x83\x93\x83h\x83\x89\x82̏\x89\x8A\xFA\x89\xBB */
+	SymInitialize(hProcess, NULL, TRUE);
+
+	// \x83\x8C\x83W\x83X\x83^\x83_\x83\x93\x83v
+	msg[0] = '\0';
+	_snprintf_s(buf, sizeof(buf), _TRUNCATE, "eax=%08X ebx=%08X ecx=%08X edx=%08X esi=%08X edi=%08X\r\n"
+		   "ebp=%08X esp=%08X eip=%08X efl=%08X\r\n"
+		   "cs=%04X ss=%04X ds=%04X es=%04X fs=%04X gs=%04X\r\n",
+		   ExInfo->ContextRecord->Eax,
+		   ExInfo->ContextRecord->Ebx,
+		   ExInfo->ContextRecord->Ecx,
+		   ExInfo->ContextRecord->Edx,
+		   ExInfo->ContextRecord->Esi,
+		   ExInfo->ContextRecord->Edi,
+		   ExInfo->ContextRecord->Ebp,
+		   ExInfo->ContextRecord->Esp,
+		   ExInfo->ContextRecord->Eip,
+		   ExInfo->ContextRecord->EFlags,
+		   ExInfo->ContextRecord->SegCs,
+		   ExInfo->ContextRecord->SegSs,
+		   ExInfo->ContextRecord->SegDs,
+		   ExInfo->ContextRecord->SegEs,
+		   ExInfo->ContextRecord->SegFs,
+		   ExInfo->ContextRecord->SegGs
+	);
+	strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
+
+	if (ExInfo->ExceptionRecord != NULL) {
+		_snprintf_s(buf, sizeof(buf), _TRUNCATE, "Exception: %s\r\n", GetExceptionString(ExInfo->ExceptionRecord->ExceptionCode));
+		strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
+	}
+
+	/* \x83X\x83^\x83b\x83N\x83t\x83\x8C\x81[\x83\x80\x82\xF0\x8F\x87\x82ɕ\\x8E\xA6\x82\xB5\x82Ă\xA2\x82\xAD */
+	frame = 0;
+	for (;;) {
+		/* \x8E\x9F\x82̃X\x83^\x83b\x83N\x83t\x83\x8C\x81[\x83\x80\x82̎擾 */
+		bResult = StackWalk(
+			IMAGE_FILE_MACHINE_I386,
+			hProcess,
+			hThread,
+			&sf,
+			NULL,
+			NULL,
+			SymFunctionTableAccess,
+			SymGetModuleBase,
+			NULL);
+
+		/* \x8E\xB8\x94s\x82Ȃ\xE7\x82΁A\x83\x8B\x81[\x83v\x82𔲂\xAF\x82\xE9 */
+		if (!bResult || sf.AddrFrame.Offset == 0)
+			break;
+
+		frame++;
+
+		/* \x83v\x83\x8D\x83O\x83\x89\x83\x80\x83J\x83E\x83\x93\x83^\x81i\x89\xBC\x91z\x83A\x83h\x83\x8C\x83X\x81j\x82\xA9\x82\xE7\x8A֐\x94\x96\xBC\x82ƃI\x83t\x83Z\x83b\x83g\x82\xF0\x8E擾 */
+		bResult = SymGetSymFromAddr(hProcess, sf.AddrPC.Offset, &Disp, pSym);
+
+		/* \x8E擾\x8C\x8B\x89ʂ\xF0\x95\\x8E\xA6 */
+		_snprintf_s(buf, sizeof(buf), _TRUNCATE, "#%d  0x%08x in ", frame, sf.AddrPC.Offset);
+		strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
+		if (bResult) {
+			_snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s() + 0x%x ", pSym->Name, Disp);
+			strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
+		} else {
+			_snprintf_s(buf, sizeof(buf), _TRUNCATE, " --- ");
+			strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
+		}
+
+		// \x8E\xC0\x8Ds\x83t\x83@\x83C\x83\x8B\x96\xBC\x82̎擾
+		ZeroMemory( &(ih_module), sizeof(ih_module) );
+		ih_module.SizeOfStruct = sizeof(ih_module);
+		bResult = SymGetModuleInfo( hProcess, sf.AddrPC.Offset, &(ih_module) );
+		strncat_s(msg, sizeof(msg), "at ", _TRUNCATE);
+		if (bResult) {
+			_snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s ", ih_module.ImageName );
+			strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
+		} else {
+			_snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s ", "<Unknown Module>" );
+			strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
+		}
+
+		// \x83t\x83@\x83C\x83\x8B\x96\xBC\x82ƍs\x94ԍ\x86\x82̎擾
+		ZeroMemory( &(ih_line), sizeof(ih_line) );
+		ih_line.SizeOfStruct = sizeof(ih_line);
+		bResult = SymGetLineFromAddr( hProcess, sf.AddrPC.Offset, &Disp, &ih_line );
+		if (bResult)
+		{
+			_snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s:%lu", ih_line.FileName, ih_line.LineNumber );
+			strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
+		}
+
+		strncat_s(msg, sizeof(msg), "\n", _TRUNCATE);
+	}
+
+	/* \x8C㏈\x97\x9D */
+	SymCleanup(hProcess);
+	GlobalUnlock(pSym);
+	GlobalFree(pSym);
+
+	// \x97\xE1\x8AO\x8F\x88\x97\x9D\x92\x86\x82Ȃ̂ŁAAPI\x82𒼐ڌĂяo\x82\xB7
+	::MessageBoxA(NULL, msg, "Tera Term: Application fault", MB_OK | MB_ICONEXCLAMATION);
+
+error:
+//	return (EXCEPTION_EXECUTE_HANDLER);  /* \x82\xBB\x82̂܂܃v\x83\x8D\x83Z\x83X\x82\xF0\x8FI\x97\xB9\x82\xB3\x82\xB9\x82\xE9 */
+	return (EXCEPTION_CONTINUE_SEARCH);  /* \x88\xF8\x82\xAB\x91\xB1\x82\xAB\x81m\x83A\x83v\x83\x8A\x83P\x81[\x83V\x83\x87\x83\x93\x83G\x83\x89\x81[\x81n\x83|\x83b\x83v\x83A\x83b\x83v\x83\x81\x83b\x83Z\x81[\x83W\x83{\x83b\x83N\x83X\x82\xF0\x8CĂяo\x82\xB7 */
+}
+#endif // !defined(_M_X64 )
+
+
+/**
+ *  \x97\xE1\x8AO\x83n\x83\x93\x83h\x83\x89\x82̃t\x83b\x83N
+ */
+void DebugSetException(void)
+{
+#if !defined(_M_X64)
+	SetUnhandledExceptionFilter(ApplicationFaultHandler);
+#endif
+}

Added: trunk/teraterm/teraterm/ttdebug.h
===================================================================
--- trunk/teraterm/teraterm/ttdebug.h	                        (rev 0)
+++ trunk/teraterm/teraterm/ttdebug.h	2021-01-16 05:19:55 UTC (rev 9124)
@@ -0,0 +1,46 @@
+/*
+ * (C) 2020- TeraTerm Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <windows.h>
+
+// \x8BN\x93\xAE\x8E\x9E\x82Ƀf\x83o\x83O\x97p\x83R\x83\x93\x83\\x81[\x83\x8B\x82\xF0\x83I\x81[\x83v\x83\x93\x82\xB7\x82\xE9
+// #define DEBUG_OPEN_CONSOLE_AT_STARTUP 1
+
+// \x93\xFC\x97̓R\x81[\x83h\x82\xF0\x83_\x83\x93\x83v\x82\xB7\x82\xE9
+// #define DEBUG_DUMP_INPUTCODE 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void DebugSetException(void);
+HWND DebugConsoleOpen(void);
+
+#ifdef __cplusplus
+}
+#endif

Modified: trunk/teraterm/teraterm/ttermpro.v16.vcxproj
===================================================================
--- trunk/teraterm/teraterm/ttermpro.v16.vcxproj	2021-01-03 06:35:28 UTC (rev 9123)
+++ trunk/teraterm/teraterm/ttermpro.v16.vcxproj	2021-01-16 05:19:55 UTC (rev 9124)
@@ -169,6 +169,7 @@
     <ClCompile Include="teraprn.cpp" />
     <ClCompile Include="teraterm.cpp" />
     <ClCompile Include="ttdde.c" />
+    <ClCompile Include="ttdebug.cpp" />
     <ClCompile Include="ttdialog.c" />
     <ClCompile Include="ttfileio.c" />
     <ClCompile Include="ttime.c" />
@@ -266,6 +267,7 @@
     <ClInclude Include="telnet.h" />
     <ClInclude Include="teraprn.h" />
     <ClInclude Include="ttdde.h" />
+    <ClInclude Include="ttdebug.h" />
     <ClInclude Include="ttdialog.h" />
     <ClInclude Include="ttfileio.h" />
     <ClInclude Include="ttime.h" />
@@ -310,4 +312,4 @@
       <UserProperties RESOURCE_FILE="ttermpro.rc" />
     </VisualStudio>
   </ProjectExtensions>
-</Project>
\ No newline at end of file
+</Project>

Modified: trunk/teraterm/teraterm/ttermpro.v16.vcxproj.filters
===================================================================
--- trunk/teraterm/teraterm/ttermpro.v16.vcxproj.filters	2021-01-03 06:35:28 UTC (rev 9123)
+++ trunk/teraterm/teraterm/ttermpro.v16.vcxproj.filters	2021-01-16 05:19:55 UTC (rev 9124)
@@ -183,6 +183,9 @@
     <ClCompile Include="..\ttpfile\filesys_win32.cpp">
       <Filter>ffpfile</Filter>
     </ClCompile>
+    <ClCompile Include="ttdebug.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <Image Include="..\..\cygterm\cygterm.ico">
@@ -441,5 +444,8 @@
     <ClInclude Include="..\ttpfile\filesys_win32.h">
       <Filter>ffpfile</Filter>
     </ClInclude>
+    <ClInclude Include="ttdebug.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
 </Project>
\ No newline at end of file

Modified: trunk/teraterm/teraterm/ttermpro.v8.vcproj
===================================================================
--- trunk/teraterm/teraterm/ttermpro.v8.vcproj	2021-01-03 06:35:28 UTC (rev 9123)
+++ trunk/teraterm/teraterm/ttermpro.v8.vcproj	2021-01-16 05:19:55 UTC (rev 9124)
@@ -249,6 +249,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\ttdebug.cpp"
+				>
+			</File>
+			<File
 				RelativePath="vtwin.cpp"
 				>
 			</File>
@@ -495,6 +499,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\ttdebug.h"
+				>
+			</File>
+			<File
 				RelativePath="ttfileio.h"
 				>
 			</File>

Modified: trunk/teraterm/teraterm/vtterm.c
===================================================================
--- trunk/teraterm/teraterm/vtterm.c	2021-01-03 06:35:28 UTC (rev 9123)
+++ trunk/teraterm/teraterm/vtterm.c	2021-01-16 05:19:55 UTC (rev 9124)
@@ -6427,7 +6427,7 @@
 	LockBuffer();
 
 	while ((c>0) && (ChangeEmu==0)) {
-#if UNICODE_DEBUG
+#if defined(DEBUG_DUMP_INPUTCODE)
 		{
 			static DWORD prev_tick;
 			DWORD now = GetTickCount();

Modified: trunk/teraterm/teraterm/vtwin.cpp
===================================================================
--- trunk/teraterm/teraterm/vtwin.cpp	2021-01-03 06:35:28 UTC (rev 9123)
+++ trunk/teraterm/teraterm/vtwin.cpp	2021-01-16 05:19:55 UTC (rev 9124)
@@ -69,7 +69,6 @@
 #include <shlobj.h>
 #include <io.h>
 #include <errno.h>
-#include <imagehlp.h>
 
 #include <windowsx.h>
 #include <imm.h>
@@ -223,207 +222,6 @@
 	AutoDisconnectedPort = port;
 }
 
-//
-// \x97\xE1\x8AO\x83n\x83\x93\x83h\x83\x89\x82̃t\x83b\x83N\x81i\x83X\x83^\x83b\x83N\x83g\x83\x8C\x81[\x83X\x82̃_\x83\x93\x83v\x81j
-//
-// cf. http://svn.collab.net/repos/svn/trunk/subversion/libsvn_subr/win32_crashrpt.c
-// (2007.9.30 yutaka)
-//
-// \x97\xE1\x8AO\x83R\x81[\x83h\x82𕶎\x9A\x97\xF1\x82֕ϊ\xB7\x82\xB7\x82\xE9
-#if !defined(_M_X64)
-static const char *GetExceptionString(DWORD exception)
-{
-#define EXCEPTION(x) case EXCEPTION_##x: return (#x);
-	static char buf[16];
-
-	switch (exception)
-	{
-		EXCEPTION(ACCESS_VIOLATION)
-		EXCEPTION(DATATYPE_MISALIGNMENT)
-		EXCEPTION(BREAKPOINT)
-		EXCEPTION(SINGLE_STEP)
-		EXCEPTION(ARRAY_BOUNDS_EXCEEDED)
-		EXCEPTION(FLT_DENORMAL_OPERAND)
-		EXCEPTION(FLT_DIVIDE_BY_ZERO)
-		EXCEPTION(FLT_INEXACT_RESULT)
-		EXCEPTION(FLT_INVALID_OPERATION)
-		EXCEPTION(FLT_OVERFLOW)
-		EXCEPTION(FLT_STACK_CHECK)
-		EXCEPTION(FLT_UNDERFLOW)
-		EXCEPTION(INT_DIVIDE_BY_ZERO)
-		EXCEPTION(INT_OVERFLOW)
-		EXCEPTION(PRIV_INSTRUCTION)
-		EXCEPTION(IN_PAGE_ERROR)
-		EXCEPTION(ILLEGAL_INSTRUCTION)
-		EXCEPTION(NONCONTINUABLE_EXCEPTION)
-		EXCEPTION(STACK_OVERFLOW)
-		EXCEPTION(INVALID_DISPOSITION)
-		EXCEPTION(GUARD_PAGE)
-		EXCEPTION(INVALID_HANDLE)
-
-	default:
-		_snprintf_s(buf, sizeof(buf), _TRUNCATE, "0x%x", exception);
-		return buf;
-		//return "UNKNOWN_ERROR";
-	}
-#undef EXCEPTION
-}
-
-/* \x97\xE1\x8AO\x94\xAD\x90\xB6\x8E\x9E\x82Ɋ֐\x94\x82̌Ăяo\x82\xB5\x97\x9A\x97\xF0\x82\xF0\x95\\x8E\xA6\x82\xB7\x82\xE9\x81A\x97\xE1\x8AO\x83t\x83B\x83\x8B\x83^\x8A֐\x94 */
-static LONG CALLBACK ApplicationFaultHandler(EXCEPTION_POINTERS *ExInfo)
-{
-	HGLOBAL gptr;
-	STACKFRAME sf;
-	BOOL bResult;
-	PIMAGEHLP_SYMBOL pSym;
-	DWORD Disp;
-	HANDLE hProcess = GetCurrentProcess();
-	HANDLE hThread = GetCurrentThread();
-	IMAGEHLP_MODULE	ih_module;
-	IMAGEHLP_LINE	ih_line;
-	int frame;
-	char msg[3072], buf[256];
-	HMODULE h, h2;
-	char imagehlp_dll[MAX_PATH];
-
-	// Windows98/Me/NT4\x82ł͓\xAE\x82\xA9\x82Ȃ\xA2\x82\xBD\x82߃X\x83L\x83b\x83v\x82\xB7\x82\xE9\x81B(2007.10.9 yutaka)
-	GetSystemDirectory(imagehlp_dll, sizeof(imagehlp_dll));
-	strncat_s(imagehlp_dll, sizeof(imagehlp_dll), "\\imagehlp.dll", _TRUNCATE);
-	h2 = LoadLibrary(imagehlp_dll);
-	if (((h = GetModuleHandle(imagehlp_dll)) == NULL) ||
-		(GetProcAddress(h, "SymGetLineFromAddr") == NULL)) {
-			FreeLibrary(h2);
-			goto error;
-	}
-	FreeLibrary(h2);
-
-	/* \x83V\x83\x93\x83{\x83\x8B\x8F\xEE\x95\xF1\x8Ai\x94[\x97p\x83o\x83b\x83t\x83@\x82̏\x89\x8A\xFA\x89\xBB */
-	gptr = GlobalAlloc(GMEM_FIXED, 10000);
-	if (gptr == NULL) {
-		goto error;
-	}
-	pSym = (PIMAGEHLP_SYMBOL)GlobalLock(gptr);
-	ZeroMemory(pSym, sizeof(IMAGEHLP_SYMBOL));
-	pSym->SizeOfStruct = 10000;
-	pSym->MaxNameLength = 10000 - sizeof(IMAGEHLP_SYMBOL);
-
-	/* \x83X\x83^\x83b\x83N\x83t\x83\x8C\x81[\x83\x80\x82̏\x89\x8A\xFA\x89\xBB */
-	ZeroMemory(&sf, sizeof(sf));
-	sf.AddrPC.Offset = ExInfo->ContextRecord->Eip;
-	sf.AddrStack.Offset = ExInfo->ContextRecord->Esp;
-	sf.AddrFrame.Offset = ExInfo->ContextRecord->Ebp;
-	sf.AddrPC.Mode = AddrModeFlat;
-	sf.AddrStack.Mode = AddrModeFlat;
-	sf.AddrFrame.Mode = AddrModeFlat;
-
-	/* \x83V\x83\x93\x83{\x83\x8B\x83n\x83\x93\x83h\x83\x89\x82̏\x89\x8A\xFA\x89\xBB */
-	SymInitialize(hProcess, NULL, TRUE);
-
-	// \x83\x8C\x83W\x83X\x83^\x83_\x83\x93\x83v
-	msg[0] = '\0';
-	_snprintf_s(buf, sizeof(buf), _TRUNCATE, "eax=%08X ebx=%08X ecx=%08X edx=%08X esi=%08X edi=%08X\r\n"
-		   "ebp=%08X esp=%08X eip=%08X efl=%08X\r\n"
-		   "cs=%04X ss=%04X ds=%04X es=%04X fs=%04X gs=%04X\r\n",
-		   ExInfo->ContextRecord->Eax,
-		   ExInfo->ContextRecord->Ebx,
-		   ExInfo->ContextRecord->Ecx,
-		   ExInfo->ContextRecord->Edx,
-		   ExInfo->ContextRecord->Esi,
-		   ExInfo->ContextRecord->Edi,
-		   ExInfo->ContextRecord->Ebp,
-		   ExInfo->ContextRecord->Esp,
-		   ExInfo->ContextRecord->Eip,
-		   ExInfo->ContextRecord->EFlags,
-		   ExInfo->ContextRecord->SegCs,
-		   ExInfo->ContextRecord->SegSs,
-		   ExInfo->ContextRecord->SegDs,
-		   ExInfo->ContextRecord->SegEs,
-		   ExInfo->ContextRecord->SegFs,
-		   ExInfo->ContextRecord->SegGs
-	);
-	strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
-
-	if (ExInfo->ExceptionRecord != NULL) {
-		_snprintf_s(buf, sizeof(buf), _TRUNCATE, "Exception: %s\r\n", GetExceptionString(ExInfo->ExceptionRecord->ExceptionCode));
-		strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
-	}
-
-	/* \x83X\x83^\x83b\x83N\x83t\x83\x8C\x81[\x83\x80\x82\xF0\x8F\x87\x82ɕ\\x8E\xA6\x82\xB5\x82Ă\xA2\x82\xAD */
-	frame = 0;
-	for (;;) {
-		/* \x8E\x9F\x82̃X\x83^\x83b\x83N\x83t\x83\x8C\x81[\x83\x80\x82̎擾 */
-		bResult = StackWalk(
-			IMAGE_FILE_MACHINE_I386,
-			hProcess,
-			hThread,
-			&sf,
-			NULL,
-			NULL,
-			SymFunctionTableAccess,
-			SymGetModuleBase,
-			NULL);
-
-		/* \x8E\xB8\x94s\x82Ȃ\xE7\x82΁A\x83\x8B\x81[\x83v\x82𔲂\xAF\x82\xE9 */
-		if (!bResult || sf.AddrFrame.Offset == 0)
-			break;
-
-		frame++;
-
-		/* \x83v\x83\x8D\x83O\x83\x89\x83\x80\x83J\x83E\x83\x93\x83^\x81i\x89\xBC\x91z\x83A\x83h\x83\x8C\x83X\x81j\x82\xA9\x82\xE7\x8A֐\x94\x96\xBC\x82ƃI\x83t\x83Z\x83b\x83g\x82\xF0\x8E擾 */
-		bResult = SymGetSymFromAddr(hProcess, sf.AddrPC.Offset, &Disp, pSym);
-
-		/* \x8E擾\x8C\x8B\x89ʂ\xF0\x95\\x8E\xA6 */
-		_snprintf_s(buf, sizeof(buf), _TRUNCATE, "#%d  0x%08x in ", frame, sf.AddrPC.Offset);
-		strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
-		if (bResult) {
-			_snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s() + 0x%x ", pSym->Name, Disp);
-			strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
-		} else {
-			_snprintf_s(buf, sizeof(buf), _TRUNCATE, " --- ");
-			strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
-		}
-
-		// \x8E\xC0\x8Ds\x83t\x83@\x83C\x83\x8B\x96\xBC\x82̎擾
-		ZeroMemory( &(ih_module), sizeof(ih_module) );
-		ih_module.SizeOfStruct = sizeof(ih_module);
-		bResult = SymGetModuleInfo( hProcess, sf.AddrPC.Offset, &(ih_module) );
-		strncat_s(msg, sizeof(msg), "at ", _TRUNCATE);
-		if (bResult) {
-			_snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s ", ih_module.ImageName );
-			strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
-		} else {
-			_snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s ", "<Unknown Module>" );
-			strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
-		}
-
-		// \x83t\x83@\x83C\x83\x8B\x96\xBC\x82ƍs\x94ԍ\x86\x82̎擾
-		ZeroMemory( &(ih_line), sizeof(ih_line) );
-		ih_line.SizeOfStruct = sizeof(ih_line);
-		bResult = SymGetLineFromAddr( hProcess, sf.AddrPC.Offset, &Disp, &ih_line );
-		if (bResult)
-		{
-			_snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s:%lu", ih_line.FileName, ih_line.LineNumber );
-			strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
-		}
-
-		strncat_s(msg, sizeof(msg), "\n", _TRUNCATE);
-	}
-
-	/* \x8C㏈\x97\x9D */
-	SymCleanup(hProcess);
-	GlobalUnlock(pSym);
-	GlobalFree(pSym);
-
-	// \x97\xE1\x8AO\x8F\x88\x97\x9D\x92\x86\x82Ȃ̂ŁAAPI\x82𒼐ڌĂяo\x82\xB7
-	::MessageBoxA(NULL, msg, "Tera Term: Application fault", MB_OK | MB_ICONEXCLAMATION);
-
-error:
-//	return (EXCEPTION_EXECUTE_HANDLER);  /* \x82\xBB\x82̂܂܃v\x83\x8D\x83Z\x83X\x82\xF0\x8FI\x97\xB9\x82\xB3\x82\xB9\x82\xE9 */
-	return (EXCEPTION_CONTINUE_SEARCH);  /* \x88\xF8\x82\xAB\x91\xB1\x82\xAB\x81m\x83A\x83v\x83\x8A\x83P\x81[\x83V\x83\x87\x83\x93\x83G\x83\x89\x81[\x81n\x83|\x83b\x83v\x83A\x83b\x83v\x83\x81\x83b\x83Z\x81[\x83W\x83{\x83b\x83N\x83X\x82\xF0\x8CĂяo\x82\xB7 */
-}
-#endif // !defined(_M_X64 )
-
-
 // Virtual Store\x82\xAA\x97L\x8C\xF8\x82ł\xA0\x82邩\x82ǂ\xA4\x82\xA9\x82𔻕ʂ\xB7\x82\xE9\x81B
 //
 // [Windows 95-XP]
@@ -524,11 +322,6 @@
 	BOOL isFirstInstance;
 	m_hInst = hInstance;
 
-	// \x97\xE1\x8AO\x83n\x83\x93\x83h\x83\x89\x82̃t\x83b\x83N (2007.9.30 yutaka)
-#if !defined(_M_X64)
-	SetUnhandledExceptionFilter(ApplicationFaultHandler);
-#endif
-
 	CommInit(&cv);
 	isFirstInstance = StartTeraTerm(&ts);
 


Ttssh2-commit メーリングリストの案内
アーカイブの一覧に戻る