如何读取运行进程的堆栈帧?

编程入门 行业动态 更新时间:2024-10-28 04:29:59
本文介绍了如何读取运行进程的堆栈帧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我们可以读取当前进程的堆栈帧吗。 因为我们知道无论何时进行函数调用在c新函数中 堆栈框架创建并将其推送到堆栈。当函数返回 时,它会从堆栈中弹出。我想知道来电者的功能 名字。 i意味着我想要这样的东西 int a( ) { printf(" File =%s \ n",__ FILE__); / *我想打印来电者在这里命名。像这样的东西 printf(" Caller function =%s \ n",__ CALLER_FUN__);它应该打印 b * / 返回0; } int b() { a(); 返回0; } int main() { b(); } 如果有的话请告诉我。 谢谢和问候 Harshal Shete

解决方案

10月17日下午3:56,harshal< harshalsh ... @ gmailwrote:

大家好, 我们可以读取当前进程的堆栈帧吗。 因为我们知道无论何时在c函数中进行函数调用 堆栈框架创建并将其推送到堆栈。当函数返回 时,它会从堆栈中弹出。我想知道来电者的功能 名字。 i意味着我想要这样的东西 int a( ) { printf(" File =%s \ n",__ FILE__); / *我想打印来电者在这里命名。像这样的东西 printf(" Caller function =%s \ n",__ CALLER_FUN__);它应该打印 b * / 返回0; } int b() { a(); 返回0; } int main() { b(); } 如果有任何方法请告诉我。

你需要了解你的系统架构,装配, 编译器非常好。 以这样一种方式写一个逻辑,你可以尝试解析生成的汇编文件并了解 $调用它的b $ b函数。 在M68K的情况下,在''b''函数中会有类似 JSR _a的内容。 Karthik Balaguru

10月17日下午3:56,harshal< harshalsh ... @ gmailwrote:

大家好, 我们可以读取当前进程的堆栈帧吗。 as我们知道每当在c函数中进行函数调用时 堆栈框架 被创建并推送到堆栈。当函数返回 时,它会从堆栈中弹出。我想知道来电者的功能 名字。 i意味着我想要这样的东西 int a( ) { printf(" File =%s \ n",__ FILE__); / *我想打印来电者在这里命名。像这样的东西 printf(" Caller function =%s \ n",__ CALLER_FUN__);它应该打印 b * / 返回0; } int b() { a(); 返回0; } int main() { b(); } 如果有任何方法请告诉我。

您可以根据Linker创建的MAP文件编写一些方法,并且 也使用汇编列表。 Karthik Balaguru

karthikbalaguru写道:

10月17日下午3:56,harshal< harshalsh ... @ gmailwrote:

>大家好, 我们可以读取当前进程的堆栈帧吗?

....

您可以根据MAP文件编写一些方法由Linker创建, 也使用汇编列表。

我认为任何有能力这样做的人都不太可能需要 发布问题......

Hi all, Can we read the stack frame''s of the current process. as we know that whenever a function call is made in c new functions stack frame is created and pushed on to the stack. and when the function returns it is popped out from the stack. i want to know the caller functions name. i mean i want something like this int a() { printf("File = %s\n",__FILE__); /* i want to print the callers name over here. something like this printf("Caller function = %s\n",__CALLER_FUN__); it should print b*/ return 0; } int b() { a(); return 0; } int main() { b(); } if there is any way please tell me. Thanks and Regards Harshal Shete

解决方案

On Oct 17, 3:56 pm, harshal <harshalsh...@gmailwrote:

Hi all, Can we read the stack frame''s of the current process. as we know that whenever a function call is made in c new functions stack frame is created and pushed on to the stack. and when the function returns it is popped out from the stack. i want to know the caller functions name. i mean i want something like this int a() { printf("File = %s\n",__FILE__); /* i want to print the callers name over here. something like this printf("Caller function = %s\n",__CALLER_FUN__); it should print b*/ return 0; } int b() { a(); return 0; } int main() { b(); } if there is any way please tell me.

You need to understand the architecture of your system, assembly, compiler very well. Write a logic in such a way that, you try parsing throught the generated assembly file and get to know the function that is calling it. In the case of M68K there will be something like JSR _a inside ''b'' function. Karthik Balaguru

On Oct 17, 3:56 pm, harshal <harshalsh...@gmailwrote:

Hi all, Can we read the stack frame''s of the current process. as we know that whenever a function call is made in c new functions stack frame is created and pushed on to the stack. and when the function returns it is popped out from the stack. i want to know the caller functions name. i mean i want something like this int a() { printf("File = %s\n",__FILE__); /* i want to print the callers name over here. something like this printf("Caller function = %s\n",__CALLER_FUN__); it should print b*/ return 0; } int b() { a(); return 0; } int main() { b(); } if there is any way please tell me.

You can write some methods based on the MAP file created by Linker and also using the assembly listing. Karthik Balaguru

karthikbalaguru wrote:

On Oct 17, 3:56 pm, harshal <harshalsh...@gmailwrote:

>Hi all,Can we read the stack frame''s of the current process.

....

You can write some methods based on the MAP file created by Linker and also using the assembly listing.

I think it''s unlikely that anyone capable of doing this would need to post the question...

更多推荐

如何读取运行进程的堆栈帧?

本文发布于:2023-11-16 02:13:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1600076.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:堆栈   进程

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!