By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,234 Members | 1,889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,234 IT Pros & Developers. It's quick & easy.

How to detect the entry point of a function?

P: n/a
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

Jun 13 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
> 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
Jun 13 '06 #2

P: n/a
On 12 Jun 2006 20:12:31 -0700, "Johnny" <jo*******@hotmail.com> 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
Jun 13 '06 #3

P: n/a

Jack Klein wrote:
On 12 Jun 2006 20:12:31 -0700, "Johnny" <jo*******@hotmail.com> 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?

Jun 13 '06 #4

P: n/a
> 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.

Jun 13 '06 #5

P: n/a

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>

Jun 13 '06 #6

P: n/a

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?

Jun 15 '06 #7

P: n/a

kl*****@xs4all.nl 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

Jun 15 '06 #8

P: n/a
"Johnny" <jo*******@hotmail.com> 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) ks***@mib.org <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.
Jun 15 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.