Bug 136536

Summary: gdb cannot see static functions in code compiled at -O2
Product: [Fedora] Fedora Reporter: Dan Williams <dcbw>
Component: gdbAssignee: Elena Zannoni <ezannoni>
Status: CLOSED WONTFIX QA Contact:
Severity: high Docs Contact:
Priority: medium    
Version: rawhideCC: jakub
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2006-08-14 19:11:21 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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.

Versions:
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:

-finline-functions
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