Debugging: The key role to perform

Debugging: The key role to perform

January 7, 2019

No Comments

What are the skills needed for a software developer? We can point out several skills – analytical thinking, algorithms, design, coding etc and last but important – debugging.
Here we are talking about the debugging. Debugging is an art of tracing and fixing the bugs, which saves a lot of time of the developer.
Let’s start it with the Basic Debugging techniques
Today, most developers still used the functions like print_r, var_dump, die and debug_print_backtrace() for debugging.
We can use these functions for small codebase applications. But for the larger codebase, these are not enough.
Suppose we have applied these functions and forget to remove these from the code. What will happen? It may expose sensitive details to others. Let a user know your code structure when you left the debug_print_backtrace() in the code.
expose the business critical or privacy-sensitive data even to the naive users
So we have other techniques
Logging
Logging is one of the best techniques to make debugging efficient. A healthy logging practice makes an application easier to Debug.
In production, enable these log levels
Warning
Fatal
In the development environment, it is suggested to enable these levels
Notice (Information Message)
Warnings (Actionable Message)
Fatal Errors
Error handling functions
Setting up the development environment correctly improves our debugging and development capability. PHP has configuration parameters which will ease the debugging purpose.
log_errors – Setting it to true will enable the error logging
log_errors_max_len – Set the maximum length of each log record
error_log – Set the file on which the error will be logged. We prefer to log errors of each technology in a separate folder, it makes it easier to manage the logs.
error_reporting – Setting to E_ALL will enable logging of all type errors.
display_errors – Enabling it will write the message on the webpage. Which will give the visibility of errors?
html_errors– Enabling it will do the formatting of errors in the webpage which make it easier to read the errors.
track_errors– If enabled, last error message will always be present in the global variable $php_errormsg.

Below is a list of debugging and monitoring tools
phpdbg: This powerful native interactive debugger comes by default with PHP 5.6 It is a CLI tool that can allow the programmer to debug using breakpoints to step through the code. It also provides easy access to PHP with built-in eval().
phptrace : This tracing and troubleshooting tool can trace running PHP processes, function calls, and request information during run-time. It can be installed as a PHP extension or a CLI tool.
strace: This is a diagnostics and debugging tool that is useful in debugging at a system level. It is used to trace any system calls and signals performed by a program and is invaluable in troubleshooting programs in which the source is not readily available.
ltrace: This is a library call tracer tool used to trace any libraries in a program. Dynamic library calls made by an executed process are intercepted and recorded.
MySQL Proxy: This is a program that sits in between your client and MySQL server(s) to monitor, analyze, or even transform the communication for real-time SQL debugging and troubleshooting. It also allows for custom configuration through Lua scripting