RESEARCHUT
Minds With Innovations

RESEARCHUT - minds with innovations

Search!

Archives

Next Archive Previous Archive

01 Jun - 30 Jun 2005
01 Jul - 31 Jul 2005
01 Aug - 31 Aug 2005
01 Sep - 30 Sep 2005
01 Oct - 31 Oct 2005
01 Dec - 31 Dec 2005
01 Jan - 31 Jan 2006
01 Feb - 28 Feb 2006
01 Mar - 31 Mar 2006
01 Apr - 30 Apr 2006
01 May - 31 May 2006
01 Jun - 30 Jun 2006
01 Jul - 31 Jul 2006
01 Aug - 31 Aug 2006
01 Oct - 31 Oct 2006
01 Nov - 30 Nov 2006
01 Dec - 31 Dec 2006
01 Jan - 31 Jan 2007
01 Mar - 31 Mar 2007
01 Apr - 30 Apr 2007
01 May - 31 May 2007
01 Jul - 31 Jul 2007
01 Aug - 31 Aug 2007
01 Oct - 31 Oct 2007
01 Nov - 30 Nov 2007
01 Jan - 31 Jan 2008
01 Feb - 29 Feb 2008
01 Mar - 31 Mar 2008
01 Apr - 30 Apr 2008
01 May - 31 May 2008
01 Jun - 30 Jun 2008
01 Jul - 31 Jul 2008
01 Aug - 31 Aug 2008

Categories

Fun
KDE
Sex
Rant
News
Debian
Romance
Computer
Software
Philosophy
Technology
Programming

About

A space which could be philosophic, energetic, poetic, technic, mantic, idealistic, frenetic and sarcastic at times,
I guess!


Copyright © Ritesh Raj Sarraf

Unless specifically stated otherwise, the information on this page is available under the terms of the
GNU Free Documentation License.

Calendar

« March 2010
S M T W T F S
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Links

RESEARCHUT
Technical Consultancy
Photo Gallery
About Me

Last Comments

Ashish Shukla (Boston, MA): So, are you also going to …
Ravi (Boston, MA): How did they allow you? BT…
Ritesh (Lambroghini Drink…): Stopped != Quit Blame th…
Ravi (Lambroghini Drink…): Someone said that you stop…
Ritesh Raj Sarraf… (KDE4 with KDE3): Sorry. One more important …

Powered By

Powered by Pivot - 1.40.6: 'Dreadwind'
XML: RSS Feed
XML: Atom Feed
Pivot Blacklist
Powered by Debian

Linkdump

+ 6 - 2 | § Good Morning

Good Morning. Good Food. Good Place.......

Finally, I ended up with a change.

+ 1 - 6 | § Debugging Techniques

Abnormal Program Termination are not something just seen on Microsoft Windows. I hope most users will have seen some kind of program error in GNU/Linux and *BSD platforms also.

Abnormal Program Termination can happen for multiple reasons of which Programming Errors are one of the major reasons. Badly Carelessly written programs often end up having such bugs.

Here's a sample C program which has generic programming errors because of which the compiler doesn't catch it but the program does do unexpected behavior.

#include <stdio.h>
#include <unistd.h>

int divide (int x, int y);

int main(void)
{
    int x, y = 0;

    printf ("Enter divident:\n");
    scanf ("%d", &x);

    printf ("Enter divisor:\n");
    scanf ("%d", &y);

    printf("The result is %d\n", divide(x, y));
    return 0;
}

int divide (int x, int y)
{
    return x / y;
}

The problem with the above mentioned code is that it has no checkings for the integers. This program will give an Arithmetic Division By Zero Error. Upon execution of such programs, most Unixes during termination of the program dump the core.

A core dump is noting but the state of the memory when the abnormal behavior occured. This comes out to be very handly to debug nasty bugs which creep away from the compiler.

Assuming you execute this program and get the core dump, you can easily debug and find the bug with gdb.

rrs@learner:~ $ gdb test coreGNU gdb 6.4-debian
Copyright 2005 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".

Core was generated by `./test'.
Program terminated with signal 8, Arithmetic exception.

warning: Can't read pathname for load map: Input/output error.
Reading symbols from /lib/tls/i686/cmov/libc.so.6...done.
Loaded symbols for /lib/tls/i686/cmov/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
#0 0x08048463 in divide (x=9, y=0) at test.c:22
22 return x / y;
(gdb)

If you look at the output of gdb you can clearly see what kind of error led to the unexpected behavior.

(gdb) bt
#0 0x08048463 in divide (x=9, y=0) at test.c:22
#1 0x08048437 in main () at test.c:16

You can do a backtrace and figure out the complete flow of the program andd see where exactly the error occured.

In this case the bug is in the divide() where y is passed the value 0 which has led to an Arithmetic Exception.

Analyzing core dumps is very helpful and fun while debugging applications. :-)

HTH,

Ritesh Raj Sarraf

Used tags: , ,

Keywords: Debugging,GDB,Core,Dump

- Powered by vIm && Mozilla - Best viewed with your eyes