www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Dustmite can't handle my memory segfault

reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
I'm struggling with finding a memory management problem in my 
latest array container (non-RC just C++-style) at

https://github.com/nordlow/phobos-next/blob/master/src/array_ex.d

When I run the program separately my terminal spits out


*** Error in `./array_ex': corrupted double-linked list: 
0x0000000001c3a2b0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x77725)[0x7fc0bb3be725]
...
./array_ex[0x4a3b7f]
...
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7fc0bb367830]
./array_ex[0x401ef9]
======= Memory map: ========
00400000-004fe000 r-xp 00000000 08:05 5379197                     
        /home/per/Work/justd/phobos-next/src/array_ex
004fe000-004ff000 r--p 000fd000 08:05 5379197                     
        /home/per/Work/justd/phobos-next/src/array_ex
004ff000-00515000 rw-p 000fe000 08:05 5379197                     
        /home/per/Work/justd/phobos-next/src/array_ex
00515000-00516000 rw-p 00000000 00:00 0
01c2f000-02001000 rw-p 00000000 00:00 0                           
        [heap]
7fc0b4000000-7fc0b4021000 rw-p 00000000 00:00 0
7fc0b4021000-7fc0b8000000 ---p 00000000 00:00 0
7fc0bb347000-7fc0bb507000 r-xp 00000000 08:05 2410363             
        /lib/x86_64-linux-gnu/libc-2.23.so
7fc0bb507000-7fc0bb706000 ---p 001c0000 08:05 2410363             
        /lib/x86_64-linux-gnu/libc-2.23.so
7fc0bb706000-7fc0bb70a000 r--p 001bf000 08:05 2410363             
        /lib/x86_64-linux-gnu/libc-2.23.so
7fc0bb70a000-7fc0bb70c000 rw-p 001c3000 08:05 2410363             
        /lib/x86_64-linux-gnu/libc-2.23.so
7fc0bb70c000-7fc0bb710000 rw-p 00000000 00:00 0
7fc0bb710000-7fc0bb726000 r-xp 00000000 08:05 2369742             
        /lib/x86_64-linux-gnu/libgcc_s.so.1
7fc0bb726000-7fc0bb925000 ---p 00016000 08:05 2369742             
        /lib/x86_64-linux-gnu/libgcc_s.so.1
7fc0bb925000-7fc0bb926000 r--p 00015000 08:05 2369742             
        /lib/x86_64-linux-gnu/libgcc_s.so.1
7fc0bb926000-7fc0bb927000 rw-p 00016000 08:05 2369742             
        /lib/x86_64-linux-gnu/libgcc_s.so.1
7fc0bb927000-7fc0bb92e000 r-xp 00000000 08:05 2410358             
        /lib/x86_64-linux-gnu/librt-2.23.so
7fc0bb92e000-7fc0bbb2d000 ---p 00007000 08:05 2410358             
        /lib/x86_64-linux-gnu/librt-2.23.so
7fc0bbb2d000-7fc0bbb2e000 r--p 00006000 08:05 2410358             
        /lib/x86_64-linux-gnu/librt-2.23.so
7fc0bbb2e000-7fc0bbb2f000 rw-p 00007000 08:05 2410358             
        /lib/x86_64-linux-gnu/librt-2.23.so
7fc0bbb2f000-7fc0bbb47000 r-xp 00000000 08:05 2410362             
        /lib/x86_64-linux-gnu/libpthread-2.23.so
7fc0bbb47000-7fc0bbd46000 ---p 00018000 08:05 2410362             
        /lib/x86_64-linux-gnu/libpthread-2.23.so
7fc0bbd46000-7fc0bbd47000 r--p 00017000 08:05 2410362             
        /lib/x86_64-linux-gnu/libpthread-2.23.so
7fc0bbd47000-7fc0bbd48000 rw-p 00018000 08:05 2410362             
        /lib/x86_64-linux-gnu/libpthread-2.23.so
7fc0bbd48000-7fc0bbd4c000 rw-p 00000000 00:00 0
7fc0bbd4c000-7fc0bbd72000 r-xp 00000000 08:05 2410359             
        /lib/x86_64-linux-gnu/ld-2.23.so
7fc0bbe42000-7fc0bbf46000 rw-p 00000000 00:00 0
7fc0bbf6e000-7fc0bbf71000 rw-p 00000000 00:00 0
7fc0bbf71000-7fc0bbf72000 r--p 00025000 08:05 2410359             
        /lib/x86_64-linux-gnu/ld-2.23.so
7fc0bbf72000-7fc0bbf73000 rw-p 00026000 08:05 2410359             
        /lib/x86_64-linux-gnu/ld-2.23.so
7fc0bbf73000-7fc0bbf74000 rw-p 00000000 00:00 0
7ffdbd0cc000-7ffdbd0ee000 rw-p 00000000 00:00 0                   
        [stack]
7ffdbd1f9000-7ffdbd1fb000 r--p 00000000 00:00 0                   
        [vvar]
7ffdbd1fb000-7ffdbd1fd000 r-xp 00000000 00:00 0                   
        [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0           
        [vsyscall]
Interrupted (SIGABRT


The problem here is that I can't even pipe the call to a file; 
neither

     ./array_ex > dump

nor

     ./array_ex 2> dump

succeeds in creating any file. This might be the reason why my 
Dustmite call


dustmite --no-redirect src "dmd -main -unittest -g -debug \
     array_ex container_traits searching_ex && \
     ./array_ex 2>&1 | grep -qF double-linked"


stops and spits out


Aborted (core dumped)
No
object.Exception dustmite.d(270): Initial test fails
----------------
??:? _Dmain [0x5c6be8]
??:? 
_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv 
[0x62544e]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) [0x625398]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).runAll() [0x62540a]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) [0x625398]
??:? _d_run_main [0x625309]
??:? main [0x61732d]
??:? __libc_start_main [0xaf26b82f]
[


It seems there is some special behaviour of not being able to 
redirect the ouputs of stdout and stderr here.
What to do?

I need your help here, I'm complete stuck. Vladimir?


Note: The problem should be reproducable by cloning

     https://github.com/nordlow/phobos-next.git

and doing the call to DustMite at the root of this checkout.
Oct 20 2016
parent reply Vladimir Panteleev <thecybershadow.lists gmail.com> writes:
On Thursday, 20 October 2016 at 21:33:59 UTC, Nordlöw wrote:
 I need your help here, I'm complete stuck. Vladimir?
If you see output even after redirecting stdout and stderr, the program is probably writing to /dev/tty or similar. I'm not sure what the "proper" way is to run a program without a TTY... but what happens if you run the program via ssh, without allocating a PTY? I.e. with -T, or with a command and without -t.
Oct 20 2016
parent reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Thursday, 20 October 2016 at 22:18:20 UTC, Vladimir Panteleev 
wrote:
 On Thursday, 20 October 2016 at 21:33:59 UTC, Nordlöw wrote:
 I need your help here, I'm complete stuck. Vladimir?
The exit status of the `./array_ex` call (as seen from bash) is 134. How do I, in Bash, map that exit status to zero, and all other exit statuses to non-zero?
Oct 20 2016
next sibling parent =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
Next try:

dustmite --no-redirect src "dmd -main -unittest -g -debug 
array_ex container_traits searching_ex && { ./array_ex; } >&log; 
grep SIGABRT log"

but that fails too as

Loading src/w3c.html
None => /bin/sh: 1: Syntax error: Bad fd number
No
object.Exception dustmite.d(270): Initial test fails
----------------
??:? _Dmain [0x5c6be8]
??:? 
_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv 
[0x62544e]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) [0x625398]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).runAll() [0x62540a]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) [0x625398]
??:? _d_run_main [0x625309]
??:? main [0x61732d]
??:? __libc_start_main [0x8b69a82f]


I can't get ! operator to work either.
Oct 21 2016
prev sibling parent reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Friday, 21 October 2016 at 06:44:54 UTC, Nordlöw wrote:
 On Thursday, 20 October 2016 at 22:18:20 UTC, Vladimir 
 Panteleev wrote:
 On Thursday, 20 October 2016 at 21:33:59 UTC, Nordlöw wrote:
 I need your help here, I'm complete stuck. Vladimir?
The exit status of the `./array_ex` call (as seen from bash) is 134. How do I, in Bash, map that exit status to zero, and all other exit statuses to non-zero?
Solution construct a Bash script named, say show-segfault: #!/usr/bin/env python3 import sys import pty stat = pty.spawn(sys.argv[1:]) if stat == 256: exit(42) # remap to 42 else: exit(stat) and wrap call to rdmd as show-segfault rdmd ...
Oct 21 2016
parent Anonymouse <asdf asdf.net> writes:
On Friday, 21 October 2016 at 10:13:23 UTC, Nordlöw wrote:
 #!/usr/bin/env python3

 import sys
 import pty

 stat = pty.spawn(sys.argv[1:])
 if stat == 256:
     exit(42)                    # remap to 42
 else:
     exit(stat)
Assuming you want to remap 134 to 0 (success): #!/bin/bash cmd="$1" shift 2>/dev/null $cmd "$ " [ $? = 134 ] && exit 0 || exit 1
Oct 22 2016