Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How to detect the entry point of a function?

Reply
Thread Tools

How to detect the entry point of a function?

 
 
Johnny
Guest
Posts: n/a
 
      06-13-2006
Hi,
Is there a way to detect the entry point of all the functions in a
project? If so, can I make a function that will be called at the every
entry point? Thanks for your consideration.

Regards,
Johnny

 
Reply With Quote
 
 
 
 
Gordon Burditt
Guest
Posts: n/a
 
      06-13-2006
> Is there a way to detect the entry point of all the functions in a
>project?


Not portably, unless you're willing to construct a list of all
the functions from the source code.

>If so, can I make a function that will be called at the every
>entry point? Thanks for your consideration.


What is "the every entry point"? Some compilers have a profiling
setup, which might be what you are looking for.

Gordon L. Burditt
 
Reply With Quote
 
 
 
 
Jack Klein
Guest
Posts: n/a
 
      06-13-2006
On 12 Jun 2006 20:12:31 -0700, "Johnny" <(E-Mail Removed)> wrote
in comp.lang.c:

> Hi,
> Is there a way to detect the entry point of all the functions in a
> project? If so, can I make a function that will be called at the every
> entry point? Thanks for your consideration.
>
> Regards,
> Johnny


C has no concept of "entry point". All that you can do it call
another function as the first executable statement of the function(s)
that you want to do this.

Unless you are using a compiler in C99 conforming mode, this must be
after the definitions of any objects defined in the function's top
level block scope. Depending on what auto objects you define, and how
you initialize them, the compiler might generate executable code
before the first executable statement that you write.

Example:

int function(int x, int y)
{
int z = x + y;
call_special_entry_function();
if (z == x * y)
{
/* ... */
}
return z;
}

This useless example shows that the compiler will generate code to add
x and y and store the result in z before calling your special
function. One way around this is to put the call at the top of the
function, then move everything else into a nested block:

int function(int x, int y)
{
call_special_entry_function();
{
int z = x + y;
if (z == x * y)
{
/* ... */
}
return z;
}
}

Now your function call will be executed before any initialization code
for locals happens. The compiler might still have lower level
function entry code (generally called prologue) that executes before
anything you can write.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
 
Reply With Quote
 
Johnny
Guest
Posts: n/a
 
      06-13-2006

Jack Klein wrote:
> On 12 Jun 2006 20:12:31 -0700, "Johnny" <(E-Mail Removed)> wrote
> in comp.lang.c:
>
> > Hi,
> > Is there a way to detect the entry point of all the functions in a
> > project? If so, can I make a function that will be called at the every
> > entry point? Thanks for your consideration.
> >
> > Regards,
> > Johnny

>
> C has no concept of "entry point". All that you can do it call
> another function as the first executable statement of the function(s)
> that you want to do this.
>
> Unless you are using a compiler in C99 conforming mode, this must be
> after the definitions of any objects defined in the function's top
> level block scope. Depending on what auto objects you define, and how
> you initialize them, the compiler might generate executable code
> before the first executable statement that you write.
>
> Example:
>
> int function(int x, int y)
> {
> int z = x + y;
> call_special_entry_function();
> if (z == x * y)
> {
> /* ... */
> }
> return z;
> }
>
> This useless example shows that the compiler will generate code to add
> x and y and store the result in z before calling your special
> function. One way around this is to put the call at the top of the
> function, then move everything else into a nested block:
>
> int function(int x, int y)
> {
> call_special_entry_function();
> {
> int z = x + y;
> if (z == x * y)
> {
> /* ... */
> }
> return z;
> }
> }
>
> Now your function call will be executed before any initialization code
> for locals happens. The compiler might still have lower level
> function entry code (generally called prologue) that executes before
> anything you can write.
>
> --
> Jack Klein
> Home: http://JK-Technology.Com
> FAQs for
> comp.lang.c http://c-faq.com/
> comp.lang.c++ http://www.parashift.com/c++-faq-lite/
> alt.comp.lang.learn.c-c++
> http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


Thanks Jack, in fact, that's what i was thinking about. But if there
are millions of functions in a project, adding the calling of
call_special_entry_function() would be a great deal of workload and
also, is very difficult for maintainance. Is there a clean way to do
such kind of things?

 
Reply With Quote
 
