← cproj

add valgrind to build system

c9a67dd509971f72212cf92ebfa86ddb6d9a8bf4 · Ovidiu · Aug 30, 2020 19:42

+210 −6 · 5 files changed

  • Tuprules.tup +10 −1
  • include/square.h +1 −1
  • test/Tupfile +5 −4
  • test/program_debug.txt +97 −0
  • test/program_release.txt +97 −0
diff --git a/Tuprules.tup b/Tuprules.tup
index 8191385..6e38d3e 100644
--- a/Tuprules.tup
+++ b/Tuprules.tup
@@ -1,6 +1,7 @@
 &libdir  = include/
 &objdir  = obj/
 &bindir  = bin/
+
 CDEBUG += -Weverything
 CDEBUG += -g
 CDEBUG += -Og
@@ -12,11 +13,19 @@ CRELEASE += -fexceptions
 CRELEASE += -fvisibility=hidden
 CRELEASE += -Werror
 
+VALGRND  += --leak-check=full
+VALGRND  += --show-leak-kinds=all
+VALGRND  += --track-origins=yes
+VALGRND  += --verbose
+VALGRND  += --log-file=
+
 # Do the object files
 !ccodbg = |> clang $(CDEBUG) -I&(libdir) -c %f -o &(objdir)/%o |> %B_debug.o
 !ccorel = |> clang $(CRELEASE) -I&(libdir) -c %f -o &(objdir)/%o |> %B_release.o
 # macro for the archive command
 !ar = |> ar crs %o %f |>
+# Do binaries, debug and release 
 !ccbdbg = |> clang $(CDEBUG) %f -o &(bindir)/%o |> %B
 !ccbrel = |> clang $(CRELEASE) %f -o &(bindir)/%o |> %B
-
+# Valgrind the binaries
+!valgrnd = |> valgrind $(VALGRND)%o %f |> %B.txt
diff --git a/include/square.h b/include/square.h
index ad344d9..f642d8e 100644
--- a/include/square.h
+++ b/include/square.h
@@ -1,2 +1,2 @@
 #include <stdio.h>
-extern int squares(int x,int y);
+extern int square(int x,int y);
diff --git a/test/Tupfile b/test/Tupfile
index 19e6d6d..205d6ea 100644
--- a/test/Tupfile
+++ b/test/Tupfile
@@ -1,12 +1,13 @@
 include_rules
 #&Libs =
