Chapter 28 . Programming Tools and Utilities 745 Listing 28-5: A Buggy Program /* * debugme.c - poorly written program to debug */ #include #define BIGNUM 5000 void index_to_the_moon(int ary[]); int main(int argc, char *argv[]) { int intary[100]; index_to_the_moon(intary); return 0; } void index_to_the_moon(int ary[]) { int i; for (i = 0; i < BIGNUM; ++i) ary[i] = i; } Compile this program using the command gcc -g debugme.c -o debugme. Then, execute the program using the command ./debugme. $ ./debugme Segmentation fault (core dumped) $ file core core: ELF 32-big LSB core file Intel 80386, version 1 (SYSV ), SVR4-style, SVR4-stylee, from debugme On most systems, when you execute ./debugme, it immediately causes a segmentation fault and dumps core, as shown in the output listing. If you don t see the core dumped message, try executing the shell command ulimit -c unlimited, which allows programs to drop a memory dump in their current working directory. The program has a bug, so you need to debug it. The first step is to start GDB, using the program name, debugme, and the core file, core, as arguments: $ gdb debugme core
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.
This entry was posted
on Wednesday, December 19th, 2007 at 1:20 am and is filed under Linux.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.