Macro to get function name and parameter values ​​from inside function

I am working on a debugging / registration program and am wondering if it is possible to create a macro that can be inserted inside each function and it will print the function name and parameter values ​​every time the called function. The function name can be canceled at compile time, the problem is how to print the parameter values?

UPDATE: I remember reading an article to get parameters, but this assembled code and working manipulation of stack pointers that are not cross-platform compatible are what I need.

+5
source share
6 answers

__FUNCTION__ __func__ . , .

__LINE__ __FILE__.

EDIT:

__FUNCTION__ __func__ , .

16.8 :

__cplusplus
__DATE__
__FILE__
__LINE__
__STDC_HOSTED__
__TIME__

, :

__STDC__
__STDC_VERSION__
__STDC_ISO_10646__
+2

( C99) __func__.

++ GNU __PRETTY_FUNCTION__ .

+1

- , , . , .

0
0

, . ( ), , .

:

void func(char *param1, int param2);

:

PROFILE_FUNC(__FILE__, __LINE__, "param1 = %s, param2 = %d", param1, param2);

PROFILE_FUNC (__ FILE__, __LINE __,... . , .

- , . , __PRETTY_FUNCTION__ , , .

EDIT

. :

  1. gcc __builtin_return_address
  2. glibc backtrace backtrace_symbols
  3. libunwind
0

C . .

, TRACE (foo, bar) TRACE2, TRACE3 .. , TRACE() .

. & lt; & lt; _Generic , .

, , , . : 1/ . , . 2/ C -

. , . . , , , , XML/JSON. , python lua, C . LLVM tablegen.

0

All Articles