SlideShare a Scribd company logo
Xdebug
                             Alltagshilfe und professioneller Debugger


                                     TobiasSchlitt <toby@php.net>

                                           PHP World Kongress 2009


                                                2009-11-24




Tobias Schlitt (PHP World Kongress 2009)            Xdebug               2009-11-24   1 / 41
About me



         Tobias Schlitt <toby@php.net>
         PHP since 2001
         Freelancing consultant
         Qualified IT Specialist
         Studying CS at TU Dortmund
         (finishing mid 2010)
         OSS addicted
                eZ Components
                PHPUnit
                Various other projects . . .




Tobias Schlitt (PHP World Kongress 2009)       Xdebug   2009-11-24   2 / 41
Overview



  1 About Debugging


  2 Installation


  3 Development goodies


  4 Tracing


  5 More features...


  6 The end



Tobias Schlitt (PHP World Kongress 2009)   Xdebug   2009-11-24   3 / 41
Outline



  1 About Debugging


  2 Installation


  3 Development goodies


  4 Tracing


  5 More features...


  6 The end



Tobias Schlitt (PHP World Kongress 2009)   Xdebug   2009-11-24   4 / 41
Why a debugger?

         I don’t need a debugger

                No bug free code
                Living life the easy way . . .


         var dump(), print r() and echo

                Sometimes, yes
                Slow and a lot of work


         Using a debugger = using an IDE

                No, but you can



Tobias Schlitt (PHP World Kongress 2009)         Xdebug   2009-11-24   5 / 41
Why a debugger?

         I don’t need a debugger

                No bug free code
                Living life the easy way . . .


         var dump(), print r() and echo

                Sometimes, yes
                Slow and a lot of work


         Using a debugger = using an IDE

                No, but you can



Tobias Schlitt (PHP World Kongress 2009)         Xdebug   2009-11-24   5 / 41
Why a debugger?

         I don’t need a debugger

                No bug free code
                Living life the easy way . . .


         var dump(), print r() and echo

                Sometimes, yes
                Slow and a lot of work


         Using a debugger = using an IDE

                No, but you can



Tobias Schlitt (PHP World Kongress 2009)         Xdebug   2009-11-24   5 / 41
Why a debugger?

         I don’t need a debugger

                No bug free code
                Living life the easy way . . .


         var dump(), print r() and echo

                Sometimes, yes
                Slow and a lot of work


         Using a debugger = using an IDE

                No, but you can



Tobias Schlitt (PHP World Kongress 2009)         Xdebug   2009-11-24   5 / 41
Why a debugger?

         I don’t need a debugger

                No bug free code
                Living life the easy way . . .


         var dump(), print r() and echo

                Sometimes, yes
                Slow and a lot of work


         Using a debugger = using an IDE

                No, but you can



Tobias Schlitt (PHP World Kongress 2009)         Xdebug   2009-11-24   5 / 41
Why a debugger?

         I don’t need a debugger

                No bug free code
                Living life the easy way . . .


         var dump(), print r() and echo

                Sometimes, yes
                Slow and a lot of work


         Using a debugger = using an IDE

                No, but you can



Tobias Schlitt (PHP World Kongress 2009)         Xdebug   2009-11-24   5 / 41
Why a debugger?

         I don’t need a debugger

                No bug free code
                Living life the easy way . . .


         var dump(), print r() and echo

                Sometimes, yes
                Slow and a lot of work


         Using a debugger = using an IDE

                No, but you can



Tobias Schlitt (PHP World Kongress 2009)         Xdebug   2009-11-24   5 / 41
Why a debugger?

         I don’t need a debugger

                No bug free code
                Living life the easy way . . .


         var dump(), print r() and echo

                Sometimes, yes
                Slow and a lot of work


         Using a debugger = using an IDE

                No, but you can



Tobias Schlitt (PHP World Kongress 2009)         Xdebug   2009-11-24   5 / 41
Why a debugger?

         I don’t need a debugger

                No bug free code
                Living life the easy way . . .


         var dump(), print r() and echo

                Sometimes, yes
                Slow and a lot of work


         Using a debugger = using an IDE

                No, but you can



Tobias Schlitt (PHP World Kongress 2009)         Xdebug   2009-11-24   5 / 41
Why a debugger?

         I don’t need a debugger

                No bug free code
                Living life the easy way . . .


         var dump(), print r() and echo

                Sometimes, yes
                Slow and a lot of work


         Using a debugger = using an IDE

                No, but you can



Tobias Schlitt (PHP World Kongress 2009)         Xdebug   2009-11-24   5 / 41
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.5
          Created and maintained by Derick Rethans
          http://xdebug.org




