Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncompile a gch file

I accidentally removed a .h file I hadn't added to version control, but I still have the .h.gch. Is there any way to uncompile the .gch?

like image 723
Aaron Yodaiken Avatar asked Jun 20 '11 21:06

Aaron Yodaiken


3 Answers

You can try to run strings utility. GCH have a lot of internal gcc macro defined, so I suggest you do two dumps with strings:

First is for your gch: $ strings file.h.gch

and second is for precompiled empty header file (or, if you can remember, what was included into your header - include in this file too)

Then you can save both dumps and do a diff run:

For my example:

#define d1234

#undef dsgf

int asdfgh(char a);
int ghjkl(int g, int h);

there are in the diff all names at very top:

1074a1075
> asdfgh
1189a1191
> d1234
1200a1203
> dsgf
1287a1291
> ghjkl

how to get structures and parameters of functions- i don't know. But I suggest if you can use this pch (e.g. replace #include "file.h" with #pragma GCC pch_preprocess "file.h.gch" ) - then you can do a tree and rtl dump with -fdump-tree-all-all and -frtl-dump-all-all. Some of dumps will contain more information, derived from lost header.

like image 188
osgx Avatar answered Oct 20 '22 20:10

osgx


It is probably not possible. Compilation is typically a one way process; once you do it there is no way to reconstruct your initial source code, and things like variable names, comments and even certain subroutines will be inlined and ironed out. The same goes to precompiled headers, so there is not likely any good way to reconstruct the documentation and names from your .gch file. You could perhaps reconstruct some version of the names in the header, but then again this would be no different than what you already have. Unless you have a back up, you are pretty much out of luck.

like image 43
Mikola Avatar answered Oct 20 '22 20:10

Mikola


AFAIK the gch files are some kind of dump of the memory of the compiler after processing the header (at least as far as the data structures involved in its IR are involved); maybe a good part of the information contained in the original header is still there in some form, but I don't think there's a tool to extract it.

like image 29
Matteo Italia Avatar answered Oct 20 '22 20:10

Matteo Italia