简体   繁体   English

如何识别源代码中的所有 C++ 标准库调用?

[英]How to identify all C++ standard library calls in source code?

I want to get the information about how many kind of C++ standard library features are used in my application source code, eg, whether vector is used or some STL algorithm is used?我想获取有关我的应用程序源代码中使用了多少种 C++ 标准库功能的信息,例如,是使用矢量还是使用了某些 STL 算法? For C library, I know that I can use objdump -T | grep GLIBC对于 C 库,我知道我可以use objdump -T | grep GLIBC use objdump -T | grep GLIBC on the compiled binary as the post how to identify all libc calls at compile time?已编译二进制文件上的use objdump -T | grep GLIBC作为帖子如何在编译时识别所有 libc 调用? shows.显示。 But this method is not applicable for C++, eg, as the result of objdump -T | grep GLIBCxx但是这种方法不适用于 C++,例如,作为objdump -T | grep GLIBCxx的结果。 objdump -T | grep GLIBCxx is not what I expect as below: objdump -T | grep GLIBCxx不是我所期望的,如下所示:

0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4 _Znam
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.21 _ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7compareERKS4_
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.19 _ZNSt6chrono3_V212system_clock3nowEv
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.15 _ZNSt8__detail15_List_node_base7_M_hookEPS0_
0000000000000000      DO *UND*  0000000000000000  GLIBCXX_3.4.22 _ZTINSt6thread6_StateE
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4 _ZSt29_Rb_tree_insert_and_rebalancebPSt18_Rb_tree_node_baseS0_RS_
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.21 _ZNSt14overflow_errorC1EPKc
0000000000000000      DO *UND*  0000000000000000  GLIBCXX_3.4 _ZTVSt9basic_iosIcSt11char_traitsIcEE
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.14 _ZSt20__throw_future_errori
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.21 _ZNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEED1Ev
0000000000000000      DO *UND*  0000000000000000  GLIBCXX_3.4 _ZSt7nothrow
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4 _ZSt9terminatev
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.21 _ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7compareEPKc
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4 _ZNSt8ios_baseC2Ev
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.21 _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_appendEPKcm
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4 _ZNSt8ios_baseD2Ev
0000000000000000      DO *UND*  0000000000000000  GLIBCXX_3.4.21 _ZTTNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEE
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4 _ZSt17__throw_bad_allocv
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.14 _ZSt25__throw_bad_function_callv
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.15 _ZNSt16invalid_argumentD2Ev
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.21 _ZNSt13runtime_errorC1EPKc

I think I can use libclang to static analyze the source code to get such information, but is there any other method?我想我可以使用 libclang 对源代码进行静态分析以获取此类信息,但是还有其他方法吗? Thanks!谢谢!

Many components of the C++ standard library are templates. C++ 标准库的许多组件都是模板。 Other non-template functions could be declared inline .其他非模板函数可以声明为inline In either case, there's no guarantee that there will be a call to a function visible in the assembly.无论哪种情况,都不能保证调用程序集中可见的函数。 The compiler could easily inline all of these, and there would be virtually no way to tell that this had happened.编译器可以轻松地内联所有这些,并且几乎没有办法告诉这已经发生了。

Only analysis of the literal source text can tell you what you're looking for.只有对文字源文本的分析才能告诉您您在寻找什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM