5.4. Working with the Stack

One of the most important tasks during the debugging process is to deal with the stack. The stack provides a lot of information about what happened in the past. You can backtrace to higher levels in the stack using gdb. Using the backtrace feature, you can move step-by-step backward to find out how you reached the current position. To demonstrate some of the commands used with stack, let us take the example of sumf.c program that you used in the last section. The program takes two numbers as input and then calls a function to sum() to add these two numbers. The function returns the result back to the main function.

When you start debugging this program, first you set up a break point right at the beginning of the main ...

Get Linux Development Platform: Configuring, Using, and Maintaining a Complete Programming Environment, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.