Listing C/C++ functions (Code analysis in Unix)

后端 未结 5 1467
栀梦
栀梦 2021-01-04 09:42

Whether we\'re maintaining unfamiliar code or checking out the implementation details of an Apache module it can help if we can quickly traverse the code and build up an ove

相关标签:
5条回答
  • 2021-01-04 10:15

    Doxygen is able to generate some reasonable html documentation and parse out comments. It's not perfect, but it might help. You could incorporate Ctags into your editor to jump you to the functions that you're looking for.

    Personally, I use grep ;)

    0 讨论(0)
  • 2021-01-04 10:19

    Exuberant Ctags http://ctags.sourceforge.net/

    I've only used it from time to time some time ago, and from within a text editor, but check out the list of utilities/tools which can use it:

    http://ctags.sourceforge.net/tools.html

    0 讨论(0)
  • 2021-01-04 10:20

    Run it through doxygen. It will complain about lack of commenting , but it will still produce call graphs and list all the functions. Presented in HTML with links to follow code paths.

    doxygen

    0 讨论(0)
  • 2021-01-04 10:24

    cscope is very good for this sort of thing. Unlike ctags, cscope provides an interface suitible for searching (ctags requires an editor).

    Just run cscope in the root directory of the code you want to inspect. It will: create a database if one isn't there, update the database if one is there, and open a curses gui where you can query all sorts of useful info

    • all references to a symbol
    • global definitions
    • functions called by a function
    • functions calling a function
    • text string
    • regular expression pattern
    • a file
    • files including a file

    ctags only does the first one, 'all references to a symbol'.

    0 讨论(0)
  • 2021-01-04 10:24

    grep '^[a-zA-Z0-9][ *]+ {[a-zA-Z0-9_]+}\([a-zA-Z0-9\,\.\-\>]\*\)$'

    Is roughly what you want. It may take some playing with, but match a valid C++ return type, give the option of it being a pointer, then a function name (which will be \1), open parentheses, parameters, close.

    That general form (return, name, (param)) should work unless you may have line-breaks within a function declaration.

    I'd use Doxygen or another tool to parse it, but if you need to do it quickly and once, regex might be easier (or might not, with regex you never know).

    0 讨论(0)
提交回复
热议问题