Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 39

Thread: detecting function calls

  1. #21
    Join Date
    Aug 2012
    Beans
    533

    Re: detecting function calls

    Quote Originally Posted by dwhitney67 View Post
    Look into gprof. You will also need to compile your applications using the -pg option.
    Quote Originally Posted by spjackson View Post
    gprof is the only profiler I have used on Linux.
    Quote Originally Posted by Tony Flury View Post
    Maybe if you explain why you need the information, what you are actually trying to acheive - then we might have better luck helping you identify the tools you need.
    Quote Originally Posted by trent.josephsen View Post
    Perhaps you should describe what problem you're trying to solve, rather than how you want to solve it, and we can suggest other solutions.
    Right now, most of my attention is on gprof and the backtrace function (Please see http://www.gnu.org/software/libc/man...acktraces.html )
    I'm very happy with gprof, but the only problem is that my executable runs on powerPC, and so I'll have to cross compile binutils for gprof. I being a beginner, don't think , will be able to do that.

    backtrace is good enough although it's static. The only problem with backtrace is that you have to call the backtrace function in the last function defined. That's a huge overhead - to go and find out the last function if it's a huge application. Is there a way to mention the backtrace function in the very beginning, and let the compiler know that you expect the backtrace for this code, and when it reaches the last function, just call it for me, rather than me calling it explicitly. Theoritically, it is possible right ?

    Thanks.

  2. #22
    Join Date
    Aug 2012
    Beans
    533

    Re: detecting function calls

    I'm sorry, I was writing the previous comment when you replied. Please can you see it for a more specific question.

    Quote Originally Posted by Tony Flury View Post
    If there is a clear boundary between the layers - and opbvious intefaces without global variables (ugggh), then why not break all the 2nd level functions into a separate module - and Cunit test that first. You can then test the first level functions knowing that your helper functions work.
    Tony, thanks for the reply.
    The only issue with that is, I wouldn't want to manually separate it as first layer and second layer. That's why I wanted something which tells me what function calls what. From the call order, I would be able to figure out which functions come under first layer, and subsequent layers.
    Once that is done,I can proceed as you said.
    Last edited by IAMTubby; October 22nd, 2012 at 10:13 AM.

  3. #23

    Re: detecting function calls

    Maybe I'm missing something, but why do you need to know the flow of control to write unit tests? Shouldn't you be able to test fun2() without knowing in what context it's called? I mean, that is kind of the central notion of unit testing: test your code in small units so that you know they will integrate properly.

  4. #24
    Join Date
    Aug 2012
    Beans
    533

    Re: detecting function calls

    Quote Originally Posted by trent.josephsen View Post
    Maybe I'm missing something, but why do you need to know the flow of control to write unit tests? Shouldn't you be able to test fun2() without knowing in what context it's called? I mean, that is kind of the central notion of unit testing: test your code in small units so that you know they will integrate properly.
    Trent, but I want a program to tell me that a function called fun2() exists ,rather than me browsing through the code and getting to know it.

  5. #25
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,220
    Distro
    Kubuntu

    Re: detecting function calls

    Quote Originally Posted by IAMTubby View Post
    Trent, but I want a program to tell me that a function called fun2() exists ,rather than me browsing through the code and getting to know it.
    Your goal is way too lofty. gprof will provide metrics on what functions where called during a particular run of the application. If the application takes in a variety of inputs, then one run may very well differ from another.

    CUnit on the other hand will assist you with unit testing the code. The latter requires that you have intimate knowledge of the code, because after all, you need to develop a test for each function so that you can verify that it performs as expected, with and without nominal input data.

    It seems that you do not want to make the effort to learn the code in detail, which is generally the case once an application has been fully developed and is already deployed. Time could also be a factor.

    Typically unit testing is performed during development, and rarely done after an application has been developed/deployed.

    Since it seems that the work you are doing is at the professional level, perhaps you should invest in professional-grade tools to perform the task that you need. I was recently introduced to Klocwork (via a training class); it is a static analysis tool that can catch coding problems in software. Whether it meets your needs or not, I cannot be certain. Surely an off-the-shelf tool must exist that could meet your needs.

  6. #26
    Join Date
    Aug 2012
    Beans
    533

    Re: detecting function calls

    Quote Originally Posted by dwhitney67 View Post
    Your goal is way too lofty. gprof will provide metrics on what functions where called during a particular run of the application. If the application takes in a variety of inputs, then one run may very well differ from another.

    CUnit on the other hand will assist you with unit testing the code. The latter requires that you have intimate knowledge of the code, because after all, you need to develop a test for each function so that you can verify that it performs as expected, with and without nominal input data.
    Thanks Sir for the reply. Shall take note of the points.

    It seems that you do not want to make the effort to learn the code in detail, which is generally the case once an application has been fully developed and is already deployed. Time could also be a factor.
    Not at all Sir, just thought it'd be cooler to get an automatic trace of the functions.

    Since it seems that the work you are doing is at the professional level, perhaps you should invest in professional-grade tools to perform the task that you need.
    Yup, college internship

    I was recently introduced to Klocwork (via a training class); it is a static analysis tool that can catch coding problems in software. Whether it meets your needs or not, I cannot be certain. Surely an off-the-shelf tool must exist that could meet your needs.
    Was just going through the wiki page, shall go through in more details . Thanks for the suggestion.

  7. #27
    Join Date
    Aug 2012
    Beans
    533

    Re: detecting function calls

    Is it possible to generate a dynamic function call trace using nm ?
    I tried reading the man pages and was excited to see -D, but I guess I have to use some other argument.

    Please advise.
    Thanks.

  8. #28
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,079
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: detecting function calls

    Quote Originally Posted by IAMTubby View Post
    Is it possible to generate a dynamic function call trace using nm ?
    I tried reading the man pages and was excited to see -D, but I guess I have to use some other argument.
    No. It is not possible to get a dynamic function call trace without running the program. nm does not run the program.

  9. #29
    Join Date
    Aug 2012
    Beans
    533

    Re: detecting function calls

    Quote Originally Posted by spjackson View Post
    No. It is not possible to get a dynamic function call trace without running the program. nm does not run the program.
    okay, I meant using something like $nm -SomeOptiojn <ExecuatbleName>

  10. #30
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,079
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: detecting function calls

    OK, let's return to your original post 3 weeks ago, and take your example source and put it in a file fun.c.

    Now take this code and put it in a file called dotrace.sh
    Code:
    #!/bin/bash
    
    image="$1"
    
    echo "Functions called are as follows"
    for line in $(egrep '^E' trace.txt)
    do
        address=$(echo $line | sed 's/^.//')
        function_name=$(addr2line -e $image -f -s $address | head -1)
        echo ${function_name}'()'
    done
    Now let's go to my first reply which referred to http://www.ibm.com/developerworks/li...ry/l-graphvis/ and said:
    This gives some strong clues.
    The source code for that article is linked on the above page, so let's get it and use it.

    Code:
    $ chmod +x ./dotrace.sh
    $ wget http://www.mtjones.com/developerworks/pvtrace.zip
    $ unzip pvtrace.zip
    $ gcc -g -finstrument-functions -o fun fun.c pvtrace/instrument.c
    $ ./fun
    $ ./dotrace.sh
    Functions called are as follows
    main()
    fun1()
    fun2()
    fun2_1()
    fun3()
    The output is precisely what you described in your first post. Is this what you still want? I'm afraid I've lost track somewhat.

    Of course there's scope for improvement to the above script and the trace that is always written to ./trace.txt. However, the basic functionality is what you first described.

Page 3 of 4 FirstFirst 1234 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •