Login
Username:

Password:

Remember me



Lost Password?

Register now!
Main Menu
Site Info
Webmasters
admin
admin

Who's Online
6 user(s) are online (2 user(s) are browsing XOOPS Docman)

Members: 0
Guests: 6

more...

Chapter 4. Debugging

The following section (Section 4.1, “PHP Source Level Debugging”) describes one of the most interesting aspects when developing software: Debugging.

The second section (Section 4.1, “PHP Source Level Debugging”) within this chapter will describe how you can debug PHPeclipse itself. In case you want to find out how things work, or you found a bug in PHPeclipse and want to help the PHPeclipse developers.

4.1. PHP Source Level Debugging

Besides the method of outputting runtime information by adding echo or var_dump functions to your code, the more sophisticated and convenient method is using a so called “Source Level Debugger”.

With the current release of PHPeclipse only DBG is supported. XDebug is currently supported only by directly checking out from the PHPeclipse CVS repository and setting it up appropriately (see Section 1.5.2, “Installing XDEBUG”).

In case you havn't already installed DBG, see Section 1.5.1, “Installing DBG”. When you are sure the DBG module is correctly installed, you can go forward.

To do debugging in PHPeclipse you need to set up a so called “Debug Configuration”. The following sections describe how to set up such a “Debug Configuration” and how to start a debug session.

4.1.1. Setting up a Debug Configuration

