Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-16665

Use "Include What You Use" tool

XMLWordPrintable

    • 1

      Include What You Use is a clang-based tool which can automatically detect issues like ZBX-16317.

      It takes some time to figure out how to compile the tool. Feel free to poke me for instructions for Ubuntu.

      Once you have it installed you can use it with Zabbix sources like so:

      $ ./bootstrap.sh
      $ ./configure ...
      $ CC=include-what-you-use make --keep-going --environment-overrides
      

      --environment-overrides is needed since CC is hardcoded in makefiles produced by autotools.

      One more Zabbix-specific hint (Zabbix sources tend to include sysinc.h via common.h instead of standard headers):

      diff --git a/include/common.h b/include/common.h
      index 4a342f380c..a0fa37a80d 100644
      --- a/include/common.h
      +++ b/include/common.h
      @@ -20,10 +20,12 @@
       #ifndef ZABBIX_COMMON_H
       #define ZABBIX_COMMON_H
       
      +/* IWYU pragma: begin_exports */
       #include "sysinc.h"
       #include "zbxtypes.h"
       #include "version.h"
       #include "md5.h"
      +/* IWYU pragma: end_exports */
       
       #ifndef va_copy
       #      if defined(__va_copy)
      diff --git a/include/sysinc.h b/include/sysinc.h
      index a0beb02c0a..0858c581c7 100644
      --- a/include/sysinc.h
      +++ b/include/sysinc.h
      @@ -17,6 +17,8 @@
       ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
       **/
       
      +/* IWYU pragma: begin_exports */
      +
       #ifndef ZABBIX_SYSINC_H
       #define ZABBIX_SYSINC_H
       
      @@ -425,3 +427,5 @@
       #endif
       
       #endif
      +
      +/* IWYU pragma: end_exports */
      

      This also may be useful. With these changes:

      diff --git a/src/libs/zbxlog/log.c b/src/libs/zbxlog/log.c
      index 2e63ce8eb9..f2e458f8c0 100644
      --- a/src/libs/zbxlog/log.c
      +++ b/src/libs/zbxlog/log.c
      @@ -18,7 +18,7 @@
       **/
       
       #include "common.h"
      -#include "log.h"
      +#include "log.h"       /* IWYU pragma: associated */
       #include "mutexs.h"
       #include "threads.h"
       #include "cfg.h"
      

      ...the tool says:

      Making all in zbxlog
      
      ../../../include/log.h should add these lines:
      #include "common.h"  // for SUCCEED, FAIL, HAVE___VA_ARGS__, ZBX_TASK_EX
      

      This is exactly what ZBX-16317 is about!

            arimdjonoks Artjoms Rimdjonoks
            cyclone Glebs Ivanovskis
            Votes:
            2 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: