Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking the code generated implicitly by the C++ compiler

Is there a way (g++ option?) to check what code is generated implicitly by the C++ compiler (e.g. all the default constructors/destructors)?

Having the generated C++ code would be ideal, but at least the assembly would be good. Using:

g++ -S -g -O0 <file.cpp>

does not give me any label with generated constructors/destructors.

like image 671
nicolas Avatar asked Jul 21 '14 05:07

nicolas


1 Answers

I think option the -fdump-tree-original is about as close as you can get. Unfortunately it'll show both your own code and automatically generated code, but it won't label which is which. However it's the most readable of GCC's dumps and it shows the generated code before any optimizations are performed.

Another option would be to use -fdump-translation-unit. That creates a raw dump of the tree with literally everything in it. The nodes that compiler made up will be marked as "artificial". However, the format isn't easy for humans to read and there's a lot of it wade through even for a trivial source file. To get any useful information out of it you'd probably need to write a program to read it in and then walk the tree to find the nodes you're interested in and print them out it a more readable format.

like image 58
Ross Ridge Avatar answered Sep 17 '22 13:09

Ross Ridge