How do I figure things out? (debugging, developing)

Events happening in the community are now at Drupal community events on www.drupal.org.
nadavoid's picture

This is a pretty general question, I know, but bear with me for a minute...

Suppose you observe some code that is being displayed on a page of your site (maybe something that is in a menu, or in the page body somewhere). And you think to yourself: I'd really like to add a class to that, or I'd like a deeper menu depth, or DL tags instead of DIVs or UL.

It seems to me that, step one would be to locate the chain of function calls that generate this. I'd really like to be able to work my way backward from the output code itself. (There's a name for this... something like "function chain" or "backtrace" ech, I can't remember it right now.)

Then, once you know what function is creating your output, you have a chance at figuring out how to override it - whether it's something that you put in your own theme or module.

Is this what remote debugging is all about? If so, could you point me to some "getting started with remote debugging and backtracing in drupal" arcticle?

Would this be a good idea for a screencast?

Comments

Various things to see/read/do

Chris Charlton's picture

One starter is use PHP's print_r($array), replacing "$array" with whatever array/object you're trying to inspect. I'd probably add <pre> tags around that print_r().

But as for tracing event flow, call stacks, hooks, events - whatever it's called - then you may need to look for a tool, or really get into reading PHP/Apache logs to catch something fishy. If nothing is broke and you're just poking around then keep doing that. :)

Chris Charlton, Author & Drupal Community Leader, Enterprise Level Consultant

I teach you how to build Drupal Themes http://tinyurl.com/theme-drupal and provide add-on software at http://xtnd.us

print_r() and other things

nadavoid's picture

Yes, print_r() is my development friend. :) Especially in theming, so far.

Visualize Backtrace module

sagannotcarl's picture

Check out the Visualize Backtrace module (http://drupal.org/project/visualize_backtrace). If I remember correctly it takes a little setting up (potentially configuring an external debugging tool along with it), but once you get it going it seems like a great tool.

Basically shows everything that goes into rendering a page and a big colorful flowchart. At least when I saw it demo'd it looked pretty useful.
Colin


[ Quilted, Stitching Together Technology and Social Change ]


[ Quilted, Stitching Together Technology and Social Change ]

That looks great!

nadavoid's picture

That Visualize Backtrace module does look very helpful. I've never seen anything like that before. I'm going to see if I can get that going, along with a "regular" remote debugging tool, over the next few days.

There's always quick-and-dirty debugging...

I've got it together now. ;)

nadavoid's picture

thanks webchick for that last tip. That does help. I'll encapsulate that informative and fun article into just a couple of items here:

  • inside bootstrap.inc -> drupal_ set_ message() set this
    if ($type == 'error') {
      $message .= '<pre>'. print_r(debug_backtrace(), 1) .'</pre>';
    }
  • put the following anywhere you want to see what's going on (content, theme file, etc.)
    <pre><?php print (htmlspecialchars (print_r (debug_backtrace(), 1) ) ); ?></pre>

This was my introduction to the debug_backtrace() function in PHP. It's amazing what some good PHP knowledge will do for ya.

And here's the rest of what I've gotten worked out for debugging techniques:

There's also Trace module

mlncn's picture

Trace. (Could use more documentation...)

... but we're looking for more, more, more on this subject!

benjamin, agaric

Firefox Developer Toolbar and Firebug

wolfderby's picture

Although I'm pretty new to web development myself, these tools have proven useful to me:

Firebug finds errors on the page and lets you know which line the occur, as well as lets your experiment with tweaking code by clicking edit (although it doesn't save your changes) There's also some pretty sweet highlighting that goes on as you "mouse over" the code.

Firefox firebug
https://addons.mozilla.org/en-US/firefox/addon/1843

The firefox developer toolbar is also worth checking out.

Firefox Developer Toolbar
https://addons.mozilla.org/en-US/firefox/addon/60