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

Passing Defines during generation #3

Closed
sebirdman opened this issue Jul 17, 2019 · 2 comments
Closed

Passing Defines during generation #3

sebirdman opened this issue Jul 17, 2019 · 2 comments

Comments

@sebirdman
Copy link
Contributor

sebirdman commented Jul 17, 2019

Hello,

First off, thanks so much for this! this is a fantastic project!

I'm running into an issue with some includes where generation fails becuase something is not defined.

for example. from list.h in FreeRTOS:

#ifndef INC_FREERTOS_H
	#error FreeRTOS.h must be included before list.h
#endif

Is there any way i can pass defines into the generator?

@sebirdman
Copy link
Contributor Author

wow i'm blind

-D exists

@ChiefGokhlayeh
Copy link
Owner

ChiefGokhlayeh commented Jul 17, 2019

FreeRTOS has a somewhat nasty include policy which forces us to include FreeRTOS.h before ever attempting to include any other FreeRTOS header file.

When compiling C files this is barely an issue (just put the #include <FreeRTOS.h> before #include <list.h>.

But I guess you're facing a different kind of issue:

The current autofff gcc-scanner works by looking at an individual header file and then trying to extract all function declarations. We essentially run the gcc preprocessor per header, which should work fine for the average API header but FreeRTOS' include policy may ruin this per-file approach.
Let's say autofff is tasked with parsing list.h, so in order to get all the function declarations we run the gcc preprocessor on list.h with all the necessary includes needed for that header to be happy (${FREERTOS_DIR}/portable/GCC/MemMang ${FREERTOS_DIR}/include and usually some ${APP_DIR}/config, which contains FreeRTOSConfig.h). Now mind that we are not preprocessing a C file which does the required #include <FreeRTOS> business beforehand. If list.h doesn't include FreeRTOS.h itself, we're screwed. That's why the preprocessing fails for most FreeRTOS headers.
The underlying issue is the reliance on the header to be preprocessable without requiring any obscure include hierarchy. I encountered these issues with a few libs so far (FreeRTOS, CMSIS, ASFLib).

Now, don't think I'm trying to talk bad about any of these cases, it simply makes the job of automatically and reliably faking/mocking incredibly hard.

One workaround I included for cases like these is the ability to inject a list of header files before the target header is preprocessed. Check out the -i or --includefile flag, it might help with some of these cases. For FreeRTOS you could probably run autofff like this:

python3 -m autofff
    [...]/include/list.h
    -o [...]
    -i [...]/include/FreeRTOS.h <<< inject FreeRTOS.h before preprocessing list.h
    -F [...]

Alternatively, as you stated, you could just fake the include check by passing -D INC_FREERTOS_H to autofff.

I plan on adding an alternative parser which should be able to parse for function declarations using objdump, the map-file or other compiler generated metadata apart from just relying on source-code. I might also look into clang/llvm instead of pycparser (which can't handle __asm__ directives btw ... very annoying in embedded code!).

We'll see when I get around to look into all these possibilities... :)

Your feedback is very much welcome!

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

No branches or pull requests

2 participants