3
(gdb) l main
...

4614        if (do_daemonize)
4615            save_pid(getpid(), pid_file);
(gdb) l save_pid
  Function "save_pid" not defined.

and there's its definition in source file:

static void save_pid(const pid_t pid, const char *pid_file) {
    FILE *fp;
    ...
}

save_pid and main are in the same source file,but only main has debug symbol,why??

UPDATE

Another test case with a really simple static function:

#include <stdio.h>

static int test()
{
        return 0;
}
int main(void)
{
        //int i = 6;
        printf("%f",6.4);
        return 0;
}

gcc -Wall -g test.c test

But the symbol test is there!

gdb
  • 7,189
  • 12
  • 38
  • 36

1 Answers1

0

If the function is simple enough and its address is never used, being static it may have been inlined and then discarded (since there is no possibility of it being called from elsewhere).

geekosaur
  • 59,309
  • 11
  • 123
  • 114
  • @geekosaur,thanks for the reply!But I just made another test,with a really simple static function,but it's not discarded. – gdb Apr 01 '11 at 06:42
  • You'll have to show the whole source file, then. But to be honest, I think you want to ask the compiler what it did (`gcc -v ...`). – geekosaur Apr 01 '11 at 06:43
  • 1
    Ah, but that time you don't call it at all. I suspect that, depending on optimization level, the fact that it can't find a use at all will make it consider that it doesn't know what's going on and had better output it as is. But this depends on the compiler version and optimization level. You might include `-v -Wall` as well to get some idea of what it thinks is going on. – geekosaur Apr 01 '11 at 06:51
  • In case it's not clear: how the compiler decides whether to emit the standalone version as well as any inlined code is somewhat complex. In the end, you may have to ask a `gcc` developer, including the compiler versipn, platform, full source code, and full compiler options. – geekosaur Apr 01 '11 at 06:55