In this article I’ve gathered my thoughts to help developers to get better in debugging especially if they find debugging really hard. The article also lists a set of tools which will help them to debug efficiently and to improve their skills. Hopefully you will find some value in this article, if you are also looking for debugging advice.
Last week has been a firefighting week at work (i.e. debugging and troubleshooting). I’m writing this article to share my experience with debugging a system configuration at work. In the end of article, I have placed some lessons learned points so hopefully someone can learn from it to improve their career.
I was working on a bug fix on our application with another fellow programmer. First we understood the root cause of the bug and what makes it to happen. All that was good. Then we thought of a solution and applied the first fix that I thought. Code works and bug is fixed, happy days. But wait.
Then I thought about the fix and it’s complexity. The bug was causing due to a list that is not getting updated and it was referring to an old memorized list that we lose track once the list is created. The first fix that we came is to have a reference to the memorized list as then we could update the memorized list. Even though this was a fixed, after looking at the Class, there was another list that is maintained to manage the same elements.
Given that we already have a working solution. I decided it is better to keep that as a backup solution and use the list that was managed by the Class as the reference. With simple line of changes we update the references to point to the list managed by the Class. Apart from fixing the buggy behavior we also managed simply our fix compared to the first approach.
So lessons learned:
Its better to get a working code quickly but also see the code and behavior in different perspectives. It will help you to find a better solution than the one you have right now.
This guide provide a step by step details on how to set up phpstorm IDE to work with xdebug.
Installing on Ubuntu
In software search for xdebug and install.
Add to the following xdebug settings to php.ini file
xdebug.remote_enable = 1 xdebug.remote_port = 9000 xdebug.remote_handler = dbgp xdebug.remote_mode = req
Installing on Windows XAMPP
First download xdebug and copy it into the extension folder. Copy the full path the extension.
Add the following xdebug settings to php.ini file.
[XDebug] zend_extension = "C:xamppphpextphp_xdebug-2.2.5-5.5-vc11.dll" xdebug.remote_enable=1 xdebug.remote_host=localhost xdebug.remote_port=9000 xdebug.remote_log="c:tmpxdebugxdebug.log" xdebug.show_exception_trace=0 xdebug.show_local_vars=9 xdebug.show_mem_delta=0 xdebug.trace_format=0 xdebug.profiler_enable = 1 xdebug.profiler_output_dir ="c:tmpxdebug"
Install easiest xdebug for Firefox and specify the remote IDE key for Firefox
Then in the xdebug configuration apply following
Put debug points and run the remote debug setting.
enable the easiest debug and navigate the test page through the browser. Your debug point should be hit, the request url is reading the debug file.
To stop breaking at the first line Untick Run->break and first line…