Home > OS >  How do I find out where a function is defined?
How do I find out where a function is defined?

Time:01-03

Let's say I have the following program (a.c):

#include <stdio.h>

void f()
{
    printf("Hello, world!");
}

int main(void)
{
    f();
    return 0;
}
$ gcc -g a.c

Having a.out, how do I find out where main() is defined? I mean, in a big project it's not always clear where main() comes from.

CodePudding user response:

You can use gdb. Probably there's a better command, anyway I know of:

$ gdb -batch -ex "info function main" a.out
All functions matching regular expression "main":

File a.c:
8:   int main(void);
  • Related