# Sporadic "abort trap" when using trace/2

**URL:** <https://swi-prolog.discourse.group/t/sporadic-abort-trap-when-using-trace-2/8755>\
**Category:** General\
**Tags:** bug, how-to\
**Created:** [January 26, 2025, 8:50am UTC](https://swi-prolog.discourse.group/t/sporadic-abort-trap-when-using-trace-2/8755 "2025-01-26T08:50:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Boris](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/boris/32/7486_2.png) [@Boris](https://swi-prolog.discourse.group/u/Boris)\
**Post date:** [January 26, 2025, 8:50am UTC](https://swi-prolog.discourse.group/t/sporadic-abort-trap-when-using-trace-2/8755/1 "2025-01-26T08:50:29Z")

</div>

Every now and then I get the following just after running `make.` on the top level:

```prolog
?- 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?

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [January 26, 2025, 9:10am UTC](https://swi-prolog.discourse.group/t/sporadic-abort-trap-when-using-trace-2/8755/2 "2025-01-26T09:10:38Z")

</div>

What OS? The typical way to debug this on Linux would be using valgrind or build using gcc/clang address sanitizer.

---

<div class="post-metadata">

**Author:** ![Boris](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/boris/32/7486_2.png) [@Boris](https://swi-prolog.discourse.group/u/Boris)\
**Post date:** [January 26, 2025, 10:12am UTC](https://swi-prolog.discourse.group/t/sporadic-abort-trap-when-using-trace-2/8755/3 "2025-01-26T10:12:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [January 26, 2025, 2:24pm UTC](https://swi-prolog.discourse.group/t/sporadic-abort-trap-when-using-trace-2/8755/4 "2025-01-26T14:24:35Z")

</div>

The simplest way, given a checked out source tree is

```prolog
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 🙂
