如何读取运行进程的堆栈帧? [英] How can i read the stack frames of running process?

查看:83
本文介绍了如何读取运行进程的堆栈帧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我们可以读取当前进程的堆栈帧吗。

因为我们知道无论何时进行函数调用在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 ... @ gmail.comwrote:


大家好,


我们可以读取当前进程的堆栈帧吗。

因为我们知道无论何时在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 ... @ gmail.comwrote:


大家好,


我们可以读取当前进程的堆栈帧吗。

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 ... @ gmail.comwrote:


>大家好,

我们可以读取当前进程的堆栈帧吗?



....


您可以根据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...@gmail.comwrote:

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...@gmail.comwrote:

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...@gmail.comwrote:

>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...


这篇关于如何读取运行进程的堆栈帧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