step into debugging - drupalcon · introducing xdebug a php extension that enables you to step...

64
STEP INTO GARY HOCKIN @GeeH DEBUGGING

Upload: others

Post on 26-Aug-2020

19 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

STEP INTO

GARY HOCKIN@GeeH

DEBUGGING

Page 2: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

IN THE BEGINNING, THERE WAS VAR_DUMP

Page 3: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

AND IT WAS GOOD

Page 4: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

<?phpdie(var_dump($countries));array (size=239) 0 => object(Application\Entities\Country)[321] private 'code' => string 'ABW' (length=3) private 'name' => string 'Aruba' (length=5) private 'continent' => string 'North America' (length=13) private 'region' => string 'Caribbean' (length=9) private 'surfaceArea' => string '193.00' (length=6) private 'indepYear' => null private 'population' => string '103000' (length=6) private 'lifeExpectancy' => string '78.4' (length=4) ...

Page 5: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

AND IT’S STILL GOOD

Page 6: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

AND IT’S STILL GOOD(SOMETIMES)

Page 7: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

<?phppublic function getDQL() { if ($this->_dql !== null && $this->_state === self::STATE_CLEAN) { echo ‘FIRST IF' . PHP_EOL; return $this->_dql; } switch ($this->_type) { case self::DELETE: echo 'DELETE' . PHP_EOL; $dql = $this->_getDQLForDelete(); break; case self::UPDATE: echo 'UPDATE' . PHP_EOL; $dql = $this->_getDQLForUpdate(); break; case self::SELECT: default: echo 'DEFAULT' . PHP_EOL; $dql = $this->_getDQLForSelect(); break; } $this->_state = self::STATE_CLEAN; $this->_dql = $dql; var_dump($dql); return $dql; }

Page 8: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

INTRODUCING XDEBUG

A PHP extension that enables you to step debug PHP scripts (and much more)

http://xdebug.org

Page 9: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

DERICK RETHANS@derickr

http://www.facesoftheelephpant.com/image/134982910242

Page 10: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

XDEBUG “CLIENT”

XDEBUG “SERVER”

debug “events”

Page 11: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

XDEBUG “CLIENT”

XDEBUG “SERVER”

debug “events”

Page 12: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

XDEBUG “CLIENT”

XDEBUG “SERVER”

debug “events”

Page 13: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

XDEBUG “CLIENT”

XDEBUG “SERVER”

debug “events”

Page 14: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

OTHER IDES ARE AVAILABLE

Page 15: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

INSTALL THE XDEBUG EXTENSION

Page 16: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

OSX

brew install php<version>-xdebug

Page 17: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

LINUX

apt-get install php<version>-xdebug

yum install php<version>-xdebug

Page 18: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

WINDOWS

Download the binaries from:

https://xdebug.org/download.php

(GOOD LUCK)

Page 19: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

$php -v

PHP 5.6.17 (cli) (built: Jan 8 2016 10:27:48) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans

Page 20: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

$php -v

PHP 5.6.17 (cli) (built: Jan 8 2016 10:27:48) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans

Page 21: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

$php —-ini

Configuration File (php.ini) Path: /usr/local/etc/php/5.6 Loaded Configuration File: /usr/local/etc/php/5.6/php.ini Scan for additional .ini files in: /usr/local/etc/php/5.6/conf.d Additional .ini files parsed: /usr/local/etc/php/5.6/conf.d/ext-intl.ini, /usr/local/etc/php/5.6/conf.d/ext-xdebug.ini

Page 22: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

$vim /usr/local/etc/php/5.6/conf.d/ext-xdebug.ini

[xdebug] zend_extension="/usr/local/opt/php56-xdebug/xdebug.so" xdebug.remote_enable=on xdebug.remote_connect_back=on

Page 23: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

INSTALL XDEBUG

CHECK PHP CONFIG

UPDATE XDEBUG

brew install php56-xdebug

php -v php —ini

xdebug.remote_enable=on xdebug.remote_connect_back=on

Page 24: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

PLEASE DON’T USE IN PRODUCTION

Page 25: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

Use either a query string parameter OR a cookie

TELL XDEBUG YOU WANT TO DEBUG

XDEBUG_SESSION=PHPSTORM

Page 26: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)
Page 27: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)
Page 28: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)
Page 29: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

Hello?XDEBUG “CLIENT”

XDEBUG “SERVER”

Page 30: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

Hello?

breakpoints

XDEBUG “CLIENT”

XDEBUG “SERVER”

Page 31: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

Hello?

breakpoint!

XDEBUG “CLIENT”

XDEBUG “SERVER”

breakpoints

Page 32: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

Hello?

breakpoint!

step into

XDEBUG “CLIENT”

XDEBUG “SERVER”

breakpoints

Page 33: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

BREAKPOINT?!?!?!

Page 34: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

Please BREAK at this POINT and tell the server what’s going on

BREAKPOINT?!?!?!

Page 35: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

http://www.goldposter.com/86057/

Page 36: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

TELL PHPSTORM TO LISTEN

Page 37: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

ONOFF

Page 38: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)
Page 39: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

STEP OVER (F8)

Step over the current function/method

Runs the function/method, but doesn’t debug into it

Page 40: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)
Page 41: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

STEP INTO (F9)

Step into the current function/method

Move to the file the function was declared and steps over that function

Page 42: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)
Page 43: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

STEP OUT (F9)

Step out of the current function/method

Move to the place that the return value is used

Page 44: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)
Page 45: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

ADVANCED BREAKPOINTS

Page 46: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

http://www.comingsoon.net/movies/trailers/480825-new-point-break-poster

Page 47: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

VIEW BREAKPOINTS

Misnomer as you can add/remove/edit existing breakpoints

Page 48: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)
Page 49: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

BONUS

https://flic.kr/p/gqhi3N

Page 50: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

CONSOLE

Page 51: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

Allows you to view and manipulate variable values on-the-fly

CONSOLE

Page 52: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)
Page 53: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

https://flic.kr/p/7ZAdXH

Page 54: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

COMMAND LINE

Page 55: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

EXPORT an XDEBUG_CONFIG value to set IDE key

COMMAND LINE

Page 56: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

$export XDEBUG_CONFIG="idekey=PhpStorm"

Page 57: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)
Page 58: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

Don’t forget to UNSET the XDEBUG_CONFIG value to avoid confusion

COMMAND LINE

Page 59: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

$unset XDEBUG_CONFIG

Page 60: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

ANY QUESTIONS?

GARY HOCKIN@GeeH

https://joind.in/talk/e43ec

Page 61: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

SUPER DUPER BONUS

https://twitter.com/jmikola/status/695659879244177408

Page 62: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

FRAMEWORKS

Page 63: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)
Page 64: STEP INTO DEBUGGING - DrupalCon · INTRODUCING XDEBUG A PHP extension that enables you to step debug PHP scripts (and much more)

ANY QUESTIONS?

GARY HOCKIN@GeeH

https://joind.in/talk/e43ec