开发者

Complete state of a process

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 sav开发者_如何学Goe-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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