Tutorial :Complete state of a process



Question:

I wrote a small program which is as follows:

#include<stdio.h>  int c=0;  int main()  {      int a=10,b=20;      printf("Hello World\n");      c = a+b;      printf("%d\n",c);      return 0;  }  

I can create a.out file using the command gcc -save-temps helloworld.c. The save-temps flag allows us to save the intermediate files, helloworld.i, helloworld.s, helloworld.o

Now i want to know exactly how the stack of this program changes during the execution. Can some one please tell me how to go about it.

My aim of this question is to know exactly what all happens during the execution of any program.


Solution:1

You could simply look at helloworld.s, it will have a listing of the assembly code in the program, from this you can tell exactly what happens to stack and can observe where and when variables are popped off/pushed onto it. If you want to observe the program executing, you could compile the code with the -g flag as well, and then run it through gdb.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »