Is it possible to know a function arguments and variables' name types at runtime in C program ? For example, if I have a function:
int abc(int x, float y , somestruct z ){
char a;
int b ;
}
Can I know inside this function abc()
, what are the names of arguments and variables i.e. in this case its x
, y
, z
, a
, b
and they are of type int
, float
, somestruct
, char
, int
.
Say if there is another function:
float some_func(specialstruct my_struct, int index){
}
I should know that arguments name are my_struct
, index
and types are specialstruct
, int
.
I need this info at runtime ?
I have access to base pointer and return address , can I get required info using above pointer.
I was able to extract function name using return address and dladdr()
function.
I see GDB
does this, so it should be possible to extract this info?
There is no kind of reflection or similar things in C. If you want such facility - you should design some utilities, macros for this purpose and use special coding rules to achieve desired effect. But IMO - it won't be a readable and understandable C code.