Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Debugging Web Applications


Understanding Code Internals

Knowing what to do to achieve perfect (or perfectly debuggable) code is one thing. Knowing what to expect and look for is another. There are many different models for Web application development and deployment environments. It's vital that you know exactly how yours works and how it differs from others you've worked with, so that you can adjust your analysis appropriately.

For example, Java Server Pages (JSPs) are popular because to the developer, JSP code appears to be simple inline Java statements embedded in the context of an HTML document—similar to ASP or PHP. But once they're deployed, JSPs are actually compiled into servlets. Trying to isolate the cause of a symptom described by an unnerved and possibly furious end user can be mind-numbingly difficult unless you know how to look for the actual servlet code.

Some other systems, such as Mason (a tool similar in architecture to JSP, but based on Apache and mod_perl), also let you inspect the actual code used to create the runtime component.

Bug-Free Markup

Beyond writing good, testable code, and being familiar with the environment in which the code will be executed, you should consider tools that will reduce the tedium and error-prone nature of debugging itself. For HTML and XHTML, there are many validators and emulators that can show you whether your markup is well-formed and valid. Validators can also suggest ways in which your application went wrong by showing you a representation of the visual display that the end user sees. These tools may be especially useful when the description of the symptom you received from a user of Browser XYZ doesn't resemble anything familiar. There are also validators for CSS stylesheets, syntax and lint checkers for JavaScript, and so on. But beyond simply providing assurances that the bug isn't in your markup, validators stop short of serious serious debugging.

Fortunately, some basic CGI scripts and programs are so simple that they don't require much debugging. However, more complex CGIs, especially those using popular libraries like Lincoln Stein's CGI.pm or Thomas Boutell's cgic, may require extensive debugging. Both of these libraries include built-in support for debugging.

Dynamic XHTML can be extremely difficult to debug. Often, the bugs that you (or your users) find are the results of a badly implemented feature in a particular version of a particular browser on a particular platform. Fortunately, this situation is improving almost daily, as the browsers' support for advanced features of the DOM and CSS2 improves.

Sadly, however, DXHTML suffers from mediocre error reporting under Internet Explorer, making it nearly impossible to use even IE's verbose error messages reliably. On the other hand, Mozilla has a wide range of tools that provide excellent and powerful debugging capabilities. From the Venkman JavaScript debugger to the DOM Inspector, practically every aspect of the DXHTML environment can be inspected and manipulated. For those on other browser platforms, a common debugging aid is to use a layer containing a <TEXTAREA> to which messages may be written. The <TEXTAREA> makes it possible for long messages to scroll, and it's easy to copy and paste them into other applications for later perusal.

Third-Party Solutions

PHP 3 provides a remote debugging service, and Zend provides similar tools that may be used as add-ons for PHP 4 in addition to third party products such as DBG and the Advanced PHP Debugger. NuSphere's PHPEd is a Windows editor that supports PHP's remote debugging and can synchronize error reports with the actual code in the editor.

The popular Apache module mod_perl embeds a Perl interpreter directly into the Web server, offering superior performance to the traditional CGI approach. A popular and useful CPAN library for debugging mod_perl applications is Data::Dumper, which can dump arbitrary data structures for offline perusal. The mod_perl component is also the foundation for Mason, a component architecture for Web applications that has many debugging abilities of its own.

As for Java, a wide variety of tools and architectural specifications are available, from debugging support in editors and IDEs such as JBuilder or WebSphere, to log4j, which provides a robust and sophisticated logging service for the Jakarta suite. Test harness and logging software such as that from Identify (formerly Mutek) can also aid in tracking down bugs in sophisticated Java and .Net Web applications.

Many of these debugging tools are available free of charge. You can find more information and URLs for each in the sidebar, "Web Debugging Tools." So go forth, and sin no more. If you can't write code that works right the first time, at least aim to write code that's easy to fix.


Steven is CTO of Hesketh, a Web solutions vendor based in Raleigh, NC. He can be reached at [email protected].



Web Debugging Tools

Need help debugging your Web applications, but you aren't sure where to turn? Don't worry, you aren't alone. A wide variety of debugging tools have been written with Web developers in mind. You're liable to find several useful products or projects no matter what your language and development platform of choice.

Among the most popular tools in use on the Web are the Web markup language validators provided by the World Wide Web Consortium (W3C). The HTML/XHTML validator (validator.w3.org) automatically verifies the structure and syntax of code found at any URI, or alternately accepts uploads in cases where a file is behind a firewall. The CSS validator (jigsaw.w3.org/css-validator/) has an online version as well. You can also download the source code from the W3C's CVS repository.

Programmer Liam Quinn has developed two validators of his own. A longtime SGML advocate, Quinn claims a high degree of accuracy for his tools, owing to their use of internal SGML parsers. Quinn's WDG HTML Validator (www.htmlhelp.com/tools/validator/) operates much like the W3C's online tool, while A Real Validator (www.arealvalidator.com) is a shareware Windows program that runs locally.

The open source Mozilla browser has several tools for developing JavaScript applications. Venkman, the Mozilla JavaScript debugger (www.mozilla.org/projects/venkman/), is a built-in component of the browser on all platforms, and lets you set breakpoints, step through code, set watches, and more. The DOM Inspector (www.mozilla.org/projects/inspector/) offers a variety of views into the document hierarchy of the current page.

CGI remains a popular technology for Web programming, but the tools used to debug it largely depend on the language used. For CGI programs written in C, Thomas Boutell's cgic library (www.boutell.com/cgic/) provides tools for capturing snapshots of the CGI environment. For Perl hackers, Lincoln Stein's CGI.pm (stein.cshl.org/WWW/software/CGI/) module lets you debug scripts at the command line without worrying about setting environmental variables.

Most of the more sophisticated development environments offer some built-in support for debugging. Mason (www.masonhq.com) includes a workaround that permits access to the Perl debugger even from a mod_perl environment.

PHP's debugging tools are widely documented. PHP 3 included a remote debugging service, and PHP 4 allows for plug-ins that accomplish the same thing, including DBG (dd.cron.ru/dbg/). Many editors and IDEs, including NuSphere's PHPEd (www.nusphere.com/products/phpadv.htm), integrate with those tools. Though not an interactive tool, the Advanced PHP Debugger (apd.communityconnect.com) provides stack tracing and event logging.

Java is perhaps the most sophisticated Web development platform. The Java 2 Platform includes the Java Platform Debugger Architecture (JPDA), which is a complete infrastructure for building end-user debugger applications (java.sun.com/products/jpda/). Many Java tools provide debugging facilities, either as built-in components and libraries or as separate applications, that are often integrated with the deployment environment. Apache's Jakarta project offers Log4J (jakarta.apache.org/log4j/), which allows for logging of execution context without modifying the shipping binary.

Borland's JBuilder, and IBM's WebSphere both ship with advanced Java debugging facilities, but several third-party debuggers are also available, including Karmira's BugSeeker (www.karmira.com/products/bugseeker2/). JUnit (www.junit.org) provides a testing framework for managing the debugging process, while Identify Software's AppSight (www.identify.com) lets developers track execution context and fix errors throughout the development and deployment life cycle.

—SC


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.