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)
Jakub, what exactly does GCC do with static functions at -O2 and higher?
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
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.
unfortunately known limmitation of gdb. We are trying to address this type of issues with Frysk. http://sources.rehdat.com/frysk