To set up a “Debug Configuration” click on Run->Debug... (see Figure 4.1, “Open the Debug Configuration dialog”. Within the opened dialog click on “PHP DBG Script” and click on New (see Figure 4.2, “Debug Configuration with the Perspectives view”). This opens the “Create, manage, and run configuration” dialog.

[Note]Note

The first time you open the configuration dialog, you will see an error message within this dialog, complaining about a missing interpreter setting. For entering the interpreter see

Open the Debug Configuration dialog

Figure 4.1. Open the Debug Configuration dialog

Debug Configuration with the Perspectives view

Figure 4.2. Debug Configuration with the “Perspectives” view

4.1.1.1. Name the Debug Configuration

Within the “Name:” text field you should change the name (which is “New_configuration” per default) to a more reasonable one (see Figure 4.3, “Set up Debug Configuration - File”).

4.1.1.2. Configure File

Within the “File” tab you find two entries:

  • Project: This is the project this debug configuration belongs to.

  • File: This is used for “Non Remote Debugging”. The given file is directly given the interpreter which is entered within the Interpreter tab (see Section 4.1.1.4.1, “Configure Environment Interpreter”). And/or is it called when configured for using the internal browser.

Set up Debug Configuration - File

Figure 4.3. Set up Debug Configuration - File

4.1.1.3. Configure Arguments

These settings are used for “Non Remote Debugging”. If the given Interpreter is directly called by PHPeclipse (see Section 4.1.3, “Debugging CLI”).

  • Working Directory:

  • Use default working directory:

  • Interpreter Arguments: Here you can specify the arguments which will passed to the interpreter (see Using PHP from the command line).

  • Program Arguments: Here you can specify the arguments which will be passed to your script, and can be accessed by the $argv[] - array.

4.1.1.4. Configure Environment

Within this tab you have to enter the most important settings for a successful debugging session.

4.1.1.4.1. Configure Environment Interpreter

Although the setting of the interpreter isn't really necessary for “Remote Debugging”, you have to set it up. For a default XAMPP installation this would be C:\Program Files\apachefriends\xampp\php\php.exe.

The interpreter is used when you set a “Debug Configuration” with “Remote Debug” deactivated. This is true if you want to debug a script which is started per php cli.

4.1.1.4.2. Configure Environment Remote Debug

Here can you have up to five options to enter:

  • Remote Debug: You activate this if you want to debug a script which is started from an external browser (this is in opposite of the usage of the browser which is build into PHPeclipse). When you disable this checkbox the appropriate script is forwarded directly to the given interpreter (php.exe)

  • Cross Platform debugging: Originally used for converting the path seperator (which are different on *nix and Windows systems). As far as I can remember this isn't necessary anymore.

  • Open with DBGSession URL in internal Browser: Activate this if you don't want to use the an external browser but start a debug session in internal browser.

  • Remote Sourcepath: The incorrect setting of this path information is responsible for the most annoyances in respect of debugging problems. The “Remote Sourcepath” is important because it is used for translating the path informations which are exchanged between PHPeclipse and DBG. So, if this translation is incorrect, PHPeclipse will not find the correct file which is currently running, nor will DBG know for which file it should set a breakpoint. More different and detailed examples are to come:

  • Mapped Path: Although in most cases a single path mapping is sufficient, but there are situations where this isn't enough. This is when you use PHP files (e.g. phplib) which are located on a total different path. To use this option, it is necessary to leave the “Remote Sourcepath” field empty. More different and detailed examples are to come:

4.1.1.5. Configure Environment Variables

Used within “Non Remote Debugging”. You can specify variable - value pairs which are passed to the script within the $_ENV and the $HTTP_ENV_VARS array.

4.1.1.6. Configure Common

Leave all as it is per default.

4.1.1.7. Save Configuration

When you have done all the necessary settings click on Apply to save the configuration. You can recall this configuration by clicking on the name of the desired configuration in the “Configurations pane” on the left side.

4.1.1.8. Start a Debug Configuration

4.1.2. Remote Debugging

It is called “Remote Debugging” if you want to debug php scripts which are started by web server. This is the case if you are doing so called “Web Devolepment”. In opposite you also can write php scripts and start them from a shell or command line (see Section 4.1.3, “Debugging CLI”.

4.1.3. Debugging CLI

In contrary to “Remote Debugging” where your php scripts are started by a web server, you could also write scripts and start them from command line[3]. For that task you have to deactivate the “Remote Debug” checkbox (see Section 4.1.1.4.2, “Configure Environment Remote Debug”), and set the appropriate php cli application. According the PHP version you use, this is:

  • phpcli.exe for PHP 4

  • php-win.exe for PHP 5

The prerequiste for debugging is also that you have installed dbg as it is described in Section 1.5.1, “Installing DBG”. In addition, for the breakpoints to work, you have to add the following line to the “[debugger]” section of your php.ini:

debugger.JIT_enabled=on

And also you need the following code at the top of your php file you want to debug. At least this code snippet should be located before the first breakpoint you want to set.

if (function_exists ("DebugBreak")) {
  DebugBreak ();
}

[Note]Note

For debugging a php-cli script you need the appropriate PHPeclipse version, which is > phpeclipse-1.1.9-cvs-20060424. This is due to the fact that older PHPeclipse versions listen on port 10001, but dbg uses the standard port 7869, and there is no way to submit a different port neither by cli nor through the php.ini[4].

[Tip]Tip

If you don't want to change the php.ini which you also do use for your web scripts, you can “importy” the appropriate php.ini to your project, and modify this project related local copy of the php.ini file. To use this local php.ini set the “Interpreter Argument” (see Section 4.1.1.3, “Configure Arguments”) as follows: “-c your_project_name/php.ini”.

4.1.4. Debug Scenarios

4.1.4.1. Same Machine, Workspace is “document root

4.1.4.2. Same Machine, Workspace and “document root” is Different

4.1.4.3. Different Machine, Workspace and “document root” is Different

4.1.5. Running a Debug Session

Open Debug perspective. Select a existing debug configuration. Or create a new one. Should see following in Debug View. Internal Browser or external browser. Submit URL in external browser.

4.1.5.1. Resume

4.1.5.2. Suspend

4.1.5.3. Terminate

4.1.5.4. Step Into

4.1.5.5. Step Into

4.1.5.6. Step Return

4.1.5.7. Breakpoints

The Breakpoints View

Figure 4.4. The “Breakpoints View

The Breakpoints View context menu

Figure 4.5. The “Breakpoints View” context menu

The Breakpoints View icon bar

Figure 4.6. The “Breakpoints View” icon bar

The Editor View left ruler context menu

Figure 4.7. The “Editor View” left ruler context menu

4.1.5.7.1. Set Breakpoint

A breakpoint can be set by the following methods:

4.1.5.7.2. Remove Breakpoint

A breakpoint can be removed by the following methods:

4.1.5.7.3. Enable/Disable Breakpoint

A breakpoint can temporary disabled (and enabled) by the following methods:

4.1.5.7.4. Conditional Breakpoints

You can assign a condition to a breakpoint via the “Breakpoints View” context menu item Properties (see Figure 4.5, “The Breakpoints View context menu”). This opens a dialog (see Figure 4.8, “The breakpoint Properties dialog”). Within the text field “Break Condition” you can set a condition. Don't forget to activate the conditional break via the check box “Enable Condition” at the bottom of the dialog.

For example, if you type “$a == 12” as condition, the program will break if the variable “$a” has the value “12”.

The breakpoint Properties dialog

Figure 4.8. The breakpoint “Properties” dialog

4.1.5.7.5. Breakpoint Skipcounts

An additional feature to set for breakpoints is the “Skipcounts” condition. Normally the skipcounts is set to 0, which means the program breaks immediately if it scores a breakpoint. If the “Skiptcounts” is set to 1 it means, that the first score of a breakpoint is ignored (skipped) and the second score will lead to a break of the program.

The “Skipcounts” can be set via the same dialog box as the conditional breakpoints (see Section 4.1.5.7.4, “Conditional Breakpoints”). For the “Skipcounts” the checkbox need not to be activated.

[Note]Note

The “Break Condition” has precedence over the “Skipcounts”.

4.1.5.8. Inspect Variables

Within the “Variables View” you can see all the variables with their values.

To open the “Variables View” within the “Debug Perspective” go to Window->Show View->Variables (see Figure 4.9, “Open the Variables View”).

[Note]Note

Be sure that your current perspective is the “Debug Perspective”. Although you can open the “Variable View” within a different perspective, this doesn't make sense.

Open the Variables View

Figure 4.9. Open the “Variables View

The Variables View context menu

Figure 4.10. The “Variables View” context menu

4.1.5.9. Show Variable Value by Hovering

Besides inspecting the value of a variable by looking into the “Variables View” or the “Expressions View” a simple and quick method is to position the mouse pointer over the variable within the source code. Within a second the value and type of the variable is shown (see Figure 4.11, “Show variable value by hovering”).

Show variable value by hovering

Figure 4.11. Show variable value by hovering

4.1.5.10. Watch Expressions

Within the “Expressions View” you can see the result of an expression. In the simplest form, this is just a variable and the corresponding value. But of course an expression can also be more complex, e.g. a mathematical formula.

There are different ways to open the “Expressions View” and to add an expression.

4.1.5.10.1. Open “Expressions View” via Main Menu

To open the “Expressions View” within the “Debug Perspective” go to Window->Show View->Variables (see ???).

[Note]Note

Be sure that your current perspective is the “Debug Perspective”. Although you can open the “Expressions View” within a different perspective, this doesn't make sense.

Open the Expressions View via the main menu

Figure 4.12. Open the “Expressions View” via the main menu

4.1.5.10.2. Open “Expressions View” via the “Variables View

Right clicking on a variable within the “Variables View” opens the context menu. Then click on Create Watch Expression. This adds the selected variable to the “Expressions View” and opens/activates the “Expressions View”. Window->Show View->Variables (see Figure 4.9, “Open the Variables View”)

Open the Expressions View via the Variables View context menu

Figure 4.13. Open the “Expressions View” via the “Variables View” context menu

4.1.5.10.3. Open “Expressions View” via context menu

Unfortunately, yet this isn't implemented.

4.1.5.10.4. Remove a watch expression

An expression can be removed from the “Expressions View” by activating the appropriate watch expression and typing Del or via the context menu Remove.



[3] cli stands for “Command Line Interface

[4] This is true for the free dbg version.

The comments are owned by the author. We aren't responsible for their content.

Author Thread
dalong
Published: 2006/11/16 8:00  Updated: 2006/11/16 8:00
Just popping in
Joined: 2006/11/16
From:
Comments: 2
 Re: xo-002 http://www.apachefriends.org/en/xampp.html
very good!
I like here!

Author Thread
dalong
Published: 2006/11/16 10:13  Updated: 2006/11/16 10:13
Just popping in
Joined: 2006/11/16
From:
Comments: 2
 Re: xo-002 http://www.apachefriends.org/en/xampp.html
thank for your work!

Author Thread
huqilong
Published: 2006/11/20 2:50  Updated: 2006/11/20 2:50
Just popping in
Joined: 2006/11/16
From:
Comments: 3
 Re: xo-002 http://www.apachefriends.org/en/xampp.html
I hava a question ,when I have installed phpeclipse,I can't user the button for the apache in the Eclipse IDE,how shoud I do?

Author Thread
huqilong
Published: 2006/11/20 3:10  Updated: 2006/11/20 3:10
Just popping in
Joined: 2006/11/16
From:
Comments: 3
 Re: xo-002 http://www.apachefriends.org/en/xampp.html
dddd

Author Thread
Mark_1900
Published: 2006/11/18 11:05  Updated: 2006/11/18 11:09
Just popping in
Joined: 2006/11/18
From:
Comments: 2
 Alias Permission Problems
For an Alias I also had to add a Directory tag to the httpd.conf, otherwise I had permission problems accessing the files... <br /> [code] Alias /wiki "C:/Documents and Settings/Me/wiki"<br /> <Directory "C:/Documents and Settings/Me/wiki"><br /> Options Indexes MultiViews<br /> AllowOverride None<br /> Order allow,deny<br /> Allow from all<br /> </Directory><br /> [/code]<br /> Oh and all these editing tags seem broken!!

Author Thread
Mark_1900
Published: 2006/11/18 11:21  Updated: 2006/11/18 11:32
Just popping in
Joined: 2006/11/18
From:
Comments: 2
 Getting the correct php_dbg.dll
I want a debugger. I downloaded the latest XAMPP 1.5.4a and noticed that it comes with PHP 5.1.6 & PHP 4.4.4, and neither are supported. The debugger module only supports a subset of these major versions from 5.1.0 to 5.1.2 and 4.4.0 to 4.4.2 (http://dd.cron.ru/dbg/downloads.php). I think right at the beginning you should specify which versions to download to get a debugger Version "XAMPP 1.5.2" would be fine.

Author Thread
huqilong
Published: 2006/11/30 6:28  Updated: 2006/11/30 6:28
Just popping in
Joined: 2006/11/16
From:
Comments: 3
 Re: xo-002 http://www.apachefriends.org/en/xampp-windows....
I want to know how to use phpeclipse with eclipse detailly!

Author Thread
thierrybo
Published: 2007/2/3 16:19  Updated: 2007/2/3 16:21
Just popping in
Joined: 2007/2/3
From:
Comments: 1
 Re: xo-002 ch02s03.html Workspace Method 2
I do not agree with the suggested method 2: Quote:
For example you have set up XAMPP and your “document root” path is the XAMPP default:
C:Program Filesapachefriendsxampphtdocs
Quote:
,then your appropriate workspace path should be one level less:
C:Program Filesapachefriendsxampp
If htdocs is your document root, then each folder inside IS a new project and you should set workspace directory as Document Root directory. With suggested method, all your web projects are managed with ONE big PHPeclipse project.

Author Thread
dafydd
Published: 2007/4/3 6:01  Updated: 2007/4/3 6:01
Just popping in
Joined: 2007/4/3
From:
Comments: 2
 Re: xo-002 ch01.html
Trying this out on a Mac. J2SE 1.5.0_07-164 installed. 1.5.0_06 is what's available on the download site. However, it would almost certainly be updated with Software Update.

Author Thread
dafydd
Published: 2007/4/6 1:00  Updated: 2007/4/6 1:00
Just popping in
Joined: 2007/4/3
From:
Comments: 2
 Re: xo-002 ch01s04.html
Second question: How do we point the XAMPP start/stop buttons in the Eclipse toobar to where we put XAMPP?

dafydd

Author Thread
dysmas
Published: 2007/8/4 14:18  Updated: 2007/8/4 14:18
Just popping in
Joined: 2007/8/4
From:
Comments: 1
 Debugging standalone PHP applications
Thanks hundred times for all the detailed explanations here !!

And especially for the note which explains why debugging a CLI application does not work in 1.1.8 version and only in 1.1.9. (wrong port, as I guessed, but I have been looking for this information for some hours before coming here). Unfortunately this 1.1.9 CVS version does not work in the last 3.2.0 Eclipse version I just got. Let us hope the stable version is going quickly.

Author Thread
Mercyful
Published: 2007/9/10 14:46  Updated: 2007/9/10 14:46
Just popping in
Joined: 2007/9/10
From:
Comments: 1
 Re: dbg is not working
I want using eclipse3.2 with php-plugin and for debugging i want using dbg.
I'm using xampp 1.6.3a with php 4.4.7. and php_dbg.dll-4.4.x
After step by step installation
http://docs.schuetzengau-freising.de/ ... =xo-002&file=ch01s05.html
the debugger dbg will not work.
When i called phpinfo() there is no section dbg shown.
Who have any ideas?
Thanks a lot!
Regards Mercyful

Author Thread
keryx
Published: 2007/9/26 22:59  Updated: 2007/9/26 22:59
Just popping in
Joined: 2007/9/26
From:
Comments: 1
 Re: xo-002 ch04.html
A section about verrors should be nice. I get the following:


<terminated, exit value: 0>PHP C:\Program\PHP\php.exe : <path>/<fil>.php

I've googled like crazy but to no avail. And yes - it does not stop at breakpoints and "variables" are empty. DBG is working:

if (function_exists ("DebugBreak")) {
DebugBreak ();
echo "debugging started!<br />\n";
}

Outputs "debugging started!" And DBG is reported on phpinfo().

Author Thread
koski
Published: 2007/10/19 3:55  Updated: 2007/10/19 3:55
Just popping in
Joined: 2007/10/19
From:
Comments: 1
 Re: xo-002 ch01s03.html
Hi,

Seems that the mentioned link for cvs:

http://phpeclipse.sourceforge.net/update/cvs

is out of date or wrong.

Author Thread
andybruk
Published: 2007/11/18 1:11  Updated: 2007/11/18 1:11
Just popping in
Joined: 2007/11/18
From:
Comments: 1
 Re: xo-002 index.html
I've been searching for a PHP debugger for ages. This is the only one I can find that works perfectly, thanks very much for providing this documentation.<br /><br />I doubt if I could ever get it to work on Windows, but it works so well with Ubuntu Linux and Eclipse 3.1.<br />
Powered by XOOPS 2.0 © 2001-2005 The XOOPS Project