函数调用位置 [英] Function invocation location

查看:102
本文介绍了函数调用位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能从

函数中找出调用该特定函数调用

的文件和行号,请记住,该函数可能会从许多不同的文件中调用
。我想我正在寻找

类似于__FILE__和__LINE__符号,但在函数调用堆栈中有一个

升级。

I was wondering if it would be possible to find out, from within a
function, the file and line number where that particular function call
was invoked, bearing in mind that the function can potentially be
invoked from many different files. I guess that what I am looking for
is something similar to the __FILE__ and __LINE__ symbols, but one
level up in the function call stack.

推荐答案

1.*****@gmail.com 写道:
我想知道是否有可能从
函数中找出该特定函数调用的文件和行号
调用,请记住,可以从许多不同的文件中调用该函数。我想我正在寻找的东西类似于__FILE__和__LINE__符号,但在函数调用堆栈中有一个级别。
I was wondering if it would be possible to find out, from within a
function, the file and line number where that particular function call
was invoked, bearing in mind that the function can potentially be
invoked from many different files. I guess that what I am looking for
is something similar to the __FILE__ and __LINE__ symbols, but one
level up in the function call stack.




不,没有好的便携方式。


您可能会做一些事情,包括将额外的参数传递给你的函数
,但是它不会很漂亮。


源级调试器应该能够以交互方式显示这些信息




你想要完成什么?


-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。



No, there''s no good portable way to do that.

You could probably do something involving passing extra arguments to
your functions, but it wouldn''t be pretty.

A source level debugger should be able to show this information
interactively.

What are you trying to accomplish?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


我使用宏来执行它


#include< stdio.h>


#define perform_action(a)_perform_action((a),__ FILE __,__ LINE__)

void _perform_action(int actCd,const char * file,int lineno);

void _perform_action(int actCd,const char * file,int lineno){

printf(" called perform_action from%s:%d \ n",file,lineno) );

}

int main(无效){

perform_action(4);

返回0;

}

I use macros to do it

#include <stdio.h>

#define perform_action(a) _perform_action((a),__FILE__,__LINE__)
void _perform_action(int actCd, const char * file, int lineno);
void _perform_action(int actCd, const char * file, int lineno) {
printf("Called perform_action from %s:%d\n", file, lineno);
}
int main(void) {
perform_action(4);
return 0;
}


Keith Thompson写道:
Keith Thompson wrote:
1. ***** @ gmail.com 写道:
我想知道是否有可能从
函数,调用特定函数调用的文件和行号,记住该函数可能会被许多不同的函数调用。 LES。我想我正在寻找的东西类似于__FILE__和__LINE__符号,但是在函数调用堆栈中有一个升级。
I was wondering if it would be possible to find out, from within a
function, the file and line number where that particular function call
was invoked, bearing in mind that the function can potentially be
invoked from many different files. I guess that what I am looking for
is something similar to the __FILE__ and __LINE__ symbols, but one
level up in the function call stack.



不,没有好的便携方法可以做到这一点。

你可能会做一些事情,包括将额外的参数传递给你的功能,但它不会很漂亮。

源级调试器应该能够以交互方式显示这些信息。

你想要完成什么?



No, there''s no good portable way to do that.

You could probably do something involving passing extra arguments to
your functions, but it wouldn''t be pretty.

A source level debugger should be able to show this information
interactively.

What are you trying to accomplish?




几乎我所说的:找出谁在调用某个

函数,以及在什么时候。我正在使用一个嵌入式环境,并且一个

源代码级别的调试器确实会干扰事情,所以我想要的东西不会再出现了。我能想到的唯一方法是通过

表示上面的信息,并且放置得很好的printf(其输出

进入控制台可通过串口)。



Pretty much what I said: To find out who is invoking a certain
function, and at what point. I am using an embedded environment, and a
source level debugger does disturb things so that what I am trying to
see is not there anymore. The only way I could think of to do it is by
means of the info above, and well-placed printf (the output of which
goes to a console accessible through a serial port).


这篇关于函数调用位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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