views:

62

answers:

1

Hi,

I was wondering what strategies you guys are using to fix runtime errors? Really appreciate if you could share some tips!

Here is some of my thought (possibly with the help of gdb):

when runtime error happens because some memory is wrongly accessed, is the address stored in the dumped core showing where the memory is?

If I can find the address/memory whose being accessed causes the runtime error, is it possible to find out which variable is using that address (which may be at the begining or middle of the memory of the variable)? And find out the nearby variables that takes the memory down below and right above that memory block?

If all these are possible, will it help to fix the bugs?

Thanks and regards!

A: 

I use gdb's --args option to start my programs from the command-line.

Example:

gdb --args foocode --with-super-awesome-option
run

This will load the program foocode and pass the --with-super-awesome-option parameter to it. When the program fails, you'll have a ready-to-use gdb session to work within.

From there you can use the backtrace command:

bt

This will show you the chain of events (function calls) that lead to your crash.

Will Bickford