Save a Memory Dump for debugging Crashes: Difference between revisions

From The DarkMod Wiki
Jump to navigationJump to search
(Quoted how to enable WER with regedit, application-specific approach moved to the very bottom.)
Line 5: Line 5:
In principle, recording memory dumps is not limited to crashed applications. It is possible to record memory dump of alive process, although in most cases such dump would be useless.
In principle, recording memory dumps is not limited to crashed applications. It is possible to record memory dump of alive process, although in most cases such dump would be useless.


Note: At the moment this only applies to the Windows OS, we don't know if there's something similar available for Linux environments.
Note: At the moment this only applies to the Windows OS.
== Record the Memory Dump (for Dark Radiant) ==
There is similar mechanism (core dumps) on Linux environments, but it is not covered by this article yet.
 
 
== Enable Memory Dumps ==
 
When application crashes, it usually shows a dialog like this:
When application crashes, it usually shows a dialog like this:


[[File:Dr has stopped working.png]]
[[File:Dr has stopped working.png]]


Note: If you don't get that window showing up for you (e.g. Windows 10), you'll probably need to re-enable that fix to make it show up again: https://superuser.com/a/1349113
If you don't get that window showing up for you, please check the WER flag in registry editor:
* Run the Registry Editor and under the key <tt>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting</tt>, create a <tt>DWORD DontShowUI</tt> of value <tt>0</tt>.
 
See alternative approach here: https://superuser.com/a/1349113
 
 
== Record Memory Dumps ==


When it appears, keep that window open, '''don't close that dialog''', instead open your Task Manager. To open the Task Manager, press Ctrl + Shift + Escape. Another way is to hit Windows + R and type "taskmgr" and click OK.
When the dialog appears, keep that window open, '''don't close that dialog''', instead open your Task Manager. To open the Task Manager, press Ctrl + Shift + Escape. Another way is to hit Windows + R and type "taskmgr" and click OK.
In the Task Manager, switch to the Processes tab and locate the program which crashed (DarkRadiant.exe, TheDarkModx64.exe or tdm_update.exe). It should be in that list since you still have the "XXX has stopped working" dialog open in the background.
In the Task Manager, switch to the Processes tab and locate the program which crashed (DarkRadiant.exe, TheDarkModx64.exe or tdm_installer.exe). It should be in that list since you still have the "XXX has stopped working" dialog open in the background.


[[File:Dr process in task manager.png]]
[[File:Dr process in task manager.png]]


Now right-click the DarkRadiant.exe line and select "Create dump file":
Now right-click the line with the name of the crashed program and select "Create dump file":


[[File:Dr process create dump.png]]
[[File:Dr process create dump.png]]
Line 29: Line 39:
<br>
<br>
<br>
<br>
== Record the Memory Dump (for The Dark Mod) ==
<br>
Most of the time when TDM chrashes, it just stops.<br>
So then it is impossible to record a memorydump when the executable still "runs", using the taskmanager,<br> 
But the system can generate a memory dump automatically, if you enable "[https://docs.microsoft.com/nl-nl/windows/win32/wer/collecting-user-mode-dumps windows User-Mode Dumps]". <br>
By activating this in the Windows Registry.
<br>
Enabling user-mode dumps, by running the following commands in "command prompt with administration rights"
#hit windowskey+r, fill in "cmd" and hit keycombination ctrl+shift+enterkey
#a black window will apear. Check the title bar, if it is running with administrator rights. 
#Enter in this black window following command lines in.<br> For every command line, type the commandline in and hit the enter-key.<br>(tip: copy an comandline, the mouse-rightclick inside the black window to paste the line)
#reg add "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\TheDarkModx64.exe" /t REG_SZ /v "DumpFolder" /d "c:\temp\CrashDumps"
#reg add "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\TheDarkModx64.exe" /t REG_DWORD /v "DumpCount" /d "0x1"
#reg add "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\TheDarkModx64.exe" /t REG_DWORD /v "DumpType" /d "0x1"
#reg add "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\TheDarkModx64.exe" /t REG_DWORD /v "CustomDumpFlags" /d "0"
#net start WerSvc <br>(if there is a windows service named "Windows Error Reporting Service")
#Then close the black window.
#After this Run TDM.<br> If TDM then crashes, a dump will be recorded and placed in folderlocation: c:\temp\CrashDumps.<br>(windows explorer > this computer > disk c > folder "temp" > folder "crashdumps")
#After getting a crashdump, disable the memorydump setting for TheDarkModx64, <br>by removing the registrykey by running command: reg delete "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\TheDarkModx64.exe"
#end.
<br>
or Enabling user-mode dumps, using the windows registry editor.<br>
#hit windowskey+r, fill in "regedit" and hit keycombination ctrl+shift+enterkey
#This windows registry widows will appear.<br>On the navigation secion (left side), select Computer > HKEY_LOCAL_MACHINE > SOFTWARE > Microsoft > Windows > Windows Error Reporting
#Rightclick on that folder > new > key. Call it "LocalDumps"
#in the localdumps folder, rightclick in a empty space, new >  string. name "DumpFolder", and value "c:\temp\CrashDumps""
#in the localdumps folder, rightclick in a empty space, new >  dword32. name "DumpCount", and value "1" (decimal)
#in the localdumps folder, rightclick in a empty space, new >  dword32. name "DumpType", and value "2" (decimal), or value "1"
#in the localdumps folder, rightclick in a empty space, new >  dword32. name "CustomDumpFlags", and value "0"
#close application and restart windows.
#After this Run TDM.<br> If TDM then crashes, a dump will be recorded and placed in folderlocation: c:\temp\CrashDumps.<br>(windows explorer > this computer > disk c > folder "temp" > folder "crashdumps")
#After getting a crashdump, disable the memorydump setting, by change "DumpCount" value to "0"
#end.
<br>
<br>you can change dumptype. to "1" for a minidump or "2" for a full dump
(or using reg, use values "0x1" or "0x2")


