Thread: C guru help needed URGENT

  1. #16
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    thanx i little progress

    ltimer.c:5:5: error: unknown type name ‘suseconds_t’

  2. #17
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    after including sys/time.h

    ltimer.c: In function ‘gettimeofday’:
    ltimer.c:10:23: error: ‘CLOCK_REALTIME’ undeclared (first use in this function)
    ltimer.c:10:23: note: each undeclared identifier is reported only once for each function it appears in

  3. #18
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    If the precision of the result isn't that important, then returning the previous answer with the time bumped up would work.
    Code:
    #define THROTTLE 1000
    int __wrap_gettimeofday(struct timeval *tv, struct timezone *tz) {
        static struct timeval savetv;
        static struct timezone savetz;
        static int count = 0;
        static int result = 0;
        if ( count++ == 0 ) {
            // get a real result
            result = __real_gettimeofday(&savetv,&savetz);
        } else {
            // bump the time (add overflow)
            savetv.tv_usec++;
        }
        if ( count == THROTTLE ) {
            count = 0;
        }
        if ( tv ) *tv = savetv;
        if ( tz ) *tz = savetz;
        return result;
    }
    You will need the GNU linker option --wrap
    --wrap=symbol
    Use a wrapper function for symbol. Any undefined reference to symbol will be resolved to "__wrap_symbol". Any undefined reference to "__real_symbol" will be
    resolved to symbol.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #19
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Try replacing CLOCK_REALTIME with 0.

    EDIT:
    Salem's shown the cool way to do it, allowing you to call the real function.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  5. #20
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    ok got the salem solution compiled

    I also wrote a little test program to see if this library is getting used

    it looks like only the original gettime is getting used salem
    Last edited by NetworkLearning; 09-19-2012 at 01:20 AM.

  6. #21
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    guys,
    can anyone help ? you will help a lot of people study ..this is a program for studying ..


    I have
    Code:
    #include <stdio.h>
    #include <sys/time.h>
    #define THROTTLE 10000
    int __wrap_gettimeofday(struct timeval *tv, struct timezone *tz) {
        static struct timeval savetv;
        static struct timezone savetz;
        static int count = 0;
        static int result = 0;
        if ( count++ == 0 ) {
            // get a real result
            result = __real_gettimeofday(&savetv,&savetz);
        } else {
            // bump the time (add overflow)
            savetv.tv_usec++;
        }
        if ( count == THROTTLE ) {
            count = 0;
        }
        if ( tv ) *tv = savetv;
        if ( tz ) *tz = savetz;
         return result;
    }
    and program that calls it
    Code:
    #include <stdio.h>
    #include <sys/time.h>
    int main () {
    double  frame_count,
            start_time,
            last_time;
            struct timeval tempo;
    
            gettimeofday(&tempo, NULL);
            printf("Running for %f milliseconds\n\n", ((double)tempo.tv_usec - start_time)/1000);
    
    
    }
    Then i have

    LD_PRELOAD=/home/myhome
    LD_LIBRARY_PATH=/home/myhome


    in /etc/ld.so.preload : /home/myhome



    then i execute it with
    home$ strace ./main

  7. #22
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Forgetting the code for a minute, what are you trying to do with this program?

    Does your hardware have the high performance timer?

    What is your OS? Linux of course, but what's the distro?

  8. #23
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    ubuntu 12.04
    on a core i7 machine

  9. #24
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    btw i ran boomerang on the binary and have some code that i can share if that will help

  10. #25
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    You just do
    $ gcc foo.c -Wl,--wrap=gettimeofday
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #26
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    I did

  12. #27
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    gcc -Wl,--wrap=gettimeofday -c ltimer.c -o ltimer.o

  13. #28
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Actually, what I suggested is of no use to you, since it seems you're trying to patch an executable that has already been built.

    The first thing you need to find out is if gettimeofday is being statically linked or dynamically linked.
    If it's statically linked, then the LD_PRELOAD isn't going to work anyway.

    Here's how to tell.
    Code:
    $ gcc foo.c
    $ nm a.out | grep gettime
                     U gettimeofday@@GLIBC_2.2.5
    $ gcc -static foo.c
    $ nm a.out | grep gettime
    000000000040d030 T __gettimeofday
    000000000040d030 T __gettimeofday_internal
    000000000040d030 W gettimeofday
    If you have something like "U gettimeofday@@GLIBC_2.2.5", then the preload thing might work.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  14. #29
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    Actually i get
    nm: i86-image: no symbols

  15. #30
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    and i was able to make my program use an empty gettime
    then it was hanging at different spot
    so the preload thing should work

    but if we can just figure out this test program first

    thanx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Urgent help needed
    By bathulasubbu in forum C Programming
    Replies: 3
    Last Post: 03-25-2011, 09:33 AM
  2. Urgent, help needed.
    By sinnclaus in forum C Programming
    Replies: 4
    Last Post: 03-29-2010, 06:08 AM
  3. Urgent! Help Needed
    By DarkManiac in forum C++ Programming
    Replies: 4
    Last Post: 04-14-2004, 07:16 PM
  4. Urgent: Help needed.
    By Cn00b in forum C Programming
    Replies: 12
    Last Post: 04-02-2003, 10:18 PM
  5. Urgent help needed!!!
    By gibs21 in forum C Programming
    Replies: 2
    Last Post: 09-26-2002, 01:45 PM