Author Topic: C/C++ parser ignores includes with minus  (Read 7093 times)

Offline l_inc

  • Multiple posting newcomer
  • *
  • Posts: 56
C/C++ parser ignores includes with minus
« on: October 27, 2015, 04:07:35 pm »
Hi everybody. I have CodeBlocks 13.12.svn.10538 on Fedora 22. <fcntl.h> includes <bits/fcntl.h>, which includes <bits/fcntl-linux.h>. Including <fcntl.h> in a cpp file does not allow to see the definitions from fcntl-linux.h unless I rename the latter into fcntl_linux.h and modify <bits/fcntl.h> accordingly.

Is that a one more bug, or am I missing something? Seems like a very common use case, and it's strange I couldn't find any related complaints on the forum.

Offline Manolo

  • Multiple posting newcomer
  • *
  • Posts: 47
Re: C/C++ parser ignores includes with minus
« Reply #1 on: October 28, 2015, 01:47:32 am »
Yes, very common usage. I doubt it's a bug. Showing some sample code may put some light.
Anyhow, why do you think your problem is related to C:B?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: C/C++ parser ignores includes with minus
« Reply #2 on: October 28, 2015, 09:53:20 am »
l_inc can you provide a minimal self-contained project that can be used to reproduce the bug?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline l_inc

  • Multiple posting newcomer
  • *
  • Posts: 56
Re: C/C++ parser ignores includes with minus
« Reply #3 on: October 28, 2015, 01:08:31 pm »
oBFusCATed
Sure. Here's main.cbp:
Code
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="main" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Release">
<Option output="main" prefix_auto="1" extension_auto="1" />
<Option object_output="." />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
<Add directory="/usr/include" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add directory="/usr/include" />
</Compiler>
<Unit filename="main.cpp" />
<Extensions>
<code_completion>
<search_path add="/usr/include" />
</code_completion>
<envvars />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>
And here's main.cpp:
Code
#include <unistd.h>
#include <fcntl.h>

int main(int argc, char *argv[])
{
    int fdFile = open("/dev/urandom", O_RDONLY);
    close(fdFile);
    return 0;
}
Code completion as well as "Context Menu -> Find declaration of:" don't work on O_RDONLY. Both work OK however if I apply the modifications mentioned in the first post.

Manolo
Quote
Anyhow, why do you think your problem is related to C:B?
I'm gonna try to stay serious and ask, what else you think C::B parser problems could be related to.

Offline Manolo

  • Multiple posting newcomer
  • *
  • Posts: 47
Re: C/C++ parser ignores includes with minus
« Reply #4 on: October 28, 2015, 06:33:18 pm »
I copied & pasted your both files and tested them with C:B 13.12 (not nightly updates) in Ubuntu 14.04. Compilation and execution went smoothly. Also, O_RDONLY definition is found.

You may open a terminal and execute g++ -H main.cpp It will tell all included files. It this command fails, it's you gcc instalation, not C:B.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: C/C++ parser ignores includes with minus
« Reply #5 on: October 29, 2015, 12:45:34 am »
l_inc: By self-contained I've meant a project that doesn't depend on external files.

Manolo: Reread the first post, please.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline l_inc

  • Multiple posting newcomer
  • *
  • Posts: 56
Re: C/C++ parser ignores includes with minus
« Reply #6 on: October 29, 2015, 06:46:00 am »
oBFusCATed
Sorry, I misunderstood you. All dependencies are included in the attachment. Same situation there: O_RDONLY not resolved unless the minus replaced.

Manolo
I don't have any problems compiling the project. Neither from the console nor from CodeBlocks. In Ubuntu the header fcntl-linux.h is indeed resolved by the C::B parser. Unfortunately I killed my Ubuntu installation before checking how it works with the attached project.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: C/C++ parser ignores includes with minus
« Reply #7 on: October 29, 2015, 08:34:47 pm »
Still not minimal.
I can reproduce the problem.

ollydbg: Can you look at it?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline l_inc

  • Multiple posting newcomer
  • *
  • Posts: 56
Re: C/C++ parser ignores includes with minus
« Reply #8 on: October 29, 2015, 11:07:21 pm »
oBFusCATed
Quote
Still not minimal.
It's as minimal as I could get without taking a dive into the CodeBlocks source codes. I was unable to make the bug manifest in an artificial environment, so I decided to just cut it off the natural and hope it will behave deterministically.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: C/C++ parser ignores includes with minus
« Reply #9 on: November 09, 2015, 02:16:26 pm »
Still not minimal.
I can reproduce the problem.

ollydbg: Can you look at it?
A little late response, sorry.
I just download the achieve file, and unzip it, and open the cbp inside the nightly build(rev10553), and right click on the context menu of main.cpp, and I can correctly jump to the definition of macro O_RDONLY inside the file "include\bits\fcntl-linux.h", the mouse hover messages also shows the definitions, see image shot below:


So, It works fine here on my test environment.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline l_inc

  • Multiple posting newcomer
  • *
  • Posts: 56
Re: C/C++ parser ignores includes with minus
« Reply #10 on: November 09, 2015, 02:40:24 pm »
ollydbg
It works for me in Windows either. I even mentioned that I had not been able to make the bug manifest in Ubuntu, so I was glad oBFusCATed confirmed it was reproducible. I think the only way to fix this is to debug it myself. But... is there any reason to continue supporting the plugin anyway, considering there is a more stable, more functional and much easier to maintain alternative?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: C/C++ parser ignores includes with minus
« Reply #11 on: November 09, 2015, 02:58:21 pm »
ollydbg
It works for me in Windows either. I even mentioned that I had not been able to make the bug manifest in Ubuntu, so I was glad oBFusCATed confirmed it was reproducible. I think the only way to fix this is to debug it myself.
Debugging is not that hard, mainly, when you see a "#include xxxx" statement, you just call the "HandleInclude()" function inside the parser, and it should locate the "xxxx" file, and parse that included file.
The error mainly happens the file "xxxx" can't be found by CC, maybe, it does not know the search path?

Quote
But... is there any reason to continue supporting the plugin anyway, considering there is a more stable, more functional and much easier to maintain alternative?
If you looked a similar IDE(codelite), you will see it have two alternative cc engine, one is its native cc, and the other is the clang.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline l_inc

  • Multiple posting newcomer
  • *
  • Posts: 56
Re: C/C++ parser ignores includes with minus
« Reply #12 on: November 09, 2015, 04:47:35 pm »
ollydbg
Quote
Debugging is not that hard
Right. What's hard is to setup the environment with all those dependencies that need to be additionally compiled and installed. Btw. I've just overwrote my previous compilation just because I forgot to change the prefix, and spent some half an hour restoring it. Anyway, I can't reproduce the bug anymore. No idea, what made that happen. I did system update since then, installed many dependencies etc... could be anything.