Difference between revisions of "DebuggingCrashes"

From TTWiki
Jump to navigationJump to search
m (9 revisions)
(Reformat and update)
Line 1: Line 1:
 
'''''How to debug crashes with no crash log or hangs'''''
 
 
=Debugging Crashes=
 
 
How to debug crashes with no crash log or hangs
 
 
{maketoc}
 
 
 
When TTDPatch or TTD crash without producing a crash log file (crash###.txt), it is very hard for the developers to figure out what went wrong or how to fix it. The same applies for when TTD stops responding and hangs, so that you have to kill it with the task manager.
 
When TTDPatch or TTD crash without producing a crash log file (crash###.txt), it is very hard for the developers to figure out what went wrong or how to fix it. The same applies for when TTD stops responding and hangs, so that you have to kill it with the task manager.
   
Line 14: Line 5:
 
The process to get this information uses a debugger, a program that can catch crashes and interrupt a hung process in a controlled manner. If you've never used a debugger before, don't worry, we have step-by-step instructions here to tell you how to use it.
 
The process to get this information uses a debugger, a program that can catch crashes and interrupt a hung process in a controlled manner. If you've never used a debugger before, don't worry, we have step-by-step instructions here to tell you how to use it.
   
If you need help at any time, the best choice is to visit the [irc://irc.oftc.net/tycoon|#tycoon] IRC channel, or use the chat applet on TT-Forums. There's usually a patch developer there who can help you.
+
If you need help at any time, the best choice is to visit the [irc://irc.oftc.net/tycoon #tycoon] IRC channel, or use the chat applet on TT-Forums. There's usually a patch developer there who can help you.
   
 
==Install a debugger==
 
==Install a debugger==
   
First you need to install a debugger, if you don't have it already. Download [http://www.ollydbg.de/|OllyDbg] and install it.
+
First you need to install a debugger, if you don't have it already. Download [http://www.ollydbg.de/ OllyDbg] and install it.
   
Run it once, and open the "Debugging options" dialog.
+
Run it once, and open the "Debugging options" dialog.
   
  +
[[File:Options.png]]
</center>
 
   
Now open the &quot;Exceptions&quot; tab, and check the &quot;Integer division by 0&quot; and &quot;All FPU exceptions&quot; boxes.
+
Now open the "Exceptions" tab, and check the "Integer division by 0" and "All FPU exceptions" boxes.
   
  +
[[File:Options2.png]]
</center>
 
   
Click &quot;OK&quot; and quit. ))OllyDbg[[]]OllyDbg[[ is now set up properly for debugging TTD/TTDPatch.
+
Click "OK" and quit. OllyDbg is now set up properly for debugging TTD/TTDPatch.
   
 
==Debugging a crash==
 
==Debugging a crash==
Line 34: Line 25:
 
If the game crashes, but does not create a crash log, you need to have the debugger catch the crash. There are two possible ways of doing this. If the crash happens before you get to the TTD title screen, or if the following instructions do not work or do not catch the crash, try those in the next section below.
 
If the game crashes, but does not create a crash log, you need to have the debugger catch the crash. There are two possible ways of doing this. If the crash happens before you get to the TTD title screen, or if the following instructions do not work or do not catch the crash, try those in the next section below.
   
This requires that you can ))Alt-Tab[[]]Alt-Tab[[ or ))Alt-Esc[[]]Alt-Esc[[ out of TTD back to Windows. If you can't ))Alt-Tab[[]]Alt-Tab[[ out, try running TTD in windowed mode. Note that you will not be able to save your game when it happens (but it would crash anyway so that's no different to what you had before).
+
This requires that you can Alt-Tab or Alt-Esc out of TTD back to Windows. If you can't Alt-Tab out, try running TTD in windowed mode. Note that you will not be able to save your game when it happens (but it would crash anyway so that's no different to what you had before).
 
* Start TTD normally
 
* Start TTD normally
* When TTD shows the title screen, press ))Alt-Tab[[]]Alt-Tab[[ or ))Alt-Esc[[]]Alt-Esc[[ to return to Windows
+
* When TTD shows the title screen, press Alt-Tab or Alt-Esc to return to Windows
* Start ))OllyDbg[[]]OllyDbg[[
+
* Start OllyDbg
* Select File|Attach, then choose &quot;Transport Tycoon Deluxe&quot; (it should have TTDLOADW.OVL in the name and path columns), then click &quot;Attach&quot;
+
* Select File|Attach, then choose "Transport Tycoon Deluxe" (it should have TTDLOADW.OVL in the name and path columns), then click "Attach"
  +
: [[File:attach.png]]
 
 
* You will now get an "Entry point alert" warning. Simply click "OK".
</center>
 
 
* Continue to run TTD by pressing the "F9" key or clicking the "run" button [[File:runbutton.png]].
* You will now get an &quot;Entry point alert&quot; warning. Simply click &quot;OK&quot;.
 
 
* Now return to TTD in the task bar or with Alt-Tab
* Continue to run TTD by pressing the &quot;F9&quot; key or clicking the &quot;run&quot; button .
 
* Now return to TTD in the task bar or with ))Alt-Tab[[]]Alt-Tab[[
 
 
* Reproduce the steps that caused the crash last time
 
* Reproduce the steps that caused the crash last time
* At the time of the crash, ))OllyDbg[[]]OllyDbg[[ should start flashing in the task bar
+
* At the time of the crash, OllyDbg should start flashing in the task bar
* Click on it there to bring up the window, maximize ))OllyDbg[[]]OllyDbg[[, and take a screenshot
+
* Click on it there to bring up the window, maximize OllyDbg, and take a screenshot
   
Submit this screenshot to the patch developers. It is best to go to the [irc://irc.quakenet.org/tycoon|#tycoon] IRC channel or the forum chat applet right away, with the windows still open, to see if the patch developers need any further information at this point.
+
Submit this screenshot to the patch developers. It is best to go to the [irc://irc.oftc.net/tycoon #tycoon] IRC channel or the forum chat applet right away, with the windows still open, to see if the patch developers need any further information at this point.
   
When done, simply close ))OllyDbg[[]]OllyDbg[[. This will also close TTD.
+
When done, simply close OllyDbg. This will also close TTD.
   
 
==Debugging a crash (alternate)==
 
==Debugging a crash (alternate)==
Line 58: Line 48:
 
First, open your ttdpatch.cfg in Notepad, and enter the following line somewhere:
 
First, open your ttdpatch.cfg in Notepad, and enter the following line somewhere:
   
<pre>-+debugswitches r+-</pre>
+
<pre>debugswitches r</pre>
   
 
With this, TTD/TTDPatch will no longer start up normally, so be sure to remove it again when you're done with this procedure.
 
With this, TTD/TTDPatch will no longer start up normally, so be sure to remove it again when you're done with this procedure.
Line 64: Line 54:
 
Now start TTDPatch. It will do the normal steps and then show the following warning:
 
Now start TTDPatch. It will do the normal steps and then show the following warning:
   
<pre>-+Couldn't execute TTDLOADW.OVL: DEBUG SWITCH+-</pre>
+
<pre>Couldn't execute TTDLOADW.OVL: DEBUG SWITCH</pre>
   
At this point, start ))OllyDbg[[]]OllyDbg[[. Select File|Open, browse to your TTD folder, and open TTDLOADW.OVL.
+
At this point, start OllyDbg. Select File|Open, browse to your TTD folder, and open TTDLOADW.OVL.
* You will now get an &quot;Entry point alert&quot; warning. Simply click &quot;OK&quot;.
+
* You will now get an "Entry point alert" warning. Simply click "OK".
* Now press F9 or the &quot;run&quot; button to start TTDPatch and TTD.
+
* Now press F9 or the "run" button [[File:runbutton.png]] to start TTDPatch and TTD.
 
* Reproduce the steps that caused the crash last time
 
* Reproduce the steps that caused the crash last time
* At the time of the crash, ))OllyDbg[[]]OllyDbg[[ should start flashing in the task bar
+
* At the time of the crash, OllyDbg should start flashing in the task bar
* Click on it there to bring up the window, maximize ))OllyDbg[[]]OllyDbg[[, and take a screenshot
+
* Click on it there to bring up the window, maximize OllyDbg, and take a screenshot
   
Submit this screenshot to the patch developers. It is best to go to the [irc://irc.quakenet.org/tycoon|#tycoon] IRC channel or the forum chat applet right away, with the windows still open, to see if the patch developers need any further information at this point.
+
Submit this screenshot to the patch developers. It is best to go to the [irc://irc.oftc.net/tycoon #tycoon] IRC channel or the forum chat applet right away, with the windows still open, to see if the patch developers need any further information at this point.
   
When done, simply close ))OllyDbg[[]]OllyDbg[[. This will also close TTD. Press any key in the TTDPatch window to close it as well.
+
When done, simply close OllyDbg. This will also close TTD. Press any key in the TTDPatch window to close it as well.
   
 
==Debugging a hang==
 
==Debugging a hang==
   
Follow this procedure if TTD stops responding for a long time. This requires that you can ))Alt-Tab[[]]Alt-Tab[[ or ))Alt-Esc[[]]Alt-Esc[[ out of TTD back to Windows. If you can't ))Alt-Tab[[]]Alt-Tab[[ out, try running TTD in windowed mode. Note that you will not be able to save your game when it happens (but it would hang anyway so that's no different to what you had before).
+
Follow this procedure if TTD stops responding for a long time. This requires that you can Alt-Tab or Alt-Esc out of TTD back to Windows. If you can't Alt-Tab out, try running TTD in windowed mode. Note that you will not be able to save your game when it happens (but it would hang anyway so that's no different to what you had before).
 
* Reproduce what you were doing when TTD stopped responding
 
* Reproduce what you were doing when TTD stopped responding
* When TTD stops responding again, press ))Alt-Tab[[]]Alt-Tab[[ or ))Alt-Esc[[]]Alt-Esc[[ to return to Windows
+
* When TTD stops responding again, press Alt-Tab or Alt-Esc to return to Windows
* Start ))OllyDbg[[]]OllyDbg[[
+
* Start OllyDbg
* Select File|Attach, then choose &quot;Transport Tycoon Deluxe&quot; (it should have TTDLOADW.OVL in the name and path columns), then click &quot;Attach&quot;
+
* Select File|Attach, then choose "Transport Tycoon Deluxe" (it should have TTDLOADW.OVL in the name and path columns), then click "Attach"
   
  +
[[File:attach.png]]
</center>
 
   
You will now get an &quot;Entry point alert&quot; warning. Simply click &quot;OK&quot;. At this point the window should look like this (click on thumbnail for full size view):
+
You will now get an "Entry point alert" warning. Simply click "OK". At this point the window should look like this (click on thumbnail for full size view):
   
  +
[[File:postattach.png]]
src=&quot;img/wiki_up/postattach_t.jpg&quot; ]</center>
 
   
Note the &quot;EIP&quot; line on the right. After 8 hex digits, it will say something with either &quot;NTDLL&quot; or &quot;KERNEL32&quot;, depending on your Windows version. If it doesn't, ask for help at this point.
+
Note the "EIP" line on the right. After 8 hex digits, it will say something with either "NTDLL" or "KERNEL32", depending on your Windows version. If it doesn't, ask for help at this point.
   
Now select &quot;Debug|Execute till user code&quot; or press ))Alt-F9[[]]Alt-F9[[, and check the EIP line again. It should say &quot;TTDLOADW&quot; after the 8 hex digits:
+
Now select "Debug|Execute till user code" or press Alt-F9, and check the EIP line again. It should say "TTDLOADW" after the 8 hex digits:
   
  +
[[File:ttdloadw.png]]
</center>
 
   
 
Note that the letters/digits don't matter, just check that it says TTDLOADW. If it doesn't, something is probably not working, so ask for help at this point.
 
Note that the letters/digits don't matter, just check that it says TTDLOADW. If it doesn't, something is probably not working, so ask for help at this point.
   
At this point, take a screenshot of the entire ))OllyDbg[[]]OllyDbg[[ window and submit it to the patch developers. It is best to go to the [irc://irc.quakenet.org/tycoon|#tycoon] IRC channel or the forum chat applet right away, with the windows still open, to see if the patch developers need any further information at this point.
+
At this point, take a screenshot of the entire OllyDbg window and submit it to the patch developers. It is best to go to the [irc://irc.oftc.net/tycoon tycoon] IRC channel or the forum chat applet right away, with the windows still open, to see if the patch developers need any further information at this point.
  +
 
When done, simply close OllyDbg. This will also close TTD.
   
 
==Final notes==
When done, simply close ))OllyDbg[[]]OllyDbg[[. This will also close TTD.
 
 
# When using OllyDbg to debug crashes or hangs, it is very much advisable, although not absolutely required, to start TTD in windowed mode, not full-screen mode.
 
# For unknown reasons, OllyDbg sometimes fails to provide us as much information as we would like. Sometimes, the screenshot will look like this (click on thumbnail for full size view):
   
  +
<center>[[File:debug1.png]]</center>
=Final notes=
 
# When using ))OllyDbg[[]]OllyDbg[[ to debug crashes or hangs, it is very much advisable, although not absolutely required, to start TTD in windowed mode, not full-screen mode.
 
# For unknown reasons, ))OllyDbg[[]]OllyDbg[[ sometimes fails to provide us as much information as we would like. Sometimes, the screenshot will look like this (click on thumbnail for full size view):
 
   
 
<center>(It doesn't matter which letters/digits appear in the "Same number" area, but it will be the same set on every line, and all three areas marked "Empty" will be.)</center>
src=&quot;img/wiki_up/debug_thumb.png&quot; ]</center>
 
   
 
If this happens, something went wrong with OllyDbg. Submit the screenshot as normal, but then please contact [mailto:Ollydbg@t-online.de?subject=Have%20question|Oleh Yuschuk], and tell him you can reproduce the problem DaleStan reported. Please do everything he asks of you, so this issue may be resolved as quickly as possible.
<center>(It doesn't matter which letters/digits appear in the &quot;Same number&quot; area, but it will be the same set on every line, and all three areas marked &quot;Empty&quot; will be.)</center>
 
   
  +
[[Category:TTDPatch Development]]
If this happens, something went wrong with ))OllyDbg[[]]OllyDbg[[. Submit the screenshot as normal, but then please contact [mailto:Ollydbg@t-online.de?subject=Have%20question|Oleh Yuschuk], and tell him you can reproduce the problem ))DaleStan[[]]DaleStan[[ reported. Please do everything he asks of you, so this issue may be resolved as quickly as possible.
 

Revision as of 17:36, 30 July 2011

When TTDPatch or TTD crash without producing a crash log file (crash###.txt), it is very hard for the developers to figure out what went wrong or how to fix it. The same applies for when TTD stops responding and hangs, so that you have to kill it with the task manager.

If a crash log is produced, simply forward it to the patch developers. This document explains how to get the information that's usually in the crash log to the patch developers so they may attempt to figure out what the problem is in the absense of a crash log.

The process to get this information uses a debugger, a program that can catch crashes and interrupt a hung process in a controlled manner. If you've never used a debugger before, don't worry, we have step-by-step instructions here to tell you how to use it.

If you need help at any time, the best choice is to visit the #tycoon IRC channel, or use the chat applet on TT-Forums. There's usually a patch developer there who can help you.

Install a debugger

First you need to install a debugger, if you don't have it already. Download OllyDbg and install it.

Run it once, and open the "Debugging options" dialog.

Options.png

Now open the "Exceptions" tab, and check the "Integer division by 0" and "All FPU exceptions" boxes.

Options2.png

Click "OK" and quit. OllyDbg is now set up properly for debugging TTD/TTDPatch.

Debugging a crash

If the game crashes, but does not create a crash log, you need to have the debugger catch the crash. There are two possible ways of doing this. If the crash happens before you get to the TTD title screen, or if the following instructions do not work or do not catch the crash, try those in the next section below.

This requires that you can Alt-Tab or Alt-Esc out of TTD back to Windows. If you can't Alt-Tab out, try running TTD in windowed mode. Note that you will not be able to save your game when it happens (but it would crash anyway so that's no different to what you had before).

  • Start TTD normally
  • When TTD shows the title screen, press Alt-Tab or Alt-Esc to return to Windows
  • Start OllyDbg
  • Select File|Attach, then choose "Transport Tycoon Deluxe" (it should have TTDLOADW.OVL in the name and path columns), then click "Attach"
Attach.png
  • You will now get an "Entry point alert" warning. Simply click "OK".
  • Continue to run TTD by pressing the "F9" key or clicking the "run" button Runbutton.png.
  • Now return to TTD in the task bar or with Alt-Tab
  • Reproduce the steps that caused the crash last time
  • At the time of the crash, OllyDbg should start flashing in the task bar
  • Click on it there to bring up the window, maximize OllyDbg, and take a screenshot

Submit this screenshot to the patch developers. It is best to go to the #tycoon IRC channel or the forum chat applet right away, with the windows still open, to see if the patch developers need any further information at this point.

When done, simply close OllyDbg. This will also close TTD.

Debugging a crash (alternate)

If the above instructions don't catch the crash, especially if the crash happens before the title window comes up, try this method.

First, open your ttdpatch.cfg in Notepad, and enter the following line somewhere:

debugswitches r

With this, TTD/TTDPatch will no longer start up normally, so be sure to remove it again when you're done with this procedure.

Now start TTDPatch. It will do the normal steps and then show the following warning:

Couldn't execute TTDLOADW.OVL: DEBUG SWITCH

At this point, start OllyDbg. Select File|Open, browse to your TTD folder, and open TTDLOADW.OVL.

  • You will now get an "Entry point alert" warning. Simply click "OK".
  • Now press F9 or the "run" button Runbutton.png to start TTDPatch and TTD.
  • Reproduce the steps that caused the crash last time
  • At the time of the crash, OllyDbg should start flashing in the task bar
  • Click on it there to bring up the window, maximize OllyDbg, and take a screenshot

Submit this screenshot to the patch developers. It is best to go to the #tycoon IRC channel or the forum chat applet right away, with the windows still open, to see if the patch developers need any further information at this point.

When done, simply close OllyDbg. This will also close TTD. Press any key in the TTDPatch window to close it as well.

Debugging a hang

Follow this procedure if TTD stops responding for a long time. This requires that you can Alt-Tab or Alt-Esc out of TTD back to Windows. If you can't Alt-Tab out, try running TTD in windowed mode. Note that you will not be able to save your game when it happens (but it would hang anyway so that's no different to what you had before).

  • Reproduce what you were doing when TTD stopped responding
  • When TTD stops responding again, press Alt-Tab or Alt-Esc to return to Windows
  • Start OllyDbg
  • Select File|Attach, then choose "Transport Tycoon Deluxe" (it should have TTDLOADW.OVL in the name and path columns), then click "Attach"

Attach.png

You will now get an "Entry point alert" warning. Simply click "OK". At this point the window should look like this (click on thumbnail for full size view):

Postattach.png

Note the "EIP" line on the right. After 8 hex digits, it will say something with either "NTDLL" or "KERNEL32", depending on your Windows version. If it doesn't, ask for help at this point.

Now select "Debug|Execute till user code" or press Alt-F9, and check the EIP line again. It should say "TTDLOADW" after the 8 hex digits:

Ttdloadw.png

Note that the letters/digits don't matter, just check that it says TTDLOADW. If it doesn't, something is probably not working, so ask for help at this point.

At this point, take a screenshot of the entire OllyDbg window and submit it to the patch developers. It is best to go to the tycoon IRC channel or the forum chat applet right away, with the windows still open, to see if the patch developers need any further information at this point.

When done, simply close OllyDbg. This will also close TTD.

Final notes

  1. When using OllyDbg to debug crashes or hangs, it is very much advisable, although not absolutely required, to start TTD in windowed mode, not full-screen mode.
  2. For unknown reasons, OllyDbg sometimes fails to provide us as much information as we would like. Sometimes, the screenshot will look like this (click on thumbnail for full size view):
Debug1.png
(It doesn't matter which letters/digits appear in the "Same number" area, but it will be the same set on every line, and all three areas marked "Empty" will be.)

If this happens, something went wrong with OllyDbg. Submit the screenshot as normal, but then please contact Yuschuk, and tell him you can reproduce the problem DaleStan reported. Please do everything he asks of you, so this issue may be resolved as quickly as possible.