Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support targeting function declarations/headers with -fplugin-arg-instrument_attribute-include-file-list #23

Open
christophebedard opened this issue Jun 8, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@christophebedard
Copy link
Owner

christophebedard commented Jun 8, 2021

Currently, it seems that providing a (partial) path to header files, i.e. files with function declarations, as opposed to definitions, with -fplugin-arg-instrument_attribute-include-file-list doesn't work. We need to point to files with function definitions instead (i.e. source files).

This is probably due to these lines:

// Make sure it's a function
if (FUNCTION_DECL == TREE_CODE(fndecl)) {

One would think that FUNCTION_DECL refers to the function declaration, but I guess not. I've been looking at the gcc plugin headers, but I don't know most of the terminology.

@christophebedard christophebedard added the enhancement New feature or request label Jun 8, 2021
@christophebedard christophebedard self-assigned this Jun 8, 2021
@christophebedard
Copy link
Owner Author

christophebedard commented Jun 12, 2021

We need to register a callback with PLUGIN_FINISH_DECL instead of PLUGIN_FINISH_PARSE_FUNCTION to process #included headers/function declarations (including system headers): https://github.com/gcc-mirror/gcc/blob/d64584d2fbe79b34e7176681a9d9f85851628ce8/gcc/plugin.def#L32-L33

However, even if the instrumentation gets enabled following a match with a function declaration in a header file, when the function definition gets processed, instrumentation will be disabled unless there is also a match. For example, this means that we would need to either just use -fplugin-arg-instrument_attribute-include-function-list or use -fplugin-arg-instrument_attribute-include-file-list with (sub)paths that match the header and the source file. This kind of defeats the purpose.

We would need a separate flag or way to know that we have already decided to instrumentation a given function so that we don't disable the instrumentation later on. There might be a way to keep track of this using some sort of hash table, but it starts getting weird a bit and would probably affect performance.

@christophebedard
Copy link
Owner Author

Until a proper solution is found, this should be properly documented in the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant