简体   繁体   中英

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? For C library, I know that I can 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? shows. But this method is not applicable for C++, eg, as the result of objdump -T | grep GLIBCxx objdump -T | grep GLIBCxx is not what I expect as below:

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? Thanks!

Many components of the C++ standard library are templates. Other non-template functions could be declared 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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