[M3devel] malloc/free from Modula-3 (more details)

Mika Nystrom mika at async.caltech.edu
Fri Apr 15 12:46:47 CEST 2011

Here is some more info.

Note that all my access to the pq library is inside a single giant lock
(I've run this code for years and years but not under CM3 and not
under AMD64_LINUX or for that matter any kind of Linux).  The locking
is not likely to be obviously wrong, but of course there could be something
subtly wrong.

In gdb the program is completely frozen:

(gdb) stepi
Program received signal SIGINT, Interrupt.
0x00002ac519a9202e in ?? () from /lib/libc.so.6
(gdb) info registers
rax            0xfffffffffffffe00       -512
rbx            0x2ac519d059e0   47026030008800
rcx            0xffffffffffffffff       -1
rdx            0x2      2
rsi            0x80     128
rdi            0x2ac519d059e0   47026030008800
rbp            0x2ac63b0ef0e0   0x2ac63b0ef0e0
rsp            0x2ac63b0ef028   0x2ac63b0ef028
r8             0x2fe2620        50210336
r9             0x2ac6400008ef   47030965635311
r10            0x0      0
r11            0x302    770
r12            0x411858 4266072
r13            0x1      1
r14            0x2f5b6d0        49657552
r15            0x0      0
rip            0x2ac519a9202e   0x2ac519a9202e
eflags         0x202    [ IF ]
cs             0x33     51
ss             0x2b     43
ds             0x0      0
es             0x0      0
fs             0x0      0
gs             0x0      0
fctrl          0x37f    895
fstat          0x0      0
ftag           0xffff   65535
fiseg          0x0      0
fioff          0x0      0
foseg          0x0      0
fooff          0x0      0
fop            0x0      0
mxcsr          0x1fa0   [ PE IM DM ZM OM UM PM ]

