SlideShare ist ein Scribd-Unternehmen logo
1 von 50
Downloaden Sie, um offline zu lesen
Xdebug
                           Daily helper and professional debugger


                                TobiasSchlitt <toby@php.net>

                                      PHP@FrOSCon 2009


                                        2009-08-23




Tobias Schlitt (PHP@FrOSCon 2009)           Xdebug                  2009-08-23   1 / 36
About me



      Tobias Schlitt <toby@php.net>
      PHP since 2001
      Freelancing consultant
      Qualified IT Specialist
      Studying CS at TU Dortmund
      (expect to finish this year)
      OSS addicted
             PHP
             eZ Components
             PHPUnit




Tobias Schlitt (PHP@FrOSCon 2009)   Xdebug   2009-08-23   2 / 36
Overview



1 About Xdebug


2 Installation


3 Development goodies


4 Tracing


5 More features...




Tobias Schlitt (PHP@FrOSCon 2009)   Xdebug   2009-08-23   3 / 36
Outline




1 About Xdebug


2 Installation


3 Development goodies


4 Tracing


5 More features...




Tobias Schlitt (PHP@FrOSCon 2009)   Xdebug   2009-08-23   4 / 36
Why a debugger?




       “I don’t need a debugger”
              There is no bug free code
              Make live easier, use a debugger!
       “var dump(), print r() and echo are sufficient”
              In a lot of cases they are
              Debugging with them is slow and a lot of work
       “Using a debugger = using an IDE”
              No, but you can




Tobias Schlitt (PHP@FrOSCon 2009)        Xdebug               2009-08-23   5 / 36
What is Xdebug?




       Open Source debugger for PHP
       PHP (Zend Engine) extension
       Works (at least) on Linux, Mac and Windows
       About 5 years old
       Current stable version: 2.0.3
       Created and maintained by Derick Rethans
       http://xdebug.org




Tobias Schlitt (PHP@FrOSCon 2009)      Xdebug       2009-08-23   6 / 36
Xdebug features




       Enhance daily work with PHP
       Trace PHP program runs
       Profile PHP applications
       Analyze code coverage (e.g. PHPUnit)
       Remote-debugging with an external client
       Including break-points, stepping, . . .




Tobias Schlitt (PHP@FrOSCon 2009)         Xdebug   2009-08-23   7 / 36
Outline



1 About Xdebug


2 Installation
       Installation
       Configuration

3 Development goodies


4 Tracing


5 More features...



Tobias Schlitt (PHP@FrOSCon 2009)   Xdebug   2009-08-23   8 / 36
Via PEAR



       Easiest way to install
       Working PEAR assumed:
       $ pear install pecl/xdebug
       PEAR Installer performs necessary steps:
          1   Download source
          2   Compiling module
          3   Copying module to destination
       After that: Add module to php.ini
       Only on *nix systems




Tobias Schlitt (PHP@FrOSCon 2009)       Xdebug    2009-08-23   9 / 36
Manual


       Compile by hand
       Typical PHP module compile process
                     wget h t t p : / / xdebug . o r g / l i n k . php ? u r l=xdebug201
                     t a r −x z f xdebug − 2 . 0 . 2 . t g z
                     cd xdebug − 2 . 0 . 2
                     phpize
                     . / c o n f i g u r e −−enable −xdebug
                            −−w i t h −php−c o n f i g =/ u s r / b i n / php−c o n f i g
                     make
                     cp m o d u l e s / xdebug . s o /<m o d u l e p a t h >/xdebug . s o

       After that: Add module to php.ini
       Only on *nix systems



Tobias Schlitt (PHP@FrOSCon 2009)             Xdebug                            2009-08-23   10 / 36
Windows




       Download binary module from
              http://xdebug.org
              http://pecl4win.php.net/ext.php/php_xdebug.dll
       Copy module to modules directory
       After that: Add module to php.ini




Tobias Schlitt (PHP@FrOSCon 2009)    Xdebug                2009-08-23   11 / 36
Add module to php.ini




       Not a “normal” extension
       Add to php.ini:
       zend extension = ”/path/to/xdebug.so”
       On Windows: zend extension ts
       For debug builds zend extension debug
       Check $ php −v or phpinfo() ;




Tobias Schlitt (PHP@FrOSCon 2009)      Xdebug   2009-08-23   12 / 36
Common pitfalls




        extension dir     directive does not take effect!
       Binary modules (Windows) do not work with PHP debug builds
       −−enable−versioning          prevents loading
       Other zend-extensions interfere with Xdebug




