clang-callgraph icon indicating copy to clipboard operation
clang-callgraph copied to clipboard

Improve argument filtering before passing to `index.parse()`

Open gsingh93 opened this issue 2 years ago • 2 comments

This is the current way we're filtering the command arguments before passing it to index.parse():

c = [
    x for x in cmd['command'].split()
    if x.startswith('-I') or x.startswith('-std=') or x.startswith('-D')
] + cfg['clang_args']

I ran into issues with this in cases where -include was used, or when there was a space between -I/-include and the actual path. In my particular case, I found that if I didn't do any argument filtering, but just used cmd['command'].split()[1:-3] instead of all the arguments, it worked. This filtered out the compiler executable (the first argument) and the '-o output_file source_file` part of the command. While this fixed my issue, this wouldn't generally fix the issue as it's relying on those three tokens being at the end of the command, which is why I didn't submit a PR for it.

I also ran into issues, because some arguments contained single quotes that would have been removed on the command line, i.e. -DFOO='BAR', and I needed to do x.replace("'", '') to fix it.

gsingh93 avatar Mar 09 '22 00:03 gsingh93

Hi!

Thank you for caring about this project. As you can see, this has not been maintained or used for 5 years. Would you like having contributor privileges?

I think you would do a much better job at fixing the bugs you have found than me, given that you just ran those investigations and have them in your mind, while I forgot it all and feel like I have never seen this code in my life.

Thank you for your contribution!

Vermeille avatar Mar 09 '22 01:03 Vermeille

Sure, I have a number of fixes and improvements locally. If you want me to update this project with them, you can grant me contributor privileges.

gsingh93 avatar Mar 09 '22 06:03 gsingh93