Skip to Content

Debug Drupal using Xdebug, Eclipse and Wamp

Hi All,

I was searching for debugging tool for drupal since i do module development and deals with so many websites during my projects. I found Xdebug is the one way to go . I am listing here step by step process to debug drupal using xdebug and Eclipse.

Step 1: Download Eclipse PDT from here http://www.eclipse.org/downloads/download.php?file=/technology/epp/downl...

Step2: Download php_xdebug-2.0.4-5.2.8.dll dll and place in C:\wamp\bin\php\php5.2.5\ext.

Step3: Edit your php.ini file with the following code at the end of file....
[xdebug]
zend_extension_ts="C:\wamp\bin\php\php5.2.5\ext\php_xdebug-2.0.4-5.2.8.dll"
xdebug.remote_enable=1
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"

Please check the path and version of php you are using in zend_extension_ts.

STEP 4: Restart your wamp.

STEP 5: On successful installation of xdebug you can see the below mentioned text just below php info.
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
with Xdebug v2.0.4, Copyright (c) 2002-2008, by Derick Rethans

The above mentioned text confirms successful installation of xdebug.

STEP 6: Open your Eclipse and add the drupal folder as php project. Todo this just create an emty php project and give the project workspace as c://wamp/www and add import your existing drupal folder to this project as a general folder import in eclipse.

STEP 7: Open Window->Preferences->General->Web Browser and set your browser here as external browser and select anyone of your browser.

STEP 8: Next go to Window->Preferences->PHP->Debug, and set the PHP Debugger option to XDebug

STEP 9: Now select your index.php --> right click -> Debug as -> Php webpage. Now your firefox open and you can see your project running.

STEP 10: Now goto window -> open perspective -> php debug. You can see now code is halted at first line of code.If you press play button in green color code will execute.

STEP 11: Set break points wherever you want in the files and click on step into to see the code flow.

STEP 12: To Debug other pages you can set the break points in corresponding module files and
open the corresponding page to debug.

STEP 13: To debug other that index.php copy the url like ?XDEBUG_SESSION_START=ECLIPSE_DBGP&KEY=12581835388283 and insert after your url and keep break points in the relevant code.Happy debugging. :-)

TIP: To make module files open in eclipse please add extensions to *.module to window->preferences->general->editors->fileassociations file type as *.module and associated editor as PHP

Please leave a comment in case if you have any issue. I am happy to help you.

Cheers,
Anil

Tagged in:

Comments

Tnx alot!

good Article! i set it up in 5 min!

Good Post

I have seen your step by step process to debug drupal using xdebug and Eclipse.it's really nice.actually whatever information you provided i really appreciate so I got very important information for debugging.Thanks.

Sweepstakes

Hi

Thanks for you appreciation... :-) It helps me to write more articles.....

Thanks Very Much for This.

I've just started out developing for Drupal and had no idea where to start with debugging tools.

Your blog got me up and running in 20 mins.

Very helpful. Thanks again.

J

xdebug in .module files stops only at function declarations

Thanks for the tutorial!
I have a question...
I installed xdebug and the debugger steps in and breaks at break points I place at function declarations in my .module files.
The problem is that if I try to "Step into" the functions, the debugger jumps to the next function call, and doesn't allow me to debug the code inside each function.
I guess this is not a limitation of the debugger, but something I configured\doing wrong.

Any suggestions?

Thanks in advance
Zion

Hi Zion

While you debug, you can see three options in eclipse.
* Step Into
* Step Over
* Step Out
Here is the functionality of each.

Step Into

Stepping is the process of running one statement at a time. After stepping through a statement, you can see its effect in the other Debugging windows.

Once you have stepped through all the statements in that procedure, eclipse will jump back to the next statement of the procedure it was called from.

Step Over

Step Over is the same as Step Into, except that when it reaches a call for another procedure, it will not step into the procedure. The procedure will run, and you will be brought to the next statement in the current procedure.

For example, if you had the following code:

Sub GetData()
Dim gName As String
gName = InputBox("Enter your name")
SetData(gName)
End Sub

Sub SetData(gName As String)
Text1 = "Name: " & gName
End Sub

Both Step Into and Step Over would behave the same, until they reached SetData(gName) . Using Step Over, Ecliplse would run the SetData procedure, and the cursor would be moved to the next statement in that procedure (in this case, End Sub). Using Step Into, the cursor would be moved to the beginning of the SetData procedure

Step Out

If you are using Step Into and have been moved to a called procedure, you can automatically run the current procedure, and return to the procedure it was called from by pressing the Step Out on the Debug menu, or pressing the button.

So basically you might be using step over function which restricts cursor going to statements of that functions. So you need to use step Into the first icon in the eclipse. Please let me know if you have any queries. I will make a video tutorial, it may help others too :-)

Cheers,
Anil

Hi Anil

Thanks very much for your reply!

I'm aware of what each option does and I'm using the "Step into" option.
Let me try to be more clear about the problem.
Let's say I have a function in my drupal module:

function myFunc() {
$var = 1;
}

I set the breakpoint to the line where the function is declared, and indeed the debugger gets to that line, but when I hit "Step Into", the debugger doesn't continue inside the function code, but instead jumps to the next function declaration.

Any ideas?

Hi Zion

I got your problem. I guess you are testing this debugging with drupal index.php file. The first line you encounter in index.php is

require_once './includes/bootstrap.inc';

Which will include all the functions in that file. That's why its not going into the function statements.But later on once the required file is included, set the break point on the second line that is

drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

Now you do step into you can see the cursor going to the statements inside the function. Let me know you found the answer for your question.

Cheers,
Anil

Function in .module file

Hi Anil,

I'm sorry if I wasn't clear enough.
The code I'm trying to debug is in my .module file (or any other .module file, not index.php).
When I set a breakpoint at a hook function declaration (for example, hook_view), the debugger stops ok, but if I try to "step into" the function it jumps to the next function call.

Hope it make more sense now,
Zion

Hi Zion

Hi Zion,

You need to run the web page corresponding the code so that you can see the execution of each and every statements.

For example if you are debugging the user.module file and you want to see the flow of the user.module, just try to run the /user/login page. You can place the breakpoints near user_form functions and you can see the cursor moving inside the functions.

Basically you need to run the web page corresponding to that code. As i explained earlier may be you are going to some code like require_once.

Just to test debug index.php and press stepinto till it halts. During this process you can see cursor moving into function statements. Try this and let me know the outcome.

Still you have any doubts please tell me which module you are using, which part of code you want to debug, which page you are running to check the flow. I am happy to help you :-)

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.