8

I'm running into an issue with my Features modules and installation profile when installing the site with drush si. There are a number of probably related issues in the Features issue queue, but none with good solutions. The interesting part (mentioned in some of the issues) is that it works fine when installing the site through the browser, but fails when installing with drush si.

I have an idea of what's wrong, but need to confirm it. The only way I can think of confirming it is to step through the code with a debugger (Xdebug is what I have set up). So, is it possible to trigger Xdebug from a command run with Drush? Specifically, can I get Xdebug to kick in when I run drush si?

3

you have to remember that with drush you are (most supposedly) in cli, so this should help :

https://stackoverflow.com/questions/1947395/how-can-i-debug-a-php-cli-script-with-xdebug

also, try running the command with the option -d (--debug) - it should give you quite a lot of info about what is going wrong.

  • Can you add some information about setting a break point in Drush/Drupal-specific code? i.e. a line number in a file that the debugger will break on if drush is run? – therobyouknow Jun 19 '14 at 15:37
  • An answer to my question appears to be here: randyfay.com/content/… :- " if you're debugging most drush actions, you could put a breakpoint on the first line of drupal_bootstrap() in includes/bootstrap.inc." – therobyouknow Jun 19 '14 at 15:42
2

I use XDebug on drush requests all the time.

  1. Make sure XDebug is loaded in your CLI php by running php -i
  2. Make sure your client is listening for XDebug connections, and is doing so on the right port. I have successfully debugged using PHPStorm, Netbeans, and Komodo IDE as clients.
  • 1
    Can you give an example of where (within drush itself or within another piece of Drupal code that drush calls) a breakpoint would be set so that xdebug breaks on this line of code when drush is run? – therobyouknow Jun 19 '14 at 15:36
  • An answer to my question appears to be here: randyfay.com/content/… :- " if you're debugging most drush actions, you could put a breakpoint on the first line of drupal_bootstrap() in includes/bootstrap.inc." – therobyouknow Jun 19 '14 at 15:41
2

You may use xdebug_start_trace() and xdebug_stop_trace() XDebug functions to kick off the debugger on demand. Make sure that you've configured XDebug in CLI first (php -i | grep xdebug).

Then create new one-liner PHP file as follows (e.g. drush_xdebug_start.inc):

<?php xdebug_start_trace();

Then run the drush as:

drush --early="$PWD"/drush_xdebug_start.inc whatever_command_you_need
1

Assuming you have Xdebug configured properly, it's very easy to integrate your IDE to step through code. Just set the environment variable XDEBUG_CONFIG to "idekey=MYIDEKEY".

Make it easier by setting up an alias for it. this is what I use in my .alias file (tcsh):

alias xdebugon 'setenv XDEBUG_CONFIG "idekey=MYIDEKEY"'
alias xdebugoff 'unsetenv XDEBUG_CONFIG'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.