(gdb) where
#0  0x00002ac519a9202e in ?? () from /lib/libc.so.6
#1  0x00002ac519a2fb43 in ?? () from /lib/libc.so.6
#2  0x00002ac519a2caab in free () from /lib/libc.so.6
#3  0x000000000091462f in Cstdlib__free (a=Cannot access memory at address 0x2ac73b0ef0d8
) at ../src/C/Common/CstdlibC.c:26
#4  0x000000000091477d in M3toC__FreeCopiedS (s=Cannot access memory at address 0x2ac73b0ef0f8
) at ../src/C/Common/M3toC.m3:46
#5  0x00000000007884f0 in UnsafeDatabase_M3_LINE_230.1181 (L_2=Cannot access memory at address 0x2ac73b0ef118
) at ../src/UnsafeDatabase.m3:230
#6  0x000000000078881f in UnsafeDatabase__ExecM (t=Cannot access memory at address 0x2ac73b0ef148
) at ../src/UnsafeDatabase.m3:228
#7  0x0000000000788aa6 in UnsafeDatabase__TExecM (t=Cannot access memory at address 0x2ac73b0ef268
) at ../src/UnsafeDatabase.m3:258
#8  0x000000000077ad5b in DesynchronizedDB__SExec (t=Cannot access memory at address 0x2ac73b0ef328
) at ../src/DesynchronizedDB.m3:126
#9  0x000000000077c190 in DesynchronizedDB__SMExec (t=Cannot access memory at address 0x2ac73b0ef3e8
) at ../src/DesynchronizedDB.m3:293
#10 0x0000000000569367 in GCOMSOrderManager__OrderEntered (t=Cannot access memory at address 0x2ac73b0ef5a8
) at ../src/GCOMSOrderManager.m3:596
#11 0x0000000000566b95 in GCOMSOrderManager__PlaceSingleOrder (t=Cannot access memory at address 0x2ac73b0ef668
) at ../src/GCOMSOrderManager.m3:310
#12 0x000000000041ba25 in EuroDriver__OApply__PlaceOrder.1253 (price={<No data fields>}, count=Cannot access memory at address 0x2ac73b0ef7b8
) at ../src/EuroDriver.m3:1108
#13 0x000000000041d97c in EuroDriver__OApply__MainLoop.1289 () at ../src/EuroDriver.m3:1401
#14 0x00000000004197a1 in EuroDriver__OApply (cl=Cannot access memory at address 0x2ac73b0efd38
) at ../src/EuroDriver.m3:1545
#15 0x00000000009112c1 in ThreadPosix__RunThread () at ../src/thread/POSIX/ThreadPosix.m3:1174
#16 0x00002ac5199fa7b0 in ?? () from /lib/libc.so.6
#17 0x0000000000000000 in ?? ()
(gdb) disassemble  0x00002ac519a9202e
No function contains specified address.
(gdb) disassemble 0x00002ac519a2caab
Dump of assembler code for function free:
0x00002ac519a2ca40 <free+0>:    mov    0x2d7519(%rip),%rax        # 0x2ac519d03f60
0x00002ac519a2ca47 <free+7>:    push   %rbx
0x00002ac519a2ca48 <free+8>:    mov    %rdi,%r8
0x00002ac519a2ca4b <free+11>:   mov    (%rax),%rax
0x00002ac519a2ca4e <free+14>:   test   %rax,%rax
0x00002ac519a2ca51 <free+17>:   je     0x2ac519a2ca60 <free+32>
0x00002ac519a2ca53 <free+19>:   mov    0x8(%rsp),%rsi
0x00002ac519a2ca58 <free+24>:   mov    %rax,%r11
0x00002ac519a2ca5b <free+27>:   pop    %rbx
0x00002ac519a2ca5c <free+28>:   jmpq   *%r11
0x00002ac519a2ca5f <free+31>:   nop    
0x00002ac519a2ca60 <free+32>:   test   %rdi,%rdi
0x00002ac519a2ca63 <free+35>:   je     0x2ac519a2cad2 <free+146>
0x00002ac519a2ca65 <free+37>:   mov    -0x8(%rdi),%rax
0x00002ac519a2ca69 <free+41>:   lea    -0x10(%rdi),%rdx
0x00002ac519a2ca6d <free+45>:   test   $0x2,%al
0x00002ac519a2ca6f <free+47>:   jne    0x2ac519a2cad8 <free+152>
0x00002ac519a2ca71 <free+49>:   test   $0x4,%al
0x00002ac519a2ca73 <free+51>:   lea    0x2d8f66(%rip),%rbx        # 0x2ac519d059e0
0x00002ac519a2ca7a <free+58>:   je     0x2ac519a2ca86 <free+70>
0x00002ac519a2ca7c <free+60>:   and    $0xfffffffffc000000,%rdx
0x00002ac519a2ca83 <free+67>:   mov    (%rdx),%rbx
0x00002ac519a2ca86 <free+70>:   mov    $0x1,%esi
0x00002ac519a2ca8b <free+75>:   xor    %eax,%eax
0x00002ac519a2ca8d <free+77>:   cmpl   $0x0,0x2dc594(%rip)        # 0x2ac519d09028
0x00002ac519a2ca94 <free+84>:   je     0x2ac519a2caa2 <free+98>
0x00002ac519a2ca96 <free+86>:   lock cmpxchg %esi,(%rbx)
0x00002ac519a2ca9a <free+90>:   jne    0x2ac519a2fb34
0x00002ac519a2caa0 <free+96>:   jmp    0x2ac519a2caab <free+107>
0x00002ac519a2caa2 <free+98>:   cmpxchg %esi,(%rbx)
0x00002ac519a2caa5 <free+101>:  jne    0x2ac519a2fb34
0x00002ac519a2caab <free+107>:  mov    %r8,%rsi
0x00002ac519a2caae <free+110>:  mov    %rbx,%rdi
0x00002ac519a2cab1 <free+113>:  callq  0x2ac519a2c2b0
0x00002ac519a2cab6 <free+118>:  cmpl   $0x0,0x2dc56b(%rip)        # 0x2ac519d09028
0x00002ac519a2cabd <free+125>:  je     0x2ac519a2caca <free+138>
0x00002ac519a2cabf <free+127>:  lock decl (%rbx)
0x00002ac519a2cac2 <free+130>:  jne    0x2ac519a2fb4f
0x00002ac519a2cac8 <free+136>:  jmp    0x2ac519a2cad2 <free+146>
0x00002ac519a2caca <free+138>:  decl   (%rbx)
0x00002ac519a2cacc <free+140>:  jne    0x2ac519a2fb4f
0x00002ac519a2cad2 <free+146>:  pop    %rbx
0x00002ac519a2cad3 <free+147>:  retq   
0x00002ac519a2cad4 <free+148>:  nopl   0x0(%rax)
0x00002ac519a2cad8 <free+152>:  mov    0x2d97c6(%rip),%ecx        # 0x2ac519d062a4
0x00002ac519a2cade <free+158>:  test   %ecx,%ecx
0x00002ac519a2cae0 <free+160>:  jne    0x2ac519a2cb10 <free+208>
0x00002ac519a2cae2 <free+162>:  cmp    0x2d97a7(%rip),%rax        # 0x2ac519d06290
0x00002ac519a2cae9 <free+169>:  jbe    0x2ac519a2cb10 <free+208>
0x00002ac519a2caeb <free+171>:  cmp    $0x2000000,%rax
0x00002ac519a2caf1 <free+177>:  ja     0x2ac519a2cb10 <free+208>
0x00002ac519a2caf3 <free+179>:  and    $0xfffffffffffffff8,%rax
0x00002ac519a2caf7 <free+183>:  mov    %rax,0x2d9792(%rip)        # 0x2ac519d06290
0x00002ac519a2cafe <free+190>:  add    %rax,%rax
0x00002ac519a2cb01 <free+193>:  mov    %rax,0x2d9778(%rip)        # 0x2ac519d06280
0x00002ac519a2cb08 <free+200>:  nopl   0x0(%rax,%rax,1)
---Type <return> to continue, or q <return> to quit---
0x00002ac519a2cb10 <free+208>:  pop    %rbx
0x00002ac519a2cb11 <free+209>:  mov    %rdx,%rdi
0x00002ac519a2cb14 <free+212>:  jmpq   0x2ac519a2bc40
End of assembler dump.


More information about the M3devel mailing list