Wednesday, April 25, 2007

Absolutely cool dbx commands

Have you ever used dbx to debug a program? Its really cool. I have been using dbx for more than 6 years now. I am hoping that I will write a full fledged tutorial on using dbx (before it is dead and deep buried :-) Here are a few things which I felt absolutely essential to any programmer using dbx.

  1. edit and fix
  2. examine
  3. assign
  4. set follow_fork_mode and set follow_fork_inherit commands
Most of the time I find that people who are new to dbx exiting the dbx session just to make a small fix. Well, you don't really have to exit, recompile and start a new dbx session. You can use a combination of edit and fix commands. If you simply give edit, dbx will open the current file in the editor set by EDITOR environmental variable(vi is default). If you wish to edit a specific file, you can give that file's name as an argument to the edit commend. You don't have to give the full path, as dbx is smart enough to find out the full path of the known files. (Give files command to find out what are all the files that dbx can find out without specifying the full path). So you give edit command, and make all your changes. You save the file and exit. You give the command "fix -a". Boom! All the files that were modified are identified by dbx, and they are recompiled and their respective new object files are loaded. However the changes are temporary and you should build your application when you exit dbx session.

An important thing to remember when you use fix command. If your program is active, and recompiling an object might cause an issue, dbx will warn you so. So you could stop your program by giving "kill" command. Then give a "fix -a" command.

Examine command is used to examine arbitrary memory regions. In case you feel that your application has made an array boundary write, the best way to confirm that is to give the examine command and examine the memory region. For e.g. "examine (void*)&MyStruct /128c" will print 128 bytes as characters, occupied by the variable MyStruct.

Assign command will come in handy when you have to change a variable's value. For e.g. you find that an if block like "if(ShouldProcess) { }" will be executed only when ShouldProcess is set to be non zero and its current value is zero. You can set this variable to be some non zero value using assign and get this block executed. But remember one thing: if you use assign without prudence, the integrity of your program's state might be lost!

The set follow_fork_mode and set follow_fork_inherit commands are very handy when your program performs forks. If follow_fork_mode is not set, then dbx will continue with the parent program, where as your real objective might be to trace the child program. So set it like "set follow_fork_mode ask", and the dbx will prompt you every time it encounters fork. You might have set breakpoints in your parent program. If you don't set follow_fork_inherit to be "on" they will be lost. So you can use a combination of these two.

Above everything else: use the "help" command if you are struck up some where or you want to know what more options you could pass. dbx online help is pretty decent.

Hopefully these commands help you save some time and make your debugging faster.

SublimeText 3/Anaconda error

When I installed Anaconda manually by downloading and untarring the file (as given in the manual installation instructions here ), I got th...