如何获得使用锵一个C / C ++程序的所有全局声明的列表? [英] How to get a list of all global declarations of a C/C++ program using Clang?

查看:187
本文介绍了如何获得使用锵一个C / C ++程序的所有全局声明的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个程序,通过使用锵列出了所有的C或C ++程序的公开导出变量和函数。

I'm trying to write a program that lists all of the publicly exported variables and functions of a C or C++ program by using Clang.

我跟着本教程的一部分05,但它并不适用于当前的工作版本铛的。上面说,我得到了一些提示中的 CompilerInstance 可以使code短,但我不完全知道如何使用它。

I followed part 05 of this tutorial, but it doesn't work for current version of clang. Above that, I got some hints that CompilerInstance can make the code shorter, but I'm not entirely sure how to use it.

您将如何实现这个功能?你能不能给我任何指针到正确的方向?例如:是否有全局声明变量的大哈希表或做我必须遍历AST

How would you implement this functionality? Can you give me any pointers into the right direction? For example: is there a large hash table of globally declared variables or do I have to traverse the AST?

推荐答案

公开导出的 - ?你的意思是使用外部链接符号

publicly exported - do you mean symbols with external linkage?

您可以使用 纳米 目标文件,共享库和可执行文件与 - EXTERN仅--defined只--demangle 选项,以显示定义具有外部链接的符号。符号类型字段告诉你那是什么样的符号,全局变量通常有类型B,B,C,D,D,G,G,R,R,S,S和W,W在声明模板静态数据成员头文件和函数范围的静态。

You can use nm on object files, shared libraries and executables with --extern-only --defined-only --demangle options to display defined symbols with external linkage. Symbol type field tells you what kind of symbol it is, global variables normally have types B, b, C, D, d, G, g, R, r, S, s and W, w for static data members of templates declared in header files and function-scope statics.

这篇关于如何获得使用锵一个C / C ++程序的所有全局声明的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