Can gcc spit out, given a C file, a list of the all function calls that occur, with filename and line number both for the call itself and for the function’s declaration?
I know gcc somehow retains this information with -g (debuggers rely on it) and that it can dump control flow graphs with -dr (but without filenames or line numbers); but is there a ready-to-use tool that takes gcc output and does what I want?
The reason I want such a tool to use gcc is that this will allow me to use it with the standard build system most gcc-based software comes with (e.g. ./configure && make) even in cases where tools that rely on their own preprocessor and/or parser are a major hassle to fit in. I’m already aware of several such tools, e.g. ctags. So this question is a followup to question 525899.
Try gcc option
-fdump-tree-fixupcfg-lineno.It will ‘pretty print’ parsing AST (with line numbers) in a way that can easily be parsed using relatively simple lexer or any regex engine. Just find all non-keywords preceded by ‘=’ and followed by ‘(‘ – it will be function calls.
All complex expressions will be split into several lines so no two function calls will appear on one line.
Take simple program:
Compile it with
-fdump-tree-fixupcfg-linenoand you get something like this:You won’t get any complex expressions – just assignments and function call and no CPP macros, very easy to parse. Loops and conditionals don’t make it much more difficult.