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

New logging breaks eclipse #35286

Closed
xhpohanka opened this issue May 14, 2021 · 5 comments · Fixed by #35851
Closed

New logging breaks eclipse #35286

xhpohanka opened this issue May 14, 2021 · 5 comments · Fixed by #35851
Assignees
Labels
area: Logging bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@xhpohanka
Copy link
Contributor

Describe the bug
With recent changes in logging API (logging v2) using Eclipse IDE for zephyr projects is almost unpossible.
It could be an issue in eclipse parser but AFAIK it is not much maintained these days.

To Reproduce
Steps to reproduce the behavior:

  1. create an eclipse project west build -b MY_BOARD -- -G "Eclipse CDT4 - Ninja"
  2. insert multiple LOG_XXX statements
  3. see how eclipse is slow and lagging on most of editting

Additional context
After last cleanup for zephyr 2.6 eclipse states that it needs 674 steps to expand LOG_ERR macro and results with around 600 lines below.
With first commit where I noticed this behaviour (f1bb20f) there was even around 1900 expand steps and 2000 lines. It is regardless of which logging version is selected through Kconfig.
Originaly it was to about 70 lines.

do { \
	if (!(0 &&					    \
	((1U <= 0U) \
	||								    \
	((0 == 0) &&		    \
	(1U <= __log_level) &&					    \
	(1U <= 0U)				    \
	)								    \
	))) { \
		break; \
	} \
	if (0) { \
		do { \
	z_log_minimal_printk("%c: " "test" "\n", \
			     z_log_minimal_level_to_char(1U)); \
} while (0); \
		break; \
	} \
	\
	_Bool is_user_context = k_is_user_context(); \
	uint32_t filters = 0 ? \
						(__log_current_dynamic_data)->filters : 0;\
	if (0 && !is_user_context && \
	    1U > ((*(&filters) >> (3U * (0))) & ((1UL << (3U)) - 1U))) { \
		break; \
	} \
	if (0) { \
		int _mode; \
		void *_src = 0 ? \
			(void *)__log_current_dynamic_data : (void *)__log_current_const_data; \
		do { \
	; \
	if (({\
	_Pragma("GCC diagnostic push") \
	_Pragma("GCC diagnostic ignored \"-Wpointer-arith\"") \
	int _rv = 0; \
	_Pragma("GCC diagnostic pop")\
	_rv; \
})) { \
		;\
		z_log_msg2_runtime_create(0U, (void *)_src, \
					  1U, (uint8_t *)((void *)0), 0,\
					  "test");\
		_mode = Z_LOG_MSG2_MODE_RUNTIME; \
	} else if (0 && 1 && ((0) == 0)) {\
		;\
		do { \
	int _plen; \
	do { \
	_Pragma("GCC diagnostic push") \
	_Pragma("GCC diagnostic ignored \"-Wpointer-arith\"") \
	 \
	_Static_assert(!0 || \
		     (0 && \
		      !(sizeof(struct log_msg2_hdr) % (0 ? \
		sizeof(long double) : (((sizeof(double)) > (sizeof(long long))) ? (sizeof(double)) : (sizeof(long long)))))), "" "Xtensa requires aligned package."); \
	_Static_assert((sizeof(struct log_msg2_hdr) % sizeof(int)) == 0, "" "Alignment offset must be multiply of a word."); \
	if (0) { \
		{ }; \
	} \
	uint8_t *_pbuf = ((void *)0); \
	size_t _pmax = (((void *)0) != ((void *)0)) ? 0 : __INT32_MAX__; \
	int _pkg_len = 0; \
	int _pkg_offset = sizeof(struct log_msg2_hdr); \
	union z_cbprintf_hdr *_len_loc; \
	/* package starts with string address and field with length */ \
	if (_pmax < sizeof(union z_cbprintf_hdr)) { \
		_plen = -28; \
		break; \
	} \
	_len_loc = (union z_cbprintf_hdr *)_pbuf; \
	_pkg_len += sizeof(union z_cbprintf_hdr); \
	_pkg_offset += sizeof(union z_cbprintf_hdr); \
	/* Pack remaining arguments */\
	do { \
	_Static_assert(!((sizeof(double) < (((8) > (__alignof__(long double))) ? (8) : (__alignof__(long double)))) && \
			_Generic(("test") + 0, long double : 1, default : 0) && \
			!0), "" "Packaging of long double not enabled in Kconfig."); \
	while (_pkg_offset % (((_Generic(("test") + 0, \
		float : (((8) > (__alignof__(double))) ? (8) : (__alignof__(double))), \
		double : (((8) > (__alignof__(double))) ? (8) : (__alignof__(double))), \
		long double : (((8) > (__alignof__(long double))) ? (8) : (__alignof__(long double))), \
		long long : (((8) > (__alignof__(long long))) ? (8) : (__alignof__(long long))), \
		unsigned long long : (((8) > (__alignof__(long long))) ? (8) : (__alignof__(long long))), \
		default : \
			__alignof__(("test") + 0))) > (8)) ? (_Generic(("test") + 0, \
		float : (((8) > (__alignof__(double))) ? (8) : (__alignof__(double))), \
		double : (((8) > (__alignof__(double))) ? (8) : (__alignof__(double))), \
		long double : (((8) > (__alignof__(long double))) ? (8) : (__alignof__(long double))), \
		long long : (((8) > (__alignof__(long long))) ? (8) : (__alignof__(long long))), \
		unsigned long long : (((8) > (__alignof__(long long))) ? (8) : (__alignof__(long long))), \
		default : \
			__alignof__(("test") + 0))) : (8))) { \
		_pkg_len += sizeof(int); \
		_pkg_offset += sizeof(int); \
	} \
	uint32_t _arg_size = ({\
	__auto_type _v = ("test") + 0; \
	size_t _arg_size = _Generic(("test"), \
		float : sizeof(double), \
		default : \
			sizeof((_v)) \
		); \
	_arg_size; \
}); \
	if (_pbuf && _pkg_len < (int)_pmax) { \
		do { \
	if (0) { \
		/* If required, copy arguments by word to avoid unaligned access.*/ \
		__auto_type _v = ("test") + 0; \
		double _d = _Generic(("test") + 0, \
				float : ("test") + 0, \
				default : \
					0.0); \
		size_t arg_size = ({\
	__auto_type _v = ("test") + 0; \
	size_t _arg_size = _Generic(("test"), \
		float : sizeof(double), \
		default : \
			sizeof((_v)) \
		); \
	_arg_size; \
}); \
		size_t _wsize = arg_size / sizeof(int); \
		z_cbprintf_wcpy((int *)&_pbuf[_pkg_len], \
			      (int *) _Generic(("test") + 0, float : &_d, default : &_v), \
			      _wsize); \
	} else { \
		*_Generic(("test") + 0, \
			char : (int *)&_pbuf[_pkg_len], \
			unsigned char: (int *)&_pbuf[_pkg_len], \
			short : (int *)&_pbuf[_pkg_len], \
			unsigned short : (int *)&_pbuf[_pkg_len], \
			int : (int *)&_pbuf[_pkg_len], \
			unsigned int : (unsigned int *)&_pbuf[_pkg_len], \
			long : (long *)&_pbuf[_pkg_len], \
			unsigned long : (unsigned long *)&_pbuf[_pkg_len], \
			long long : (long long *)&_pbuf[_pkg_len], \
			unsigned long long : (unsigned long long *)&_pbuf[_pkg_len], \
			float : (double *)&_pbuf[_pkg_len], \
			double : (double *)&_pbuf[_pkg_len], \
			long double : (long double *)&_pbuf[_pkg_len], \
			default : \
				(const void **)&_pbuf[_pkg_len]) = "test"; \
	} \
} while (0); \
	} \
	_pkg_len += _arg_size; \
	_pkg_offset += _arg_size; \
} while (0);\
	/* Store length */ \
	_plen = (_pkg_len > (int)_pmax) ? -28 : _pkg_len; \
	/* Store length in the header, set number of dumped strings to 0 */ \
	if (_pbuf) { \
		union z_cbprintf_hdr hdr = { \
			.desc = {.len = (uint8_t)(_pkg_len / sizeof(int)) } \
		}; \
		*_len_loc = hdr; \
	} \
	_Pragma("GCC diagnostic pop") \
} while (0); \
	size_t _msg_wlen = ((((((unsigned long)((sizeof(struct log_msg2_hdr) + _plen + (0))) + ((unsigned long)((0 ? \
		sizeof(long double) : (((sizeof(double)) > (sizeof(long long))) ? (sizeof(double)) : (sizeof(long long))))) - 1)) & \
	 ~((unsigned long)((0 ? \
		sizeof(long double) : (((sizeof(double)) > (sizeof(long long))) ? (sizeof(double)) : (sizeof(long long))))) - 1))) + ((sizeof(uint32_t)) - 1)) / (sizeof(uint32_t))); \
	struct log_msg2 *_msg = z_log_msg2_alloc(_msg_wlen); \
	struct log_msg2_desc _desc = \
		{ \
	.type = 0, \
	.domain = 0U, \
	.level = 1U, \
	.package_len = (uint32_t)_plen, \
	.data_len = 0, \
}; \
	; \
	if (_msg) { \
		do { \
	_Pragma("GCC diagnostic push") \
	_Pragma("GCC diagnostic ignored \"-Wpointer-arith\"") \
	 \
	_Static_assert(!0 || \
		     (0 && \
		      !(sizeof(struct log_msg2_hdr) % (0 ? \
		sizeof(long double) : (((sizeof(double)) > (sizeof(long long))) ? (sizeof(double)) : (sizeof(long long)))))), "" "Xtensa requires aligned package."); \
	_Static_assert((sizeof(struct log_msg2_hdr) % sizeof(int)) == 0, "" "Alignment offset must be multiply of a word."); \
	if (0) { \
		{ }; \
	} \
	uint8_t *_pbuf = _msg->data; \
	size_t _pmax = (_msg->data != ((void *)0)) ? _plen : __INT32_MAX__; \
	int _pkg_len = 0; \
	int _pkg_offset = sizeof(struct log_msg2_hdr); \
	union z_cbprintf_hdr *_len_loc; \
	/* package starts with string address and field with length */ \
	if (_pmax < sizeof(union z_cbprintf_hdr)) { \
		_plen = -28; \
		break; \
	} \
	_len_loc = (union z_cbprintf_hdr *)_pbuf; \
	_pkg_len += sizeof(union z_cbprintf_hdr); \
	_pkg_offset += sizeof(union z_cbprintf_hdr); \
	/* Pack remaining arguments */\
	do { \
	_Static_assert(!((sizeof(double) < (((8) > (__alignof__(long double))) ? (8) : (__alignof__(long double)))) && \
			_Generic(("test") + 0, long double : 1, default : 0) && \
			!0), "" "Packaging of long double not enabled in Kconfig."); \
	while (_pkg_offset % (((_Generic(("test") + 0, \
		float : (((8) > (__alignof__(double))) ? (8) : (__alignof__(double))), \
		double : (((8) > (__alignof__(double))) ? (8) : (__alignof__(double))), \
		long double : (((8) > (__alignof__(long double))) ? (8) : (__alignof__(long double))), \
		long long : (((8) > (__alignof__(long long))) ? (8) : (__alignof__(long long))), \
		unsigned long long : (((8) > (__alignof__(long long))) ? (8) : (__alignof__(long long))), \
		default : \
			__alignof__(("test") + 0))) > (8)) ? (_Generic(("test") + 0, \
		float : (((8) > (__alignof__(double))) ? (8) : (__alignof__(double))), \
		double : (((8) > (__alignof__(double))) ? (8) : (__alignof__(double))), \
		long double : (((8) > (__alignof__(long double))) ? (8) : (__alignof__(long double))), \
		long long : (((8) > (__alignof__(long long))) ? (8) : (__alignof__(long long))), \
		unsigned long long : (((8) > (__alignof__(long long))) ? (8) : (__alignof__(long long))), \
		default : \
			__alignof__(("test") + 0))) : (8))) { \
		_pkg_len += sizeof(int); \
		_pkg_offset += sizeof(int); \
	} \
	uint32_t _arg_size = ({\
	__auto_type _v = ("test") + 0; \
	size_t _arg_size = _Generic(("test"), \
		float : sizeof(double), \
		default : \
			sizeof((_v)) \
		); \
	_arg_size; \
}); \
	if (_pbuf && _pkg_len < (int)_pmax) { \
		do { \
	if (0) { \
		/* If required, copy arguments by word to avoid unaligned access.*/ \
		__auto_type _v = ("test") + 0; \
		double _d = _Generic(("test") + 0, \
				float : ("test") + 0, \
				default : \
					0.0); \
		size_t arg_size = ({\
	__auto_type _v = ("test") + 0; \
	size_t _arg_size = _Generic(("test"), \
		float : sizeof(double), \
		default : \
			sizeof((_v)) \
		); \
	_arg_size; \
}); \
		size_t _wsize = arg_size / sizeof(int); \
		z_cbprintf_wcpy((int *)&_pbuf[_pkg_len], \
			      (int *) _Generic(("test") + 0, float : &_d, default : &_v), \
			      _wsize); \
	} else { \
		*_Generic(("test") + 0, \
			char : (int *)&_pbuf[_pkg_len], \
			unsigned char: (int *)&_pbuf[_pkg_len], \
			short : (int *)&_pbuf[_pkg_len], \
			unsigned short : (int *)&_pbuf[_pkg_len], \
			int : (int *)&_pbuf[_pkg_len], \
			unsigned int : (unsigned int *)&_pbuf[_pkg_len], \
			long : (long *)&_pbuf[_pkg_len], \
			unsigned long : (unsigned long *)&_pbuf[_pkg_len], \
			long long : (long long *)&_pbuf[_pkg_len], \
			unsigned long long : (unsigned long long *)&_pbuf[_pkg_len], \
			float : (double *)&_pbuf[_pkg_len], \
			double : (double *)&_pbuf[_pkg_len], \
			long double : (long double *)&_pbuf[_pkg_len], \
			default : \
				(const void **)&_pbuf[_pkg_len]) = "test"; \
	} \
} while (0); \
	} \
	_pkg_len += _arg_size; \
	_pkg_offset += _arg_size; \
} while (0);\
	/* Store length */ \
	_plen = (_pkg_len > (int)_pmax) ? -28 : _pkg_len; \
	/* Store length in the header, set number of dumped strings to 0 */ \
	if (_pbuf) { \
		union z_cbprintf_hdr hdr = { \
			.desc = {.len = (uint8_t)(_pkg_len / sizeof(int)) } \
		}; \
		*_len_loc = hdr; \
	} \
	_Pragma("GCC diagnostic pop") \
} while (0); \
	} \
	z_log_msg2_finalize(_msg, (void *)_src, _desc, ((void *)0)); \
} while (0); \
		_mode = Z_LOG_MSG2_MODE_ZERO_COPY; \
	} else { \
		;\
		do { \
	int _plen; \
	if ("test" == ((void *)0)) { \
		_plen = 0; \
	} else { \
		do { \
	_Pragma("GCC diagnostic push") \
	_Pragma("GCC diagnostic ignored \"-Wpointer-arith\"") \
	 \
	_Static_assert(!0 || \
		     (0 && \
		      !(sizeof(struct log_msg2_hdr) % (0 ? \
		sizeof(long double) : (((sizeof(double)) > (sizeof(long long))) ? (sizeof(double)) : (sizeof(long long)))))), "" "Xtensa requires aligned package."); \
	_Static_assert((sizeof(struct log_msg2_hdr) % sizeof(int)) == 0, "" "Alignment offset must be multiply of a word."); \
	if (0) { \
		{ }; \
	} \
	uint8_t *_pbuf = ((void *)0); \
	size_t _pmax = (((void *)0) != ((void *)0)) ? 0 : __INT32_MAX__; \
	int _pkg_len = 0; \
	int _pkg_offset = sizeof(struct log_msg2_hdr); \
	union z_cbprintf_hdr *_len_loc; \
	/* package starts with string address and field with length */ \
	if (_pmax < sizeof(union z_cbprintf_hdr)) { \
		_plen = -28; \
		break; \
	} \
	_len_loc = (union z_cbprintf_hdr *)_pbuf; \
	_pkg_len += sizeof(union z_cbprintf_hdr); \
	_pkg_offset += sizeof(union z_cbprintf_hdr); \
	/* Pack remaining arguments */\
	do { \
	_Static_assert(!((sizeof(double) < (((8) > (__alignof__(long double))) ? (8) : (__alignof__(long double)))) && \
			_Generic(("test") + 0, long double : 1, default : 0) && \
			!0), "" "Packaging of long double not enabled in Kconfig."); \
	while (_pkg_offset % (((_Generic(("test") + 0, \
		float : (((8) > (__alignof__(double))) ? (8) : (__alignof__(double))), \
		double : (((8) > (__alignof__(double))) ? (8) : (__alignof__(double))), \
		long double : (((8) > (__alignof__(long double))) ? (8) : (__alignof__(long double))), \
		long long : (((8) > (__alignof__(long long))) ? (8) : (__alignof__(long long))), \
		unsigned long long : (((8) > (__alignof__(long long))) ? (8) : (__alignof__(long long))), \
		default : \
			__alignof__(("test") + 0))) > (8)) ? (_Generic(("test") + 0, \
		float : (((8) > (__alignof__(double))) ? (8) : (__alignof__(double))), \
		double : (((8) > (__alignof__(double))) ? (8) : (__alignof__(double))), \
		long double : (((8) > (__alignof__(long double))) ? (8) : (__alignof__(long double))), \
		long long : (((8) > (__alignof__(long long))) ? (8) : (__alignof__(long long))), \
		unsigned long long : (((8) > (__alignof__(long long))) ? (8) : (__alignof__(long long))), \
		default : \
			__alignof__(("test") + 0))) : (8))) { \
		_pkg_len += sizeof(int); \
		_pkg_offset += sizeof(int); \
	} \
	uint32_t _arg_size = ({\
	__auto_type _v = ("test") + 0; \
	size_t _arg_size = _Generic(("test"), \
		float : sizeof(double), \
		default : \
			sizeof((_v)) \
		); \
	_arg_size; \
}); \
	if (_pbuf && _pkg_len < (int)_pmax) { \
		do { \
	if (0) { \
		/* If required, copy arguments by word to avoid unaligned access.*/ \
		__auto_type _v = ("test") + 0; \
		double _d = _Generic(("test") + 0, \
				float : ("test") + 0, \
				default : \
					0.0); \
		size_t arg_size = ({\
	__auto_type _v = ("test") + 0; \
	size_t _arg_size = _Generic(("test"), \
		float : sizeof(double), \
		default : \
			sizeof((_v)) \
		); \
	_arg_size; \
}); \
		size_t _wsize = arg_size / sizeof(int); \
		z_cbprintf_wcpy((int *)&_pbuf[_pkg_len], \
			      (int *) _Generic(("test") + 0, float : &_d, default : &_v), \
			      _wsize); \
	} else { \
		*_Generic(("test") + 0, \
			char : (int *)&_pbuf[_pkg_len], \
			unsigned char: (int *)&_pbuf[_pkg_len], \
			short : (int *)&_pbuf[_pkg_len], \
			unsigned short : (int *)&_pbuf[_pkg_len], \
			int : (int *)&_pbuf[_pkg_len], \
			unsigned int : (unsigned int *)&_pbuf[_pkg_len], \
			long : (long *)&_pbuf[_pkg_len], \
			unsigned long : (unsigned long *)&_pbuf[_pkg_len], \
			long long : (long long *)&_pbuf[_pkg_len], \
			unsigned long long : (unsigned long long *)&_pbuf[_pkg_len], \
			float : (double *)&_pbuf[_pkg_len], \
			double : (double *)&_pbuf[_pkg_len], \
			long double : (long double *)&_pbuf[_pkg_len], \
			default : \
				(const void **)&_pbuf[_pkg_len]) = "test"; \
	} \
} while (0); \
	} \
	_pkg_len += _arg_size; \
	_pkg_offset += _arg_size; \
} while (0);\
	/* Store length */ \
	_plen = (_pkg_len > (int)_pmax) ? -28 : _pkg_len; \
	/* Store length in the header, set number of dumped strings to 0 */ \
	if (_pbuf) { \
		union z_cbprintf_hdr hdr = { \
			.desc = {.len = (uint8_t)(_pkg_len / sizeof(int)) } \
		}; \
		*_len_loc = hdr; \
	} \
	_Pragma("GCC diagnostic pop") \
} while (0); \
	} \
	struct log_msg2 *_msg; \
	long long _ll_buf32[32 / sizeof(long long)]; \
	long long _ll_buf48[48 / sizeof(long long)]; \
	long long _ll_buf64[64 / sizeof(long long)]; \
	long long _ll_buf128[128 / sizeof(long long)]; \
	long long _ll_buf256[256 / sizeof(long long)]; \
	long double _ld_buf32[32 / sizeof(long double)]; \
	long double _ld_buf48[48 / sizeof(long double)]; \
	long double _ld_buf64[64 / sizeof(long double)]; \
	long double _ld_buf128[128 / sizeof(long double)]; \
	long double _ld_buf256[256 / sizeof(long double)]; \
	if (sizeof(long double) == (0 ? \
		sizeof(long double) : (((sizeof(double)) > (sizeof(long long))) ? (sizeof(double)) : (sizeof(long long))))) { \
		_msg = ((sizeof(struct log_msg2_hdr) + _plen + (0)) > 128) ? (struct log_msg2 *)_ld_buf256 : \
			(((sizeof(struct log_msg2_hdr) + _plen + (0)) > 64) ? (struct log_msg2 *)_ld_buf128 : \
			(((sizeof(struct log_msg2_hdr) + _plen + (0)) > 48) ? (struct log_msg2 *)_ld_buf64 : \
			(((sizeof(struct log_msg2_hdr) + _plen + (0)) > 32) ? (struct log_msg2 *)_ld_buf48 : \
				      (struct log_msg2 *)_ld_buf32)));\
	} else { \
		_msg = ((sizeof(struct log_msg2_hdr) + _plen + (0)) > 128) ? (struct log_msg2 *)_ll_buf256 : \
			(((sizeof(struct log_msg2_hdr) + _plen + (0)) > 64) ? (struct log_msg2 *)_ll_buf128 : \
			(((sizeof(struct log_msg2_hdr) + _plen + (0)) > 48) ? (struct log_msg2 *)_ll_buf64 : \
			(((sizeof(struct log_msg2_hdr) + _plen + (0)) > 32) ? (struct log_msg2 *)_ll_buf48 : \
				      (struct log_msg2 *)_ll_buf32)));\
	} \
	if (0) { \
		/* During test fill with 0's to simplify message comparison */ \
		memset(_msg, 0, (sizeof(struct log_msg2_hdr) + _plen + (0))); \
	}; \
	if (_plen) { \
		do { \
	_Pragma("GCC diagnostic push") \
	_Pragma("GCC diagnostic ignored \"-Wpointer-arith\"") \
	 \
	_Static_assert(!0 || \
		     (0 && \
		      !(sizeof(struct log_msg2_hdr) % (0 ? \
		sizeof(long double) : (((sizeof(double)) > (sizeof(long long))) ? (sizeof(double)) : (sizeof(long long)))))), "" "Xtensa requires aligned package."); \
	_Static_assert((sizeof(struct log_msg2_hdr) % sizeof(int)) == 0, "" "Alignment offset must be multiply of a word."); \
	if (0) { \
		{ }; \
	} \
	uint8_t *_pbuf = _msg->data; \
	size_t _pmax = (_msg->data != ((void *)0)) ? _plen : __INT32_MAX__; \
	int _pkg_len = 0; \
	int _pkg_offset = sizeof(struct log_msg2_hdr); \
	union z_cbprintf_hdr *_len_loc; \
	/* package starts with string address and field with length */ \
	if (_pmax < sizeof(union z_cbprintf_hdr)) { \
		_plen = -28; \
		break; \
	} \
	_len_loc = (union z_cbprintf_hdr *)_pbuf; \
	_pkg_len += sizeof(union z_cbprintf_hdr); \
	_pkg_offset += sizeof(union z_cbprintf_hdr); \
	/* Pack remaining arguments */\
	do { \
	_Static_assert(!((sizeof(double) < (((8) > (__alignof__(long double))) ? (8) : (__alignof__(long double)))) && \
			_Generic(("test") + 0, long double : 1, default : 0) && \
			!0), "" "Packaging of long double not enabled in Kconfig."); \
	while (_pkg_offset % (((_Generic(("test") + 0, \
		float : (((8) > (__alignof__(double))) ? (8) : (__alignof__(double))), \
		double : (((8) > (__alignof__(double))) ? (8) : (__alignof__(double))), \
		long double : (((8) > (__alignof__(long double))) ? (8) : (__alignof__(long double))), \
		long long : (((8) > (__alignof__(long long))) ? (8) : (__alignof__(long long))), \
		unsigned long long : (((8) > (__alignof__(long long))) ? (8) : (__alignof__(long long))), \
		default : \
			__alignof__(("test") + 0))) > (8)) ? (_Generic(("test") + 0, \
		float : (((8) > (__alignof__(double))) ? (8) : (__alignof__(double))), \
		double : (((8) > (__alignof__(double))) ? (8) : (__alignof__(double))), \
		long double : (((8) > (__alignof__(long double))) ? (8) : (__alignof__(long double))), \
		long long : (((8) > (__alignof__(long long))) ? (8) : (__alignof__(long long))), \
		unsigned long long : (((8) > (__alignof__(long long))) ? (8) : (__alignof__(long long))), \
		default : \
			__alignof__(("test") + 0))) : (8))) { \
		_pkg_len += sizeof(int); \
		_pkg_offset += sizeof(int); \
	} \
	uint32_t _arg_size = ({\
	__auto_type _v = ("test") + 0; \
	size_t _arg_size = _Generic(("test"), \
		float : sizeof(double), \
		default : \
			sizeof((_v)) \
		); \
	_arg_size; \
}); \
	if (_pbuf && _pkg_len < (int)_pmax) { \
		do { \
	if (0) { \
		/* If required, copy arguments by word to avoid unaligned access.*/ \
		__auto_type _v = ("test") + 0; \
		double _d = _Generic(("test") + 0, \
				float : ("test") + 0, \
				default : \
					0.0); \
		size_t arg_size = ({\
	__auto_type _v = ("test") + 0; \
	size_t _arg_size = _Generic(("test"), \
		float : sizeof(double), \
		default : \
			sizeof((_v)) \
		); \
	_arg_size; \
}); \
		size_t _wsize = arg_size / sizeof(int); \
		z_cbprintf_wcpy((int *)&_pbuf[_pkg_len], \
			      (int *) _Generic(("test") + 0, float : &_d, default : &_v), \
			      _wsize); \
	} else { \
		*_Generic(("test") + 0, \
			char : (int *)&_pbuf[_pkg_len], \
			unsigned char: (int *)&_pbuf[_pkg_len], \
			short : (int *)&_pbuf[_pkg_len], \
			unsigned short : (int *)&_pbuf[_pkg_len], \
			int : (int *)&_pbuf[_pkg_len], \
			unsigned int : (unsigned int *)&_pbuf[_pkg_len], \
			long : (long *)&_pbuf[_pkg_len], \
			unsigned long : (unsigned long *)&_pbuf[_pkg_len], \
			long long : (long long *)&_pbuf[_pkg_len], \
			unsigned long long : (unsigned long long *)&_pbuf[_pkg_len], \
			float : (double *)&_pbuf[_pkg_len], \
			double : (double *)&_pbuf[_pkg_len], \
			long double : (long double *)&_pbuf[_pkg_len], \
			default : \
				(const void **)&_pbuf[_pkg_len]) = "test"; \
	} \
} while (0); \
	} \
	_pkg_len += _arg_size; \
	_pkg_offset += _arg_size; \
} while (0);\
	/* Store length */ \
	_plen = (_pkg_len > (int)_pmax) ? -28 : _pkg_len; \
	/* Store length in the header, set number of dumped strings to 0 */ \
	if (_pbuf) { \
		union z_cbprintf_hdr hdr = { \
			.desc = {.len = (uint8_t)(_pkg_len / sizeof(int)) } \
		}; \
		*_len_loc = hdr; \
	} \
	_Pragma("GCC diagnostic pop") \
} while (0);\
	} \
	struct log_msg2_desc _desc = \
		{ \
	.type = 0, \
	.domain = 0U, \
	.level = 1U, \
	.package_len = (uint32_t)_plen, \
	.data_len = 0, \
}; \
	; \
	z_log_msg2_static_create((void *)_src, _desc, _msg->data, ((void *)0)); \
} while (0); \
		_mode = Z_LOG_MSG2_MODE_FROM_STACK; \
	} \
	(void)_mode; \
} while (0); \
	} else { \
		do { \
	uint16_t src_id = \
		0 ? \
		0 : 0; \
	struct log_msg_ids src_level = { \
		.level = 1U, \
		.domain_id = 0U, \
		.source_id = src_id \
	}; \
	do { \
	if (is_user_context) { \
		log_from_user(src_level, "test"); \
	} else if (0) { \
		log_string_sync(src_level, "test"); \
	} else { \
		log_0("test", src_level); \
	} \
} while (0); \
} while (0);\
	} \
	if (0) { \
		/* Arguments checker present but never evaluated.*/ \
		/* Placed here to ensure that __VA_ARGS__ are*/ \
		/* evaluated once when log is enabled.*/ \
		z_log_printf_arg_checker("test"); \
	} \
} while (0)
@xhpohanka xhpohanka added the bug The issue is a bug, or the PR is fixing a bug label May 14, 2021
@xhpohanka
Copy link
Contributor Author

