annotate src/os/windows/crashlog_win.cpp @ 16150:bf70498c9e20 draft

(svn r20846) -Fix: some whitespace.
author frosch <frosch@openttd.org>
date Sat, 25 Sep 2010 19:13:25 +0000
parents bb38f90b1402
children c8b6698f2078
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
1 /* $Id$ */
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
2
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
3 /*
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
4 * This file is part of OpenTTD.
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
5 * OpenTTD 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, version 2.
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
6 * OpenTTD 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.
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
8 */
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
9
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
10 /** @file crashlog_win.cpp Implementation of a crashlogger for Windows */
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
11
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
12 #include "../../stdafx.h"
15914
4fab5de4b857 (svn r20598) -Codechange: [Win32] Replace the external x64 asm with a built-in Windows function.
michi_cc <michi_cc@openttd.org>
parents: 15604
diff changeset
13 #if defined(_MSC_VER) && defined(_M_AMD64)
4fab5de4b857 (svn r20598) -Codechange: [Win32] Replace the external x64 asm with a built-in Windows function.
michi_cc <michi_cc@openttd.org>
parents: 15604
diff changeset
14 /* Redefine WinNT version to get RtlCaptureContext prototype. */
4fab5de4b857 (svn r20598) -Codechange: [Win32] Replace the external x64 asm with a built-in Windows function.
michi_cc <michi_cc@openttd.org>
parents: 15604
diff changeset
15 #undef _WIN32_WINNT
4fab5de4b857 (svn r20598) -Codechange: [Win32] Replace the external x64 asm with a built-in Windows function.
michi_cc <michi_cc@openttd.org>
parents: 15604
diff changeset
16 #undef NTDDI_VERSION
4fab5de4b857 (svn r20598) -Codechange: [Win32] Replace the external x64 asm with a built-in Windows function.
michi_cc <michi_cc@openttd.org>
parents: 15604
diff changeset
17 #define _WIN32_WINNT _WIN32_WINNT_WINXP
4fab5de4b857 (svn r20598) -Codechange: [Win32] Replace the external x64 asm with a built-in Windows function.
michi_cc <michi_cc@openttd.org>
parents: 15604
diff changeset
18 #endif /* defined(_MSC_VER) && defined(_M_AMD64) */
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
19 #include "../../crashlog.h"
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
20 #include "win32.h"
12918
d595a7dce1de (svn r17410) -Codechange: use the same define for determining whether windows does crash reports instead of using several that aren't necessarily equal
rubidium <rubidium@openttd.org>
parents: 12917
diff changeset
21 #include "../../core/alloc_func.hpp"
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
22 #include "../../core/math_func.hpp"
12918
d595a7dce1de (svn r17410) -Codechange: use the same define for determining whether windows does crash reports instead of using several that aren't necessarily equal
rubidium <rubidium@openttd.org>
parents: 12917
diff changeset
23 #include "../../string_func.h"
d595a7dce1de (svn r17410) -Codechange: use the same define for determining whether windows does crash reports instead of using several that aren't necessarily equal
rubidium <rubidium@openttd.org>
parents: 12917
diff changeset
24 #include "../../fileio_func.h"
d595a7dce1de (svn r17410) -Codechange: use the same define for determining whether windows does crash reports instead of using several that aren't necessarily equal
rubidium <rubidium@openttd.org>
parents: 12917
diff changeset
25 #include "../../strings_func.h"
12959
3a7d79750a1f (svn r17452) -Fix (r17450): emergency savegames weren't rejected by the crash logger anymore
rubidium <rubidium@openttd.org>
parents: 12957
diff changeset
26 #include "../../gamelog.h"
14279
22e76a982410 (svn r18831) -Change [FS#3537]: do not go into the crashlog handler in case loading a savegame misses with missing NewGRFs. This way the load game crash handler gets better visibility and the user is instructed to find the missing NewGRFs before filing a bug report
rubidium <rubidium@openttd.org>
parents: 14080
diff changeset
27 #include "../../saveload/saveload.h"
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
28
12918
d595a7dce1de (svn r17410) -Codechange: use the same define for determining whether windows does crash reports instead of using several that aren't necessarily equal
rubidium <rubidium@openttd.org>
parents: 12917
diff changeset
29 #include <windows.h>
13915
5a588b3068cf (svn r18446) -Fix (r17450): abort() doesn't trigger crashlog on windows
glx <glx@openttd.org>
parents: 13660
diff changeset
30 #include <signal.h>
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
31
15915
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
32 static const uint MAX_SYMBOL_LEN = 512;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
33 static const uint MAX_FRAMES = 64;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
34
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
35 /* printf format specification for 32/64-bit addresses. */
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
36 #ifdef _M_AMD64
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
37 #define PRINTF_PTR "0x%016IX"
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
38 #else
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
39 #define PRINTF_PTR "0x%08X"
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
40 #endif
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
41
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
42 /**
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
43 * Windows implementation for the crash logger.
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
44 */
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
45 class CrashLogWindows : public CrashLog {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
46 /** Information about the encountered exception */
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
47 EXCEPTION_POINTERS *ep;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
48
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
49 /* virtual */ char *LogOSVersion(char *buffer, const char *last) const;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
50 /* virtual */ char *LogError(char *buffer, const char *last, const char *message) const;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
51 /* virtual */ char *LogStacktrace(char *buffer, const char *last) const;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
52 /* virtual */ char *LogRegisters(char *buffer, const char *last) const;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
53 /* virtual */ char *LogModules(char *buffer, const char *last) const;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
54 public:
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
55 #if defined(_MSC_VER)
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
56 /* virtual */ int WriteCrashDump(char *filename, const char *filename_last) const;
15915
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
57 char *AppendDecodedStacktrace(char *buffer, const char *last) const;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
58 #else
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
59 char *AppendDecodedStacktrace(char *buffer, const char *last) const { return buffer; }
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
60 #endif /* _MSC_VER */
12918
d595a7dce1de (svn r17410) -Codechange: use the same define for determining whether windows does crash reports instead of using several that aren't necessarily equal
rubidium <rubidium@openttd.org>
parents: 12917
diff changeset
61
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
62 /** Buffer for the generated crash log */
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
63 char crashlog[65536];
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
64 /** Buffer for the filename of the crash log */
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
65 char crashlog_filename[MAX_PATH];
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
66 /** Buffer for the filename of the crash dump */
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
67 char crashdump_filename[MAX_PATH];
13660
b9302d9e1874 (svn r18184) -Codechange: add crash screenshot for win32
glx <glx@openttd.org>
parents: 12993
diff changeset
68 /** Buffer for the filename of the crash screenshot */
b9302d9e1874 (svn r18184) -Codechange: add crash screenshot for win32
glx <glx@openttd.org>
parents: 12993
diff changeset
69 char screenshot_filename[MAX_PATH];
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
70
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
71 /**
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
72 * A crash log is always generated when it's generated.
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
73 * @param ep the data related to the exception.
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
74 */
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
75 CrashLogWindows(EXCEPTION_POINTERS *ep = NULL) :
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
76 ep(ep)
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
77 {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
78 this->crashlog[0] = '\0';
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
79 this->crashlog_filename[0] = '\0';
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
80 this->crashdump_filename[0] = '\0';
13660
b9302d9e1874 (svn r18184) -Codechange: add crash screenshot for win32
glx <glx@openttd.org>
parents: 12993
diff changeset
81 this->screenshot_filename[0] = '\0';
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
82 }
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
83
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
84 /**
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
85 * Points to the current crash log.
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
86 */
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
87 static CrashLogWindows *current;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
88 };
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
89
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
90 /* static */ CrashLogWindows *CrashLogWindows::current = NULL;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
91
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
92 /* virtual */ char *CrashLogWindows::LogOSVersion(char *buffer, const char *last) const
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
93 {
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
94 _OSVERSIONINFOA os;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
95 os.dwOSVersionInfoSize = sizeof(os);
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
96 GetVersionExA(&os);
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
97
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
98 return buffer + seprintf(buffer, last,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
99 "Operating system:\n"
14303
979a0a9ae875 (svn r18855) -Codechange: record compiler name and version in the crash log
smatz <smatz@openttd.org>
parents: 14279
diff changeset
100 " Name: Windows\n"
979a0a9ae875 (svn r18855) -Codechange: record compiler name and version in the crash log
smatz <smatz@openttd.org>
parents: 14279
diff changeset
101 " Release: %d.%d.%d (%s)\n",
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
102 (int)os.dwMajorVersion,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
103 (int)os.dwMinorVersion,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
104 (int)os.dwBuildNumber,
14303
979a0a9ae875 (svn r18855) -Codechange: record compiler name and version in the crash log
smatz <smatz@openttd.org>
parents: 14279
diff changeset
105 os.szCSDVersion
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
106 );
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
107
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
108 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
109
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
110 /* virtual */ char *CrashLogWindows::LogError(char *buffer, const char *last, const char *message) const
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
111 {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
112 return buffer + seprintf(buffer, last,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
113 "Crash reason:\n"
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
114 " Exception: %.8X\n"
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
115 #ifdef _M_AMD64
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
116 " Location: %.16IX\n"
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
117 #else
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
118 " Location: %.8X\n"
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
119 #endif
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
120 " Message: %s\n\n",
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
121 (int)ep->ExceptionRecord->ExceptionCode,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
122 (size_t)ep->ExceptionRecord->ExceptionAddress,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
123 message == NULL ? "<none>" : message
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
124 );
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
125 }
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
126
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
127 struct DebugFileInfo {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
128 uint32 size;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
129 uint32 crc32;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
130 SYSTEMTIME file_time;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
131 };
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
132
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
133 static uint32 *_crc_table;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
134
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
135 static void MakeCRCTable(uint32 *table)
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
136 {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
137 uint32 crc, poly = 0xEDB88320L;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
138 int i;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
139 int j;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
140
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
141 _crc_table = table;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
142
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
143 for (i = 0; i != 256; i++) {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
144 crc = i;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
145 for (j = 8; j != 0; j--) {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
146 crc = (crc & 1 ? (crc >> 1) ^ poly : crc >> 1);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
147 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
148 table[i] = crc;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
149 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
150 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
151
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
152 static uint32 CalcCRC(byte *data, uint size, uint32 crc)
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
153 {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
154 for (; size > 0; size--) {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
155 crc = ((crc >> 8) & 0x00FFFFFF) ^ _crc_table[(crc ^ *data++) & 0xFF];
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
156 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
157 return crc;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
158 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
159
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
160 static void GetFileInfo(DebugFileInfo *dfi, const TCHAR *filename)
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
161 {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
162 HANDLE file;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
163 memset(dfi, 0, sizeof(*dfi));
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
164
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
165 file = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
166 if (file != INVALID_HANDLE_VALUE) {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
167 byte buffer[1024];
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
168 DWORD numread;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
169 uint32 filesize = 0;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
170 FILETIME write_time;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
171 uint32 crc = (uint32)-1;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
172
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
173 for (;;) {
15552
683f2dbe75bb (svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents: 14303
diff changeset
174 if (ReadFile(file, buffer, sizeof(buffer), &numread, NULL) == 0 || numread == 0) {
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
175 break;
15552
683f2dbe75bb (svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents: 14303
diff changeset
176 }
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
177 filesize += numread;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
178 crc = CalcCRC(buffer, numread, crc);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
179 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
180 dfi->size = filesize;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
181 dfi->crc32 = crc ^ (uint32)-1;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
182
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
183 if (GetFileTime(file, NULL, NULL, &write_time)) {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
184 FileTimeToSystemTime(&write_time, &dfi->file_time);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
185 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
186 CloseHandle(file);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
187 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
188 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
189
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
190
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
191 static char *PrintModuleInfo(char *output, const char *last, HMODULE mod)
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
192 {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
193 TCHAR buffer[MAX_PATH];
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
194 DebugFileInfo dfi;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
195
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
196 GetModuleFileName(mod, buffer, MAX_PATH);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
197 GetFileInfo(&dfi, buffer);
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
198 output += seprintf(output, last, " %-20s handle: %p size: %d crc: %.8X date: %d-%.2d-%.2d %.2d:%.2d:%.2d\n",
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
199 WIDE_TO_MB(buffer),
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
200 mod,
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
201 dfi.size,
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
202 dfi.crc32,
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
203 dfi.file_time.wYear,
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
204 dfi.file_time.wMonth,
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
205 dfi.file_time.wDay,
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
206 dfi.file_time.wHour,
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
207 dfi.file_time.wMinute,
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
208 dfi.file_time.wSecond
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
209 );
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
210 return output;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
211 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
212
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
213 /* virtual */ char *CrashLogWindows::LogModules(char *output, const char *last) const
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
214 {
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
215 MakeCRCTable(AllocaM(uint32, 256));
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
216 BOOL (WINAPI *EnumProcessModules)(HANDLE, HMODULE*, DWORD, LPDWORD);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
217
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
218 output += seprintf(output, last, "Module information:\n");
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
219
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
220 if (LoadLibraryList((Function*)&EnumProcessModules, "psapi.dll\0EnumProcessModules\0\0")) {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
221 HMODULE modules[100];
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
222 DWORD needed;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
223 BOOL res;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
224
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
225 HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
226 if (proc != NULL) {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
227 res = EnumProcessModules(proc, modules, sizeof(modules), &needed);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
228 CloseHandle(proc);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
229 if (res) {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
230 size_t count = min(needed / sizeof(HMODULE), lengthof(modules));
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
231
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
232 for (size_t i = 0; i != count; i++) output = PrintModuleInfo(output, last, modules[i]);
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
233 return output + seprintf(output, last, "\n");
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
234 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
235 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
236 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
237 output = PrintModuleInfo(output, last, NULL);
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
238 return output + seprintf(output, last, "\n");
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
239 }
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
240
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
241 /* virtual */ char *CrashLogWindows::LogRegisters(char *buffer, const char *last) const
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
242 {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
243 buffer += seprintf(buffer, last, "Registers:\n");
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
244 #ifdef _M_AMD64
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
245 buffer += seprintf(buffer, last,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
246 " RAX: %.16llX RBX: %.16llX RCX: %.16llX RDX: %.16llX\n"
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
247 " RSI: %.16llX RDI: %.16llX RBP: %.16llX RSP: %.16llX\n"
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
248 " R8: %.16llX R9: %.16llX R10: %.16llX R11: %.16llX\n"
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
249 " R12: %.16llX R13: %.16llX R14: %.16llX R15: %.16llX\n"
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
250 " RIP: %.16llX EFLAGS: %.8X\n",
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
251 ep->ContextRecord->Rax,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
252 ep->ContextRecord->Rbx,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
253 ep->ContextRecord->Rcx,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
254 ep->ContextRecord->Rdx,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
255 ep->ContextRecord->Rsi,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
256 ep->ContextRecord->Rdi,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
257 ep->ContextRecord->Rbp,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
258 ep->ContextRecord->Rsp,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
259 ep->ContextRecord->R8,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
260 ep->ContextRecord->R9,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
261 ep->ContextRecord->R10,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
262 ep->ContextRecord->R11,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
263 ep->ContextRecord->R12,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
264 ep->ContextRecord->R13,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
265 ep->ContextRecord->R14,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
266 ep->ContextRecord->R15,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
267 ep->ContextRecord->Rip,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
268 ep->ContextRecord->EFlags
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
269 );
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
270 #else
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
271 buffer += seprintf(buffer, last,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
272 " EAX: %.8X EBX: %.8X ECX: %.8X EDX: %.8X\n"
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
273 " ESI: %.8X EDI: %.8X EBP: %.8X ESP: %.8X\n"
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
274 " EIP: %.8X EFLAGS: %.8X\n",
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
275 (int)ep->ContextRecord->Eax,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
276 (int)ep->ContextRecord->Ebx,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
277 (int)ep->ContextRecord->Ecx,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
278 (int)ep->ContextRecord->Edx,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
279 (int)ep->ContextRecord->Esi,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
280 (int)ep->ContextRecord->Edi,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
281 (int)ep->ContextRecord->Ebp,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
282 (int)ep->ContextRecord->Esp,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
283 (int)ep->ContextRecord->Eip,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
284 (int)ep->ContextRecord->EFlags
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
285 );
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
286 #endif
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
287
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
288 buffer += seprintf(buffer, last, "\n Bytes at instruction pointer:\n");
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
289 #ifdef _M_AMD64
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
290 byte *b = (byte*)ep->ContextRecord->Rip;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
291 #else
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
292 byte *b = (byte*)ep->ContextRecord->Eip;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
293 #endif
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
294 for (int i = 0; i != 24; i++) {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
295 if (IsBadReadPtr(b, 1)) {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
296 buffer += seprintf(buffer, last, " ??"); // OCR: WAS: , 0);
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
297 } else {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
298 buffer += seprintf(buffer, last, " %.2X", *b);
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
299 }
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
300 b++;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
301 }
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
302 return buffer + seprintf(buffer, last, "\n\n");
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
303 }
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
304
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
305 /* virtual */ char *CrashLogWindows::LogStacktrace(char *buffer, const char *last) const
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
306 {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
307 buffer += seprintf(buffer, last, "Stack trace:\n");
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
308 #ifdef _M_AMD64
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
309 uint32 *b = (uint32*)ep->ContextRecord->Rsp;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
310 #else
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
311 uint32 *b = (uint32*)ep->ContextRecord->Esp;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
312 #endif
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
313 for (int j = 0; j != 24; j++) {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
314 for (int i = 0; i != 8; i++) {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
315 if (IsBadReadPtr(b, sizeof(uint32))) {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
316 buffer += seprintf(buffer, last, " ????????"); // OCR: WAS - , 0);
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
317 } else {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
318 buffer += seprintf(buffer, last, " %.8X", *b);
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
319 }
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
320 b++;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
321 }
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
322 buffer += seprintf(buffer, last, "\n");
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
323 }
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
324 return buffer + seprintf(buffer, last, "\n");
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
325 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
326
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
327 #if defined(_MSC_VER)
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
328 #include <dbghelp.h>
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
329
15915
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
330 char *CrashLogWindows::AppendDecodedStacktrace(char *buffer, const char *last) const
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
331 {
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
332 #define M(x) x "\0"
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
333 static const char dbg_import[] =
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
334 M("dbghelp.dll")
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
335 M("SymInitialize")
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
336 M("SymSetOptions")
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
337 M("SymCleanup")
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
338 M("StackWalk64")
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
339 M("SymFunctionTableAccess64")
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
340 M("SymGetModuleBase64")
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
341 M("SymGetModuleInfo64")
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
342 M("SymGetSymFromAddr64")
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
343 M("SymGetLineFromAddr64")
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
344 M("")
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
345 ;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
346 #undef M
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
347
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
348 struct ProcPtrs {
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
349 BOOL (WINAPI * pSymInitialize)(HANDLE, PCSTR, BOOL);
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
350 BOOL (WINAPI * pSymSetOptions)(DWORD);
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
351 BOOL (WINAPI * pSymCleanup)(HANDLE);
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
352 BOOL (WINAPI * pStackWalk64)(DWORD, HANDLE, HANDLE, LPSTACKFRAME64, PVOID, PREAD_PROCESS_MEMORY_ROUTINE64, PFUNCTION_TABLE_ACCESS_ROUTINE64, PGET_MODULE_BASE_ROUTINE64, PTRANSLATE_ADDRESS_ROUTINE64);
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
353 PVOID (WINAPI * pSymFunctionTableAccess64)(HANDLE, DWORD64);
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
354 DWORD64 (WINAPI * pSymGetModuleBase64)(HANDLE, DWORD64);
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
355 BOOL (WINAPI * pSymGetModuleInfo64)(HANDLE, DWORD64, PIMAGEHLP_MODULE64);
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
356 BOOL (WINAPI * pSymGetSymFromAddr64)(HANDLE, DWORD64, PDWORD64, PIMAGEHLP_SYMBOL64);
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
357 BOOL (WINAPI * pSymGetLineFromAddr64)(HANDLE, DWORD64, PDWORD, PIMAGEHLP_LINE64);
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
358 } proc;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
359
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
360 buffer += seprintf(buffer, last, "\nDecoded stack trace:\n");
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
361
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
362 /* Try to load the functions from the DLL, if that fails because of a too old dbghelp.dll, just skip it. */
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
363 if (LoadLibraryList((Function*)&proc, dbg_import)) {
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
364 /* Initialize symbol handler. */
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
365 HANDLE hCur = GetCurrentProcess();
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
366 proc.pSymInitialize(hCur, NULL, TRUE);
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
367 /* Load symbols only when needed, fail silently on errors, demangle symbol names. */
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
368 proc.pSymSetOptions(SYMOPT_DEFERRED_LOADS | SYMOPT_FAIL_CRITICAL_ERRORS | SYMOPT_UNDNAME);
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
369
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
370 /* Initialize starting stack frame from context record. */
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
371 STACKFRAME64 frame;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
372 memset(&frame, 0, sizeof(frame));
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
373 #ifdef _M_AMD64
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
374 frame.AddrPC.Offset = ep->ContextRecord->Rip;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
375 frame.AddrFrame.Offset = ep->ContextRecord->Rbp;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
376 frame.AddrStack.Offset = ep->ContextRecord->Rsp;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
377 #else
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
378 frame.AddrPC.Offset = ep->ContextRecord->Eip;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
379 frame.AddrFrame.Offset = ep->ContextRecord->Ebp;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
380 frame.AddrStack.Offset = ep->ContextRecord->Esp;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
381 #endif
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
382 frame.AddrPC.Mode = AddrModeFlat;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
383 frame.AddrFrame.Mode = AddrModeFlat;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
384 frame.AddrStack.Mode = AddrModeFlat;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
385
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
386 /* Copy context record as StackWalk64 may modify it. */
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
387 CONTEXT ctx;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
388 memcpy(&ctx, ep->ContextRecord, sizeof(ctx));
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
389
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
390 /* Allocate space for symbol info. */
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
391 IMAGEHLP_SYMBOL64 *sym_info = (IMAGEHLP_SYMBOL64*)alloca(sizeof(IMAGEHLP_SYMBOL64) + MAX_SYMBOL_LEN - 1);
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
392 sym_info->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
393 sym_info->MaxNameLength = MAX_SYMBOL_LEN;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
394
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
395 /* Walk stack at most MAX_FRAMES deep in case the stack is corrupt. */
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
396 for (uint num = 0; num < MAX_FRAMES; num++) {
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
397 if (!proc.pStackWalk64(
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
398 #ifdef _M_AMD64
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
399 IMAGE_FILE_MACHINE_AMD64,
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
400 #else
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
401 IMAGE_FILE_MACHINE_I386,
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
402 #endif
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
403 hCur, GetCurrentThread(), &frame, &ctx, NULL, proc.pSymFunctionTableAccess64, proc.pSymGetModuleBase64, NULL)) break;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
404
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
405 if (frame.AddrPC.Offset == frame.AddrReturn.Offset) {
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
406 buffer += seprintf(buffer, last, " <infinite loop>\n");
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
407 break;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
408 }
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
409
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
410 /* Get module name. */
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
411 const char *mod_name = "???";
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
412
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
413 IMAGEHLP_MODULE64 module;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
414 module.SizeOfStruct = sizeof(module);
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
415 if (proc.pSymGetModuleInfo64(hCur, frame.AddrPC.Offset, &module)) {
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
416 mod_name = module.ModuleName;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
417 }
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
418
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
419 /* Print module and instruction pointer. */
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
420 buffer += seprintf(buffer, last, "[%02d] %-20s " PRINTF_PTR, num, mod_name, frame.AddrPC.Offset);
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
421
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
422 /* Get symbol name and line info if possible. */
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
423 DWORD64 offset;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
424 if (proc.pSymGetSymFromAddr64(hCur, frame.AddrPC.Offset, &offset, sym_info)) {
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
425 buffer += seprintf(buffer, last, " %s + %I64u", sym_info->Name, offset);
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
426
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
427 DWORD line_offs;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
428 IMAGEHLP_LINE64 line;
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
429 line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
430 if (proc.pSymGetLineFromAddr64(hCur, frame.AddrPC.Offset, &line_offs, &line)) {
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
431 buffer += seprintf(buffer, last, " (%s:%d)", line.FileName, line.LineNumber);
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
432 }
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
433 }
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
434 buffer += seprintf(buffer, last, "\n");
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
435 }
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
436
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
437 proc.pSymCleanup(hCur);
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
438 }
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
439
16150
bf70498c9e20 (svn r20846) -Fix: some whitespace.
frosch <frosch@openttd.org>
parents: 15915
diff changeset
440 return buffer + seprintf(buffer, last, "\n*** End of additional info ***\n");
15915
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
441 }
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
442
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
443 /* virtual */ int CrashLogWindows::WriteCrashDump(char *filename, const char *filename_last) const
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
444 {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
445 int ret = 0;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
446 HMODULE dbghelp = LoadLibrary(_T("dbghelp.dll"));
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
447 if (dbghelp != NULL) {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
448 typedef BOOL (WINAPI *MiniDumpWriteDump_t)(HANDLE, DWORD, HANDLE,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
449 MINIDUMP_TYPE,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
450 CONST PMINIDUMP_EXCEPTION_INFORMATION,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
451 CONST PMINIDUMP_USER_STREAM_INFORMATION,
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
452 CONST PMINIDUMP_CALLBACK_INFORMATION);
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
453 MiniDumpWriteDump_t funcMiniDumpWriteDump = (MiniDumpWriteDump_t)GetProcAddress(dbghelp, "MiniDumpWriteDump");
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
454 if (funcMiniDumpWriteDump != NULL) {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
455 seprintf(filename, filename_last, "%scrash.dmp", _personal_dir);
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
456 HANDLE file = CreateFile(OTTD2FS(filename), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
457 HANDLE proc = GetCurrentProcess();
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
458 DWORD procid = GetCurrentProcessId();
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
459 MINIDUMP_EXCEPTION_INFORMATION mdei;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
460 MINIDUMP_USER_STREAM userstream;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
461 MINIDUMP_USER_STREAM_INFORMATION musi;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
462
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
463 userstream.Type = LastReservedStream + 1;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
464 userstream.Buffer = (void*)this->crashlog;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
465 userstream.BufferSize = (ULONG)strlen(this->crashlog) + 1;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
466
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
467 musi.UserStreamCount = 1;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
468 musi.UserStreamArray = &userstream;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
469
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
470 mdei.ThreadId = GetCurrentThreadId();
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
471 mdei.ExceptionPointers = ep;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
472 mdei.ClientPointers = false;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
473
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
474 funcMiniDumpWriteDump(proc, procid, file, MiniDumpWithDataSegs, &mdei, &musi, NULL);
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
475 ret = 1;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
476 } else {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
477 ret = -1;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
478 }
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
479 FreeLibrary(dbghelp);
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
480 }
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
481 return ret;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
482 }
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
483 #endif /* _MSC_VER */
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
484
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
485 extern bool CloseConsoleLogIfActive();
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
486 static void ShowCrashlogWindow();
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
487
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
488 /**
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
489 * Stack pointer for use when 'starting' the crash handler.
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
490 * Not static as gcc's inline assembly needs it that way.
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
491 */
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
492 void *_safe_esp = NULL;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
493
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
494 static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep)
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
495 {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
496 if (CrashLogWindows::current != NULL) {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
497 CrashLog::AfterCrashLogCleanup();
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
498 ExitProcess(2);
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
499 }
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
500
12959
3a7d79750a1f (svn r17452) -Fix (r17450): emergency savegames weren't rejected by the crash logger anymore
rubidium <rubidium@openttd.org>
parents: 12957
diff changeset
501 if (GamelogTestEmergency()) {
3a7d79750a1f (svn r17452) -Fix (r17450): emergency savegames weren't rejected by the crash logger anymore
rubidium <rubidium@openttd.org>
parents: 12957
diff changeset
502 static const TCHAR _emergency_crash[] =
15604
ca959eb5d431 (svn r20266) -Doc: Mostly typo fixes, a few doxygen-related improvements.
alberth <alberth@openttd.org>
parents: 15552
diff changeset
503 _T("A serious fault condition occurred in the game. The game will shut down.\n")
12959
3a7d79750a1f (svn r17452) -Fix (r17450): emergency savegames weren't rejected by the crash logger anymore
rubidium <rubidium@openttd.org>
parents: 12957
diff changeset
504 _T("As you loaded an emergency savegame no crash information will be generated.\n");
3a7d79750a1f (svn r17452) -Fix (r17450): emergency savegames weren't rejected by the crash logger anymore
rubidium <rubidium@openttd.org>
parents: 12957
diff changeset
505 MessageBox(NULL, _emergency_crash, _T("Fatal Application Failure"), MB_ICONERROR);
3a7d79750a1f (svn r17452) -Fix (r17450): emergency savegames weren't rejected by the crash logger anymore
rubidium <rubidium@openttd.org>
parents: 12957
diff changeset
506 ExitProcess(3);
3a7d79750a1f (svn r17452) -Fix (r17450): emergency savegames weren't rejected by the crash logger anymore
rubidium <rubidium@openttd.org>
parents: 12957
diff changeset
507 }
3a7d79750a1f (svn r17452) -Fix (r17450): emergency savegames weren't rejected by the crash logger anymore
rubidium <rubidium@openttd.org>
parents: 12957
diff changeset
508
14279
22e76a982410 (svn r18831) -Change [FS#3537]: do not go into the crashlog handler in case loading a savegame misses with missing NewGRFs. This way the load game crash handler gets better visibility and the user is instructed to find the missing NewGRFs before filing a bug report
rubidium <rubidium@openttd.org>
parents: 14080
diff changeset
509 if (SaveloadCrashWithMissingNewGRFs()) {
22e76a982410 (svn r18831) -Change [FS#3537]: do not go into the crashlog handler in case loading a savegame misses with missing NewGRFs. This way the load game crash handler gets better visibility and the user is instructed to find the missing NewGRFs before filing a bug report
rubidium <rubidium@openttd.org>
parents: 14080
diff changeset
510 static const TCHAR _saveload_crash[] =
15604
ca959eb5d431 (svn r20266) -Doc: Mostly typo fixes, a few doxygen-related improvements.
alberth <alberth@openttd.org>
parents: 15552
diff changeset
511 _T("A serious fault condition occurred in the game. The game will shut down.\n")
14279
22e76a982410 (svn r18831) -Change [FS#3537]: do not go into the crashlog handler in case loading a savegame misses with missing NewGRFs. This way the load game crash handler gets better visibility and the user is instructed to find the missing NewGRFs before filing a bug report
rubidium <rubidium@openttd.org>
parents: 14080
diff changeset
512 _T("As you loaded an savegame for which you do not have the required NewGRFs\n")
22e76a982410 (svn r18831) -Change [FS#3537]: do not go into the crashlog handler in case loading a savegame misses with missing NewGRFs. This way the load game crash handler gets better visibility and the user is instructed to find the missing NewGRFs before filing a bug report
rubidium <rubidium@openttd.org>
parents: 14080
diff changeset
513 _T("no crash information will be generated.\n");
22e76a982410 (svn r18831) -Change [FS#3537]: do not go into the crashlog handler in case loading a savegame misses with missing NewGRFs. This way the load game crash handler gets better visibility and the user is instructed to find the missing NewGRFs before filing a bug report
rubidium <rubidium@openttd.org>
parents: 14080
diff changeset
514 MessageBox(NULL, _saveload_crash, _T("Fatal Application Failure"), MB_ICONERROR);
22e76a982410 (svn r18831) -Change [FS#3537]: do not go into the crashlog handler in case loading a savegame misses with missing NewGRFs. This way the load game crash handler gets better visibility and the user is instructed to find the missing NewGRFs before filing a bug report
rubidium <rubidium@openttd.org>
parents: 14080
diff changeset
515 ExitProcess(3);
22e76a982410 (svn r18831) -Change [FS#3537]: do not go into the crashlog handler in case loading a savegame misses with missing NewGRFs. This way the load game crash handler gets better visibility and the user is instructed to find the missing NewGRFs before filing a bug report
rubidium <rubidium@openttd.org>
parents: 14080
diff changeset
516 }
22e76a982410 (svn r18831) -Change [FS#3537]: do not go into the crashlog handler in case loading a savegame misses with missing NewGRFs. This way the load game crash handler gets better visibility and the user is instructed to find the missing NewGRFs before filing a bug report
rubidium <rubidium@openttd.org>
parents: 14080
diff changeset
517
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
518 CrashLogWindows *log = new CrashLogWindows(ep);
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
519 CrashLogWindows::current = log;
15915
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
520 char *buf = log->FillCrashLog(log->crashlog, lastof(log->crashlog));
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
521 log->WriteCrashDump(log->crashdump_filename, lastof(log->crashdump_filename));
bb38f90b1402 (svn r20599) -Add: [Win32] Append a decoded stack trace to the debug.log. Most of the time, the result will only be useful if the corresponding PDB file is present.
michi_cc <michi_cc@openttd.org>
parents: 15914
diff changeset
522 log->AppendDecodedStacktrace(buf, lastof(log->crashlog));
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
523 log->WriteCrashLog(log->crashlog, log->crashlog_filename, lastof(log->crashlog_filename));
13660
b9302d9e1874 (svn r18184) -Codechange: add crash screenshot for win32
glx <glx@openttd.org>
parents: 12993
diff changeset
524 log->WriteScreenshot(log->screenshot_filename, lastof(log->screenshot_filename));
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
525
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
526 /* Close any possible log files */
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
527 CloseConsoleLogIfActive();
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
528
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
529 if (_safe_esp) {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
530 #ifdef _M_AMD64
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
531 ep->ContextRecord->Rip = (DWORD64)ShowCrashlogWindow;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
532 ep->ContextRecord->Rsp = (DWORD64)_safe_esp;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
533 #else
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
534 ep->ContextRecord->Eip = (DWORD)ShowCrashlogWindow;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
535 ep->ContextRecord->Esp = (DWORD)_safe_esp;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
536 #endif
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
537 return EXCEPTION_CONTINUE_EXECUTION;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
538 }
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
539
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
540 CrashLog::AfterCrashLogCleanup();
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
541 return EXCEPTION_EXECUTE_HANDLER;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
542 }
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
543
13915
5a588b3068cf (svn r18446) -Fix (r17450): abort() doesn't trigger crashlog on windows
glx <glx@openttd.org>
parents: 13660
diff changeset
544 static void CDECL CustomAbort(int signal)
5a588b3068cf (svn r18446) -Fix (r17450): abort() doesn't trigger crashlog on windows
glx <glx@openttd.org>
parents: 13660
diff changeset
545 {
5a588b3068cf (svn r18446) -Fix (r17450): abort() doesn't trigger crashlog on windows
glx <glx@openttd.org>
parents: 13660
diff changeset
546 RaiseException(0xE1212012, 0, 0, NULL);
5a588b3068cf (svn r18446) -Fix (r17450): abort() doesn't trigger crashlog on windows
glx <glx@openttd.org>
parents: 13660
diff changeset
547 }
5a588b3068cf (svn r18446) -Fix (r17450): abort() doesn't trigger crashlog on windows
glx <glx@openttd.org>
parents: 13660
diff changeset
548
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
549 /* static */ void CrashLog::InitialiseCrashLog()
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
550 {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
551 #if defined(_MSC_VER)
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
552 #ifdef _M_AMD64
15914
4fab5de4b857 (svn r20598) -Codechange: [Win32] Replace the external x64 asm with a built-in Windows function.
michi_cc <michi_cc@openttd.org>
parents: 15604
diff changeset
553 CONTEXT ctx;
4fab5de4b857 (svn r20598) -Codechange: [Win32] Replace the external x64 asm with a built-in Windows function.
michi_cc <michi_cc@openttd.org>
parents: 15604
diff changeset
554 RtlCaptureContext(&ctx);
4fab5de4b857 (svn r20598) -Codechange: [Win32] Replace the external x64 asm with a built-in Windows function.
michi_cc <michi_cc@openttd.org>
parents: 15604
diff changeset
555
4fab5de4b857 (svn r20598) -Codechange: [Win32] Replace the external x64 asm with a built-in Windows function.
michi_cc <michi_cc@openttd.org>
parents: 15604
diff changeset
556 /* The stack pointer for AMD64 must always be 16-byte aligned inside a
4fab5de4b857 (svn r20598) -Codechange: [Win32] Replace the external x64 asm with a built-in Windows function.
michi_cc <michi_cc@openttd.org>
parents: 15604
diff changeset
557 * function. As we are simulating a function call with the safe ESP value,
4fab5de4b857 (svn r20598) -Codechange: [Win32] Replace the external x64 asm with a built-in Windows function.
michi_cc <michi_cc@openttd.org>
parents: 15604
diff changeset
558 * we need to subtract 8 for the imaginary return address otherwise stack
4fab5de4b857 (svn r20598) -Codechange: [Win32] Replace the external x64 asm with a built-in Windows function.
michi_cc <michi_cc@openttd.org>
parents: 15604
diff changeset
559 * alignment would be wrong in the called function. */
4fab5de4b857 (svn r20598) -Codechange: [Win32] Replace the external x64 asm with a built-in Windows function.
michi_cc <michi_cc@openttd.org>
parents: 15604
diff changeset
560 _safe_esp = (void *)(ctx.Rsp - 8);
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
561 #else
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
562 _asm {
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
563 mov _safe_esp, esp
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
564 }
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
565 #endif
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
566 #else
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
567 asm("movl %esp, __safe_esp");
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
568 #endif
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
569
13915
5a588b3068cf (svn r18446) -Fix (r17450): abort() doesn't trigger crashlog on windows
glx <glx@openttd.org>
parents: 13660
diff changeset
570 /* SIGABRT is not an unhandled exception, so we need to intercept it. */
5a588b3068cf (svn r18446) -Fix (r17450): abort() doesn't trigger crashlog on windows
glx <glx@openttd.org>
parents: 13660
diff changeset
571 signal(SIGABRT, CustomAbort);
5a588b3068cf (svn r18446) -Fix (r17450): abort() doesn't trigger crashlog on windows
glx <glx@openttd.org>
parents: 13660
diff changeset
572 #if defined(_MSC_VER)
5a588b3068cf (svn r18446) -Fix (r17450): abort() doesn't trigger crashlog on windows
glx <glx@openttd.org>
parents: 13660
diff changeset
573 /* Don't show abort message as we will get the crashlog window anyway. */
5a588b3068cf (svn r18446) -Fix (r17450): abort() doesn't trigger crashlog on windows
glx <glx@openttd.org>
parents: 13660
diff changeset
574 _set_abort_behavior(0, _WRITE_ABORT_MSG);
5a588b3068cf (svn r18446) -Fix (r17450): abort() doesn't trigger crashlog on windows
glx <glx@openttd.org>
parents: 13660
diff changeset
575 #endif
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
576 SetUnhandledExceptionFilter(ExceptionHandler);
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
577 }
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
578
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
579 /* The crash log GUI */
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
580
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
581 static bool _expanded;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
582
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
583 static const TCHAR _crash_desc[] =
15604
ca959eb5d431 (svn r20266) -Doc: Mostly typo fixes, a few doxygen-related improvements.
alberth <alberth@openttd.org>
parents: 15552
diff changeset
584 _T("A serious fault condition occurred in the game. The game will shut down.\n")
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
585 _T("Please send the crash information and the crash.dmp file (if any) to the developers.\n")
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
586 _T("This will greatly help debugging. The correct place to do this is http://bugs.openttd.org. ")
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
587 _T("The information contained in the report is displayed below.\n")
12981
bee7b7b5b53e (svn r17475) -Codechange: show path to crash.log and crash.dmp in crash window. Also tells the user where crash.sav is when saving succeeded.
glx <glx@openttd.org>
parents: 12959
diff changeset
588 _T("Press \"Emergency save\" to attempt saving the game. Generated file(s):\n")
13660
b9302d9e1874 (svn r18184) -Codechange: add crash screenshot for win32
glx <glx@openttd.org>
parents: 12993
diff changeset
589 _T("%s");
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
590
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
591 static const TCHAR _save_succeeded[] =
13660
b9302d9e1874 (svn r18184) -Codechange: add crash screenshot for win32
glx <glx@openttd.org>
parents: 12993
diff changeset
592 _T("Emergency save succeeded.\nIts location is '%s'.\n")
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
593 _T("Be aware that critical parts of the internal game state may have become ")
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
594 _T("corrupted. The saved game is not guaranteed to work.");
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
595
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
596 static const TCHAR * const _expand_texts[] = {_T("S&how report >>"), _T("&Hide report <<") };
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
597
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
598 static void SetWndSize(HWND wnd, int mode)
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
599 {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
600 RECT r, r2;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
601
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
602 GetWindowRect(wnd, &r);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
603 SetDlgItemText(wnd, 15, _expand_texts[mode == 1]);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
604
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
605 if (mode >= 0) {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
606 GetWindowRect(GetDlgItem(wnd, 11), &r2);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
607 int offs = r2.bottom - r2.top + 10;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
608 if (!mode) offs = -offs;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
609 SetWindowPos(wnd, HWND_TOPMOST, 0, 0,
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
610 r.right - r.left, r.bottom - r.top + offs, SWP_NOMOVE | SWP_NOZORDER);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
611 } else {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
612 SetWindowPos(wnd, HWND_TOPMOST,
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
613 (GetSystemMetrics(SM_CXSCREEN) - (r.right - r.left)) / 2,
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
614 (GetSystemMetrics(SM_CYSCREEN) - (r.bottom - r.top)) / 2,
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
615 0, 0, SWP_NOSIZE);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
616 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
617 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
618
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
619 static INT_PTR CALLBACK CrashDialogFunc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
620 {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
621 switch (msg) {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
622 case WM_INITDIALOG: {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
623 #if defined(UNICODE)
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
624 /* We need to put the crash-log in a seperate buffer because the default
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
625 * buffer in MB_TO_WIDE is not large enough (512 chars) */
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
626 wchar_t crash_msgW[lengthof(CrashLogWindows::current->crashlog)];
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
627 #endif
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
628 /* Convert unix -> dos newlines because the edit box only supports that properly :( */
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
629 const char *unix_nl = CrashLogWindows::current->crashlog;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
630 char dos_nl[lengthof(CrashLogWindows::current->crashlog)];
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
631 char *p = dos_nl;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
632 WChar c;
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
633 while ((c = Utf8Consume(&unix_nl)) && p < lastof(dos_nl) - 4) { // 4 is max number of bytes per character
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
634 if (c == '\n') p += Utf8Encode(p, '\r');
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
635 p += Utf8Encode(p, c);
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
636 }
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
637 *p = '\0';
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
638
12981
bee7b7b5b53e (svn r17475) -Codechange: show path to crash.log and crash.dmp in crash window. Also tells the user where crash.sav is when saving succeeded.
glx <glx@openttd.org>
parents: 12959
diff changeset
639 /* Add path to crash.log and crash.dmp (if any) to the crash window text */
13660
b9302d9e1874 (svn r18184) -Codechange: add crash screenshot for win32
glx <glx@openttd.org>
parents: 12993
diff changeset
640 size_t len = _tcslen(_crash_desc) + 2;
b9302d9e1874 (svn r18184) -Codechange: add crash screenshot for win32
glx <glx@openttd.org>
parents: 12993
diff changeset
641 len += _tcslen(OTTD2FS(CrashLogWindows::current->crashlog_filename)) + 2;
b9302d9e1874 (svn r18184) -Codechange: add crash screenshot for win32
glx <glx@openttd.org>
parents: 12993
diff changeset
642 len += _tcslen(OTTD2FS(CrashLogWindows::current->crashdump_filename)) + 2;
b9302d9e1874 (svn r18184) -Codechange: add crash screenshot for win32
glx <glx@openttd.org>
parents: 12993
diff changeset
643 len += _tcslen(OTTD2FS(CrashLogWindows::current->screenshot_filename)) + 1;
b9302d9e1874 (svn r18184) -Codechange: add crash screenshot for win32
glx <glx@openttd.org>
parents: 12993
diff changeset
644
12981
bee7b7b5b53e (svn r17475) -Codechange: show path to crash.log and crash.dmp in crash window. Also tells the user where crash.sav is when saving succeeded.
glx <glx@openttd.org>
parents: 12959
diff changeset
645 TCHAR *text = AllocaM(TCHAR, len);
13660
b9302d9e1874 (svn r18184) -Codechange: add crash screenshot for win32
glx <glx@openttd.org>
parents: 12993
diff changeset
646 _sntprintf(text, len, _crash_desc, OTTD2FS(CrashLogWindows::current->crashlog_filename));
b9302d9e1874 (svn r18184) -Codechange: add crash screenshot for win32
glx <glx@openttd.org>
parents: 12993
diff changeset
647 if (OTTD2FS(CrashLogWindows::current->crashdump_filename)[0] != _T('\0')) {
b9302d9e1874 (svn r18184) -Codechange: add crash screenshot for win32
glx <glx@openttd.org>
parents: 12993
diff changeset
648 _tcscat(text, _T("\n"));
b9302d9e1874 (svn r18184) -Codechange: add crash screenshot for win32
glx <glx@openttd.org>
parents: 12993
diff changeset
649 _tcscat(text, OTTD2FS(CrashLogWindows::current->crashdump_filename));
b9302d9e1874 (svn r18184) -Codechange: add crash screenshot for win32
glx <glx@openttd.org>
parents: 12993
diff changeset
650 }
b9302d9e1874 (svn r18184) -Codechange: add crash screenshot for win32
glx <glx@openttd.org>
parents: 12993
diff changeset
651 if (OTTD2FS(CrashLogWindows::current->screenshot_filename)[0] != _T('\0')) {
b9302d9e1874 (svn r18184) -Codechange: add crash screenshot for win32
glx <glx@openttd.org>
parents: 12993
diff changeset
652 _tcscat(text, _T("\n"));
b9302d9e1874 (svn r18184) -Codechange: add crash screenshot for win32
glx <glx@openttd.org>
parents: 12993
diff changeset
653 _tcscat(text, OTTD2FS(CrashLogWindows::current->screenshot_filename));
b9302d9e1874 (svn r18184) -Codechange: add crash screenshot for win32
glx <glx@openttd.org>
parents: 12993
diff changeset
654 }
12981
bee7b7b5b53e (svn r17475) -Codechange: show path to crash.log and crash.dmp in crash window. Also tells the user where crash.sav is when saving succeeded.
glx <glx@openttd.org>
parents: 12959
diff changeset
655
bee7b7b5b53e (svn r17475) -Codechange: show path to crash.log and crash.dmp in crash window. Also tells the user where crash.sav is when saving succeeded.
glx <glx@openttd.org>
parents: 12959
diff changeset
656 SetDlgItemText(wnd, 10, text);
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
657 SetDlgItemText(wnd, 11, MB_TO_WIDE_BUFFER(dos_nl, crash_msgW, lengthof(crash_msgW)));
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
658 SendDlgItemMessage(wnd, 11, WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT), FALSE);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
659 SetWndSize(wnd, -1);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
660 } return TRUE;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
661 case WM_COMMAND:
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
662 switch (wParam) {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
663 case 12: // Close
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
664 CrashLog::AfterCrashLogCleanup();
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
665 ExitProcess(2);
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
666 case 13: // Emergency save
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
667 char filename[MAX_PATH];
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
668 if (CrashLogWindows::current->WriteSavegame(filename, lastof(filename))) {
12993
90133be1c216 (svn r17487) -Fix: silence some MSVC warnings
rubidium <rubidium@openttd.org>
parents: 12981
diff changeset
669 size_t len = _tcslen(_save_succeeded) + _tcslen(OTTD2FS(filename)) + 1;
12981
bee7b7b5b53e (svn r17475) -Codechange: show path to crash.log and crash.dmp in crash window. Also tells the user where crash.sav is when saving succeeded.
glx <glx@openttd.org>
parents: 12959
diff changeset
670 TCHAR *text = AllocaM(TCHAR, len);
bee7b7b5b53e (svn r17475) -Codechange: show path to crash.log and crash.dmp in crash window. Also tells the user where crash.sav is when saving succeeded.
glx <glx@openttd.org>
parents: 12959
diff changeset
671 _sntprintf(text, len, _save_succeeded, OTTD2FS(filename));
bee7b7b5b53e (svn r17475) -Codechange: show path to crash.log and crash.dmp in crash window. Also tells the user where crash.sav is when saving succeeded.
glx <glx@openttd.org>
parents: 12959
diff changeset
672 MessageBox(wnd, text, _T("Save successful"), MB_ICONINFORMATION);
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
673 } else {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
674 MessageBox(wnd, _T("Save failed"), _T("Save failed"), MB_ICONINFORMATION);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
675 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
676 break;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
677 case 15: // Expand window to show crash-message
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
678 _expanded ^= 1;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
679 SetWndSize(wnd, _expanded);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
680 break;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
681 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
682 return TRUE;
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
683 case WM_CLOSE:
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
684 CrashLog::AfterCrashLogCleanup();
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
685 ExitProcess(2);
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
686 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
687
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
688 return FALSE;
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
689 }
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
690
12957
ae69ac470a83 (svn r17450) -Codechange: refactor the windows crash logger so parts of it can be reused by other crash logger implementations
rubidium <rubidium@openttd.org>
parents: 12924
diff changeset
691 static void ShowCrashlogWindow()
12917
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
692 {
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
693 ShowCursor(TRUE);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
694 ShowWindow(GetActiveWindow(), FALSE);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
695 DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(100), NULL, CrashDialogFunc);
d223546bf49d (svn r17409) -Codechange: split the crash log and other windows 'glue' code
rubidium <rubidium@openttd.org>
parents:
diff changeset
696 }