Tobias Schlitt (PHP@FrOSCon 2009)              Xdebug      2009-08-23   13 / 36
Configuration




       Huge variety of options
       Most shown later, some not
       Overview: http://xdebug.org/docs/all_settings
       Most options adjustably with ini set () at runtime, except for
              xdebug.extended info
              xdebug. profiler ∗




Tobias Schlitt (PHP@FrOSCon 2009)     Xdebug                     2009-08-23   14 / 36
Outline


1 About Xdebug


2 Installation


3 Development goodies
       Error messages
       Dumping variables
       Infinity
       Useful functions

4 Tracing


5 More features...


Tobias Schlitt (PHP@FrOSCon 2009)   Xdebug   2009-08-23   15 / 36
Getting started




       Install module
       Switch it on
       Tweak some settings
       Work as usual




Tobias Schlitt (PHP@FrOSCon 2009)   Xdebug   2009-08-23   16 / 36
Error messages




       PHP error messages not very useful
              Sometimes poor error location
              Almost no info on affected data
              No info on code context
       Xdebug enhances that for you!




Tobias Schlitt (PHP@FrOSCon 2009)       Xdebug   2009-08-23   17 / 36
Warnings

Functions producing warnings

f u n c t i o n openSomeFile ()
{
        r e t u r n o p e n M y F i l e ( ’ / p a t h / t o / f i l e ’ , ’ Reason t o open f i l e .
                ’ , a r r a y ( 2 3 , 4 2 , ’ Random d a t a . ’ ) ) ;
}

f u n c t i o n o p e n M y F i l e ( $path , $ r e a s o n , $ d a t a )
{
        r e t u r n fopen ( $path , ’ r ’ ) ;
}

function performOperationOnFile ( $ f i l e )
{
    r e t u r n f r e a d ( $ f i l e , 1024 ) ;
}



Tobias Schlitt (PHP@FrOSCon 2009)               Xdebug                              2009-08-23    18 / 36
Warnings

Triggering a warning

require once            ’ w a r n i n g / f u n c t i o n s . php ’ ;

f u n c t i o n performAComplexOperation ()
{
        $ f i l e = openSomeFile () ;
        return performOperationOnFile ( $ f i l e ) ;
}

echo p e r f o r m A C o m p l e x O p e r a t i o n ( ) ;




Tobias Schlitt (PHP@FrOSCon 2009)                     Xdebug            2009-08-23   18 / 36
Warnings

Live
Let’s look what it does




Tobias Schlitt (PHP@FrOSCon 2009)   Xdebug   2009-08-23   18 / 36
Errors

Producing an exception

r e q u i r e o n c e ’ /home/ d o t x p / dev /PHP/ e z c o m p o n e n t s / t r u n k / Base / s r c
       / b a s e . php ’ ;

function        a u t o l o a d ( $className )
{
    r e t u r n ezcBase : : a u to l o ad ( $className ) ;
}

$pop3 = new e z c M a i l P o p 3 T r a n s p o r t ( ” l o c a l h o s t ” ) ;




Tobias Schlitt (PHP@FrOSCon 2009)               Xdebug                                2009-08-23    19 / 36
Errors

Live
Let’s look what it does




Tobias Schlitt (PHP@FrOSCon 2009)   Xdebug   2009-08-23   19 / 36
var dump()



       Using var dump()
              Everyone does it
              There is nothing bad about it
       var dump()     in the browser sucks
       Xdebug enhances var dump()

Live
Let’s look what it does




Tobias Schlitt (PHP@FrOSCon 2009)        Xdebug   2009-08-23   20 / 36
var dump()



       Using var dump()
              Everyone does it
              There is nothing bad about it
       var dump()     in the browser sucks
       Xdebug enhances var dump()

Live
Let’s look what it does




Tobias Schlitt (PHP@FrOSCon 2009)        Xdebug   2009-08-23   20 / 36
Infinite loops




       Endless recursions
       Extremely hard to find
       Script just times out . . . or worse!
       Xdebug can protect you
       Note: Not from endless runs of loops!




Tobias Schlitt (PHP@FrOSCon 2009)       Xdebug   2009-08-23   21 / 36
Infinite recursion

Producing an infinite recursion

f u n c t i o n d o u b l e F a c u l t y ( $num )
{
       /∗
        i f ( $num < 3 )
       {
                r e t u r n $num ;
       }
       ∗/
        r e t u r n $num ∗ d o u b l e F a c u l t y ( $num − 2 ) ;
}

echo d o u b l e F a c u l t y ( 10 ) ;




Tobias Schlitt (PHP@FrOSCon 2009)           Xdebug                    2009-08-23   22 / 36
Infinite recursion

Live
Let’s look what it does




