honggyukim / heaptrace

a tool that collects and reports heap allocated memory
GNU General Public License v2.0
13 stars 3 forks source link

build: Add CMakeLists.txt for cmake build #27

Closed honggyukim closed 1 year ago

honggyukim commented 1 year ago

This patch adds cmake build support and basic usages are as follows.

  $ cmake -B out
  $ make -C out

If you want to change the depth of stacktrace, then DEPTH variable can be provided as follows.

  $ cmake -B out -DDEPTH=32
  $ make -C out

If DEPTH is not given, then the default depth is 8 as written in CMakeLists.txt.

We don't remove the existing Make build until we're sure that cmake looks stable enough.

Signed-off-by: Honggyu Kim honggyu.kp@gmail.com

honggyukim commented 1 year ago

@Bojun-Seo Please have a look if you're okay.

honggyukim commented 1 year ago

With this cmake build, we can run clang-tidy for static analysis and other linting.

$ cmake -B out
$ run-clang-tidy -p out .
      ...
clang-tidy-14 --use-color -p=out /home/honggyu/work/heaptrace/src/sighandler.cc
clang-tidy-14 --use-color -p=out /home/honggyu/work/heaptrace/src/heaptrace.cc
/home/honggyu/work/heaptrace/src/heaptrace.cc:117:8: warning: Value stored to 'old_libpath' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
        char *old_libpath = getenv("LD_LIBRARY_PATH");
              ^~~~~~~~~~~   ~~~~~~~~~~~~~~~~~~~~~~~~~
/home/honggyu/work/heaptrace/src/heaptrace.cc:117:8: note: Value stored to 'old_libpath' during its initialization is never read
        char *old_libpath = getenv("LD_LIBRARY_PATH");
              ^~~~~~~~~~~   ~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
clang-tidy-14 --use-color -p=out /home/honggyu/work/heaptrace/src/utils.cc
/home/honggyu/work/heaptrace/src/utils.cc:24:2: warning: Value stored to 'ret' is never read [clang-analyzer-deadcode.DeadStores]
        ret = vasprintf(&ptr, fmt, args);
        ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/honggyu/work/heaptrace/src/utils.cc:24:2: note: Value stored to 'ret' is never read
        ret = vasprintf(&ptr, fmt, args);
        ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
clang-tidy-14 --use-color -p=out /home/honggyu/work/heaptrace/src/libheaptrace.cc
/home/honggyu/work/heaptrace/src/libheaptrace.cc:71:8: warning: Value stored to 'tfs' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
        auto *tfs = &thread_flags;
              ^~~   ~~~~~~~~~~~~~
/home/honggyu/work/heaptrace/src/libheaptrace.cc:71:8: note: Value stored to 'tfs' during its initialization is never read
        auto *tfs = &thread_flags;
              ^~~   ~~~~~~~~~~~~~
/home/honggyu/work/heaptrace/src/libheaptrace.cc:172:24: warning: function previously declared with an explicit exception specification redeclared with an implicit exception specification [clang-diagnostic-implicit-exception-spec-mismatch]
__visible_default void operator delete(void *ptr)
                       ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/new:130:6: note: previous declaration is here
void operator delete(void*) _GLIBCXX_USE_NOEXCEPT
     ^
/home/honggyu/work/heaptrace/src/libheaptrace.cc:190:24: warning: function previously declared with an explicit exception specification redeclared with an implicit exception specification [clang-diagnostic-implicit-exception-spec-mismatch]
__visible_default void operator delete[](void *ptr)
                       ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/new:132:6: note: previous declaration is here
void operator delete[](void*) _GLIBCXX_USE_NOEXCEPT
     ^
3 warnings generated.
clang-tidy-14 --use-color -p=out /home/honggyu/work/heaptrace/src/stacktrace.cc
/home/honggyu/work/heaptrace/src/stacktrace.cc:255:26: warning: 'mallinfo' is deprecated [clang-diagnostic-deprecated-declarations]
        struct mallinfo minfo = mallinfo();
                                ^
/usr/include/malloc.h:114:48: note: 'mallinfo' has been explicitly marked deprecated here
extern struct mallinfo mallinfo (void) __THROW __MALLOC_DEPRECATED;
                                               ^
/usr/include/malloc.h:32:30: note: expanded from macro '__MALLOC_DEPRECATED'
# define __MALLOC_DEPRECATED __attribute_deprecated__
                             ^
/usr/include/x86_64-linux-gnu/sys/cdefs.h:339:51: note: expanded from macro '__attribute_deprecated__'
# define __attribute_deprecated__ __attribute__ ((__deprecated__))
                                                  ^
/home/honggyu/work/heaptrace/src/stacktrace.cc:310:10: warning: Value stored to 'count' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
                size_t count = info.count;
                       ^~~~~   ~~~~~~~~~~
/home/honggyu/work/heaptrace/src/stacktrace.cc:310:10: note: Value stored to 'count' during its initialization is never read
                size_t count = info.count;
                       ^~~~~   ~~~~~~~~~~
2 warnings generated.
Bojun-Seo commented 1 year ago

@honggyukim LGTM!