From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9143 invoked by alias); 9 Dec 2004 17:00:54 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 9124 invoked from network); 9 Dec 2004 17:00:49 -0000 Received: from unknown (HELO mail.dev.rtsoft.ru) (80.240.96.70) by sourceware.org with SMTP; 9 Dec 2004 17:00:49 -0000 Received: (qmail 30095 invoked from network); 9 Dec 2004 16:34:01 -0000 Received: from unknown (HELO ?192.168.1.213?) (192.168.1.213) by mail.dev.rtsoft.ru with SMTP; 9 Dec 2004 16:34:01 -0000 Message-ID: <41B89150.4040904@dev.rtsoft.ru> Date: Thu, 09 Dec 2004 17:00:00 -0000 From: Dmitry Antipov User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20040913 MIME-Version: 1.0 To: gcc-help@gcc.gnu.org Subject: How to use -finstrument-functions for C++ programs ? Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2004-12/txt/msg00084.txt.bz2 Hello all, I'm trying to implement a some kind of self-tracing/self-profiling feature for the shared library which should be dlopen()ed and used by the application core. I'm started from simple C program, like this (due to asm, this is x86-specific): #include #include #define rdtscll(val) asm volatile ("rdtsc" : "=A" (val)) FILE *f = NULL; int n, depth = -1; unsigned long long t; extern char *program_invocation_short_name; void __profile_begin (void) __attribute__ ((constructor,no_instrument_function)); void __profile_end (void) __attribute__ ((destructor,no_instrument_function)); void __cyg_profile_func_enter (void *, void *) __attribute__((no_instrument_function)); void __cyg_profile_func_exit (void *, void *) __attribute__((no_instrument_function)); void __profile_begin (void) { char buf[1024]; snprintf (buf, sizeof (buf), "%s.prof.%d", program_invocation_short_name, getpid ()); f = fopen (buf, "w+"); fprintf (f, "Start of profiling for %s.\n", program_invocation_short_name); } void __profile_end (void) { fprintf (f, "End of profiling for %s.\n", program_invocation_short_name); fclose (f); } void __cyg_profile_func_enter (void *func, void *caller) { rdtscll (t); depth++; for (n = 0; n < depth; n++) fprintf (f, " "); fprintf (f, "-> %p %llu\n", func, t); } void __cyg_profile_func_exit (void *func, void *caller) { rdtscll (t); for (n = 0; n < depth; n++) fprintf (f, " "); fprintf (f, "<- %p %llu\n", func, t); depth--; } void foo (void) { } void bar (void) { } int main (int argc, char *argv[]) { foo (); bar (); return 0; } When compiling as a C program (with 'gcc -finstrument-functions -o selfprof selfprof.c'), it works as expected, i.e. outputs into selfprof.prof.xxxxx something like this: Start of profiling for selfprof. -> 0x80487b0 1521198259227518 -> 0x8048750 1521198259234666 <- 0x8048750 1521198259245630 -> 0x8048780 1521198259248230 <- 0x8048780 1521198259250462 <- 0x80487b0 1521198259252738 End of profiling for selfprof. Here I can check that my code: - enters main() - enters foo() - leaves foo() - enters bar() - leaves bar() - leaves main() But, when compiling the same code as C++ program (with 'g++ -finstrument-functions -o selfprof selfprof.cxx', I've no function entry/exit marks in output: Start of profiling for selfprof. End of profiling for selfprof. I've checked this behaviour both with gcc 3.3.3 (preinstalled on my Fedora Core 2 system) and with gcc 3.4.3 bootstrapped by myself from sources, but results are the same. So, I'm confused. Can anybody explain me why this feature doesn't work for C++ programs ? Thanks, Dmitry P.S. Please also reply to me directly if possible.