Tobias Schlitt (PHP@FrOSCon 2009)   Xdebug   2009-08-23   22 / 36
Useful functions




       xdebug [en/dis ] able ()
       Manually switch stack traces on or off
       xdebug call [ class /function/ file / line ]()
       Get the call point of the currently running function
       xdebug dump superglobals()
       Dump super-globals as specified by INI setting




Tobias Schlitt (PHP@FrOSCon 2009)           Xdebug            2009-08-23   23 / 36
Useful functions




        xdebug get declared vars ()
       Returns an array containing the names of all variables in the current
       scope
        xdebug get function stack ()
       Returns the function stack trace as an array
       xdebug get stack depth()
       Get the current depth in the function stack
       Note: Includes also create a level!




Tobias Schlitt (PHP@FrOSCon 2009)        Xdebug                 2009-08-23   23 / 36
Useful functions




       xdebug time index()
       Returns the seconds since script run start




Tobias Schlitt (PHP@FrOSCon 2009)    Xdebug         2009-08-23   23 / 36
Declared vars

Getting declared variables

f u n c t i o n f o o ( $a , $b )
{
        g l o b a l $c ;
       $d = ’ I am l o c a l ’ ;
       var dump ( x d e b u g g e t d e c l a r e d v a r s ( ) ) ;
}

$c = ’ I am g l o b a l ’ ;

f o o ( 2 3 , 42 ) ;




Tobias Schlitt (PHP@FrOSCon 2009)            Xdebug                   2009-08-23   24 / 36
Declared vars

Live
Let’s look what it does




Tobias Schlitt (PHP@FrOSCon 2009)   Xdebug   2009-08-23   24 / 36
Stack depth

Retrieving stack level

echo ” S t a c k d e p t h i n ” .          FILE     . ”: ” .
    x d e b u g g e t s t a c k d e p t h ( ) . ” nn” ;

function foo ()
{
    echo ” S t a c k d e p t h i n ” .          FUNCTION       . ”: ” .
         x d e b u g g e t s t a c k d e p t h ( ) . ” nn” ;
    bar () ;
}

i n c l u d e ’ s t a c k d e p t h / d e e p e r s t a c k . php ’ ;

echo ” C a l l i n g f o o ( ) from ” .                FILE         . ” nn” ;
foo () ;




Tobias Schlitt (PHP@FrOSCon 2009)                  Xdebug                         2009-08-23   25 / 36
Stack depth

Live
Let’s look what it does




Tobias Schlitt (PHP@FrOSCon 2009)   Xdebug   2009-08-23   25 / 36
Outline




1 About Xdebug


2 Installation


3 Development goodies


4 Tracing


5 More features...




Tobias Schlitt (PHP@FrOSCon 2009)   Xdebug   2009-08-23   26 / 36
What is tracing?




       Check control flow of application
              Correct function calls
              Correct data
       Does input data produce correct workflow?
              Traces always depend on input data
              Almost impossible to create traces for every possible control flow




Tobias Schlitt (PHP@FrOSCon 2009)         Xdebug                       2009-08-23   27 / 36
Tracing



       Some developers trace like this:
                      echo ” Here I am ! ! ! ” ;
                      // . . .
                      echo ”Now I ’m h e r e ! ! ! Something i s : ” ;
                      var dump ( $ s o m e t h i n g ) ;

       Works well in small scripts
       Horror in larger apps / libraries
       Debugging like this is a sh**load of work
       Almost impossible with 3rd party code




Tobias Schlitt (PHP@FrOSCon 2009)           Xdebug                       2009-08-23   28 / 36
Tracing with Xdebug




       By functions:
              xdebug start trace ()
              xdebug stop trace ()
       Automatically (php.ini)
              xdebug.auto trace = ”1”
              Cannot be set via ini set () !




Tobias Schlitt (PHP@FrOSCon 2009)          Xdebug   2009-08-23   29 / 36
Tracing example

A simple trace

f u n c t i o n d o u b l e F a c u l t y ( $num )
{
        i f ( $num < 3 )
       {
                r e t u r n $num ;
       }
        r e t u r n $num ∗ d o u b l e F a c u l t y ( $num − 2 ) ;
}

x d e b u g s t a r t t r a c e ( ’ t r a c e s /60 s i m p l e t r a c e . x t ’ ) ;

echo d o u b l e F a c u l t y ( 10 ) ;




Tobias Schlitt (PHP@FrOSCon 2009)                Xdebug                                 2009-08-23   30 / 36
Tracing example

Live
Let’s look what it does




Tobias Schlitt (PHP@FrOSCon 2009)   Xdebug   2009-08-23   30 / 36
Notes on tracing




       Never trace in production!
       Tracing is extremely slow!
       grep & friends help a lot
       Tuning configuration makes traces more usable
       More information through Xdebug mean
              Slower performance
              Higher memory consumption




Tobias Schlitt (PHP@FrOSCon 2009)     Xdebug          2009-08-23   31 / 36
Outline




1 About Xdebug


2 Installation


3 Development goodies


4 Tracing


5 More features...




Tobias Schlitt (PHP@FrOSCon 2009)   Xdebug   2009-08-23   32 / 36
Profiling




       Which code takes which time?
       Find bottle necks in code
       Check your database queries and setup first!




Tobias Schlitt (PHP@FrOSCon 2009)   Xdebug           2009-08-23   33 / 36
Code coverage




       Mostly used in testing
       Which code is not covered by a test?
       PHPUnit can utilize this
       http://www.phpunit.de




Tobias Schlitt (PHP@FrOSCon 2009)   Xdebug    2009-08-23   34 / 36
Remote debugging

       Integrate Xdebug into your IDE
              Komodo IDE
              Eclipse




Tobias Schlitt (PHP@FrOSCon 2009)   Xdebug   2009-08-23   35 / 36
The end

                                    Thank you for listening!
       Are there any questions left?
       I hope you learned what you expected?
       Contact me: Tobias Schlitt <toby@php.net>
       Slides will be up on Slideshare




Tobias Schlitt (PHP@FrOSCon 2009)             Xdebug           2009-08-23   36 / 36
The end

                                    Thank you for listening!
       Are there any questions left?
       I hope you learned what you expected?
       Contact me: Tobias Schlitt <toby@php.net>
       Slides will be up on Slideshare




Tobias Schlitt (PHP@FrOSCon 2009)             Xdebug           2009-08-23   36 / 36
The end

                                    Thank you for listening!
       Are there any questions left?
       I hope you learned what you expected?
       Contact me: Tobias Schlitt <toby@php.net>
       Slides will be up on Slideshare




Tobias Schlitt (PHP@FrOSCon 2009)             Xdebug           2009-08-23   36 / 36
The end

                                    Thank you for listening!
       Are there any questions left?
       I hope you learned what you expected?
       Contact me: Tobias Schlitt <toby@php.net>
       Slides will be up on Slideshare




Tobias Schlitt (PHP@FrOSCon 2009)             Xdebug           2009-08-23   36 / 36
The end

                                    Thank you for listening!
       Are there any questions left?
       I hope you learned what you expected?
       Contact me: Tobias Schlitt <toby@php.net>
       Slides will be up on Slideshare




Tobias Schlitt (PHP@FrOSCon 2009)             Xdebug           2009-08-23   36 / 36

Weitere ähnliche Inhalte

Was ist angesagt?

单元测试必知必会
单元测试必知必会单元测试必知必会
单元测试必知必会智杰 付
 
[COSCUP 2021] A trip about how I contribute to LLVM
[COSCUP 2021] A trip about how I contribute to LLVM[COSCUP 2021] A trip about how I contribute to LLVM
[COSCUP 2021] A trip about how I contribute to LLVMDouglas Chen
 
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce Diane Mueller
 
Insecure coding in C (and C++)
Insecure coding in C (and C++)Insecure coding in C (and C++)
Insecure coding in C (and C++)Olve Maudal
 
Virtual platform
Virtual platformVirtual platform
Virtual platformsean chen
 
Intel Nervana Graph とは?
Intel Nervana Graph とは?Intel Nervana Graph とは?
Intel Nervana Graph とは?Mr. Vengineer
 
Finding 0days at Arab Security Conference
Finding 0days at Arab Security ConferenceFinding 0days at Arab Security Conference
Finding 0days at Arab Security ConferenceRodolpho Concurde
 
Global Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the SealGlobal Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the SealTzung-Bi Shih
 
[COSCUP 2020] How to use llvm frontend library-libtooling
[COSCUP 2020] How to use llvm frontend library-libtooling[COSCUP 2020] How to use llvm frontend library-libtooling
[COSCUP 2020] How to use llvm frontend library-libtoolingDouglas Chen
 
Zn task - defcon russia 20
Zn task  - defcon russia 20Zn task  - defcon russia 20
Zn task - defcon russia 20DefconRussia
 
Solid C++ by Example
Solid C++ by ExampleSolid C++ by Example
Solid C++ by ExampleOlve Maudal
 
Hands on clang-format
Hands on clang-formatHands on clang-format
Hands on clang-formatKai Wolf
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javaDwight Sabio
 
Surprise! It's PHP :) (unabridged)
Surprise! It's PHP :) (unabridged)Surprise! It's PHP :) (unabridged)
Surprise! It's PHP :) (unabridged)Sharon Levy
 
Crash Dump Analysis 101
Crash Dump Analysis 101Crash Dump Analysis 101
Crash Dump Analysis 101John Howard
 

Was ist angesagt? (19)

单元测试必知必会
单元测试必知必会单元测试必知必会
单元测试必知必会
 
[COSCUP 2021] A trip about how I contribute to LLVM
[COSCUP 2021] A trip about how I contribute to LLVM[COSCUP 2021] A trip about how I contribute to LLVM
[COSCUP 2021] A trip about how I contribute to LLVM
 
RAII and ScopeGuard
RAII and ScopeGuardRAII and ScopeGuard
RAII and ScopeGuard
 
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce
 
Insecure coding in C (and C++)
Insecure coding in C (and C++)Insecure coding in C (and C++)
Insecure coding in C (and C++)
 
Virtual platform
Virtual platformVirtual platform
Virtual platform
 
Intel Nervana Graph とは?
Intel Nervana Graph とは?Intel Nervana Graph とは?
Intel Nervana Graph とは?
 
Finding 0days at Arab Security Conference
Finding 0days at Arab Security ConferenceFinding 0days at Arab Security Conference
Finding 0days at Arab Security Conference
 
C++ Core Guidelines
C++ Core GuidelinesC++ Core Guidelines
C++ Core Guidelines
 
Global Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the SealGlobal Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the Seal
 
[COSCUP 2020] How to use llvm frontend library-libtooling
[COSCUP 2020] How to use llvm frontend library-libtooling[COSCUP 2020] How to use llvm frontend library-libtooling
[COSCUP 2020] How to use llvm frontend library-libtooling
 
Zn task - defcon russia 20
Zn task  - defcon russia 20Zn task  - defcon russia 20
Zn task - defcon russia 20
 
interface
interfaceinterface
interface
 
Solid C++ by Example
Solid C++ by ExampleSolid C++ by Example
Solid C++ by Example
 
Hands on clang-format
Hands on clang-formatHands on clang-format
Hands on clang-format
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Surprise! It's PHP :) (unabridged)
Surprise! It's PHP :) (unabridged)Surprise! It's PHP :) (unabridged)
Surprise! It's PHP :) (unabridged)
 
Crash Dump Analysis 101
Crash Dump Analysis 101Crash Dump Analysis 101
Crash Dump Analysis 101
 
C++ programming
C++ programmingC++ programming
C++ programming
 

Ähnlich wie Xdebug

The why and how of moving to php 7
The why and how of moving to php 7The why and how of moving to php 7
The why and how of moving to php 7Wim Godden
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.xWim Godden
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.xWim Godden
 
The why and how of moving to php 8
The why and how of moving to php 8The why and how of moving to php 8
The why and how of moving to php 8Wim Godden
 
The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6Wim Godden
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4Wim Godden
 
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...Felipe Prado
 
Is your code ready for PHP 7 ?
Is your code ready for PHP 7 ?Is your code ready for PHP 7 ?
Is your code ready for PHP 7 ?Wim Godden
 
Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3Asher Martin
 
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)Pixie Labs
 
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)Zain Asgar
 
From Generator to Fiber the Road to Coroutine in PHP
From Generator to Fiber the Road to Coroutine in PHPFrom Generator to Fiber the Road to Coroutine in PHP
From Generator to Fiber the Road to Coroutine in PHPAlbert Chen
 
Dynamic PHP web-application analysis
Dynamic PHP web-application analysisDynamic PHP web-application analysis
Dynamic PHP web-application analysisax330d
 
Practical git for developers
Practical git for developersPractical git for developers
Practical git for developersWim Godden
 
Codeception Testing Framework -- English #phpkansai
Codeception Testing Framework -- English #phpkansaiCodeception Testing Framework -- English #phpkansai
Codeception Testing Framework -- English #phpkansaiFlorent Batard
 

Ähnlich wie Xdebug (20)

Xdebug
XdebugXdebug
Xdebug
 
The why and how of moving to php 7
The why and how of moving to php 7The why and how of moving to php 7
The why and how of moving to php 7
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.x
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.x
 
The why and how of moving to php 8
The why and how of moving to php 8The why and how of moving to php 8
The why and how of moving to php 8
 
The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6
 
Xdebug from a to x
Xdebug from a to xXdebug from a to x
Xdebug from a to x
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4
 
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
 
Linux
LinuxLinux
Linux
 
Is your code ready for PHP 7 ?
Is your code ready for PHP 7 ?Is your code ready for PHP 7 ?
Is your code ready for PHP 7 ?
 
Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3
 