Tobias Schlitt (PHP World Kongress 2009)   Xdebug      2009-11-24   6 / 41
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 World Kongress 2009)     Xdebug   2009-11-24   7 / 41
Outline


  1 About Debugging


  2 Installation
          Installation
          Configuration

  3 Development goodies


  4 Tracing


  5 More features...


  6 The end


Tobias Schlitt (PHP World Kongress 2009)   Xdebug   2009-11-24   8 / 41
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 World Kongress 2009)    Xdebug   2009-11-24   9 / 41
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=xdebug205
                         t a r −x z f xdebug − 2 . 0 . 5 . t g z
                         cd xdebug − 2 . 0 . 5
                         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 World Kongress 2009)          Xdebug                            2009-11-24   10 / 41
Windows




          Download binary module from http://xdebug.org
          Copy to modules directory
          After that: Add module to php.ini




Tobias Schlitt (PHP World Kongress 2009)   Xdebug         2009-11-24   11 / 41
Add module to php.ini




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




Tobias Schlitt (PHP World Kongress 2009)   Xdebug    2009-11-24   12 / 41
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 World Kongress 2009)              Xdebug   2009-11-24   13 / 41
Configuration




          Huge variety of options
          Many shown later
          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 World Kongress 2009)   Xdebug                   2009-11-24   14 / 41
Outline

  1 About Debugging


  2 Installation


  3 Development goodies
          Error messages
          Dumping variables
          Infinity
          Useful functions

  4 Tracing


  5 More features...


  6 The end
Tobias Schlitt (PHP World Kongress 2009)   Xdebug   2009-11-24   15 / 41
Getting started




          Install module
          Switch it on
          Tweak some settings
          Work as usual




Tobias Schlitt (PHP World Kongress 2009)   Xdebug   2009-11-24   16 / 41
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 World Kongress 2009)   Xdebug   2009-11-24   17 / 41
Let’s dig into some code




 Let’s dig into some code




Tobias Schlitt (PHP World Kongress 2009)   Xdebug   2009-11-24   18 / 41
var dump()




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




Tobias Schlitt (PHP World Kongress 2009)     Xdebug   2009-11-24   19 / 41
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 World Kongress 2009)   Xdebug   2009-11-24   20 / 41
Let’s dig into some code




 Let’s dig into some code




Tobias Schlitt (PHP World Kongress 2009)   Xdebug   2009-11-24   21 / 41
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 World Kongress 2009)        Xdebug           2009-11-24   22 / 41
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 World Kongress 2009)    Xdebug                 2009-11-24   22 / 41
Let’s dig into some code




 Let’s dig into some code




Tobias Schlitt (PHP World Kongress 2009)   Xdebug   2009-11-24   23 / 41
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 World Kongress 2009)        Xdebug                   2009-11-24   24 / 41
Let’s dig into some code




 Let’s dig into some code




Tobias Schlitt (PHP World Kongress 2009)   Xdebug   2009-11-24   25 / 41
Stack depth

   Retrieving stack level

   echo ”<p r e >” ;

   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 ’ ;




Tobias Schlitt (PHP World Kongress 2009)              Xdebug                 2009-11-24   26 / 41
Let’s dig into some code




 Let’s dig into some code




Tobias Schlitt (PHP World Kongress 2009)   Xdebug   2009-11-24   27 / 41
Outline



  1 About Debugging


  2 Installation


  3 Development goodies


  4 Tracing


  5 More features...


  6 The end



Tobias Schlitt (PHP World Kongress 2009)   Xdebug   2009-11-24   28 / 41
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 World Kongress 2009)     Xdebug                       2009-11-24   29 / 41
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 World Kongress 2009)       Xdebug                       2009-11-24   30 / 41
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 World Kongress 2009)      Xdebug   2009-11-24   31 / 41
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 World Kongress 2009)            Xdebug                                 2009-11-24   32 / 41
Let’s dig into some code




 Let’s dig into some code




Tobias Schlitt (PHP World Kongress 2009)   Xdebug   2009-11-24   33 / 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 World Kongress 2009)   Xdebug        2009-11-24   34 / 41
Outline



  1 About Debugging


  2 Installation


  3 Development goodies


  4 Tracing


  5 More features...


  6 The end



Tobias Schlitt (PHP World Kongress 2009)   Xdebug   2009-11-24   35 / 41
Profiling




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




Tobias Schlitt (PHP World Kongress 2009)   Xdebug       2009-11-24   36 / 41
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 World Kongress 2009)   Xdebug   2009-11-24   37 / 41
Remote debugging

          Integrate Xdebug into your IDE
                 Komodo IDE
                 Eclipse




