When searching for macro references, Eclipse displays file+line the macro is referenced it. I would like to file+line+function.
Searching for a other type of data (e.g. function) will display file+line+function as expected, so maybe something should be tweaked in Eclipse configuration for macros?
Any ideas?
The next release of CDT (CDT 9.3, part of Eclipse Oxygen to be released in June 2017) will have support for showing function containing the macro reference. See Bug 508216 for more details.
The rest of this answer is the original answer.
There is no way in Eclipse CDT to display the function a macro is referenced in because such information is not included in the index when the index is built.
To ensure that we are talking about the same thing I provide some visuals.
Given a simplified C file containing functions, macros and globals:
Example Code
#define MACRO(X) ((X) + 2)
int function(int);
int global;
int function_results_are_in(void) {
int i = 0;
i = MACRO(i);
i = function(i);
i += global;
return i;
}
Doing a search using one of the following methods that uses the C/C++ Index (as opposed to a file/grep style search):
Setup
Results - Function search
As you can see with searches for functions, the result shows the containing function name:
Results - Macro search
But for the macro search, there is no containing function name:
Each search result in the C/C++ Search results is LineSearchElement.Match
. If its fEnclosingElement
is null
then there is no function to display.
Taking one step back you can see that the match is created from a matching IIndexName
. The Match.fEnclosingElement
field is filled from the result of IIndexName.getEnclosingDefinition()
.
In the case of a macro reference the concrete type of IIndexName
is a PDOMMacroReferenceName
, and the implementation of getEnclosingDefinition
is simply return null
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With