50 shades of PHP
50 shades of PHP50 shades of PHP
50 shades of PHP
 
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
 
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
 
From Generator to Fiber the Road to Coroutine in PHP
From Generator to Fiber the Road to Coroutine in PHPFrom Generator to Fiber the Road to Coroutine in PHP
From Generator to Fiber the Road to Coroutine in PHP
 
Dynamic PHP web-application analysis
Dynamic PHP web-application analysisDynamic PHP web-application analysis
Dynamic PHP web-application analysis
 
Practical git for developers
Practical git for developersPractical git for developers
Practical git for developers
 
Codeception Testing Framework -- English #phpkansai
Codeception Testing Framework -- English #phpkansaiCodeception Testing Framework -- English #phpkansai
Codeception Testing Framework -- English #phpkansai
 

Mehr von Tobias Schlitt

HTML to ODT to XML to PDF to …
HTML to ODT to XML to PDF to …HTML to ODT to XML to PDF to …
HTML to ODT to XML to PDF to …Tobias Schlitt
 
Validating XML - Avoiding the pain
Validating XML - Avoiding the painValidating XML - Avoiding the pain
Validating XML - Avoiding the painTobias Schlitt
 
XPath - A practical guide
XPath - A practical guideXPath - A practical guide
XPath - A practical guideTobias Schlitt
 
Professional XML with PHP
Professional XML with PHPProfessional XML with PHP
Professional XML with PHPTobias Schlitt
 
XML and XPath with PHP
XML and XPath with PHPXML and XPath with PHP
XML and XPath with PHPTobias Schlitt
 
WebDAV - The good, the bad and the evil
WebDAV - The good, the bad and the evilWebDAV - The good, the bad and the evil
WebDAV - The good, the bad and the evilTobias Schlitt
 

Mehr von Tobias Schlitt (7)

HTML to ODT to XML to PDF to …
HTML to ODT to XML to PDF to …HTML to ODT to XML to PDF to …
HTML to ODT to XML to PDF to …
 
Unit-Tests
Unit-TestsUnit-Tests
Unit-Tests
 
Validating XML - Avoiding the pain
Validating XML - Avoiding the painValidating XML - Avoiding the pain
Validating XML - Avoiding the pain
 
XPath - A practical guide
XPath - A practical guideXPath - A practical guide
XPath - A practical guide
 
Professional XML with PHP
Professional XML with PHPProfessional XML with PHP
Professional XML with PHP
 
XML and XPath with PHP
XML and XPath with PHPXML and XPath with PHP
XML and XPath with PHP
 
WebDAV - The good, the bad and the evil
WebDAV - The good, the bad and the evilWebDAV - The good, the bad and the evil
WebDAV - The good, the bad and the evil
 

Kürzlich hochgeladen

So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 

