Skip to content
November 30, 2009 / lawrencebarsanti

Save time debugging. Use the EAX register.

Once and a while I run into code like this.

if SomeObject.SomeCounter() > 0 then
    // do something
    // do something else

Under normal circumstances the exact value of SomeCounter does not matter but when your are trying to track down a nasty bug, the exact value could be really useful.  If your lucky, you can just mouse over SomeCounter or add a watch, and the debugger will tell you the value.  However, there are many cases where this does not work so you have to stop debugging and change the code to look something like this.

N := SomeObject.SomeCounter();
if N > 0 then
  // do something
  // do something else

Here is a trick that saves me a lot of time.  The return value of a function is stored in the EAX register. So to get value of SomeCounter, you can just at the watch Integer(EAX) and look at it immediately after the function returns.  What if the return type is a string or some sort of complex object?  The EAX register will hold a pointer to the object which can be casted and examined (i.e. PString(EAX)^ or TMyObject(EAX)).  So far the only type I haven’t figured out are floating point values.  Please post a comment if you know how to do this.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: