cobjdumpdwarfnmreadelf

How do I find out where main() is defined in a big project?


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.


Solution

  • 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);