-CXFLAGS += -lc
-CXFLAGS += -lm
-CXFLAGS += ../lib/*.a
+#CXFLAGS += -lc
+#CXFLAGS += -lm
+#CXFLAGS += ../lib/*.a
 
 #: *.c |> !cc |> ../obj/*.o
 #: *.c |> !cc |> ../obj/*.o | clang  %f  $(CXFLAGS) -o %f |> %B
 #:  ../obj/*.o | ../lib/*.a  |> clang  %f  $(CXFLAGS) -o testfile |> %B
 #: foreach ../lib/*.a  |> clang -v %f  $(CXFLAGS) -o %f |> %B
-: |> echo first > %o && echo second > %o.2 |> out/file.txt | %O.txt.2
+#: |> echo first > %o && echo second > %o.2 |> out/file.txt | %O.txt.2
 
+: foreach ../bin/program_* |> !valgrnd |>
diff --git a/test/program_debug.txt b/test/program_debug.txt
new file mode 100644
index 0000000..086c6b3
--- /dev/null
+++ b/test/program_debug.txt
@@ -0,0 +1,97 @@
+==79198== Memcheck, a memory error detector
+==79198== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
+==79198== Using Valgrind-3.16.1-36d6727e1d-20200622X and LibVEX; rerun with -h for copyright info
+==79198== Command: ../bin/program_debug
+==79198== Parent PID: 79188
+==79198== 
+--79198-- 
+--79198-- Valgrind options:
+--79198--    --leak-check=full
+--79198--    --show-leak-kinds=all
+--79198--    --track-origins=yes
+--79198--    --verbose
+--79198--    --log-file=program_debug.txt
+--79198-- Contents of /proc/version:
+--79198--   Linux version 5.8.5-arch1-1 (linux@archlinux) (gcc (GCC) 10.2.0, GNU ld (GNU Binutils) 2.35) #1 SMP PREEMPT Thu, 27 Aug 2020 18:53:02 +0000
+--79198-- 
+--79198-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3-avx-avx2-bmi-f16c-rdrand
+--79198-- Page sizes: currently 4096, max supported 4096
+--79198-- Valgrind library directory: /usr/lib/valgrind
+--79198-- Reading syms from /home/kiro/proj/cproj/strings1/bin/program_debug
+--79198-- Reading syms from /usr/lib/ld-2.32.so
+--79198-- Reading syms from /usr/lib/valgrind/memcheck-amd64-linux
+--79198--    object doesn't have a dynamic symbol table
+--79198-- Scheduler: using generic scheduler lock implementation.
+--79198-- Reading suppressions file: /usr/lib/valgrind/default.supp
+==79198== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-79198-by-???-on-???
+==79198== embedded gdbserver: writing to   /tmp/vgdb-pipe-to-vgdb-from-79198-by-???-on-???
+==79198== embedded gdbserver: shared mem   /tmp/vgdb-pipe-shared-mem-vgdb-79198-by-???-on-???
+==79198== 
+==79198== TO CONTROL THIS PROCESS USING vgdb (which you probably
+==79198== don't want to do, unless you know exactly what you're doing,
+==79198== or are doing some strange experiment):
+==79198==   /usr/lib/valgrind/../../bin/vgdb --pid=79198 ...command...
+==79198== 
+==79198== TO DEBUG THIS PROCESS USING GDB: start GDB like this
+==79198==   /path/to/gdb ../bin/program_debug
+==79198== and then give GDB the following command
+==79198==   target remote | /usr/lib/valgrind/../../bin/vgdb --pid=79198
+==79198== --pid is optional if only one valgrind process is running
+==79198== 
+--79198-- REDIR: 0x4021ee0 (ld-linux-x86-64.so.2:strlen) redirected to 0x580b9662 (vgPlain_amd64_linux_REDIR_FOR_strlen)
+--79198-- REDIR: 0x4021cb0 (ld-linux-x86-64.so.2:index) redirected to 0x580b967c (vgPlain_amd64_linux_REDIR_FOR_index)
+--79198-- Reading syms from /usr/lib/valgrind/vgpreload_core-amd64-linux.so
+--79198-- Reading syms from /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
+==79198== WARNING: new redirection conflicts with existing -- ignoring it
+--79198--     old: 0x04021ee0 (strlen              ) R-> (0000.0) 0x580b9662 vgPlain_amd64_linux_REDIR_FOR_strlen
+--79198--     new: 0x04021ee0 (strlen              ) R-> (2007.0) 0x0483dd90 strlen
+--79198-- REDIR: 0x401e6c0 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ec60 (strcmp)
+--79198-- REDIR: 0x4022440 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4842450 (mempcpy)
+--79198-- Reading syms from /usr/lib/libc-2.32.so
+--79198-- REDIR: 0x492a8c0 (libc.so.6:memmove) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x4929db0 (libc.so.6:strncpy) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x492ac00 (libc.so.6:strcasecmp) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x4929850 (libc.so.6:strcat) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x4929e10 (libc.so.6:rindex) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x492bfb0 (libc.so.6:rawmemchr) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x4944500 (libc.so.6:wmemchr) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x4944040 (libc.so.6:wcscmp) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x492aa20 (libc.so.6:mempcpy) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x492a850 (libc.so.6:bcmp) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x4929d40 (libc.so.6:strncmp) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x4929900 (libc.so.6:strcmp) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x492a990 (libc.so.6:memset) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x4944000 (libc.so.6:wcschr) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x4929ca0 (libc.so.6:strnlen) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x49299e0 (libc.so.6:strcspn) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x492ac50 (libc.so.6:strncasecmp) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x4929980 (libc.so.6:strcpy) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x492ada0 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x4945750 (libc.so.6:wcsnlen) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x4944080 (libc.so.6:wcscpy) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x4929e50 (libc.so.6:strpbrk) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x49298b0 (libc.so.6:index) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x4929c60 (libc.so.6:strlen) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x49303a0 (libc.so.6:memrchr) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x492aca0 (libc.so.6:strcasecmp_l) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x492a810 (libc.so.6:memchr) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x4944150 (libc.so.6:wcslen) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x4929f80 (libc.so.6:strspn) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x492aba0 (libc.so.6:stpncpy) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x492ab40 (libc.so.6:stpcpy) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x492bff0 (libc.so.6:strchrnul) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x492acf0 (libc.so.6:strncasecmp_l) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79198-- REDIR: 0x49fc8a0 (libc.so.6:__strrchr_avx2) redirected to 0x483d7d0 (rindex)
+--79198-- REDIR: 0x49fc6b0 (libc.so.6:__strchrnul_avx2) redirected to 0x4841f40 (strchrnul)
+--79198-- REDIR: 0x4925c90 (libc.so.6:malloc) redirected to 0x483a710 (malloc)
+--79198-- REDIR: 0x49ffa60 (libc.so.6:__mempcpy_avx_unaligned_erms) redirected to 0x4842050 (mempcpy)
+--79198-- REDIR: 0x49fca70 (libc.so.6:__strlen_avx2) redirected to 0x483dc70 (strlen)
+--79198-- REDIR: 0x49262f0 (libc.so.6:free) redirected to 0x483b940 (free)
+==79198== 
+==79198== HEAP SUMMARY:
+==79198==     in use at exit: 0 bytes in 0 blocks
+==79198==   total heap usage: 1 allocs, 1 frees, 4,096 bytes allocated
+==79198== 
+==79198== All heap blocks were freed -- no leaks are possible
+==79198== 
+==79198== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
diff --git a/test/program_release.txt b/test/program_release.txt
new file mode 100644
index 0000000..278c2db
--- /dev/null
+++ b/test/program_release.txt
@@ -0,0 +1,97 @@
+==79197== Memcheck, a memory error detector
+==79197== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
+==79197== Using Valgrind-3.16.1-36d6727e1d-20200622X and LibVEX; rerun with -h for copyright info
+==79197== Command: ../bin/program_release
+==79197== Parent PID: 79188
+==79197== 
+--79197-- 
+--79197-- Valgrind options:
+--79197--    --leak-check=full
+--79197--    --show-leak-kinds=all
+--79197--    --track-origins=yes
+--79197--    --verbose
+--79197--    --log-file=program_release.txt
+--79197-- Contents of /proc/version:
+--79197--   Linux version 5.8.5-arch1-1 (linux@archlinux) (gcc (GCC) 10.2.0, GNU ld (GNU Binutils) 2.35) #1 SMP PREEMPT Thu, 27 Aug 2020 18:53:02 +0000
+--79197-- 
+--79197-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3-avx-avx2-bmi-f16c-rdrand
+--79197-- Page sizes: currently 4096, max supported 4096
+--79197-- Valgrind library directory: /usr/lib/valgrind
+--79197-- Reading syms from /home/kiro/proj/cproj/strings1/bin/program_release
+--79197-- Reading syms from /usr/lib/ld-2.32.so
+--79197-- Reading syms from /usr/lib/valgrind/memcheck-amd64-linux
+--79197--    object doesn't have a dynamic symbol table
+--79197-- Scheduler: using generic scheduler lock implementation.
+--79197-- Reading suppressions file: /usr/lib/valgrind/default.supp
+==79197== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-79197-by-???-on-???
+==79197== embedded gdbserver: writing to   /tmp/vgdb-pipe-to-vgdb-from-79197-by-???-on-???
+==79197== embedded gdbserver: shared mem   /tmp/vgdb-pipe-shared-mem-vgdb-79197-by-???-on-???
+==79197== 
+==79197== TO CONTROL THIS PROCESS USING vgdb (which you probably
+==79197== don't want to do, unless you know exactly what you're doing,
+==79197== or are doing some strange experiment):
+==79197==   /usr/lib/valgrind/../../bin/vgdb --pid=79197 ...command...
+==79197== 
+==79197== TO DEBUG THIS PROCESS USING GDB: start GDB like this
+==79197==   /path/to/gdb ../bin/program_release
+==79197== and then give GDB the following command
+==79197==   target remote | /usr/lib/valgrind/../../bin/vgdb --pid=79197
+==79197== --pid is optional if only one valgrind process is running
+==79197== 
+--79197-- REDIR: 0x4021ee0 (ld-linux-x86-64.so.2:strlen) redirected to 0x580b9662 (vgPlain_amd64_linux_REDIR_FOR_strlen)
+--79197-- REDIR: 0x4021cb0 (ld-linux-x86-64.so.2:index) redirected to 0x580b967c (vgPlain_amd64_linux_REDIR_FOR_index)
+--79197-- Reading syms from /usr/lib/valgrind/vgpreload_core-amd64-linux.so
+--79197-- Reading syms from /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
+==79197== WARNING: new redirection conflicts with existing -- ignoring it
+--79197--     old: 0x04021ee0 (strlen              ) R-> (0000.0) 0x580b9662 vgPlain_amd64_linux_REDIR_FOR_strlen
+--79197--     new: 0x04021ee0 (strlen              ) R-> (2007.0) 0x0483dd90 strlen
+--79197-- REDIR: 0x401e6c0 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ec60 (strcmp)
+--79197-- REDIR: 0x4022440 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4842450 (mempcpy)
+--79197-- Reading syms from /usr/lib/libc-2.32.so
+--79197-- REDIR: 0x492a8c0 (libc.so.6:memmove) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x4929db0 (libc.so.6:strncpy) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x492ac00 (libc.so.6:strcasecmp) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x4929850 (libc.so.6:strcat) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x4929e10 (libc.so.6:rindex) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x492bfb0 (libc.so.6:rawmemchr) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x4944500 (libc.so.6:wmemchr) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x4944040 (libc.so.6:wcscmp) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x492aa20 (libc.so.6:mempcpy) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x492a850 (libc.so.6:bcmp) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x4929d40 (libc.so.6:strncmp) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x4929900 (libc.so.6:strcmp) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x492a990 (libc.so.6:memset) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x4944000 (libc.so.6:wcschr) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x4929ca0 (libc.so.6:strnlen) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x49299e0 (libc.so.6:strcspn) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x492ac50 (libc.so.6:strncasecmp) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x4929980 (libc.so.6:strcpy) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x492ada0 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x4945750 (libc.so.6:wcsnlen) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x4944080 (libc.so.6:wcscpy) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x4929e50 (libc.so.6:strpbrk) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x49298b0 (libc.so.6:index) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x4929c60 (libc.so.6:strlen) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x49303a0 (libc.so.6:memrchr) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x492aca0 (libc.so.6:strcasecmp_l) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x492a810 (libc.so.6:memchr) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x4944150 (libc.so.6:wcslen) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x4929f80 (libc.so.6:strspn) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x492aba0 (libc.so.6:stpncpy) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x492ab40 (libc.so.6:stpcpy) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x492bff0 (libc.so.6:strchrnul) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x492acf0 (libc.so.6:strncasecmp_l) redirected to 0x48301c0 (_vgnU_ifunc_wrapper)
+--79197-- REDIR: 0x49fc8a0 (libc.so.6:__strrchr_avx2) redirected to 0x483d7d0 (rindex)
+--79197-- REDIR: 0x49fc6b0 (libc.so.6:__strchrnul_avx2) redirected to 0x4841f40 (strchrnul)
+--79197-- REDIR: 0x49ffa60 (libc.so.6:__mempcpy_avx_unaligned_erms) redirected to 0x4842050 (mempcpy)
+--79197-- REDIR: 0x4925c90 (libc.so.6:malloc) redirected to 0x483a710 (malloc)
+--79197-- REDIR: 0x49fca70 (libc.so.6:__strlen_avx2) redirected to 0x483dc70 (strlen)
+--79197-- REDIR: 0x49262f0 (libc.so.6:free) redirected to 0x483b940 (free)
+==79197== 
+==79197== HEAP SUMMARY:
+==79197==     in use at exit: 0 bytes in 0 blocks
+==79197==   total heap usage: 1 allocs, 1 frees, 4,096 bytes allocated
+==79197== 
+==79197== All heap blocks were freed -- no leaks are possible
+==79197== 
+==79197== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)