Click here to Skip to main content
11,488,212 members (77,337 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C Linux GCC
I want to get function's call stack of the programm with gcc option -finstrument-functions.

Typical code
    void __cyg_profile_func_enter (void *, void *) __attribute__((no_instrument_function));
    void __cyg_profile_func_exit (void *, void *) __attribute__((no_instrument_function));
    int depth = -1;
    
    void __cyg_profile_func_enter (void *func,  void *caller)
    {    }
    
    void __cyg_profile_func_exit (void *func, void *caller)
    {    }
    
    int main()
    {
    printf("Hello world");
    return 0
    }
 
Compile it with gcc -finstrument-functions test.c

run ./a.out, and all ok.

But when I did it with g++ , I got undefined reference to __cyg_profile_func_enter function. I read that it happens because _cyg functions is part of C code and if I want to use them in C++ I should use extern "C", so there is final code.
 
    extern "C"{
    void __cyg_profile_func_enter (void *, void *) __attribute__((no_instrument_function));
    void __cyg_profile_func_exit (void *, void *) __attribute__((no_instrument_function));
    int depth = -1;
    
    void __cyg_profile_func_enter (void *func,  void *caller)
    {    }
    
    void __cyg_profile_func_exit (void *func, void *caller)
    {    }
    }
    int main()
    {
    printf("Hello world");
    return 0
    }
It compiles with g++ -finstrument-functions test.c, then try to execute it but got Core dumped error message. I trace dump with gdb and there was Segmentation fault in __cyg_profile_func_enter().

GCC version is 2.95.4. I also tested it on 4.4.3 and all Ok. So are there any posibilities to walk around this problem using 2.95.4 gcc?
Posted 21-Sep-12 1:04am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 489
1 OriginalGriff 328
2 Mehdi Gholam 145
3 Sascha Lefèvre 135
4 KarstenK 115
0 Sergey Alexandrovich Kryukov 9,308
1 OriginalGriff 8,352
2 Sascha Lefèvre 3,334
3 Maciej Los 2,956
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100