Bug 136536 - gdb cannot see static functions in code compiled at -O2
Summary: gdb cannot see static functions in code compiled at -O2
Alias: None
Product: Fedora
Classification: Fedora
Component: gdb (Show other bugs)
(Show other bugs)
Version: rawhide
Hardware: All Linux
Target Milestone: ---
Assignee: Elena Zannoni
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 2004-10-20 20:12 UTC by Dan Williams
Modified: 2007-11-30 22:10 UTC (History)
1 user (show)

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

Attachments (Terms of Use)

Description Dan Williams 2004-10-20 20:12:09 UTC
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 20:12:40 UTC
Jakub, what exactly does GCC do with static functions at -O2 and higher?

Comment 2 Dan Williams 2004-10-20 20:19:55 UTC
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 23:34:29 UTC
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 19:10:24 UTC
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.