as a quick workaround allowing me to work I have inserted this hack at the bottom of logging/log.h

#if defined(__CDT_PARSER__)
#undef LOG_ERR
#undef LOG_WRN
#undef LOG_INF
#undef LOG_DBG

#undef LOG_HEXDUMP_ERR
#undef LOG_HEXDUMP_WRN
#undef LOG_HEXDUMP_INF
#undef LOG_HEXDUMP_DBG

#define LOG_ERR(...) (void) 0
#define LOG_WRN(...) (void) 0
#define LOG_DBG(...) (void) 0
#define LOG_INF(...) (void) 0

#define LOG_HEXDUMP_ERR(...) (void) 0
#define LOG_HEXDUMP_WRN(...) (void) 0
#define LOG_HEXDUMP_DBG(...) (void) 0
#define LOG_HEXDUMP_INF(...) (void) 0
#endif

@galak
Copy link
Collaborator

galak commented May 18, 2021

@xhpohanka can you send a PR with this proposed fix.

@galak galak added the priority: low Low impact/importance bug label May 18, 2021
@xhpohanka
Copy link
Contributor Author

I can, but it's more a workaround than a fix.

@nordic-krch can you please confirm, that the example of expanded code in eclipse is somewhat expected?

@nordic-krch
Copy link
Contributor

@xhpohanka it is expected that logging macros expands in multiple steps, there are macros applied for each argument in the macro message so if this is a problem for eclipse parser then the best would be to suppress that with what you proposed with additional comment explaining why it is being done.

@galak
Copy link
Collaborator

galak commented Jun 1, 2021

@xhpohanka ping on sending a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Logging bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants