Go Back   Velocity Reviews > Newsgroups > C Programming
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

C Programming - How get list of functions in current C program

 
Thread Tools Search this Thread
Old 11-17-2008, 07:05 PM   #1
Default How get list of functions in current C program


Hi all,
I want to get list of all functions that are defined in the current C
code, for example if I have the code below:

int f(int c, int d){
int a = 10;
int b = 12;
return c+a;
}

int g(void){
...
...
}

int main(){
}


I need a function that give me *f* and *g*.

thanks,
--
Shirvani Ali


Ali Shirvani
  Reply With Quote
Old 11-17-2008, 07:13 PM   #2
s0suk3@gmail.com
 
Posts: n/a
Default Re: How get list of functions in current C program
On Nov 17, 2:05*pm, Ali Shirvani <> wrote:
> Hi all,
> I want to get list of all functions that are defined in the current C
> code, for example if I have the code below:
>
> int f(int c, int d){
> * *int a = 10;
> * *int b = 12;
> * *return c+a;
>
> }
>
> int g(void){
> * *...
> * *...
>
> }
>
> int main(){
>
> }
>
> I need a function that give me *f* and *g*.
>
> thanks,


void get_f_and_g(int (**f_result)(int c, int d),
int (**g_result)(void))
{
*f_result = f; // f and g need to be in scope, of course
*g_result = g;
}

Sebastian



s0suk3@gmail.com
  Reply With Quote
Old 11-17-2008, 08:14 PM   #3
Ali Shirvani
 
Posts: n/a
Default Re: How get list of functions in current C program
On Nov 17, 10:30*pm, gordonb.pq...@burditt.org (Gordon Burditt) wrote:
> >I want to get list of all functions that are defined in the current C
> >code, for example if I have the code below:

>
> There are a number of tools that operate on source code and will
> give you information like this. *"cproto", for example, will give
> you a list of prototypes for the external functions. *(and, of
> course, those include the function names). *These depend on being
> able to read C source code as a text file, and are fairly portable.
> Some of them invoke the C preprocessor, which isn't portable. *Some
> of those that don't invoke the C preprocessor can get confused by
> macros used in defining functions.
>
> An executable or object file may also contain the function names
> (if not stripped) mangled appropriately (some implementations add
> a leading underscore or make other changes to the name to avoid
> assembler keywords. *In C++ the function name may be horribly mangled
> to indicate argument and return types.). *Tools such as "nm" or
> "objdump" may be available. *It is common that there is a symbol
> "type" that allows you to distinguish between functions and variables,
> and to identify static vs. non-static names. *This is all very
> system-dependent.
>
> There is no guarantee that a running executable can find its own
> name accurately, and if it does, that it can open up the executable
> to look at the symbols. *And, of course, looking at the symbols is
> very system-dependent.
>
>
>
> >int f(int c, int d){
> > * int a = 10;
> > * int b = 12;
> > * return c+a;
> >}

>
> >int g(void){
> > * ...
> > * ...
> >}

>
> >int main(){
> >}

>
> >I need a function that give me *f* and *g*.

>
> Is there any particular reason why this function should *NOT* also
> give you "main", "printf", "exit", "getchar", etc. ?


Thanks for your reply.
I'm on Linux, and I want to get only the functions that I wrote them,
there is no problem, if any thing give me list of all function, I can
ignore some of them. Is there any library that work like *nm*?

Thanks


Ali Shirvani
  Reply With Quote
Old 11-17-2008, 10:11 PM   #4
CBFalconer
 
Posts: n/a
Default Re: How get list of functions in current C program
Ali Shirvani wrote:
>
> I want to get list of all functions that are defined in the
> current C code, for example if I have the code below:
>
> int f(int c, int d){
> int a = 10;
> int b = 12;
> return c+a;
> }
>
> int g(void){
> ...
> }
>
> int main(){
> }
>
> I need a function that give me *f* and *g*.


Simple. You parse the source code, and whenever you find a
definition for a function you extract and spit out that function
name. You might find it simpler to just read the source.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.


CBFalconer
  Reply With Quote
Old 11-18-2008, 05:12 AM   #5
Ali Shirvani
 
Posts: n/a
Default Re: How get list of functions in current C program
On Nov 18, 3:58*am, gor...@hammy.burditt.org (Gordon Burditt) wrote:
> >> >I need a function that give me *f* and *g*.

>
> >> Is there any particular reason why this function should *NOT* also
> >> give you "main", "printf", "exit", "getchar", etc. ?

>
> >Thanks for your reply.
> >I'm on Linux, and I want to get only the functions that I wrote them,

>
> So you didn't write main()?
>
> >there is no problem, if any thing give me list of all function, I can
> >ignore some of them. Is there any library that work like *nm*?

>
> You have the source code to nm, so go ahead and modify a copy of
> it so instead of outputting a list of symbols, it selects appropriate
> ones and returns a list of them to the caller.


I want do this on process, but nm do this on program, not process!


Ali Shirvani
  Reply With Quote
Old 11-18-2008, 06:11 AM   #6
Nate Eldredge
 
Posts: n/a
Default Re: How get list of functions in current C program
This is more appropriate for comp.unix.programmer; crossposted and
followups to there.

Ali Shirvani <> writes:

> On Nov 18, 3:58*am, gor...@hammy.burditt.org (Gordon Burditt) wrote:
>> >> >I need a function that give me *f* and *g*.

>>
>> >> Is there any particular reason why this function should *NOT* also
>> >> give you "main", "printf", "exit", "getchar", etc. ?

>>
>> >Thanks for your reply.
>> >I'm on Linux, and I want to get only the functions that I wrote them,

>>
>> So you didn't write main()?
>>
>> >there is no problem, if any thing give me list of all function, I can
>> >ignore some of them. Is there any library that work like *nm*?

>>
>> You have the source code to nm, so go ahead and modify a copy of
>> it so instead of outputting a list of symbols, it selects appropriate
>> ones and returns a list of them to the caller.

>
> I want do this on process, but nm do this on program, not process!


As far as I know, this is impossible. The names of your functions might
be stored in your program's binary, if it hasn't been stripped; but they
are certainly not loaded into your process's memory. By that time,
everything's been converted to raw addresses and the names are no longer
needed. So there is no way to get to them at runtime short of reading
the binary (which you could do with nm) or some other file where they
might be stored.

Why do you want to do this, anyway? Maybe there is a better way to
solve your underlying problem.


Nate Eldredge
  Reply With Quote
Old 11-18-2008, 11:22 AM   #7
James Harris
 
Posts: n/a
Default Re: How get list of functions in current C program
On 18 Nov, 05:12, Ali Shirvani <aj.shirv...@gmail.com> wrote:
> On Nov 18, 3:58 am, gor...@hammy.burditt.org (Gordon Burditt) wrote:
>
>
>
> > >> >I need a function that give me *f* and *g*.

>
> > >> Is there any particular reason why this function should *NOT* also
> > >> give you "main", "printf", "exit", "getchar", etc. ?

>
> > >Thanks for your reply.
> > >I'm on Linux, and I want to get only the functions that I wrote them,

>
> > So you didn't write main()?

>
> > >there is no problem, if any thing give me list of all function, I can
> > >ignore some of them. Is there any library that work like *nm*?

>
> > You have the source code to nm, so go ahead and modify a copy of
> > it so instead of outputting a list of symbols, it selects appropriate
> > ones and returns a list of them to the caller.

>
> I want do this on process, but nm do this on program, not process!


I've looked at your three messages and am not clear: Do you want to
get these names from the source code - i.e. by scanning the C source -
or from the running process - i.e. to find out while executing what
functions are present?

--
James


James Harris
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Give you enough string functions in Java web reporting tool freezea Software 0 10-08-2009 09:03 AM
This is incredible! jc_ice DVD Video 1 08-13-2006 10:47 AM
As growth slows, Hollywood faces a DVD standoff. Allan DVD Video 0 07-11-2005 02:10 PM
Been around for a while but very effective Paul A+ Certification 0 02-29-2004 12:14 PM
Re: free email addresses finding program (files included) Leonardo A+ Certification 1 12-05-2003 03:51 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46