paulfloyd / freebsd_valgrind

Git repo used to Upstream the FreeBSD Port of Valgrind
GNU General Public License v2.0
15 stars 4 forks source link

swi-pl crashes when run under Valgrind #174

Closed paulfloyd closed 2 years ago

paulfloyd commented 2 years ago

Moved from

Unhandled amd64-freebsd syscall: 247 https://bugs.kde.org/show_bug.cgi?id=445607

I tried the Linux (Fedora 34 package version), no problem.

paulfloyd commented 2 years ago

If I build swi-pl without tcmalloc then I have no problem.

wget http://www.swi-prolog.org/download/stable/src/swipl-8.2.3.tar.gz
tar xvf swipl-8.2.3.tar.gz  
cd swipl-8.2.3
patch  < /usr/ports/lang/swi-pl/files/patch-packages_clib_cmake_FindLibUUID.cmake
mkdir build
cd build
cmake .. -DSWIPL_PACKAGES_JAVA=OFF -DBUILD_TESTING=OFF -DUSE_TCMALLOC=OFF -G Ninja -DCMAKE_BUILD_TYPE=Debug
ninja
valgrind src/swipl

Looking at the source fort tcmalloc I see that there is

static int GetRunningOnValgrind(void) {
#ifdef RUNNING_ON_VALGRIND
  if (RUNNING_ON_VALGRIND) return 1;
#endif
  const char *running_on_valgrind_str = TCMallocGetenvSafe("RUNNING_ON_VALGRIND"
);
  if (running_on_valgrind_str) {
    return strcmp(running_on_valgrind_str, "0") != 0;
  }
  return 0;
}

RUNNING_ON_VALGRIND is a bit ov Valgrind magic that allows a guest application detect that it is running under Valgrind, but it requires including the valgrind.h header. I guess that the tcmalloc port is not built with the configuration that pulls in the header. I'll get in touch with the google perftools maintainer to ask about that.

So that leaves us with the environment variable.

I tried that and it seems to work perfectly.

paulf> export RUNNING_ON_VALGRIND=1                 
euler:/usr/home/paulf
paulf> /home/paulf/tools/valgrind/bin/valgrind swipl
==39358== Memcheck, a memory error detector
==39358== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==39358== Using Valgrind-3.19.0.GIT and LibVEX; rerun with -h for copyright info
==39358== Command: swipl
==39358== 
Welcome to SWI-Prolog (threaded, 64 bits, version 8.2.3)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- ^C
pid 39358 (memcheck-amd64-free): sigreturn rflags = 0x45
Action (h for help) ? exit (status 4)
==39358== 
==39358== HEAP SUMMARY:
==39358==     in use at exit: 3,144,110 bytes in 34,231 blocks
==39358==   total heap usage: 39,573 allocs, 5,342 frees, 6,575,211 bytes allocated
==39358== 
==39358== LEAK SUMMARY:
==39358==    definitely lost: 70,108 bytes in 172 blocks
==39358==    indirectly lost: 8,192 bytes in 1 blocks
==39358==      possibly lost: 10,288 bytes in 3 blocks
==39358==    still reachable: 3,055,522 bytes in 34,055 blocks
==39358==                       of which reachable via heuristic:
==39358==                         newarray           : 34,088 bytes in 903 blocks
==39358==         suppressed: 0 bytes in 0 blocks
==39358== Rerun with --leak-check=full to see details of leaked memory
==39358== 
==39358== For lists of detected and suppressed errors, rerun with: -s
==39358== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

It's a bit leaky but it seems to work.