Smoke Screen in Eclipse IDE

Firmware is often written in Eclipse. The main reason is that Eclipse IDE free.

Eclipse has a feature called smokescreen for unused preprocessor macros. Supposedly, what is not used in the code becomes a gray zone of alienation.

When the HAS_WATCHDOG macro is not defined, the smoke screen is present.

Eclipse smoke screen in action

Eclipse smoke screen in action

When the macro is defined, the haze disappears (HAS_I2C, HAS_I2S)

What's the problem?

The problem is that if you build a project with self-written make scripts and do not use the build from Eclipse plugins, i.e. do not use the mouse to write macros in the project settings, then the Eclipse text editor does not see a single macro. Everything becomes gray.

This is the argument that the huge fun base of Eclipse plugins cites as the main one for Eclipse plugins. They cite this notorious gray haze of macro highlighting as the main advantage in choosing a build system! Yes, gentlemen. That's right.

Allegedly, what is not used in the code becomes a gray area. And therefore, it is necessary to compile the code from Eclipse plugins.

However, this haze can be controlled from make scripts. Now I will show you exactly how.

Statement of the problem

It is necessary to make the macro haze work correctly in the Eclipse text editor. At the same time, the sources themselves must be assembled from Make scripts written by yourself.

What's the plan?

1–We need to somehow automatically generate a *.h file that will contain a list of all macro definitions for a given assembly. Let's call it c_defines_generated.hwhich were passed via the -D options in make scripts to the gcc compiler.

2–In a complex file filled with macros, you need to insert a line

#include "c_defines_generated.h"

to check the macro highlighting.

Implementation

What software do you need?

Utility

Purpose

Address

make

software pipeline management utility

C:\cygwin64\bin\make.exe

cpp

utility for inserting and automatically replacing text in text files

C:\cygwin64\bin\cpp.exe

eclipse

Java Virtual Machine based text editor

C:\eclipse\eclipse.exe

sort

Utility for sorting text strings

C:\cygwin64\bin\sort.exe

In my make scripts all macros are dumped into an environment variable CPP_FLAGS. It is necessary that the macro definitions are somehow crystallized later in one separate *.h file.

OPT += -DHAS_CLOCK
....
CSTANDARD = -std=c99
CPP_FLAGS += $(CSTANDARD) $(INCDIR)  $(OPT)

For this to happen, you need to pay attention to the following two options of the console utility of the preprocessor cpp.exe

cpp utility option

Option assignment

Option assignment

-E

Preprocess only; do not compile, assemble or link.

Only preprocessor should work. Do not compile or link.

-dM

Instead of the normal output, generate a list of '#define' directives for all the macros defined during the execution of the preprocessor, including predefined macros. This gives you a way of finding out what is predefined in your version of the preprocessor.

Generate a macro list for all macros defined during preprocessor execution. This gives you a way to find out what is predefined in your version of the preprocessor.

Now it is clear that we need to program such a pipeline. Create an empty file empty_source.c and run it through the preprocessor with debugging keys.

Here is a complete make script to generate a list of all macro definitions as a single target generate_definitions. This goal can be easily embedded into a general build script.

.PHONY: generate_definitions

generate_definitions:
	$(info GenerateDefinitions...)
	$(PREPROCESSOR_TOOL) $(CPP_FLAGS) $(WORKSPACE_LOC)empty_sourse.c -dM -E> c_defines_generated.h
	$(SORTER_TOOL) -u c_defines_generated.h -o c_defines_generated.h

After generating the list of macros, it would be a good idea to sort it. For clarity. This is done by the console utility sort.exe with the -u key. You will get a header file like this c_defines_generated.h

Hidden text
#define AT32F435ZM 1
#define AT32F435ZMT7 1

#define HAS_AT32F435ZM 1
#define HAS_AUDIO 1
#define HAS_BIN_2_STR 1
#define HAS_BIT_SWAP 1
#define HAS_BOARD 1
#define HAS_BOARD_CUSTOM 1
#define HAS_BOARD_CUSTOM_COMMANDS 1

#define HAS_HEALTH_MONITOR_PROC 1
#define HAS_HEAP 1
#define HAS_HW_TESTS 1
#define HAS_I2C 1
#define HAS_I2C2 1

...
#define __UINT16_MAX__ 0xffff
#define __UINT16_TYPE__ short unsigned int
#define __UINT32_C(c) c ## UL
#define __UINT32_MAX__ 0xffffffffUL
#define __UINT32_TYPE__ long unsigned int
#define __UINT64_C(c) c ## ULL
#d
#define __UINT_FAST8_TYPE__ unsigned int
#define __UINT_LEAST16_MAX__ 0xffff
#define __UINT_LEAST16_TYPE__ short unsigned int
#define __UINT_LEAST32_MAX__ 0xffffffffUL
#define __UINT_LEAST32_TYPE__ long unsigned int
#define __UINT_LEAST64_MAX__ 0xffffffffffffffffULL
#define __UINT_LEAST64_TYPE__ long long unsigned int
#define __UINT_LEAST8_MAX__ 0xff
#define __UINT_LEAST8_TYPE__ unsigned char

#define __WCHAR_WIDTH__ 32
#define __WINT_MAX__ 0xffffffffU
#define __WINT_MIN__ 0U
#define __WINT_TYPE__ unsigned int
#define __WINT_WIDTH__ 32
#define __arm__ 1

All that remains is to add one line #include “c_defines_generated.h” and the highlighting will turn on. Success!

Results

As you can see, the build from make is so flexible that you are limited only by your imagination. You can not only build the code, but also automatically synthesize a list for syntax highlighting.

I hope this text will help other programmers to improve their tools as well.

Dictionary

Acronym

Transcript

CPP

The C PreProcessor

GCC

GNU Compiler Collection

Links

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *