Tuesday, September 29, 2015

Debugging complex systems (such as Magento)

In modern day software, source code is separated in a huge number of blocks, This blocks are usually defined as classes. Debugging many problems comes down to finiding the class responsible for a particular action in particular point of time.

Case scenario:

You need to find out why your $x is always at value 0. You set its value in a model, but when you print it out , it is always zeroed.
This indicates that some other object must have altered the value of this variable.

Here's a neat way how to tell who has edited the variable:

1. Start at the end of process. Find the part of code which displays the variable with wrong value. Before displaying, add a line to print stack trace (in PHP its called debug_backtrace).

2. Find all the functions which were called prior to calling the display function. Go to the function you think that might have wrongly changed the variable value.

3. In that function , try to print out the variable value at the start, and at the end of the function. If they don't match, your problem is inside this function.


No comments:

Post a Comment

Ubuntu 12.04, 14.04, 16.04 - auto start an app or script before login

To run a command or application at startup, even before the user has logged in, you can use this file: /etc/rc.local The commands entered...