1 / 39

The Art of Debugging

The Art of Debugging. Shlomy Gantz 02/13/01 MDCFUG. Introduction - Famous Last words. “…if debugging is defined as the art of taking bugs out of a program , programming must be putting them in…” “..It’s not a bug, It’s a feature “ (Microsoft). Types of bugs. Syntax Error Run-Time Errors

Télécharger la présentation

The Art of Debugging

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Art of Debugging Shlomy Gantz 02/13/01 MDCFUG

  2. Introduction - Famous Last words • “…if debugging is defined as the art of taking bugs out of a program , programming must be putting them in…” • “..It’s not a bug, It’s a feature “ (Microsoft)

  3. Types of bugs • Syntax Error • Run-Time Errors • Logical Errors

  4. Types of bugs - Syntax Errors • Syntax Error Example <CFSET ClientName = “Shlomy Gantz”> <CFSET URLstr = URLstr & urlendcodedformat(ClientName) > View Example

  5. Types of bugs - Run-Time Errors • Run-Time Error Example <CFQUERY NAME=“GetOverPaidEmp” Datasource=“Payroll”> SELECT SUM(Salary) AS TotalSalary, COUNT(Emp_ID) as NumOfEmployees FROM AnnualSalary WHERE SALARY > 100000 </CFQUERY> <CFSET AVGSalary = GetOverPaidEmp.TotalSalary / GetOverPaidEmp.NumOfEmployees > <CFOUTPUT>#AVGSalary#</CFOUTPUT> View Example

  6. Types of bugs - Logical Errors • Logical Error example <CFSET MyList=“Shlomy,Michael,Emily,Abraham”> <CFSET ShlomyExists_YN = listfind(MyList,”shlomy”)> <CFOUTPUT>#YesNoFormat(ShlomyExists_YN)#</CFOUTPUT> View Example

  7. Other things that can go wrong • Database connection (ODBC,MDAC …) • Cold Fusion server • Web Server • OS • Hardware

  8. Debugging Steps • Plan • Back-up • Isolate • Find The error • Fix - Don’t patch • Look for similar • Document

  9. “Debugger’s Block” • If all else fails • … and if that doesn’t work

  10. Cold Fusion Administrator

  11. Enable Performance Monitoring View Example

  12. Enable CFML stack trace • CF tracks what tags have run during page process. • Can be used either through CFTRY/CFCATCH or the Studio Debugger

  13. Show Variables • Show all variables processed by ColdFusion: • FORM • URL • CGI • Cookie

  14. Show Processing Time • Show how long, in milliseconds, it takes for a page process to • run to completion

  15. Detail View • Breakdown of all templates run during a page process. • Proccessing time for each template

  16. Show SQL and Datasource Name • Shows SQL Statement & DSN in error messages

  17. Show Query Information • Query Name • RecordCount • Processing Time • Query Executed

  18. Display Template Path in Error Msg • Show the name of the actual template in which with the error occurred

  19. Restrict Debug Access • By Default All when debugging is turned on all users can see debug information. • You can restrict access to the debugging info through this feature by IP address

  20. Debugging with studio • Setting up Development Mapping.

  21. Using the interactive debugger

  22. Debugging CF applications • Show your variables (not only once) • Create breakpoints and Follow the flow • Use Exception handling • Look at your application logs • CF_ObjectDump

  23. <CFABORT> & <CFOUTPUT> • Using CFABORT to create breakpoints <cfinclude template="Header.cfm"> <cfquery datasource="#dsn#" name="getContacts"> Select * from Contacts WHERE Active_YN=1 </cfquery> <cfoutput>#getContacts.recordcount#</cfoutput> <cfabort>

  24. <CFABORT> & <CFOUTPUT> • Following the flow <CFIF …………> Step 1 <CFIF ………………..> Step 1.1 <CFELSE> Step 1.2 </CFIF> <CFELSE> Step 2 </CFIF> View Example

  25. Debugging in CFML • <cfquery debug> • <cfstoredproc debug=“yes|no”> • <cfsetting showdebug output=“yes/no”> View Example View Example

  26. Debugging CF applications • <CFERROR> • <CFTHROW> • <CFRETHROW> • <CFCATCH><CFTRY>

  27. <CFERROR> • <CFERROR TYPE="Request" or "Validation" or "Monitor" or "Exception" TEMPLATE="template_path" MAILTO="email_address" EXCEPTION="exception_type">

  28. <CFTRY><CFCATCH> • <CFTRY> • ... Add code here • <CFCATCH TYPE="exceptiontype"> • ... Add exception processing code here </CFCATCH> • ... Additional CFCATCH blocks go here </CFTRY>

  29. <CFTHROW><CFRETHROW> • <CFTHROW TYPE="exception_type" MESSAGE="message" DETAIL="detail_description" ERRORCODE="error_code" EXTENDEDINFO="additional_information">

  30. Application Logs • Read your application logs regularly Error","TID=199","07/27/00","13:32:35","127.0.0.1","Mozilla/4.0 (compatible; MSIE 4.01; Windows NT)","An error has occurred. HTTP/1.0 404 Object Not Found" "Error","TID=199","07/27/00","13:32:45","127.0.0.1","Mozilla/4.0 (compatible; MSIE 4.01; Windows NT)","Error resolving parameter SLOT_IDColdFusion was unable to determine the value of the parameter. This problem is very likely due to the fact that either: You have misspelled the parameter name, or You have not specified a QUERY attribute for a CFOUTPUT, CFMAIL, or CFTABLE tag.The error occurred while evaluating the expression: #slot_id# The error occurred while processing an element with a general identifier of (#slot_id#), occupying document position (4:12) to (4:20) in the template file D:\wwwroot\cfun2000\Examples\JS\JSexample1_CFMW\edit_def.cfmThe specific sequence of files included or processed is:D:\WWWROOT\CFUN2000\EXAMPLES\JS\JSEXAMPLE1_CFMW\EDIT_DEF.CFM &nbsp;&nbsp;&nbsp;&nbsp; .Date/Time: 07/27/00 13:32:45Browser: Mozilla/4.0 (compatible; MSIE 4.01; Windows NT)Remote Address: 127.0.0.1HTTP Referer: http://127.0.0.1/cfun2000/Examples/JS/JSexample1_CFMW/EDIT.HTMLTemplate: D:\wwwroot\cfun2000\Examples\JS\JSexample1_CFMW\edit_def.cfm" "Warning","TID=152","07/27/00","15:07:21","In a CF_TagName construct custom tag file 'C:\CFUSION\CustomTags\Pages.cfm' will occlude custom tag file 'C:\CFUSION\CustomTags\cf_pages\Pages.cfm'." "Warning","TID=152","07/27/00","15:07:21","In a CF_TagName construct custom tag file 'C:\CFUSION\CustomTags\Pages.cfm' will occlude custom tag file 'C:\CFUSION\CustomTags\cf_pages\images\Pages.cfm'." View Example

  31. CF_Objectdump • Read your application logs regularly <CF_ObjectDump Object="#Object#" Deserialize="yes|no" > View Example

  32. Debugging Databases • SQL query analyzer

  33. Debugging JavaScript • “Microsoft Script debugger”/“Netscape JavaScript Debugger” • Using alert() and return false;

  34. Debugging flash • No debug output • simulated flash requests • output in flash

  35. Tools • http://www.secretagents.com/ • BugTraq • http://www.logviewer.com/ • Automatic Code Generation Tools • CodeSaver / CodeCharge / CommerceBlocks

  36. What’s new in 5.0 • Easier Log Analysis

  37. What’s new in 5.0 • New options on CF Admin debug setting

  38. Thank You • Michael Dinowitz, Emily Kim, Michael Imhoff and Abraham Lloyd. • … Michael Smith

  39. QA • Shlomy Gantz shlomygantz@hotmail.com http://www.shlomygantz.com

More Related