octangle
Guest
Posts: n/a
 
      06-13-2006
> Thanks Jack, in fact, that's what i was thinking about. But if there
> are millions of functions in a project, adding the calling of
> call_special_entry_function() would be a great deal of workload and
> also, is very difficult for maintainance. Is there a clean way to do
> such kind of things?


I would be curious to know what the precise purpose of the call to the
special entry function is...

Write a perl (or python) script to insert a
call_special_entry_function() reference into every function in your
project that does not already have such a call ... you could run this
script as a preprocessing step in every build to assure that newly
created functions have the call added.

 
Reply With Quote
 
kleuske@xs4all.nl
Guest
Posts: n/a
 
      06-13-2006

Johnny schreef:

> Hi,
> Is there a way to detect the entry point of all the functions in a
> project? If so, can I make a function that will be called at the every
> entry point? Thanks for your consideration.


This is entirely implementation depended and goes _far_ beyond the
scope of this n.g. You may have a better chance of getting any
practical answers in another group.

<Off Topic>
There is no portable way to do so.

Unportably, there are a number of ways you can do it

1. Inspect symtables produced by your toolchain (best option)
2. Inspect object code for CALL instructions and note adresses
3. Scan for function-prologue code.

</Off Topic>

 
Reply With Quote
 
Johnny
Guest
Posts: n/a
 
      06-15-2006

octangle wrote:
> > Thanks Jack, in fact, that's what i was thinking about. But if there
> > are millions of functions in a project, adding the calling of
> > call_special_entry_function() would be a great deal of workload and
> > also, is very difficult for maintainance. Is there a clean way to do
> > such kind of things?

>
> I would be curious to know what the precise purpose of the call to the
> special entry function is...

I want to add a function to record the entering time of every function
to do some profilings. I don't know how can TrueTime to do so, maybe
also a little bit like this?
>
> Write a perl (or python) script to insert a
> call_special_entry_function() reference into every function in your
> project that does not already have such a call ... you could run this
> script as a preprocessing step in every build to assure that newly
> created functions have the call added.

That's surely better than adding the messes by hand Octangle, but I
still want to know if there is a clean way which doesn't need the help
of the script?

 
Reply With Quote
 
Johnny
Guest
Posts: n/a
 
      06-15-2006

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Johnny schreef:
>
> > Hi,
> > Is there a way to detect the entry point of all the functions in a
> > project? If so, can I make a function that will be called at the every
> > entry point? Thanks for your consideration.

>
> This is entirely implementation depended and goes _far_ beyond the
> scope of this n.g. You may have a better chance of getting any
> practical answers in another group.

If this post bothers you, sorry for that...
>
> <Off Topic>
> There is no portable way to do so.
>
> Unportably, there are a number of ways you can do it
>
> 1. Inspect symtables produced by your toolchain (best option)
> 2. Inspect object code for CALL instructions and note adresses
> 3. Scan for function-prologue code.
>
> </Off Topic>

Thanks for your suggestion, I'll try to find something more about your
suggestions.

Regards,
Johnny

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      06-15-2006
"Johnny" <(E-Mail Removed)> writes:
> octangle wrote:
>> > Thanks Jack, in fact, that's what i was thinking about. But if there
>> > are millions of functions in a project, adding the calling of
>> > call_special_entry_function() would be a great deal of workload and
>> > also, is very difficult for maintainance. Is there a clean way to do
>> > such kind of things?

>>
>> I would be curious to know what the precise purpose of the call to the
>> special entry function is...

> I want to add a function to record the entering time of every function
> to do some profilings. I don't know how can TrueTime to do so, maybe
> also a little bit like this?


Um, have you tried using a profiler?

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Share-Point-2010 ,Share-Point -2010 Training , Share-point-2010Hyderabad , Share-point-2010 Institute Saraswati lakki ASP .Net 0 01-06-2012 06:39 AM
Scenario 5: IS-IS routing on Frame Relay Multi-point and Point-to-Point David Sudjiman Cisco 0 06-08-2006 09:11 AM
Form field entry directs to diff URLs based on entry? AtomicBob HTML 14 05-02-2006 07:07 AM
Clear ATM0.1 point-to-point entry. AM Cisco 2 02-04-2005 10:38 AM



Advertisments