从c应用程序中获取所有方法

时间:2013-02-23 15:50:48

标签: c

对于任何c应用程序(在这种情况下让我们说apache)我想返回所有方法及其所在文件的列表。例如,我希望看到类似的内容:

int add (int a, int b)..... math.c
int subtract (int a, int b)..... math.c
int Multiply (int a, int b)..... math.c
int foo ()..... foo.c

我想这样做,并避免手动解析物理c文件以进行方法输出的繁琐任务。我知道其他语言都有反射器。

谢谢大家。

4 个答案:

答案 0 :(得分:3)

man nm(1)

但是,只有在(-g)中编译调试信息时,符号源文件才可用。

答案 1 :(得分:2)

您没有指定平台,因此一个可能的解决方案是'ctags'程序:

DESCRIPTION
       The ctags utility shall be provided on systems that support the User Portability Utilities option, the Software Development Utilities  option,  and
       either or both of the C-Language Development Utilities option and FORTRAN Development Utilities option. On other systems, it is optional.

       The  ctags  utility  shall  write a tagsfile or an index of objects from C-language or FORTRAN source files specified by the pathname operands. The
       tagsfile shall list the locators of language-specific objects within the source files.  A locator consists of a name, pathname, and either a search
       pattern  or  a  line  number  that  can  be  used in searching for the object definition. The objects that shall be recognized are specified in the
       EXTENDED DESCRIPTION section.

OPTIONS
...
       -x     Produce a list of object names, the line number, and filename in which each is defined, as well as the text of that line, and write this  to
              the standard output. A tagsfile shall not be created when -x is specified.

答案 2 :(得分:2)

您可以使用ctags执行此操作。来自网站:

  

Ctags生成源文件中的语言对象的索引(或标记)文件,允许文本编辑器或其他实用程序快速轻松地找到这些项目。标记表示索引条目可用的语言对象(或者,也就是为该对象创建的索引条目)。

Ctags是compatible with a wide array of tools

答案 3 :(得分:2)

听起来像链接器的工作。您是否尝试过生成地图文件?检查链接器文档以了解如何生成映射文件。