Tobias Schlitt (PHP World Kongress 2009)   Xdebug   2009-11-24   38 / 41
Outline



  1 About Debugging


  2 Installation


  3 Development goodies


  4 Tracing


  5 More features...


  6 The end



Tobias Schlitt (PHP World Kongress 2009)   Xdebug   2009-11-24   39 / 41
Questions / Answers




                                  Questions? Feedback? Critics?




Tobias Schlitt (PHP World Kongress 2009)      Xdebug              2009-11-24   40 / 41
The end




          I hope you enjoyed the session
          Slides and material
                 http://schlitt.info/opensource
                 http://www.slideshare.net/tobyS
          Contact: Tobias Schlitt <toby@php.net>




Tobias Schlitt (PHP World Kongress 2009)   Xdebug   2009-11-24   41 / 41

More Related Content

Similar to Xdebug

Open frameworks 101_fitc
Open frameworks 101_fitcOpen frameworks 101_fitc
Open frameworks 101_fitc
benDesigning
 
Python debuggers slides
Python debuggers slidesPython debuggers slides
Python debuggers slides
mattboehm
 
Unit-Tests
Unit-TestsUnit-Tests
Unit-Tests
Tobias Schlitt
 
Debugging and Profiling PHP Applications
Debugging and Profiling PHP ApplicationsDebugging and Profiling PHP Applications
Debugging and Profiling PHP Applications
Logan Lindquist
 
Symfony2 components to the rescue of your PHP projects
Symfony2 components to the rescue of your PHP projectsSymfony2 components to the rescue of your PHP projects
Symfony2 components to the rescue of your PHP projects
Xavier Lacot
 
PyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsPyCon2022 - Building Python Extensions
PyCon2022 - Building Python Extensions
Henry Schreiner
 
C# Production Debugging Made Easy
 C# Production Debugging Made Easy C# Production Debugging Made Easy
C# Production Debugging Made Easy
Alon Fliess
 
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
Wim Godden
 
DDD (Debugger Driven Development)
DDD (Debugger Driven Development)DDD (Debugger Driven Development)
DDD (Debugger Driven Development)
Carlos Granados
 
introduction to linux desktop draft 5
introduction to linux desktop draft 5introduction to linux desktop draft 5
introduction to linux desktop draft 5
swee meng ng
 
Porting your favourite cmdline tool to Android
Porting your favourite cmdline tool to AndroidPorting your favourite cmdline tool to Android
Porting your favourite cmdline tool to Android
Vlatko Kosturjak
 
Hello, Python
Hello, PythonHello, Python
Hello, Python
hardwyrd
 
Entwicker camp2007 calling-the-c-api-from-lotusscript
Entwicker camp2007 calling-the-c-api-from-lotusscriptEntwicker camp2007 calling-the-c-api-from-lotusscript
Entwicker camp2007 calling-the-c-api-from-lotusscript
Bill Buchan
 
Xdebug from a to x
Xdebug from a to xXdebug from a to x
Xdebug from a to x
Gennady Feldman
 
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
Wim 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.x
Wim Godden
 
Experience protocol buffer on android
Experience protocol buffer on androidExperience protocol buffer on android
Experience protocol buffer on android
Richard Chang
 
01. Introduction to Programming
01. Introduction to Programming01. Introduction to Programming
01. Introduction to Programming
Intro C# Book
 
Rhel8 Beta - Halifax RHUG
Rhel8 Beta - Halifax RHUGRhel8 Beta - Halifax RHUG
Rhel8 Beta - Halifax RHUG
Nicole Maselli
 
RHEL8-BETA-RHUG.pdf
RHEL8-BETA-RHUG.pdfRHEL8-BETA-RHUG.pdf
RHEL8-BETA-RHUG.pdf
Harsh Shah
 

Similar to Xdebug (20)

Open frameworks 101_fitc
Open frameworks 101_fitcOpen frameworks 101_fitc
Open frameworks 101_fitc
 
Python debuggers slides
Python debuggers slidesPython debuggers slides
Python debuggers slides
 
Unit-Tests
Unit-TestsUnit-Tests
Unit-Tests
 
Debugging and Profiling PHP Applications
Debugging and Profiling PHP ApplicationsDebugging and Profiling PHP Applications
Debugging and Profiling PHP Applications
 
Symfony2 components to the rescue of your PHP projects
Symfony2 components to the rescue of your PHP projectsSymfony2 components to the rescue of your PHP projects
Symfony2 components to the rescue of your PHP projects
 
PyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsPyCon2022 - Building Python Extensions
PyCon2022 - Building Python Extensions
 
C# Production Debugging Made Easy
 C# Production Debugging Made Easy C# Production Debugging Made Easy
C# Production Debugging Made Easy
 
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
 
DDD (Debugger Driven Development)
DDD (Debugger Driven Development)DDD (Debugger Driven Development)
DDD (Debugger Driven Development)
 
introduction to linux desktop draft 5
introduction to linux desktop draft 5introduction to linux desktop draft 5
introduction to linux desktop draft 5
 
Porting your favourite cmdline tool to Android
Porting your favourite cmdline tool to AndroidPorting your favourite cmdline tool to Android
Porting your favourite cmdline tool to Android
 
Hello, Python
Hello, PythonHello, Python
Hello, Python
 
Entwicker camp2007 calling-the-c-api-from-lotusscript
Entwicker camp2007 calling-the-c-api-from-lotusscriptEntwicker camp2007 calling-the-c-api-from-lotusscript
Entwicker camp2007 calling-the-c-api-from-lotusscript
 
Xdebug from a to x
Xdebug from a to xXdebug from a to x
Xdebug from a to 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 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
 
Experience protocol buffer on android
Experience protocol buffer on androidExperience protocol buffer on android
Experience protocol buffer on android
 
01. Introduction to Programming
01. Introduction to Programming01. Introduction to Programming
01. Introduction to Programming
 
Rhel8 Beta - Halifax RHUG
Rhel8 Beta - Halifax RHUGRhel8 Beta - Halifax RHUG
Rhel8 Beta - Halifax RHUG
 
RHEL8-BETA-RHUG.pdf
RHEL8-BETA-RHUG.pdfRHEL8-BETA-RHUG.pdf
RHEL8-BETA-RHUG.pdf
 

Recently uploaded

“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Zilliz
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 

Recently uploaded (20)

“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 

