$30 off During Our Annual Pro Sale. View Details »

Debugging For Distressed Developers

Debugging For Distressed Developers

A basic, broad introduction to debugging terms and tools for web developers, with a in-depth section on setting up XDebug for PHP and some worst and best practices when debugging code.

Danielle Suurlant

December 12, 2013
Tweet

Other Decks in Programming

Transcript

  1. Who am I Daniëlle Suurlant Developer @ Samson IT Typically

    not distressed github.com/dsuurlant twitter.com/dsuurlant www.binarystar.nl (1/1/2014)
  2. What’s this about ➔ The Basics ➔ The Tools ➔

    The In-Depth: XDebug ➔ The Don’ts and Do Instead ➔ The Best Practices
  3. The Basics ➔ Breakpoints ➔ Stepping ◆ Step Into ◆

    Step Over ◆ Step Out ➔ Run To Cursor ➔ Stack trace ➔ Variables
  4. Browser Developer’s Tools ➔ Explore all options! ◆ HTML source,

    CSS styles, source files ◆ Network traffic ◆ XHR requests ◆ JavaScript debugging ➔ Keep a Dev Tool window open ➔ Live editing ◆ ... just don’t refresh
  5. PostMan ➔ Headers and authentication ➔ GET, POST, PUT, PATCH

    ➔ Form data, text, JSON, XML ➔ Quick & basic ➔ Use with XDebug: http://project.dev/api/method/1?XDEBUG_SESSION_START=PHPSTORM
  6. git bisect ➔ Binary search algorithm dsu:~/workspace/project (master)> git bisect

    start dsu:~/workspace/project (master|BISECTING)> git bisect bad dsu:~/workspace/project (master|BISECTING)> git bisect good e765fdf56 Bisecting: 1 revisions left to test after this (roughly 1 steps) [85ae1469e7d2400920c478156f3c7faa66f928a4] Story-324 verification fixes dsu:~/workspace/project ((85ae146...)|BISECTING)> git bisect bad Bisecting: 0 revisions left to test after this (roughly 0 steps) [528da5c4529bb57d029714c96ec26022d77463ba] fixed Story-322 dsu:~/workspace/project ((528da5c...)|BISECTING)> git bisect good 4352658da938e1a5a06c6a5dcf255eb5c7fe6db3 is the first bad commit
  7. Installation ➔ Manual Installation ◆ http://xdebug.org/download.php ◆ Correct PHP version

    and 32/64 bit ◆ TS = thread safe ➔ Not sure? Wizard! ◆ http://xdebug.org/wizard.php ➔ Check installation <?php echo phpinfo(); ?>
  8. Configuration: PHP ➔ Find your php.ini ... all of them

    zend_extension= "c:/wamp/bin/php/php5.4.12/zend_ext/php_xdebug-2.2.3-5.4-vc9-x86_64.dll" [xdebug] xdebug.remote_enable = 1 xdebug.remote_host = localhost xdebug.remote_port = 9000 xdebug.idekey = "PHPSTORM" xdebug.profiler_enable = off xdebug.profiler_enable_trigger = off xdebug.profiler_output_name = cachegrind.out.%t.%p xdebug.profiler_output_dir = "c:/wamp/tmp"
  9. Configuration: IDE ➔ PHPStorm ◆ Settings -> PHP -> Debug

    ◆ Debug port 9000, accept external connections ➔ Others ◆ IDE key ◆ Debug port ◆ Check FAQ / tutorial
  10. Configuration: CLI ➔ Command line (probably) uses different php.ini ◆

    Make sure the settings match ➔ Using bash? export XDEBUG_CONFIG="idekey=PHPSTORM"
  11. Not working? ➔ IDE key ➔ IDE key ➔ IDE

    KEY ➔ Port ➔ Restarted server? ➔ Flowchart
  12. Breakpoints ➔ Don’t: ◆ Put them on every line in

    the file ◆ Forget them ➔ Do Instead: ◆ Break on one line, then use stepping ◆ Run to Cursor ◆ Closer to the problem source -> new breakpoint ◆ Clear old breakpoints
  13. Stepping ➔ Don’t: ◆ Step into infinity ◆ Step to

    understand the code ➔ Do Instead: ◆ Stop stepping ◆ Understand the code ◆ Use run to cursor
  14. Variables ➔ Don’t: ◆ Examine recursively nested variables to 100+

    levels ➔ Do Instead: ◆ Stop clicking ◆ Take a deep breath ◆ Go for a walk
  15. Shotgun debugging “Shotgun debugging is a process of making relatively

    undirected changes to software in the hope that a bug will be perturbed out of existence.” (Source: Wikipedia) ➔ Don’t: ◆ ... ◆ Just don’t ➔ Do Instead: ◆ Use breakpoints
  16. Always keep in mind ➔ Don’t panic ➔ Focus on

    what information you need ➔ Think before you run ➔ Ask a friendly programmer for help ➔ Take necessary breaks
  17. ➔ Blame doesn’t fix bugs ➔ Boy / Girl scout

    principle ➔ But... ◆ Does this need to be fixed now? ◆ Does this need to be fixed by me? I didn’t break it