நிரல் அலசிஆராய்தல் – art of debugging

Debugging – அதாவது கணினியில் பிழைகளை கண்டு திருத்தம் செய்வது எப்படி ? பைத்தான் மொழியில் இது சற்று சகஜமானது : முழு விவரம் இங்கு.

What is Debugging ?

Computer programs don’t always work like how we want them to. So at times we need to stop the program in the middle of execution and inspect them. By doing that – looking at the variables, functions, statements/source code in the debugger – we can understand the problem better than before and by stepping through the source code we can understand the source of the error to arrive at a solution.

This may sound somewhat complex, but in practice its quite repetitive and you will get the hang of it. Its the equivalent of a software detective work, and it is surprisingly fun, and you keep getting better at it with more practice.

How to Debug Python Code ?

To debug python we use the python module ‘pdb‘ [read documents இங்கு]; pdb is named evocatively like the more famous, powerful gdb – GNU source debugger. The simple usage is to call your program throwing the error from the command line as follows,

$ python -m pdb myscript.py

Once you see the (Pdb) prompt you can do the following:

  1. Setup a breakpoint at a particular function, class or module
  2. Resume the program running and
  3. Wait for the program to enter the breakpoint code or hit an exception
  4. At this time Pdb will enter the breakpoint and give you options to inspect variable, function, the call stack, and step up or down the frames
  5. For exceptions caught by gdb, we can go through the same scope variables and source-stepping inspections only via the post-mortem execution

Finally, you can figure out the cause of the problem and fix it!

Bon Voyage. You are starting on a powerful journey to write cool software and fix buggy ones!

Goodluck, and Godspeed.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.