Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining where a type is defined

I am working on a rather large code base that has a bit of the #ifdef magic going on. I'm looking at one file and trying to determine where a type is defined. Unfortunately, it includes many file, which include many files, which include many files, etc. some of which define macros that affect which definitions you might use. The structure is sufficiently complicated that after 10 minutes worth of grepping and following the include chains, I still have no idea which definition is being used. I recall that visual studio has a nice feature where I can right click on the type and it will show where the type is defined. Is there an equivalent nice tool for linux that reads make files, etc? I'm sure there is, but I still just use vim + grep for my development environment.

like image 449
pythonic metaphor Avatar asked Oct 14 '22 19:10

pythonic metaphor


1 Answers

With complicated defines and dependencies this feature doesn't always work in Visual Studio either.

Solution: ask your compiler to dump the code after it was preprocessed, ask it to print #line and #file directives too. Search through the resulted file for your type, then look at the closest #file directive to see where it came from.

(In GCC you can use the -E switch)

like image 55
Yakov Galka Avatar answered Oct 17 '22 23:10

Yakov Galka