How to detect the entry point of a function?

Discussion in 'C Programming' started by Johnny, Jun 13, 2006.

  1. Johnny

    Johnny Guest

    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
    Johnny, Jun 13, 2006
    #1
    1. Advertising

  2. > 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
    Gordon Burditt, Jun 13, 2006
    #2
    1. Advertising

  3. Johnny

    Jack Klein Guest

    On 12 Jun 2006 20:12:31 -0700, "Johnny" <> 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/~ajo/docs/FAQ-acllc.html
    Jack Klein, Jun 13, 2006
    #3
  4. Johnny

    Johnny Guest

    Jack Klein wrote:
    > On 12 Jun 2006 20:12:31 -0700, "Johnny" <> 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/~ajo/docs/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?
    Johnny, Jun 13, 2006
    #4
  5. Johnny

    octangle Guest

    > 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.
    octangle, Jun 13, 2006
    #5
  6. Johnny

    Guest

    OT: Re: How to detect the entry point of a function?

    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, 2006
    #6
  7. Johnny

    Johnny Guest

    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?
    Johnny, Jun 15, 2006
    #7
  8. Johnny

    Johnny Guest

    Re: OT: Re: How to detect the entry point of a function?

    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
    Johnny, Jun 15, 2006
    #8
  9. "Johnny" <> 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) <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.
    Keith Thompson, Jun 15, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AtomicBob
    Replies:
    14
    Views:
    857
    Toby Inkster
    May 2, 2006
  2. krishnakant Mane
    Replies:
    3
    Views:
    246
    Joshua J. Kugler
    Jan 20, 2007
  3. Lynn McGuire
    Replies:
    3
    Views:
    814
    Lynn McGuire
    Jan 4, 2007
  4. Premkumar

    Changing entry point function

    Premkumar, Aug 8, 2007, in forum: C++
    Replies:
    5
    Views:
    1,214
    Default User
    Aug 9, 2007
  5. Saraswati lakki
    Replies:
    0
    Views:
    1,287
    Saraswati lakki
    Jan 6, 2012
Loading...

Share This Page