It can be a little tricky to set-up but once you have it working you will wonder how you ever worked without it. There is this article:
Although that looks to be a little dated.
The installation steps are going to change based your local environment. In a nutshell though. You install this.
That is a php extension which you will need to add to your php installation.
Once that is installed and configured you will need to use an IDE compatible with xdebug. I use PHPStorm but that isn't free. There is a trial version available for 30 days. I think most editors have a plugin that integrates with xdebug. You will need to search around the web based on the editor/IDE you use.
I also work on VMs that I create via puphpet.com.
Using a vm with puphpet instead of XAMP is more flexible and makes it easier to install additional extensions and software like xdebug and mail hog. I use mail hog to catch all the emails sent locally instead of actually sending them out when I'm developing.