[英]How do I find out the allocated memory (both the address and its size) for a given C function and the variables declared inside it?
If I have simple C program with just one main function. 如果我只有一个主要功能的简单C程序。
If these constructs are maintained by the operating system ? 这些构造是否由操作系统维护? Which ones are accessible and why ?
哪些可以访问?为什么?
Are there any tool available for visualizing such a program state when the program is executing ? 在执行程序时,是否有任何工具可用于可视化此类程序状态?
Thanks, de costo. 谢谢,德科斯托。
A debugger (such as gdb) can show you all of this information. 调试器(例如gdb)可以向您显示所有这些信息。
There's no simple way to find this information from within the program itself AFAIK. 在程序本身的AFAIK中找不到简单的方法。
To find the location of the code section, you can take an address of the main() function (simply take the function pointer and see where it points). 要查找代码部分的位置,可以获取main()函数的地址(只需获取函数指针并查看其指向的位置)。 Alternatively, look at the instruction pointer within inline assembly.
或者,查看内联汇编中的指令指针。
To find the location of the stack roughly, take an address of a local variable, or the stack pointer from within inline assembly. 若要粗略地查找堆栈的位置,请从内联汇编中获取局部变量的地址或堆栈指针。
Under linux, each process has a directory under /proc folder, where you can read out all sorts of information about the process. 在linux下,每个进程在/ proc文件夹下都有一个目录,您可以在其中读取有关该进程的各种信息。 (I think some of that stuff is being moved to /sys)
(我认为其中一些内容已移至/ sys)
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.