Debugger

Francesco Ciannavei

Debugger

The debugger is the tool I reach for most to understand why something isn't working, in every language that allows it. Two cases, both found with Xdebug, say more than anything about how I use it.

The button that added nothing to the cart

At TUN2U, a Magento 2 store used a checkout module from an outside vendor. The "buy again" button, which should put the products of a past order back in the cart, didn't work: the product never got added.

I followed the request with Xdebug, step by step, through the module's code. The module passed Magento an identifier, the store ID as far as I remember, as a string. Magento expected an integer: it converted the string to 0 and looked the product up in store 0, where it didn't exist. That's why adding to the cart failed.

I fixed the module so it passed Magento an integer, and the button worked again.

A 404 on staging during a migration

While moving software from CodeIgniter 3 to CodeIgniter 4, staging showed a 404 whenever the app ran in a subdirectory with indexPage set. Following the flow, I found where the routing broke and proposed a fix to the framework; in the same work I found CodeIgniter 3 helper functions that no longer exist in 4 and reimplemented them. The full story, with the link to the pull request, is on the CodeIgniter page.

Xdebug, including remote

With PHP I use Xdebug every day, in PhpStorm or VS Code: breakpoints, variable inspection, the call stack. Remote mode is the one that saves me most often: it lets me debug applications running in Docker containers or on a server as if they were local. On Magento or Laravel projects, with dozens of layers of abstraction, it's the only serious way to understand the flow.

One debugger per language

I don't stop at PHP. For Go I use Delve, which inspects goroutines and channels and can attach to a running process. For Python I use Debugpy, built into VS Code and handy on asynchronous code too. For the Node.js backend I use the inspector via the --inspect flag, and for JavaScript in the browser, Chrome DevTools, with the dedicated extensions for React and Vue.

Rating
10/10

Where i've used it: