Saturday, February 13, 2010

KDevelop XDebug (Php Debugger)

Another important part of a Web IDE is a debugger. The KDevelop XDebug Plugin is a frontend for the php debugger xdebug, and just had it's first beta release.
I'll explain in this post how to set it up.

Prerequisites:

  • Php
  • XDebug extension
  • xdebug configured to accept remote connections

    • xdebug.remote_enable = 1
    • xdebug.remote_host = localhost (yourhost if on remote server)
  • KDevplatform, KDevelop
  • The following KDevelop Plugins:
    • executescript
    • executebrowser
    • xdebug
    (download here)

Debugging a CLI Script

1. Create Launch Configuration

  • Run » Configure Launches...
  • add Launch Configuration (+)
  • choose Type "Script Application"
  • enter interpreter "php"
  • enter script path
  • activate the new Launch Configuration in Run » Current Launch Config
You may test the Launch Configuration now by executing it (Run » Execute Launch)

2. Start Debugger

  • Set a breakpoint (Run » Toggle Breakpoint, or rightclick on icon border in editor
  • Run » Debug Launch
  • Happy Debugging :D
The debug session is stopped once the script has ended.

Debugging a Website

1. Create Launch Configuration

  • Run » Configure Launches...
  • add Launch Configuration (+)
  • choose Type "Browser Application"
  • enter server host and path
  • activate the new Launch Configuration in Run » Current Launch Config
You may test the Launch Configuration now by executing it (Run » Execute Launch)

2. Start Debugger

  • Set a breakpoint (Run » Toggle Breakpoint, or rightclick on icon border in editor
  • Run » Debug Launch
  • Happy Debugging :D
The debug session continues the script has ended, you can navigate in the browser to debug further scripts. To end the session execute Run » Stop Jobs.

Remote debugging is possible too, but that is not described in this tutorial.

If you have problems with configuration, or find any other problem send a mail to kdevelop-devel _at_ kdevelop.org.

30 comments:

  1. Then it's really simple to get XDebug working to debug your scripts..

    ReplyDelete
  2. Awesome, I can't wait until end of compile :) I'm really sick from the terrislow java ides.

    ReplyDelete
  3. This not work. In Kdevelop menu "Run" is not present.

    ReplyDelete
  4. I did not get it to work before, but now, together with KDE SC 4.4, I installed the latest beta of Kdevelop plus plugins as provided by OpenSuse, and now it works!!!

    Code completion works now, it is one of the most useful features, indeed.

    So that’s halfway there, and I hope that Quanta 4 comes rather sooner than later.

    ReplyDelete
  5. i thought this was a really great post to read. i'll check back for new posts by you!

    ReplyDelete
  6. Hi.

    I use kdevelop-php 1.1.0 and "all" works fine, just I cannot seem to find, configure xdebug. When I add Launch Configuration I can only choose Native Application and in debug I can only choose GDB. I can create new PHP project and use all nice features that comes with it (autocomplete), it just seems that xdebug support was not compiled with or am I wrong?

    I use Gentoo.

    Thank you and kind regards.

    ReplyDelete
  7. Rok, how did you install xdebug?
    did you run kbuildsycoca4?

    Please ask any questions on the kdevelop-devel mailing list.

    ReplyDelete
  8. Yes I did run kbuildsycoca4.

    OK, I created new topic on kdevelop forum:

    Follow:
    http://www.kdevelop.org/phorum5/read.php?7,33277

    ReplyDelete
  9. sorry, I meant the mailing list, please subscribe here: http://www.kdevelop.org/index.html?filename=mailinglist.html (kdevelop-devel)

    But I think I know the reason why it doesn't work: change X-KDevelop-Version to 11 in kdevxdebug.desktop, then it should load the plugin

    ReplyDelete
  10. I do not seem to find this file except in quanta sources. Is quanta maybe successor of kdevelop?

    ReplyDelete
  11. @Rok: the xdebug plugin moved to quanta. Quanta a kdevplatform based application optimized for web development. KDevelop is a kdevplatform based application optimized for cpp development.
    The only difference is the default set of plugins and well - the splash screen. And KDevelop is a stable application while Quanta is not.

    So you can use xdebug in kdevelop.

    ReplyDelete
  12. mmm. How would I go about remote debugging?
    Can anyone suggest?

    ReplyDelete
  13. Is this still working? Was trying with the latest kdevelop and quanta-git , changed version to 11 in the .desktop files and cant see the plugins anywhere.

    Any ideas?

    ReplyDelete
  14. @rg: it should still work. did you run kbuildsycoca4 after installing?

    please ask on the kdevelop-devel mailinglist for help.

    ReplyDelete
  15. where can I get an ubuntu build? would it be helpful to make a ppa for the plugin?

    ReplyDelete
  16. how to compile
    executescript
    executebrowser
    xdebug
    these files after downloading im using kubuntu 11.04 please help. give me the commands. I do have php code completion.

    ReplyDelete
  17. @Anonymous:
    the code is getting moved around atm.
    executescript is now in kdevplatform.
    executebrowser and xdebug are in quanta, and will soon get their own repository.
    (all to be found on projects.kde.org)

    ReplyDelete
  18. Hi Niko, that would be really a great info u have shared about the debugger, in fact debugger plays the best part in PHP programming that too with the XDebug plugin.
    Cheers !

    ReplyDelete
  19. Hello Niko,
    thanks for all your work, it would be great to use xdebug with kdevelop for me.

    Unfortunately i cannot compile the xdebug from latest Quanta repository because cmake cannot find the executescript plugin in debuggers/xdebug/CMakeLists.txt
    Code:
    find_path( EXECUTESCRIPT_INCLUDE_DIR iexecutescriptplugin.h
    PATH_SUFFIXES kdevexecutescript )

    I tried some solutions found around the web (eg: changing path to kdevplatform/executescript) unsuccessfully, do you have any idea?

    ReplyDelete
  20. I am running into the same build issue :-( I am on Kubuntu, but I will try to build on openSUSE.

    This blog entry was from almost two years ago, and this is a big issue keeping KDevelop to be used as a series PHP development tool. Is there a bug report on this?

    ReplyDelete
  21. Hi,

    use this repository:
    git://anongit.kde.org/scratch/nsams/kdev-xdebug.git

    The plan is to make xdebug plugin a standalone project and repository, for now use that one.

    ReplyDelete
  22. > Remote debugging is possible too, but that is not described in this tutorial.

    Then WWWW HHHH EEEE RRRR EEEE is it described?

    ReplyDelete
  23. Since there is no step by step on the Internet to get this going here it is:

    git clone git://anongit.kde.org/scratch/nsams/kdev-executebrowser.git
    cd kdev-executebrowser
    mkdir build
    cd build
    cmake -DCMAKE_INSTALL_PREFIX=`kde4-config --prefix` ../
    make
    sudo make install

    kdev-xdebug has been moved around but its CMakeLists.txt has not been updated to reflect this and will fail with an error about EXECUTESCRIPT_INCLUDE_DIR. Apply the simple one line patch in bug report before attempting the cmake: https://bugs.kde.org/show_bug.cgi?id=284430. With that in mind:

    git clone git://anongit.kde.org/scratch/nsams/kdev-xdebug.git
    cd kdev-executebrowser
    mkdir build
    cd build
    cmake -DCMAKE_INSTALL_PREFIX=`kde4-config --prefix` ../
    make
    sudo make install

    Might have noticed a pattern there ;)

    Hope that helps folks save some time.

    Adam

    ReplyDelete
  24. Woops. The line "cd kdev-executebrowser" in the compile steps for kdev-xdebug should obviously be: cd kdev-xdebug. That'll teach me to lazily cut and paste.

    ReplyDelete
  25. First, thanks for this plugin! I don't like using Eclipse/Netbeans for development, so being able to use xdebug+php inside of kdevelop is a serious win.

    I just got this working in Fedora 17. I tried the latest in git, but there's some commits in kdev-xdebug that don't fly with the older stable kdevelop-libs in F17. (latest git for kdev-executebrowser builds fine though) The beta released in October (1.3.80) seems to compile and load correctly. Kdevelop doesn't crash, there's no rpath warnings during the builds, etc.

    Hope these SRPM's save someone else some time:

    http://www.deepgroove.org/rpm/SRPMS/kdev-executebrowser-1.3.80-2.fc17.src.rpm
    http://www.deepgroove.org/rpm/SRPMS/kdev-xdebug-1.3.80-1.fc17.src.rpm

    compile with: rpmbuild --rebuild

    Built and tested in F17 x86_64. ymmv, hth, etc.

    ReplyDelete
  26. Hello, I have reached this tutorial which seems to be somewhat old (hopefully not really outdated). I am using kdevelop 4.5.1 and I would like to debug php apps. I've been following these instructions but I can't figure out how to install the additional plugins (executebrowser). Do I have to place them in a specific folder? Which one? Do I have to do something else?

    Thank you

    ReplyDelete
  27. Thank you so much, that's a potentially nasty exploit, especially since I'm completely new to Nginx and am a bit worried about leaving such a thing like this open.

    php

    ReplyDelete
  28. really great.Code completion works now, it is one of the most useful features, indeed.

    ReplyDelete