473,787 Members | 2,931 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to detect the entry point of a function?

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
8 1919
> 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
On 12 Jun 2006 20:12:31 -0700, "Johnny" <jo*******@hotm ail.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_en try_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_en try_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.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jun 13 '06 #3

Jack Klein wrote:
On 12 Jun 2006 20:12:31 -0700, "Johnny" <jo*******@hotm ail.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_en try_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_en try_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.l earn.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_en try_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
> 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_en try_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_en try_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

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

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_en try_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_en try_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

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
"Johnny" <jo*******@hotm ail.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_en try_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_Keit h) 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4304
by: aneesh | last post by:
Hi all, I would like to know whether we can specify another function instead of main as entry point. Thanks Aneesh
6
4554
by: Einar ?rn | last post by:
Hi all, is there a good way to detect recursive C code in large systems? A method or a free tool? Best regards, E
1
5401
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved completely/succsessfully on the client's computer before updating some metadata on the server (file downloaded date for instance) However, All examples i have tried, and all examples I have found that other people says works - doesn't work for me :-(
2
6825
by: bboule | last post by:
Hi I have developped a dll that I want to use in another program ! here is my code : using System; using System.Collections.Generic; using System.Text; namespace NameSpace
8
376
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I detect Opera/Netscape/IE? ----------------------------------------------------------------------- The « navigator » object contains strings which specify the browser and version; however, this is in general not very genuine. Mozilla (and therefore Netscape 6+) allows this to be freely set, and Opera and IE allow it to be modified. There are...
10
4176
by: Lung.S.wu | last post by:
Hi all, It is a history question. Recently, I read the book "C A reference manual, third edition". In this book, it list all C language keyword, and one is "entry". I know it is omitted from ANSCI C, but I hope I can find any data about it. Doea any one know how to use it, before?
3
5651
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I am a developer from C++ COM to C# COM. I feel confused about the entry point function for a C# COM object. In C++, we always initialize object through GetClassObject or DLLGetClassObject, but it seems C# does not need these functions? Here is a sample from MSDN.
14
6905
lotus18
by: lotus18 | last post by:
Hello all I have these records on my Day Table for my complete database table please click here 1. M 2. T 3. W 4. TH 5. F 6. S
0
9655
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.