Of course, you??™ll need a program on which to try out GDB debugging, so Listing 29-5
provides one: debugme.c.
LISTING 29-5
A Buggy Program
/*
* debugme.c - poorly written program to debug
*/
#include
#define BIGNUM 5000
#define SZ 100
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;
}
801
Programming Tools and Utilities 29
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.
A core dump refers to an application failing and copying all data stored in memory for
the application into a file named core in the current directory. That file can be used to
help debug a problem with the application. The file output may be called core, or have a numeric
extension, such as core.12345 (usually the process ID of the program that died).
Pages:
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448