Xdebug

  • 1. Xdebug Daily helper and professional debugger TobiasSchlitt <toby@php.net> PHP@FrOSCon 2009 2009-08-23 Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 1 / 36
  • 2. About me Tobias Schlitt <toby@php.net> PHP since 2001 Freelancing consultant Qualified IT Specialist Studying CS at TU Dortmund (expect to finish this year) OSS addicted PHP eZ Components PHPUnit Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 2 / 36
  • 3. Overview 1 About Xdebug 2 Installation 3 Development goodies 4 Tracing 5 More features... Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 3 / 36
  • 4. Outline 1 About Xdebug 2 Installation 3 Development goodies 4 Tracing 5 More features... Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 4 / 36
  • 5. Why a debugger? “I don’t need a debugger” There is no bug free code Make live easier, use a debugger! “var dump(), print r() and echo are sufficient” In a lot of cases they are Debugging with them is slow and a lot of work “Using a debugger = using an IDE” No, but you can Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 5 / 36
  • 6. What is Xdebug? Open Source debugger for PHP PHP (Zend Engine) extension Works (at least) on Linux, Mac and Windows About 5 years old Current stable version: 2.0.3 Created and maintained by Derick Rethans http://xdebug.org Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 6 / 36
  • 7. Xdebug features Enhance daily work with PHP Trace PHP program runs Profile PHP applications Analyze code coverage (e.g. PHPUnit) Remote-debugging with an external client Including break-points, stepping, . . . Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 7 / 36
  • 8. Outline 1 About Xdebug 2 Installation Installation Configuration 3 Development goodies 4 Tracing 5 More features... Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 8 / 36
  • 9. Via PEAR Easiest way to install Working PEAR assumed: $ pear install pecl/xdebug PEAR Installer performs necessary steps: 1 Download source 2 Compiling module 3 Copying module to destination After that: Add module to php.ini Only on *nix systems Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 9 / 36
  • 10. Manual Compile by hand Typical PHP module compile process wget h t t p : / / xdebug . o r g / l i n k . php ? u r l=xdebug201 t a r −x z f xdebug − 2 . 0 . 2 . t g z cd xdebug − 2 . 0 . 2 phpize . / c o n f i g u r e −−enable −xdebug −−w i t h −php−c o n f i g =/ u s r / b i n / php−c o n f i g make cp m o d u l e s / xdebug . s o /<m o d u l e p a t h >/xdebug . s o After that: Add module to php.ini Only on *nix systems Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 10 / 36
  • 11. Windows Download binary module from http://xdebug.org http://pecl4win.php.net/ext.php/php_xdebug.dll Copy module to modules directory After that: Add module to php.ini Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 11 / 36
  • 12. Add module to php.ini Not a “normal” extension Add to php.ini: zend extension = ”/path/to/xdebug.so” On Windows: zend extension ts For debug builds zend extension debug Check $ php −v or phpinfo() ; Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 12 / 36
  • 13. Common pitfalls extension dir directive does not take effect! Binary modules (Windows) do not work with PHP debug builds −−enable−versioning prevents loading Other zend-extensions interfere with Xdebug Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 13 / 36
  • 14. Configuration Huge variety of options Most shown later, some not Overview: http://xdebug.org/docs/all_settings Most options adjustably with ini set () at runtime, except for xdebug.extended info xdebug. profiler ∗ Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 14 / 36
  • 15. Outline 1 About Xdebug 2 Installation 3 Development goodies Error messages Dumping variables Infinity Useful functions 4 Tracing 5 More features... Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 15 / 36
  • 16. Getting started Install module Switch it on Tweak some settings Work as usual Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 16 / 36
  • 17. Error messages PHP error messages not very useful Sometimes poor error location Almost no info on affected data No info on code context Xdebug enhances that for you! Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 17 / 36
  • 18. Warnings Functions producing warnings f u n c t i o n openSomeFile () { r e t u r n o p e n M y F i l e ( ’ / p a t h / t o / f i l e ’ , ’ Reason t o open f i l e . ’ , a r r a y ( 2 3 , 4 2 , ’ Random d a t a . ’ ) ) ; } f u n c t i o n o p e n M y F i l e ( $path , $ r e a s o n , $ d a t a ) { r e t u r n fopen ( $path , ’ r ’ ) ; } function performOperationOnFile ( $ f i l e ) { r e t u r n f r e a d ( $ f i l e , 1024 ) ; } Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 18 / 36
  • 19. Warnings Triggering a warning require once ’ w a r n i n g / f u n c t i o n s . php ’ ; f u n c t i o n performAComplexOperation () { $ f i l e = openSomeFile () ; return performOperationOnFile ( $ f i l e ) ; } echo p e r f o r m A C o m p l e x O p e r a t i o n ( ) ; Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 18 / 36
  • 20. Warnings Live Let’s look what it does Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 18 / 36
  • 21. Errors Producing an exception r e q u i r e o n c e ’ /home/ d o t x p / dev /PHP/ e z c o m p o n e n t s / t r u n k / Base / s r c / b a s e . php ’ ; function a u t o l o a d ( $className ) { r e t u r n ezcBase : : a u to l o ad ( $className ) ; } $pop3 = new e z c M a i l P o p 3 T r a n s p o r t ( ” l o c a l h o s t ” ) ; Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 19 / 36
  • 22. Errors Live Let’s look what it does Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 19 / 36
  • 23. var dump() Using var dump() Everyone does it There is nothing bad about it var dump() in the browser sucks Xdebug enhances var dump() Live Let’s look what it does Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 20 / 36
  • 24. var dump() Using var dump() Everyone does it There is nothing bad about it var dump() in the browser sucks Xdebug enhances var dump() Live Let’s look what it does Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 20 / 36
  • 25. Infinite loops Endless recursions Extremely hard to find Script just times out . . . or worse! Xdebug can protect you Note: Not from endless runs of loops! Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 21 / 36
  • 26. Infinite recursion Producing an infinite recursion f u n c t i o n d o u b l e F a c u l t y ( $num ) { /∗ i f ( $num < 3 ) { r e t u r n $num ; } ∗/ r e t u r n $num ∗ d o u b l e F a c u l t y ( $num − 2 ) ; } echo d o u b l e F a c u l t y ( 10 ) ; Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 22 / 36
  • 27. Infinite recursion Live Let’s look what it does Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 22 / 36
  • 28. Useful functions xdebug [en/dis ] able () Manually switch stack traces on or off xdebug call [ class /function/ file / line ]() Get the call point of the currently running function xdebug dump superglobals() Dump super-globals as specified by INI setting Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 23 / 36
  • 29. Useful functions xdebug get declared vars () Returns an array containing the names of all variables in the current scope xdebug get function stack () Returns the function stack trace as an array xdebug get stack depth() Get the current depth in the function stack Note: Includes also create a level! Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 23 / 36
  • 30. Useful functions xdebug time index() Returns the seconds since script run start Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 23 / 36
  • 31. Declared vars Getting declared variables f u n c t i o n f o o ( $a , $b ) { g l o b a l $c ; $d = ’ I am l o c a l ’ ; var dump ( x d e b u g g e t d e c l a r e d v a r s ( ) ) ; } $c = ’ I am g l o b a l ’ ; f o o ( 2 3 , 42 ) ; Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 24 / 36
  • 32. Declared vars Live Let’s look what it does Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 24 / 36
  • 33. Stack depth Retrieving stack level echo ” S t a c k d e p t h i n ” . FILE . ”: ” . x d e b u g g e t s t a c k d e p t h ( ) . ” nn” ; function foo () { echo ” S t a c k d e p t h i n ” . FUNCTION . ”: ” . x d e b u g g e t s t a c k d e p t h ( ) . ” nn” ; bar () ; } i n c l u d e ’ s t a c k d e p t h / d e e p e r s t a c k . php ’ ; echo ” C a l l i n g f o o ( ) from ” . FILE . ” nn” ; foo () ; Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 25 / 36
  • 34. Stack depth Live Let’s look what it does Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 25 / 36
  • 35. Outline 1 About Xdebug 2 Installation 3 Development goodies 4 Tracing 5 More features... Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 26 / 36
  • 36. What is tracing? Check control flow of application Correct function calls Correct data Does input data produce correct workflow? Traces always depend on input data Almost impossible to create traces for every possible control flow Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 27 / 36
  • 37. Tracing Some developers trace like this: echo ” Here I am ! ! ! ” ; // . . . echo ”Now I ’m h e r e ! ! ! Something i s : ” ; var dump ( $ s o m e t h i n g ) ; Works well in small scripts Horror in larger apps / libraries Debugging like this is a sh**load of work Almost impossible with 3rd party code Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 28 / 36
  • 38. Tracing with Xdebug By functions: xdebug start trace () xdebug stop trace () Automatically (php.ini) xdebug.auto trace = ”1” Cannot be set via ini set () ! Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 29 / 36
  • 39. Tracing example A simple trace f u n c t i o n d o u b l e F a c u l t y ( $num ) { i f ( $num < 3 ) { r e t u r n $num ; } r e t u r n $num ∗ d o u b l e F a c u l t y ( $num − 2 ) ; } x d e b u g s t a r t t r a c e ( ’ t r a c e s /60 s i m p l e t r a c e . x t ’ ) ; echo d o u b l e F a c u l t y ( 10 ) ; Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 30 / 36
  • 40. Tracing example Live Let’s look what it does Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 30 / 36
  • 41. Notes on tracing Never trace in production! Tracing is extremely slow! grep & friends help a lot Tuning configuration makes traces more usable More information through Xdebug mean Slower performance Higher memory consumption Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 31 / 36
  • 42. Outline 1 About Xdebug 2 Installation 3 Development goodies 4 Tracing 5 More features... Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 32 / 36
  • 43. Profiling Which code takes which time? Find bottle necks in code Check your database queries and setup first! Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 33 / 36
  • 44. Code coverage Mostly used in testing Which code is not covered by a test? PHPUnit can utilize this http://www.phpunit.de Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 34 / 36
  • 45. Remote debugging Integrate Xdebug into your IDE Komodo IDE Eclipse Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 35 / 36
  • 46. The end Thank you for listening! Are there any questions left? I hope you learned what you expected? Contact me: Tobias Schlitt <toby@php.net> Slides will be up on Slideshare Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 36 / 36
  • 47. The end Thank you for listening! Are there any questions left? I hope you learned what you expected? Contact me: Tobias Schlitt <toby@php.net> Slides will be up on Slideshare Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 36 / 36
  • 48. The end Thank you for listening! Are there any questions left? I hope you learned what you expected? Contact me: Tobias Schlitt <toby@php.net> Slides will be up on Slideshare Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 36 / 36
  • 49. The end Thank you for listening! Are there any questions left? I hope you learned what you expected? Contact me: Tobias Schlitt <toby@php.net> Slides will be up on Slideshare Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 36 / 36
  • 50. The end Thank you for listening! Are there any questions left? I hope you learned what you expected? Contact me: Tobias Schlitt <toby@php.net> Slides will be up on Slideshare Tobias Schlitt (PHP@FrOSCon 2009) Xdebug 2009-08-23 36 / 36