Every now and then I get the following just after running make. on the top level:
?- make.
swipl(95277,0x16f5df000) malloc: *** error for object 0x6000015319e0: pointer being freed was not allocated
swipl(95277,0x16f5df000) malloc: *** set a breakpoint in malloc_error_break to debug
% x compiled into x 0.00 sec, 0 clauses
true.
?- Abort trap: 6
The return value to the shell is 134.
This specifically happens after I have been using trace/2, instead of format/3 or library(debug), to debug a small program.
I don’t know how to reproduce it
If I wanted to “set a breakpoint in malloc_error_break”, does that mean I will be running the top level from a debugger? What exactly should I do? Is it worth the effort?
I am using both Linux (with gcc) and MacOS (with clang) interchangeably. I have seen this behaviour on both. Is there a specific change to CMakeLists.txt I can make? I have now been reading SO answers for a while and there seem to be a dozen ways to use AddressSanitizer maybe pointing to the correct docs is good enough
The simplest way, given a checked out source tree is
mkdir build.asan
cd build.asan
../scripts/configure
<agree>
ninja
src/swipl <whatever you want>
The scripts/configure script takes the name of the build directory as build.feat1-feat2-... and for each feature adds options to cmake or sets environment variables. See the script for details.
This is a bit similar to cmake presets, but these did not exists when I started this and this schema allows combining features, e.g. build.clang-debug builds a version using clang for debugging.
Note that, as the build process does not write anything to the source tree, you can have as many of such configurations in the same source tree as you like. My main source tree has 55 of them