debugging drupal - how to debug your drupal application

22
Debugging with Drupal The art of Debugging Anoop John, CTO Vimal Joseph, Technical Architect

Upload: zyxware-technologies

Post on 13-Apr-2017

545 views

Category:

Technology


0 download

TRANSCRIPT

Debugging with DrupalThe art of Debugging

Anoop John, CTOVimal Joseph, Technical Architect

The Art of Debugging

Bugs everywhere...

SA-CORE-2014-005

The Art of Debugging

Bug-free Software?

The Art of Debugging

Debugging

It's hard enough to find an error in your code when you're looking for it; it's even harder when you've assumed your code is error-free.

Steve McConnel

The Art of Debugging

Story Time

Tell us a story on your debugging experience

The Art of Debugging

Set up Debugging Environment

PHP configuration (php.ini)display_errors = Onlog_errors = Onerror_reporting = E_ALL | E_STRICT

Drupal modulesDevel

A good editorGeanyEmacs is better – but learning curve is bit steep.

Learn to setup a development environment for a given project quickly. Drush will help.

The Art of Debugging

Debugging Tools - PHP

Basic PHPprint/echoprint_r()exit()/die()debug_backtrace()/debug_print_backtrace()

The Art of Debugging

Debugging Tools - Drupal

drupal_set_message()watchdog()Views

views_trace()Devel

dpm()dargs()dd()ddebug_backtrace()db_queryd()

The Art of Debugging

Debugging Tools - HTML, JS, CSSFirebugWeb Developer ToolbarJavascript debugger

The Art of Debugging

Debugging Tools - CLI

Drush – a life saver.archive-dump, archive-restore, vget, vset, php-eval, sql-cli, sql-query, user-login etc..

Xdebugcat, grep, awk, cut

The Art of Debugging

General Approach for DebuggingUnderstand the symptomUnderstand the contextDefine problem statementReplicate bugRead through codeIsolate location in code causing bugUnderstand codeUnderstand data / contextUnderstand causeIdentify solutionFix bug

The Art of Debugging

Tips for Debugging Code

Trial and error may work – but do not rely on thatBinary search is the best method to isolate a bugLearn to navigate through codeLearn to read logs

Webserver Access/Error logsDatabase Error logsDrupal error logs

Be familiar with the shell commandscat, zcat, grep, less etc..

The Art of Debugging

Errors, Notices, Warnings

Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1566 of /var/www/d7/includes/bootstrap.inc).Invalid argument supplied for foreach() in /var/www/d7/includes/common.inc on line 1919.Illegal offset type in isset or empty in /home/pgil1/public_html/modules/taxonomy/taxonomy.module on line 1090.

The Art of Debugging

Backtrace – your guide

views_tracedebug_backtracedebug_print_backtraceddebug_backtrace

The Art of Debugging

Tips for Debugging Code

// function drupal_set_message() bootstrap.inc if ($type == 'error') {// here are some alternatives – views_trace() // is part of views module// $message .= '<pre>' . print_r(debug_backtrace(), TRUE) . '</pre>'; // $message .= '<pre>' . views_trace() . '</pre>';}

// Or in function watchdog() bootstrap.incif ($type == 'php') { $message .= '<pre>'. print_r(debug_backtrace(), 1) .'</pre>';//$message .= '<pre>'. views_trace() .'</pre>'; }// Or in the function which error occurredddebug_backtrace(); or dpm() or print_r() //make sure to add the necessary conditions so that the debug code execute only when the error occurs.

The Art of Debugging

Tips for Debugging Code

// Debuging cron // module_invoke() module.incif ($hook == 'cron') { watchdog('debugging', "CRON: Calling $module"); }

// Errors like “Cannot use object of type stdClass as array”// Insert right before the moment of disasterif (!is_array($x)) { dpm(ddebug_backtrace(TRUE));}

The Art of Debugging

Tips for Debugging HTML, CSS, JSInspect using FirebugCreate test HTMLSet custom propertiesWalk through JS code executionInspect variables

Zyxware Technologies and Drupal

Zyxware is a leading contributor to Drupal from India and is one of only

six Featured Service Providers from India listed on drupal.org

● Over 40,000 websites use our modules and themes

● More than 30 contributed modules and themes

● Maintainer of Search404, a top 100 Drupal module

● Over 1000 commits at drupal.org

● Contributes all patches back to Drupal

● Our profile on drupal.org - http://drupal.org/user/222163

● Knowledge partnerships with Acquia, New Relic and Volacci

● Freedom Walk, a 44 day walk by a team of

Free Software Evangelists across the length of

Kerala to promote Free Software

● Building RithuOS, an Operating System for Engineering

students with Free Software Engineering applications

● GNU/Linux Install Fests in Schools, Colleges and at Technopark.

● Local language (Malayalam) computing camps in colleges

● Building and Maintenance of Freedom Toaster, a Free Software

kiosk

● Conducting Free Software workshops and

lectures in colleges in Kerala

Free Software and Zyxware Technologies

• Check us out at http://www.zyxware.com

• Mail us at [email protected]

• Like us at http://www.facebook.com/zyxware

• Follow us at http://www.twitter.com/zyxware

• Connect with us at

http://www.linkedin.com/companies/zyxware-technologies

• Talk to us at +91-9495969446 between 9AM - 9PM IST

• Skype me at aj_zyxware

Contact Us

The Art of Debugging

Thank you …

The Art of Debugging

Credits

http://randyfay.com/content/debugging-techniqueshttp://www.lullabot.com/articles/quick_and_dirty_debugging