Science Fair Projects Ideas - Stack trace

All Science Fair Projects

      

Science Fair Project Encyclopedia for Schools!

  Search    Browse    Forum  Coach    Links    Editor    Help    Tell-a-Friend    Encyclopedia    Dictionary     

Science Fair Project Encyclopedia

For information on any area of science that interests you,
enter a keyword (eg. scientific method, molecule, cloud, carbohydrate etc.).
Or else, you can start by choosing any of the categories below.

Stack trace

A stack trace (also called backtrace) is a dump of the active stack frames left in memory by the execution of a program.

Stack traces are often generated when a program aborts abnormally. The last or penultimate stack frames often indicate where the bug that generated the abnormal abort occurs.

All debuggers can produce stack traces. gdb prints a stack trace with the bt (or where) command.

Example

This intentionally ill-written C program will segfault (ie., crash) in the function function_2:

int
main(void)
{
   int x;
   printf("This program will demonstrate gdb\n");
   x=function_1();
   printf("%d", x); 
   return 0;
}

int
function_1(void)
{
   int x = function_2(24);
   return x;
}

int
function_2(int x)
{
   int *y = (int *)x;
   return *y;
}

To get an informative stack trace from a debugger, one has to compile the program with debugging information. With gcc, that is done by compiling the program with the -g option. If one then attempts to run the program in gdb, and obtain a backtrace, one would get

#0  0x080483cb in function_2 ()
#1  0x080483b4 in function_1 ()
#2  0x08048385 in main ()
#3  0x4003ddc6 in __libc_start_main () from /lib/libc.so.6

This shows that the function __libc_start_main called main, which in turn called function_1 and then function_2, whose stack frame is at the top of the stack, and it is indeed this function which is in error, the statement:

   int *y = (int *)x;

attempts to create a pointer pointing to a nonsensical memory location at the decimal address 24, which is normally inaccessible by programs running normally.

10-26-2009 08:16:03
The contents of this article is licensed from www.wikipedia.org under the GNU Free Documentation License. Click here to see the transparent copy and copyright details
Science kits, science lessons, science toys, maths toys, hobby kits, science games and books - these are some of many products that can help give your kid an edge in their science fair projects, and develop a tremendous interest in the study of science. When shopping for a science kit or other supplies, make sure that you carefully review the features and quality of the products. Compare prices by going to several online stores. Read product reviews online or refer to magazines.

Start by looking for your science kit review or science toy review. Compare prices but remember, Price $ is not everything. Quality does matter.
Science Fair Coach
What do science fair judges look out for?
ScienceHound
Science Fair Projects for students of all ages
All Science Fair Projects.com Site
All Science Fair Projects Homepage
Search | Browse | Links | From-our-Editor | Books | Help | Contact | Privacy | Disclaimer | Copyright Notice