== Compress and Upload the Dump ==
== Compress and Upload the Dump ==
Line 71: Line 44:
Depending on what you had opened in DarkRadiant or what FM you loaded in the game itself, the .dmp file might end up very large, so it's best to compress it now using 7-zip or by right-clicking it and selecting "Send to..." > "Compressed (zip) folder".
Depending on what you had opened in DarkRadiant or what FM you loaded in the game itself, the .dmp file might end up very large, so it's best to compress it now using 7-zip or by right-clicking it and selecting "Send to..." > "Compressed (zip) folder".


Upload that folder to some place in the web, and please go to the forums to tell the devs about your crash dump. '''Thanks for your time''', we know that recording and uploading crash dumps might be tedious, but without we really can't do much about the crash, so your help is appreciated!
Upload that folder to some place in the web, and please go to the forums to tell the devs about your crash dump.
 
'''Thanks for your time''', we know that recording and uploading crash dumps might be tedious, but without we really can't do much about the crash, so your help is appreciated!


== Debugging / Analysis ==
== Debugging / Analysis ==
Coders might want to check out the article on [[Analyze_a_Memory_Dump|analyzing a memory dump.]]
Coders might want to check out the article on [[Analyze_a_Memory_Dump|analyzing a memory dump.]]
== Alternative approach ==
It is possible to enable automatic saving of crash dumps for a particular program, although it is more complicated.
The process is described in [https://docs.microsoft.com/nl-nl/windows/win32/wer/collecting-user-mode-dumps Windows User-Mode Dumps].
# Press Windows-key + R, type in "cmd", and press Ctrl+Shift+Enter to run it with admin rights.
# A black window of console will appear. Check the title bar and make sure it is running with administrator rights.
# Execute the following commands in the console (copy/paste them with Ctrl+C / Ctrl+V):
# <tt>reg add "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\TheDarkModx64.exe" /t REG_SZ /v "DumpFolder" /d "c:\temp\CrashDumps"</tt>
# <tt>reg add "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\TheDarkModx64.exe" /t REG_DWORD /v "DumpCount" /d "0x1"</tt>
# <tt>reg add "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\TheDarkModx64.exe" /t REG_DWORD /v "DumpType" /d "0x2"</tt>
# <tt>reg add "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\TheDarkModx64.exe" /t REG_DWORD /v "CustomDumpFlags" /d "0"</tt>
# <tt>net start WerSvc</tt> <br>(if there is a windows service named "Windows Error Reporting Service")
# Close the console, you don't need it anymore.
Now you can run TDM as usual (run executable TheDarkModx64.exe).
If it crashes, a dump will be recorded and saved at <tt>C:\temp\CrashDumps</tt>.
Here is how you can disable automatic saving of memory dumps for TheDarkModx64.exe:
# Run console (cmd) with admin rights the same way you did it when you enabled dumps, then execute:
# <tt>reg delete "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\TheDarkModx64.exe"</tt>
Alternatively, you can add/remove registry keys directly in Registry Editor if you like.
In this case, restart Windows instead of starting WerSvc service.


[[Category:DarkRadiant]]
[[Category:DarkRadiant]]
[[Category:Coding]]
[[Category:Coding]]

Revision as of 03:24, 29 December 2021

DarkRadiant or TheDarkMod crashed? If you don't want that to happen again, you need to help the team to debug this malfunction --- you can do this by dumping process memory to a file, which can then be used by developers to debug and inspect the application's state at the point in time it crashed.

If a crash is reproducible, it might be enough to describe the exact steps that lead up to the fault and file a bug report on the bugtracker. But more often than sometimes crashes occur out of seemingly nothing and are barely reproducible, and in this case a saved memory dump is even more valuable for debugging purposes.

In principle, recording memory dumps is not limited to crashed applications. It is possible to record memory dump of alive process, although in most cases such dump would be useless.

Note: At the moment this only applies to the Windows OS. There is similar mechanism (core dumps) on Linux environments, but it is not covered by this article yet.


Enable Memory Dumps

When application crashes, it usually shows a dialog like this:

Dr has stopped working.png

If you don't get that window showing up for you, please check the WER flag in registry editor:

  • Run the Registry Editor and under the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting, create a DWORD DontShowUI of value 0.

See alternative approach here: https://superuser.com/a/1349113


Record Memory Dumps

When the dialog appears, keep that window open, don't close that dialog, instead open your Task Manager. To open the Task Manager, press Ctrl + Shift + Escape. Another way is to hit Windows + R and type "taskmgr" and click OK. In the Task Manager, switch to the Processes tab and locate the program which crashed (DarkRadiant.exe, TheDarkModx64.exe or tdm_installer.exe). It should be in that list since you still have the "XXX has stopped working" dialog open in the background.

Dr process in task manager.png

Now right-click the line with the name of the crashed program and select "Create dump file":

Dr process create dump.png

It will work a bit and then show you something like this:

Dr dump created.png

Open Windows Explorer and head to the location indicated in the dialog. Note that you can mark and copy the location from that dialog using your mouse, so you don't have to type it in entirely.

Compress and Upload the Dump

Depending on what you had opened in DarkRadiant or what FM you loaded in the game itself, the .dmp file might end up very large, so it's best to compress it now using 7-zip or by right-clicking it and selecting "Send to..." > "Compressed (zip) folder".

Upload that folder to some place in the web, and please go to the forums to tell the devs about your crash dump.

Thanks for your time, we know that recording and uploading crash dumps might be tedious, but without we really can't do much about the crash, so your help is appreciated!

Debugging / Analysis

Coders might want to check out the article on analyzing a memory dump.


Alternative approach

It is possible to enable automatic saving of crash dumps for a particular program, although it is more complicated. The process is described in Windows User-Mode Dumps.

  1. Press Windows-key + R, type in "cmd", and press Ctrl+Shift+Enter to run it with admin rights.
  2. A black window of console will appear. Check the title bar and make sure it is running with administrator rights.
  3. Execute the following commands in the console (copy/paste them with Ctrl+C / Ctrl+V):
  4. reg add "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\TheDarkModx64.exe" /t REG_SZ /v "DumpFolder" /d "c:\temp\CrashDumps"
  5. reg add "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\TheDarkModx64.exe" /t REG_DWORD /v "DumpCount" /d "0x1"
  6. reg add "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\TheDarkModx64.exe" /t REG_DWORD /v "DumpType" /d "0x2"
  7. reg add "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\TheDarkModx64.exe" /t REG_DWORD /v "CustomDumpFlags" /d "0"
  8. net start WerSvc
    (if there is a windows service named "Windows Error Reporting Service")
  9. Close the console, you don't need it anymore.

Now you can run TDM as usual (run executable TheDarkModx64.exe). If it crashes, a dump will be recorded and saved at C:\temp\CrashDumps.

Here is how you can disable automatic saving of memory dumps for TheDarkModx64.exe:

  1. Run console (cmd) with admin rights the same way you did it when you enabled dumps, then execute:
  2. reg delete "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\TheDarkModx64.exe"

Alternatively, you can add/remove registry keys directly in Registry Editor if you like. In this case, restart Windows instead of starting WerSvc service.