Xdebug

  • 1. Xdebug Alltagshilfe und professioneller Debugger TobiasSchlitt <toby@php.net> PHP World Kongress 2009 2009-11-24 Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 1 / 41
  • 2. About me Tobias Schlitt <toby@php.net> PHP since 2001 Freelancing consultant Qualified IT Specialist Studying CS at TU Dortmund (finishing mid 2010) OSS addicted eZ Components PHPUnit Various other projects . . . Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 2 / 41
  • 3. Overview 1 About Debugging 2 Installation 3 Development goodies 4 Tracing 5 More features... 6 The end Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 3 / 41
  • 4. Outline 1 About Debugging 2 Installation 3 Development goodies 4 Tracing 5 More features... 6 The end Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 4 / 41
  • 5. Why a debugger? I don’t need a debugger No bug free code Living life the easy way . . . var dump(), print r() and echo Sometimes, yes Slow and a lot of work Using a debugger = using an IDE No, but you can Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 5 / 41
  • 6. Why a debugger? I don’t need a debugger No bug free code Living life the easy way . . . var dump(), print r() and echo Sometimes, yes Slow and a lot of work Using a debugger = using an IDE No, but you can Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 5 / 41
  • 7. Why a debugger? I don’t need a debugger No bug free code Living life the easy way . . . var dump(), print r() and echo Sometimes, yes Slow and a lot of work Using a debugger = using an IDE No, but you can Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 5 / 41
  • 8. Why a debugger? I don’t need a debugger No bug free code Living life the easy way . . . var dump(), print r() and echo Sometimes, yes Slow and a lot of work Using a debugger = using an IDE No, but you can Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 5 / 41
  • 9. Why a debugger? I don’t need a debugger No bug free code Living life the easy way . . . var dump(), print r() and echo Sometimes, yes Slow and a lot of work Using a debugger = using an IDE No, but you can Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 5 / 41
  • 10. Why a debugger? I don’t need a debugger No bug free code Living life the easy way . . . var dump(), print r() and echo Sometimes, yes Slow and a lot of work Using a debugger = using an IDE No, but you can Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 5 / 41
  • 11. Why a debugger? I don’t need a debugger No bug free code Living life the easy way . . . var dump(), print r() and echo Sometimes, yes Slow and a lot of work Using a debugger = using an IDE No, but you can Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 5 / 41
  • 12. Why a debugger? I don’t need a debugger No bug free code Living life the easy way . . . var dump(), print r() and echo Sometimes, yes Slow and a lot of work Using a debugger = using an IDE No, but you can Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 5 / 41
  • 13. Why a debugger? I don’t need a debugger No bug free code Living life the easy way . . . var dump(), print r() and echo Sometimes, yes Slow and a lot of work Using a debugger = using an IDE No, but you can Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 5 / 41
  • 14. Why a debugger? I don’t need a debugger No bug free code Living life the easy way . . . var dump(), print r() and echo Sometimes, yes Slow and a lot of work Using a debugger = using an IDE No, but you can Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 5 / 41
  • 15. 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.5 Created and maintained by Derick Rethans http://xdebug.org Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 6 / 41
  • 16. 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 World Kongress 2009) Xdebug 2009-11-24 7 / 41
  • 17. Outline 1 About Debugging 2 Installation Installation Configuration 3 Development goodies 4 Tracing 5 More features... 6 The end Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 8 / 41
  • 18. 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 World Kongress 2009) Xdebug 2009-11-24 9 / 41
  • 19. 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=xdebug205 t a r −x z f xdebug − 2 . 0 . 5 . t g z cd xdebug − 2 . 0 . 5 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 World Kongress 2009) Xdebug 2009-11-24 10 / 41
  • 20. Windows Download binary module from http://xdebug.org Copy to modules directory After that: Add module to php.ini Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 11 / 41
  • 21. Add module to php.ini Not a “normal” extension Add to php.ini: zend extension = ”/path/to/xdebug.so” For threadsafe builds: zend extension ts For debug builds zend extension debug Check $ php −v or phpinfo() ; Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 12 / 41
  • 22. 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 World Kongress 2009) Xdebug 2009-11-24 13 / 41
  • 23. Configuration Huge variety of options Many shown later 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 World Kongress 2009) Xdebug 2009-11-24 14 / 41
  • 24. Outline 1 About Debugging 2 Installation 3 Development goodies Error messages Dumping variables Infinity Useful functions 4 Tracing 5 More features... 6 The end Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 15 / 41
  • 25. Getting started Install module Switch it on Tweak some settings Work as usual Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 16 / 41
  • 26. 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 World Kongress 2009) Xdebug 2009-11-24 17 / 41
  • 27. Let’s dig into some code Let’s dig into some code Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 18 / 41
  • 28. var dump() Using var dump() Everyone does it There is nothing bad about it var dump() in the browser sucks Xdebug enhances var dump() Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 19 / 41
  • 29. 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 World Kongress 2009) Xdebug 2009-11-24 20 / 41
  • 30. Let’s dig into some code Let’s dig into some code Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 21 / 41
  • 31. 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 World Kongress 2009) Xdebug 2009-11-24 22 / 41
  • 32. 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 World Kongress 2009) Xdebug 2009-11-24 22 / 41
  • 33. Let’s dig into some code Let’s dig into some code Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 23 / 41
  • 34. 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 World Kongress 2009) Xdebug 2009-11-24 24 / 41
  • 35. Let’s dig into some code Let’s dig into some code Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 25 / 41
  • 36. Stack depth Retrieving stack level echo ”<p r e >” ; 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 ’ ; Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 26 / 41
  • 37. Let’s dig into some code Let’s dig into some code Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 27 / 41
  • 38. Outline 1 About Debugging 2 Installation 3 Development goodies 4 Tracing 5 More features... 6 The end Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 28 / 41
  • 39. 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 World Kongress 2009) Xdebug 2009-11-24 29 / 41
  • 40. 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 World Kongress 2009) Xdebug 2009-11-24 30 / 41
  • 41. 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 World Kongress 2009) Xdebug 2009-11-24 31 / 41
  • 42. 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 World Kongress 2009) Xdebug 2009-11-24 32 / 41
  • 43. Let’s dig into some code Let’s dig into some code Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 33 / 41
  • 44. 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 World Kongress 2009) Xdebug 2009-11-24 34 / 41
  • 45. Outline 1 About Debugging 2 Installation 3 Development goodies 4 Tracing 5 More features... 6 The end Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 35 / 41
  • 46. Profiling Which code takes which time? Find bottle necks in code Check your database queries and setup first! Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 36 / 41
  • 47. 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 World Kongress 2009) Xdebug 2009-11-24 37 / 41
  • 48. Remote debugging Integrate Xdebug into your IDE Komodo IDE Eclipse Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 38 / 41
  • 49. Outline 1 About Debugging 2 Installation 3 Development goodies 4 Tracing 5 More features... 6 The end Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 39 / 41
  • 50. Questions / Answers Questions? Feedback? Critics? Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 40 / 41
  • 51. The end I hope you enjoyed the session Slides and material http://schlitt.info/opensource http://www.slideshare.net/tobyS Contact: Tobias Schlitt <toby@php.net> Tobias Schlitt (PHP World Kongress 2009) Xdebug 2009-11-24 41 / 41