LINUX.ORG.RU

Valgrind в деле. Что, как?

 , ,


1

2

Пытаюсь проверить библиотеку, скомпилированную ICCшкой, без отладки. Но что-то его не устаривает. либа x32

Вывод:

valgrind --tool=memcheck --leak-check=full --show-reachable=yes --undef-value-errors=yes --track-origins=yes --child-silent-after-fork=no --trace-children=no --gen-suppressions=no ./test.so
==3388== Memcheck, a memory error detector
==3388== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==3388== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==3388== Command: ./test.so
==3388== 
==3388== 
==3388== Process terminating with default action of signal 11 (SIGSEGV)
==3388==  Access not within mapped region at address 0x0
==3388==    at 0x1: ???
==3388==  If you believe this happened as a result of a stack
==3388==  overflow in your program's main thread (unlikely but
==3388==  possible), you can try to increase the size of the
==3388==  main thread stack using the --main-stacksize= flag.
==3388==  The main thread stack size used in this run was 8388608.
==3388== 
==3388== HEAP SUMMARY:
==3388==     in use at exit: 0 bytes in 0 blocks
==3388==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==3388== 
==3388== All heap blocks were freed -- no leaks are possible
==3388== 
==3388== For counts of detected and suppressed errors, rerun with: -v
==3388== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Segmentation fault

вывод с -v

algrind --tool=memcheck --leak-check=full --show-reachable=yes --undef-value-errors=yes --track-origins=yes --child-silent-after-fork=no --trace-children=no --gen-suppressions=no -v ./test.so
==3395== Memcheck, a memory error detector
==3395== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==3395== Using Valgrind-3.14.0-353a3587bb-20181007X and LibVEX; rerun with -h for copyright info
==3395== Command: ./test.so
==3395== 
--3395-- Valgrind options:
--3395--    --tool=memcheck
--3395--    --leak-check=full
--3395--    --show-reachable=yes
--3395--    --undef-value-errors=yes
--3395--    --track-origins=yes
--3395--    --child-silent-after-fork=no
--3395--    --trace-children=no
--3395--    --gen-suppressions=no
--3395--    -v
--3395-- Contents of /proc/version:
--3395--   Linux version 4.4.0-138-generic (buildd@lcy01-amd64-006) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10) ) #164-Ubuntu SMP Tue Oct 2 17:16:02 UTC 2018
--3395-- 
--3395-- Arch and hwcaps: X86, LittleEndian, x86-mmxext-sse1-sse2-sse3
--3395-- Page sizes: currently 4096, max supported 4096
--3395-- Valgrind library directory: /usr/local/lib/valgrind
--3395-- Reading syms from /root/test/test.so
--3395--    object doesn't have a symbol table
--3395-- Reading syms from /usr/local/lib/valgrind/memcheck-x86-linux
--3395--    object doesn't have a dynamic symbol table
--3395-- Scheduler: using generic scheduler lock implementation.
--3395-- Reading suppressions file: /usr/local/lib/valgrind/default.supp
==3395== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-3395-by-root-on-???
==3395== embedded gdbserver: writing to   /tmp/vgdb-pipe-to-vgdb-from-3395-by-root-on-???
==3395== embedded gdbserver: shared mem   /tmp/vgdb-pipe-shared-mem-vgdb-3395-by-root-on-???
==3395== 
==3395== TO CONTROL THIS PROCESS USING vgdb (which you probably
==3395== don't want to do, unless you know exactly what you're doing,
==3395== or are doing some strange experiment):
==3395==   /usr/local/lib/valgrind/../../bin/vgdb --pid=3395 ...command...
==3395== 
==3395== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==3395==   /path/to/gdb ./test.so
==3395== and then give GDB the following command
==3395==   target remote | /usr/local/lib/valgrind/../../bin/vgdb --pid=3395
==3395== --pid is optional if only one valgrind process is running
==3395== 
==3395== 
==3395== Process terminating with default action of signal 11 (SIGSEGV)
==3395==  Access not within mapped region at address 0x0
==3395==    at 0x1: ???
==3395==  If you believe this happened as a result of a stack
==3395==  overflow in your program's main thread (unlikely but
==3395==  possible), you can try to increase the size of the
==3395==  main thread stack using the --main-stacksize= flag.
==3395==  The main thread stack size used in this run was 8388608.
==3395== 
==3395== HEAP SUMMARY:
==3395==     in use at exit: 0 bytes in 0 blocks
==3395==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==3395== 
==3395== All heap blocks were freed -- no leaks are possible
==3395== 
==3395== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==3395== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Segmentation fault

Что делать?

★★

valgrind тестирует бинарники путём их запуска. Ты пытаешься запустить библиотеку — отсюда и segmentation fault.

Если хочешь протестить библиотеку, можешь написать бинарь, который ей пользуется, слинковаться с ней и проверить его.

Deleted ()