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.
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.
- edit and fix
- examine
- assign
- set follow_fork_mode and set follow_fork_inherit commands
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.
Comments