Page 4 of 4 FirstFirst ... 234
Results 31 to 39 of 39

Thread: detecting function calls

  1. #31
    Join Date
    Aug 2012
    Beans
    533

    Re: detecting function calls

    Quote Originally Posted by spjackson View Post
    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:

    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.
    Sir, thanks a lot for the reply. I'm trying. Will get back to you in an hour's time.

  2. #32
    Join Date
    Aug 2012
    Beans
    533

    Re: detecting function calls

    Quote Originally Posted by spjackson View Post
    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:

    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.
    Sir, I guess I'm doing a small mistake somewhere, This is the output I get
    Code:
    Functions called are as follows
    addr2line: '-f': No such file
    ()
    addr2line: '-f': No such file
    ()
    addr2line: '-f': No such file
    ()
    addr2line: '-f': No such file
    ()
    addr2line: '-f': No such file
    ()
    addr2line: '-f': No such file
    ()
    addr2line: '-f': No such file
    ()

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

    Re: detecting function calls

    My mistake. I originally had the program name fixed in the script. It is now an argument.
    Code:
    ./dotrace.sh fun
    There is a bit of a clue on line 3 of the script.
    Code:
    image="$1"

  4. #34
    Join Date
    Aug 2012
    Beans
    533

    Re: detecting function calls

    Quote Originally Posted by spjackson View Post
    My mistake. I originally had the program name fixed in the script. It is now an argument.
    Code:
    ./dotrace.sh fun
    There is a bit of a clue on line 3 of the script.
    Code:
    image="$1"
    Sir, that was wonderful. Thanks a lot, it works fine.
    However, I have 1 more question in something that's not entirely related to the thread, but necessary for me to get my application working.
    I have a lot of files in an application I'm working on. Is there a way to add this line
    Code:
    gcc -g -finstrument-functions -o fun fun.c pvtrace/instrument.c
    to all of those files from maybe the shell(as in, without editing individual makefiles, far too many to edit individually).
    The gcc part of my makefiles look like this,
    Code:
    %.o : %.cpp
            $(GXX) $< -o $@ $(CFLAGS)
    or
    Code:
    main.o: $(DIR)/main.c
            $(CC) -c $? $(CFLAGS)
    Thanks a lot Sir for the help.
    Last edited by IAMTubby; October 31st, 2012 at 08:01 PM.

  5. #35
    Join Date
    Aug 2012
    Beans
    533

    Re: detecting function calls

    Quote Originally Posted by spjackson View Post
    Now let's go to my first reply which referred to http://www.ibm.com/developerworks/li...ry/l-graphvis/
    Sir, the learning resource you gave me was excellent. Thanks a lot . I found it very helpful.

    Maybe, our very own ubuntuforums.org should follow the graph kind of an approach, by which, this reply would have come under your post, 2 posts back, instead of coming in serial order of date/time posted. Will make it easier for a person viewing this thread after 5 years. Just a random thought

    Still figuring out a way to apply the change to all the files in my application..
    Last edited by IAMTubby; October 31st, 2012 at 08:39 PM.

  6. #36
    Join Date
    Aug 2012
    Beans
    533

    Re: detecting function calls

    Sir, I would like to ask the above question on a different thread, not to mix with the original discussion.
    Marking the thread as solved. But, further replies about the makefile option would be more than welcome.
    Thanks a lot once again!

    PS : The thread about a possible make option is on http://ubuntuforums.org/showthread.p...8#post12329538

  7. #37
    Join Date
    Aug 2012
    Beans
    533

    Re: detecting function calls

    Quote Originally Posted by spjackson View Post
    Code:
    ./dotrace.sh fun
    Sir,This is 1 week old, but I have a question.

    I got the trace working with the dotrace.sh script you provided.But I'm not able to get the graph trace. I tried running
    Code:
    dot -Tjpg graph.dot -o graph.jpg
    .
    This is what I get on running the above
    Code:
     
    $ dot -Tjpg graph.dot -o graph.jpg
    -bash: dot: command not found
    I do have the necessary files. This is the output of ls
    Code:
    dotrace.sh  fun.c     graph.dot     pvtrace       trace.txtfun         gmon.out  instrument.c  pvtrace.zip
    I tried to read the manual for dot utility mentioned in the Resources on the webpage you gave, but it says "Page not found"

    Please advise.
    Thanks.
    Last edited by IAMTubby; November 8th, 2012 at 10:58 AM.

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

    Re: detecting function calls

    Code:
    $ dot
    The program 'dot' is currently not installed.  You can install it by typing:
    sudo apt-get install graphviz

  9. #39
    Join Date
    Aug 2012
    Beans
    533

    Re: detecting function calls

    Quote Originally Posted by spjackson View Post
    Code:
    $ dot
    The program 'dot' is currently not installed.  You can install it by typing:
    sudo apt-get install graphviz
    Sir, Yes I got it working
    But may I ask just 1 more question on this topic. I did a sudo apt-get remove after getting it to work, because I wanted to install from source. I found the source at http://www.graphviz.org/Download_source.php and successfully did a sudo make install in ~/Desktop/local.
    These are the steps I followed
    Code:
    wget http://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.28.0.tar.gz
    unzip graphviz-2.28.0.tar.gz
    cd graphviz-2.28.0
    mkdir -p $HOME/local
    ./configure --prefix=$HOME/local
    make clean
    make
    make install
    Now my ~/Desktop/graphviz-2.28.0 contains
    Code:
    aclocal.m4       config.h.in    doc                 iffe         Makefile.old
    ast_common.h     config.h.old   dot.demo            INSTALL      NEWS
    ast_common.h.in  config.iffe    Doxyfile            INSTALL.old  plugin
    AUTHORS          config.log     Doxyfile.in         lib          plugin.demo
    autogen.sh       Config.mk.old  FEATURE             libltdl      README
    awk              config.status  features            libtool      rtest
    builddate.h      configure      graphs              m4           share
    ChangeLog        configure.ac   graphviz.7          macosx       stamp-h1
    cmd              configure.old  graphviz.sln        makearch     tclpkg
    compat_getopt.h  contrib        graphviz.spec       Makeargs     windows
    compat.h         COPYING        graphviz.spec.in    Makefile
    config           cpl1.0.txt     graphviz.vcproj     Makefile.am
    config.h         debian         graphviz_version.h  Makefile.in
    and ~/Desktop/local contains
    Code:
    bin  include  lib  share
    How do I proceed ?
    When I try doing dot -Tjpg graph.dot -o graph.jpg, it still gives me the error
    Code:
    The program 'dot' is currently not installed.  You can install it by typing:
    sudo apt-get install graphviz
    Thanks.
    Last edited by IAMTubby; November 15th, 2012 at 12:39 AM.

Page 4 of 4 FirstFirst ... 234

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
  •