grimsniffer: (Default)
grimsniffer ([personal profile] grimsniffer) wrote in [site community profile] dw_dev_training2009-12-21 09:19 am

Debugging methods

So - I thought it might be useful to start a discussion about this, so here goes:

What are some of the debugging methods you use? I'm not talking modus operendi or bug walk-throughs. I'm speaking of the things you do when your code's not working and you need to see with your eyes what's going on.
Here are some of the ones I use, I'd love it if people can pitch in and add their own:

Javascript:
* alert()s. I add them in strategic points in my code to see what the values of certain variables are (I find this more convenient than Firebug, especially in situations where variables change their values in fractions of seconds).
* Firebug. I think there's probably been a few posts or wiki pages about it, so I won't say much more - but it's hellishly useful.

MySQL:
* querry.log. It's not enabled by default, but you can very easily enable it like shown here: http://dev.mysql.com/doc/refman/5.1/en/query-log.html. It slows down performance somewhat, but if you're not working on a live server it shouldn't be a problem.
* Connecting to the database and looking at values in tables. This is as simple as: 'mysql -uroot -p' and then entering your password. If you see what tables you're writing to, what columns you're reading from and so know what values you're supposed to get - life becomes easier. :)

Apache:
* All of apache's logs are in /var/log/apache - at least on my setup you need to be root to read them. 'tail -f logname.log' lets you see them as they're updated dynamically. You get everything from server specific information "service is up, service is down" etc. to function calls that have gone awry in the perl code (though I wouldn't count on this 100% obviously).

Perl:
* Using system() to print the values of certain variables into files and then 'tail -f'ing the files live.
* Printing variables, messages, etc. into HTML tags where applicable (messy, but sometimes necessary).
* Some other things that don't come to mind at the moment, but I'll edit in as I remember. :)

So - what are some of the methods you use that I haven't mentioned here? I think it might be a good idea to organize these and make a small wiki page out of them for reference.

yvi: Kaylee half-smiling, looking very pretty (Default)

[personal profile] yvi 2009-12-21 07:39 am (UTC)(link)
I do 'warn $variable' and such in Perl and then read the Apache log. Also, I look at the mySQL tables.
exor674: Computer Science is my girlfriend (Default)

[personal profile] exor674 2009-12-21 07:41 am (UTC)(link)
* Connecting to the database and looking at values in tables. This is as simple as: 'mysql -uroot -p' and then entering your password. If you see what tables you're writing to, what columns you're reading from and so know what values you're supposed to get - life becomes easier. :)

Or you could use the ljdb tool.
foxfirefey: A fox colored like flame over an ornately framed globe (Default)

[personal profile] foxfirefey 2009-12-21 08:00 am (UTC)(link)
I know I used the ljconsole once--it made it easier to walk through and see what certain function calls were doing.
exor674: Computer Science is my girlfriend (Default)

[personal profile] exor674 2009-12-21 08:02 am (UTC)(link)
Well ljconsole is an unofficial tool, ljdb is in dw-free and everything
foxfirefey: Fox stealing an egg. (mischief)

[personal profile] foxfirefey 2009-12-21 08:04 am (UTC)(link)
It's still a tool for debugging! After all, Firebug isn't an official tool either, hehe.
pauamma: Cartooney crab wearing hot pink and acid green facemask holding drink with straw (Default)

[personal profile] pauamma 2009-12-21 03:17 pm (UTC)(link)
Most of my coding ATM is backendish or Schwartzish (I'm working on stats), so:

- Using the verbose option for Schwartz workers (running them by hand from a shell prompt) and watching the log on stdout or stderr

- perl -mFoo::Bar -e 'Foo::Bar->Baz($quux)' # or other appropriate test oneliner