Skip to content

core: debug: rely on optimizer to kick out unused debug code#5166

Merged
smlng merged 21 commits intoRIOT-OS:masterfrom
kaspar030:syntax_check_debug_code
Jan 15, 2018
Merged

core: debug: rely on optimizer to kick out unused debug code#5166
smlng merged 21 commits intoRIOT-OS:masterfrom
kaspar030:syntax_check_debug_code

Conversation

@kaspar030
Copy link
Copy Markdown
Contributor

This PR changes DEBUG to be enclosed in if (ENABLE_DEBUG) instead of being wiped by the preprocessor if unused. That way, all debug code is always compile-checked. With any optimization enabled, the code will still be eliminated if dead.

@kaspar030 kaspar030 added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: core Area: RIOT kernel. Handle PRs marked with this with care! labels Mar 24, 2016
@kaspar030
Copy link
Copy Markdown
Contributor Author

@OlegHahm I remember you were against this as you regularly compile with -O0 to debug?

@kaspar030 kaspar030 mentioned this pull request Mar 24, 2016
@kaspar030
Copy link
Copy Markdown
Contributor Author

Launching murdock to see if this would expose trouble...

@kaspar030 kaspar030 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Mar 24, 2016
@Yonezawa-T2
Copy link
Copy Markdown
Contributor

We may need to take care of #if ENABLE_DEBUG.

@kaspar030
Copy link
Copy Markdown
Contributor Author

We may need to take care of #if ENABLE_DEBUG.

Would that evaluate to true with ENABLE_DEBUG==0?

@Yonezawa-T2
Copy link
Copy Markdown
Contributor

For example, gnrc_ipv6.c declares temporary buffer to format IP address:

#if ENABLE_DEBUG
static char addr_str[IPV6_ADDR_MAX_STR_LEN];
#endif
                DEBUG("ipv6: set packet source to %s\n",
                      ipv6_addr_to_str(addr_str, src, sizeof(addr_str)));

So we have to change it to:

#if ENABLE_DEBUG
static char addr_str[IPV6_ADDR_MAX_STR_LEN];
#else
static char addr_str[1];
#endif

or enable zero size arrays and change it to:

#if ENABLE_DEBUG
static char addr_str[IPV6_ADDR_MAX_STR_LEN];
#else
static char addr_str[0];
#endif

or change it to allocate the buffer on the stack.

* @brief Extra stacksize needed when ENABLE_DEBUG==1
*/
#if ENABLE_DEBUG
#if ENABLE_DEBUG==1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superfluous?

@OlegHahm
Copy link
Copy Markdown
Member

@OlegHahm I remember you were against this as you regularly compile with -O0 to debug?

Oops, should have read this before. Well, yes, I guess everybody who's debugging is using -O0 quite often.

@Yonezawa-T2
Copy link
Copy Markdown
Contributor

How about this?

#ifdef ELIMINATE_DEBUG_COMPLETELY
#define DEBUG(...)
#else
#define DEBUG(...) if (ENABLE_DEBUG) DEBUG_PRINT(__VA_ARGS__)
#endif

[edit] Clang and GCC seems to eliminate if (0) { ... } at -O0 optimization level [/edit]

@kaspar030 kaspar030 added State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Mar 24, 2016
@miri64 miri64 modified the milestone: Release 2016.07 Mar 29, 2016
@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Jul 22, 2016

@kaspar030 can you retake this? Since WIP label is set I think it's better to put it in the next release.

@kYc0o kYc0o added this to the Release 2016.10 milestone Jul 25, 2016
@kaspar030 kaspar030 force-pushed the syntax_check_debug_code branch from bfeef9a to 1969dd4 Compare January 15, 2018 13:37
@kaspar030
Copy link
Copy Markdown
Contributor Author

  • squashed

@kaspar030
Copy link
Copy Markdown
Contributor Author

Sorry, I thought all #if ENABLEDEBUG should be replaced by if (ENABLE_DEBUG) like done here:

Actally, yes. But I propose going in steps. This PR makes all DEBUG() compile, and fixes all #if ENABLE_DEBUG where it caused errors. The others, we can do over time.

@smlng
Copy link
Copy Markdown
Member

smlng commented Jan 15, 2018

@cladmi are we good here, or do you have any doubts/comments? Otherwise, we should merge this.

@smlng
Copy link
Copy Markdown
Member

smlng commented Jan 15, 2018

Well then, ACK & GO!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: core Area: RIOT kernel. Handle PRs marked with this with care! CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.