Bugzilla will be upgraded to version 5.0 on a still to be determined date in the near future. The original upgrade date has been delayed.
Bug 136536 - gdb cannot see static functions in code compiled at -O2
gdb cannot see static functions in code compiled at -O2
Product: Fedora
Classification: Fedora
Component: gdb (Show other bugs)
All Linux
medium Severity high
: ---
: ---
Assigned To: Elena Zannoni
Depends On:
  Show dependency treegraph
Reported: 2004-10-20 16:12 EDT by Dan Williams
Modified: 2007-11-30 17:10 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2006-08-14 15:11:21 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Dan Williams 2004-10-20 16:12:09 EDT
functions declared "static" in the code don't show up in GDB
backtraces when the code was compiled at -O2 and above, nor can you
set breakpoints on them.  You can however set a breakpoint in the
static function if you know the file name + line number.

Sample code:
#include <stdio.h>
void f3 (const char *a)
	fprintf (stderr, "f3: '%s'\n", a);
static void f2 (const char *a)
	f3 (a);
int main (int argc, char **argv)
	f2 ("bork");

So, "break f2" won't work, but "break foo.c:8" will work to break in
f2().  This greatly hampers the ability to debug programs that use
static functions since you cannot see or switch to a frame that's static.

gcc version 3.4.2 20041006 (Red Hat 3.4.2-5)
GNU gdb Red Hat Linux (6.1post-1.20040607.38rh)
Comment 1 Dan Williams 2004-10-20 16:12:40 EDT
Jakub, what exactly does GCC do with static functions at -O2 and higher?
Comment 2 Dan Williams 2004-10-20 16:19:55 EDT
From the manpage:

If all calls to a given function are integrated, and the function
is declared "static", then the function is normally not output as
assembler code in its own right.

Enabled at -O3.

So this says its enabled at -O3, but for me it happens at -O2 with the
above code using "gcc -o foo foo.c -O2".  So, if -finline-functions is
the issue, this is probably a gcc bug, either that:

1) manpage is wrong and -finline-functions is active at -O2, or
2) gcc is doing the wrong thing at -O2
Comment 3 Jakub Jelinek 2004-10-20 19:34:29 EDT
At -O2, -finline-functions is not turned on.
At -O2 starting with GCC 3.4 gcc also automatically inlines, but
only static functions that are called once (and also removes altogether
static functions that are never called).
You can use noinline, always_inline or used attributes to override
this behaviour.
Comment 4 Elena Zannoni 2006-08-14 15:10:24 EDT
unfortunately  known limmitation of gdb. We are trying to address this type of
issues with Frysk. http://sources.rehdat.com/frysk

Note You need to log in before you can comment on or make changes to this bug.