Finding the function caller in C -


All of them, I am thinking that it is possible to get the name of the program running inside the function?

Here's an example:

I said: . / RunProgram

  main () {A (); } Function A () {// If I can not use the main argc (argv) constant / is it possible to get "runprogram" ?? }     

The compiler is dependent, therefore:

  $ Cc - version i686-apple-darwin10-gcc-4.2.1 (gcc) 4.2.1 (build 5696 of apple Inc.)  

Program

  $ More xc int main (int argc, char * argv []) {printf ("Program:% s \ n", argv [0]); Foo (); } 'Make' in the 'main': xc: 2: warning: The built-in function 'printf' $ ./x The incompatible declaration of the program: ./x  int foo () {} $ make x cc xc -ox xc: 

Get the global name of argc / v vars

  $ nm. / X 0000000100000 fees stub assistants 0000000100001048 D _ Anaksaarjisi 0000000100001050 D _ Anaksaarjivi 0000000100001060 D ___ certificate 0000000100000000 a __mh_execute_header 0000000100001058 D _ Where do you _ Aksu 0000000100000 Abe T _fu 0000000100000eb8 T _man U _printf 0000000100001020 S _ Piwars U dyld_stub_binder 0000000100000e7c T start  

Add the declared global name as an extract, and keep mangling in mind.

  $ more x2.c int main (int argc, char * argv []) {printf ("Program:% s \ n", argv [0]); Foo (); } Int foo () {extern char ** NXArgv; Printf ("in fu:% s \ n", NXArgv [0]); }  

run a horror

  $ make x2 cc x2.c -o x2 x2.c: function 'main': x2.c: 2: warning : Incompatible underlying function 'printf' x2.c function 'foo': x2.c: 9: Warning: Built-in function 'printf' $. Incompatible declaration of / X2 program:. In / x2 foo: ./x2  

Please do not tell my mother.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -