Tackling Segmentation errors using DDD

Self organized List is an assignment topic for me and while coding, I was stuck with segmentation faults at many points. I lost a lot of time in figuring out how to solve this issue as the compiler doesn’t say at which point is the error occurring.

Self organised list is something very similar to the ‘Recently called numbers’ that you see in your cellphone or the history of your browser. The most recently accessed link will be at the top. Also if a link is accessed more number of times, they also come to front . A self organized list does the same. When you insert a number into the list, a counter in the node gets incremented and if the number is coming repeatedly, it will be picked from the previous position and inserted at the front without making any changes to the rest of the node.

Self organized List is an assignment topic for me and while coding, I was stuck with segmentation faults at many points. I lost a lot of time in figuring out how to solve this issue as the compiler doesn’t say at which point is the error occurring.

It was then I started using DDD(Data Display Debugger). It made my job really easy. You don’t have to worry at all if you see a segmentation fault when you start using DDD. Things become very easy.

Compile the program as below

$gcc -g filename.c

You load the program into you DDD. You can open the DDD window by typing ddd in the terminal. Open the a.out file in ddd. Now keep a break point at a point where you call a function or somewhere where you feel there can be an error. You can click on the line where you want to break and click on the break button at the top. Run the program by giving the run command. Now if you press ‘s’ it goes to the next step. You can traverse the whole program step by step in the way the compiler goes and at the point where the error occurs, the DDD stops. And shows an error message.  You can then easily figure out what the mistake must be when you get the line number. DDD made my coding experience better.

Advertisements

One thought on “Tackling Segmentation errors using DDD

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 )

w

Connecting to %s