Subject: [clisp-list] CLISP 2.33.2 segmentation fault

From: Denis Bueno <[email-masked]>
Date: Mon Jun 7 11:29:04 2004

I've been working with CLISP for a year or so now, and have very much 
enjoyed it. Just recently I have had a use for the REGEXP module, and 
so I compiled it into CLISP. However, the first expression I tried to 
evaluate segfaulted. Following are the details.

I work on a PPC Powerbook G4, 640 MB RAM.

I ran clisp -K full, and evaluated

[1]> (regexp:match "." "aoeu")
Segmentation fault

I built CLISP (as per the FAQ) with ./configure --prefix=/sw 
--with-module=regexp --with-debug --build build-g, but, when I ran 
./build-g/clisp through gdb, and typed "run", I got a SIGTRAP:

[Taggart.local ~/Download/clisp-2.33.2] gdb ./build-g/clisp
GNU gdb 5.3-20030128 (Apple version gdb-309) (Thu Dec  4 15:41:30 GMT 
2003)
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and 
you are
welcome to change it and/or distribute copies of it under certain 
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for 
details.
This GDB was configured as "powerpc-apple-darwin".
Reading symbols for shared libraries ...... done
(gdb) run
Starting program: /Users/Shared/Download/clisp-2.33.2/build-g/clisp
Reading symbols for shared libraries +. done

Program received signal SIGTRAP, Trace/breakpoint trap.
0x8fe1a4f4 in __dyld__dyld_start ()
(gdb)

Maybe I just don't know how to use gdb (I have only used it once or 
twice).

Below is the output of all the relevant info I can think of.

* Commands to build CLISP:

./configure --prefix=/sw --with-module=regexp

I chose that prefix because I use Fink.

* uname -a:

Darwin Taggart.local 7.4.0 Darwin Kernel Version 7.4.0: Wed May 12 
16:58:24 PDT 2004; root:xnu/xnu-517.7.7.obj~7/RELEASE_PPC  Power 
Macintosh powerpc

* gcc --version:

gcc (GCC) 3.3 20030304 (Apple Computer, Inc. build 1640)
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is 
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR 
PURPOSE.

* clisp -K full --version:

GNU CLISP 2.33.2 (2004-06-02) (built 3295613759) (memory 3295614633)
Software: GNU C 3.3 20030304 (Apple Computer, Inc. build 1640) ANSI C 
program
Features:
(REGEXP CLOS LOOP COMPILER CLISP ANSI-CL COMMON-LISP LISP=CL INTERPRETER
  SOCKETS GENERIC-STREAMS LOGICAL-PATHNAMES SCREEN FFI GETTEXT UNICODE
  BASE-CHAR=CHARACTER UNIX)
Installation directory: /sw/lib/clisp/
User language: ENGLISH
Machine: POWER MACINTOSH (POWER MACINTOSH) taggart.local 
[192.168.10.252]

* Crash report from OS X:

Date/Time:      2004-06-07 12:31:54 -0400
OS Version:     10.3.4 (Build 7H63)
Report Version: 2

Command: lisp.run
Path:    /sw/lib/clisp/full/lisp.run
Version: ??? (???)
PID:     18613
Thread:  0

Exception:  EXC_BAD_ACCESS (0x0001)
Codes:      KERN_INVALID_ADDRESS (0x0001) at 0x77ffd770

Thread 0 Crashed:
0   lisp.run 	0x00002c04 C_subr_regexp_regexp_exec + 0x2b4 (crt.c:300)
1   lisp.run 	0x0001c280 funcall_subr + 0x904 (crt.c:300)
2   lisp.run 	0x0001f2fc interpret_bytecode_ + 0x25ac (crt.c:300)
3   lisp.run 	0x00018b30 eval_closure + 0x1038 (crt.c:300)
4   lisp.run 	0x00015dfc eval + 0x198 (crt.c:300)
5   lisp.run 	0x0001616c eval1 + 0x180 (crt.c:300)
6   lisp.run 	0x00015dfc eval + 0x198 (crt.c:300)
7   lisp.run 	0x000b1258 C_read_eval_print + 0xac (crt.c:300)
8   lisp.run 	0x0001c280 funcall_subr + 0x904 (crt.c:300)
9   lisp.run 	0x0001f5d8 interpret_bytecode_ + 0x2888 (crt.c:300)
10  lisp.run 	0x0001ccb4 funcall_closure + 0x9e8 (crt.c:300)
11  lisp.run 	0x0002ad70 C_driver + 0x98 (crt.c:300)
12  lisp.run 	0x0001f718 interpret_bytecode_ + 0x29c8 (crt.c:300)
13  lisp.run 	0x0001ccb4 funcall_closure + 0x9e8 (crt.c:300)
14  lisp.run 	0x0001fe88 interpret_bytecode_ + 0x3138 (crt.c:300)
15  lisp.run 	0x0001ccb4 funcall_closure + 0x9e8 (crt.c:300)
16  lisp.run 	0x000b151c driver + 0x94 (crt.c:300)
17  lisp.run 	0x0000e904 main + 0x1ef8 (crt.c:300)
18  lisp.run 	0x00001fd0 _start + 0x188 (crt.c:267)
19  dyld     	0x8fe1a558 _dyld_start + 0x64

PPC Thread State:
   srr0: 0x00002c04 srr1: 0x0000f030                vrsave: 0x00000000
     cr: 0x24000442  xer: 0x20000004   lr: 0x00002ae0  ctr: 0x00002950
     r0: 0xbfffd820   r1: 0xbfffd790   r2: 0xb7ffffe0   r3: 0x19f5ef45
     r4: 0x00000001   r5: 0x001b50ac   r6: 0x001b50ac   r7: 0x00000000
     r8: 0x00000007   r9: 0x19f5ef45  r10: 0x00000000  r11: 0x001b5098
    r12: 0x00002950  r13: 0x00000000  r14: 0x00000000  r15: 0x00000000
    r16: 0x00000000  r17: 0x00000000  r18: 0x00000000  r19: 0x00000000
    r20: 0x00000000  r21: 0x00182958  r22: 0x00000000  r23: 0x00501070
    r24: 0x001b505c  r25: 0x0017b98c  r26: 0x00000008  r27: 0x00000004
    r28: 0x19f5eea5  r29: 0x001b5098  r30: 0xbfffd790  r31: 0x00002958

Binary Images Description:
     0x1000 -   0x16afff lisp.run 	/sw/lib/clisp/full/lisp.run
   0x208000 -   0x244fff libreadline.4.dylib 	/sw/lib/libreadline.4.dylib
0x72ece000 - 0x72fa3fff libiconv.2.dylib 	/sw/lib/libiconv.2.dylib
0x8594b000 - 0x8594ffff libintl.1.dylib 	/sw/lib/libintl.1.dylib
0x85a0b000 - 0x85a34fff libncurses.5.dylib 	/sw/lib/libncurses.5.dylib
0x8fe00000 - 0x8fe4ffff dyld 	/usr/lib/dyld
0x90000000 - 0x90122fff libSystem.B.dylib 	/usr/lib/libSystem.B.dylib
0x939d0000 - 0x939d4fff libmathCommon.A.dylib 
	/usr/lib/system/libmathCommon.A.dylib

Thanks. If you need more info, just ask.

--
Denis Bueno
PGP: http://pgp.mit.edu:11371/pks/lookup?search=0xA1B51B4B&op=index
"Clothes make the man. Naked people have little or no influence on 
society." - Mark Twain

---

From: Sam Steingold <[email-masked]>
Date: Mon Jun 7 12:32:16 2004

> * Denis Bueno <[email-masked]> [2004-06-07 14:24:49 -0400]:
>

Works for me.

> [Taggart.local ~/Download/clisp-2.33.2] gdb ./build-g/clisp

that should have been
$ cd build-g
$ gdb
(gdb) full
(gdb) run

or at least

$ gdb ./build-g/full/lisp.run
(gdb) run -M ./build-g/full/lispinie.mem

Thank you very much for such a thorough bug report!

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
All generalizations are wrong.  Including this.

---

From: Denis Bueno <[email-masked]>
Date: Mon Jun 7 18:15:02 2004

Here's the gdb backtrace:

[Taggart.local ~/Download/clisp-2.33.2/build-g] gdb
GNU gdb 5.3-20030128 (Apple version gdb-309) (Thu Dec  4 15:41:30 GMT  
2003)
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and  
you are
welcome to change it and/or distribute copies of it under certain  
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for  
details.
This GDB was configured as "powerpc-apple-darwin".
Reading symbols for shared libraries ...... done
Breakpoint 1 at 0x3432c: file eval.d, line 4802.
Breakpoint 2 at 0x2f8f0: file eval.d, line 3903.
Breakpoint 3 at 0x290bc: file eval.d, line 2790.
Breakpoint 4 at 0x378bc: file eval.d, line 5757.
Breakpoint 5 at 0x9128: file spvw_garcol.c, line 2683.
Hardware watchpoint 6: back_trace
Breakpoint 7 at 0xd730: file spvw.d, line 644.
Breakpoint 8 at 0x485c: file spvw.d, line 488.
Breakpoint 9 at 0x4940: file spvw.d, line 499.
Num Type           Disp Enb Address    What
1   breakpoint     keep n   0x0003432c in funcall at eval.d:4802
         xout fun
2   breakpoint     keep n   0x0002f8f0 in apply at eval.d:3903
         xout fun
3   breakpoint     keep n   0x000290bc in eval at eval.d:2790
         xout form
4   breakpoint     keep n   0x000378bc in interpret_bytecode_ at  
eval.d:5757
         xout closure
5   breakpoint     keep n   0x00009128 in gar_col at spvw_garcol.c:2683
6   hw watchpoint  keep n              back_trace
         zbacktrace
         continue
7   breakpoint     keep y   0x0000d730 in fehler_notreached at  
spvw.d:644
8   breakpoint     keep y   0x0000485c in SP_ueber at spvw.d:488
9   breakpoint     keep y   0x00004940 in STACK_ueber at spvw.d:499
Function "sigsegv_handler_failed" not defined.
.gdbinit:145: Error in sourced command file:
No symbol "byteptr" in current context.
(gdb) full
Function "my_type_error" not defined.
Function "closed_display_error" not defined.
(gdb) run
Starting program:  
/Users/Shared/Download/clisp-2.33.2/build-g/full/lisp.run -B . -M  
full/lispinit.mem -q -norc -i clx/new-clx/demos/clx-demos -p CLX-DEMOS
Reading symbols for shared libraries +. done
STACK depth: 16367
;; Loading file  
/Users/Shared/Download/clisp-2.33.2/build-g/clx/new-clx/demos/clx- 
demos.lisp ...
*** - FIND-SYMBOL: There is no package with name "XLIB"
The following restarts are available:
USE-VALUE      :R1      You may input a value to be used instead.

Break 1 [2]> :a

Program received signal EXC_BAD_ACCESS, Could not access memory.
0x000035f4 in C_subr_regexp_regexp_exec () at regexi.c:96
96        ret = (regmatch_t*)alloca((re->re_nsub+1)*sizeof(regmatch_t));
(gdb) bt
#0  0x000035f4 in C_subr_regexp_regexp_exec () at regexi.c:96
#1  0x00037a00 in funcall_subr (fun={one_o = 2498810}, args_on_stack=8)  
at eval.d:5201
#2  0x00036268 in funcall (fun={one_o = 445571049}, args_on_stack=10)  
at eval.d:4810
#3  0x0003ddfc in interpret_bytecode_ (closure={one_o = 445575221},  
codeptr=0x1a8eef8c, byteptr=0x1a8ef016  
"\031\f?\e???\e???\e???\e???\eC?\eE?\eG?\eI\032?\2204") at eval.d:6841
#4  0x00030bf0 in eval_closure (closure={one_o = 445575221}) at  
eval.d:3750
#5  0x0002b8d0 in eval1 (form={one_o = 1721543067}) at eval.d:2931
#6  0x0002b1fc in eval (form={one_o = 1721543067}) at eval.d:2810
#7  0x0002b774 in eval1 (form={one_o = 1721543067}) at eval.d:2899
#8  0x0002b1fc in eval (form={one_o = 1721543123}) at eval.d:2810
#9  0x0015d594 in C_read_eval_print () at debug.d:311
#10 0x00037a00 in funcall_subr (fun={one_o = 2504018}, args_on_stack=2)  
at eval.d:5201
#11 0x00036268 in funcall (fun={one_o = 2533441}, args_on_stack=2) at  
eval.d:4810
#12 0x0003e314 in interpret_bytecode_ (closure={one_o = 445661401},  
codeptr=0x1a8bae64, byteptr=0x1a8bae8a  
"\037\ak\a\211\b\005.\tQ\031\001?\017\v") at eval.d:6856
#13 0x00039560 in funcall_closure (closure={one_o = 445661401},  
args_on_stack=0) at eval.d:5641
#14 0x00036210 in funcall (fun={one_o = 445661401}, args_on_stack=0) at  
eval.d:4805
#15 0x00054cb0 in C_driver () at control.d:1943
#16 0x0003e538 in interpret_bytecode_ (closure={one_o = 445361889},  
codeptr=0x1a8bae14, byteptr=0x1a8bae32 "\031\001\032?N4") at  
eval.d:6862
#17 0x00039560 in funcall_closure (closure={one_o = 445361889},  
args_on_stack=0) at eval.d:5641
#18 0x00036210 in funcall (fun={one_o = 445361889}, args_on_stack=0) at  
eval.d:4805
#19 0x0003f630 in interpret_bytecode_ (closure={one_o = 445579677},  
codeptr=0x1a83f780, byteptr=0x1a83f7c2 "\031\001\032\235\227?") at  
eval.d:6912
#20 0x00039560 in funcall_closure (closure={one_o = 445579677},  
args_on_stack=0) at eval.d:5641
#21 0x00036210 in funcall (fun={one_o = 445579677}, args_on_stack=0) at  
eval.d:4805
#22 0x0015dbe8 in driver () at debug.d:380
#23 0x000205d4 in reset (count=4407836) at eval.d:513
#24 0x00042be8 in interpret_bytecode_ (closure={one_o = 444692129},  
codeptr=0x1a81715c, byteptr=0x1a8172ef "\021\030\001") at eval.d:7438
#25 0x000392e4 in funcall_closure (closure={one_o = 444692129},  
args_on_stack=1) at eval.d:5622
#26 0x000362a4 in funcall (fun={one_o = 2533469}, args_on_stack=1) at  
eval.d:4812
#27 0x0001aa98 in main (argc=11, argv=0xbffffba8) at spvw.d:2861
(gdb)

I don't exactly know what to do about the XLIB package error....

> -------------------------------------------------------
> This SF.Net email is sponsored by: GNOME Foundation
> Hackers Unite!  GUADEC: The world's #1 Open Source Desktop Event.
> GNOME Users and Developers European Conference, 28-30th June in Norway
> http://2004/guadec.org
> _______________________________________________
> clisp-list mailing list
> [email-masked]
> https://lists.sourceforge.net/lists/listinfo/clisp-list
>
>
--
Denis Bueno
PGP: http://pgp.mit.edu:11371/pks/lookup?search=0xA1B51B4B&op=index
"Be careful about reading health books. You may die of a misprint." -  
Mark Twain

---

From: Sam Steingold <[email-masked]>
Date: Tue Jun 8 07:24:14 2004

> * Denis Bueno <[email-masked]> [2004-06-07 21:14:07 -0400]:
>
> 96        ret =
> (regmatch_t*)alloca((re->re_nsub+1)*sizeof(regmatch_t));

it would be interesting to see the values the some local variables.
presumably "re" is NULL.

please try the appended patch.

thanks.

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
Fighting for peace is like screwing for virginity.

--- regexi.c	13 May 2004 22:37:36 -0400	1.19
+++ regexi.c	08 Jun 2004 10:21:48 -0400	
@@ -81,7 +81,15 @@
   regex_t *re;
   regmatch_t *ret;
   skipSTACK(5);                 /* drop all options */
+  while(1) {
   STACK_1 = check_fpointer(STACK_1,true);
+    re = (regex_t*)TheFpointer(STACK_1)->fp_pointer;
+    if (re != NULL) break;
+    pushSTACK(NIL);             /* no PLACE */
+    pushSTACK(STACK_(1+1)); pushSTACK(TheSubr(subr_self)->name);
+    check_value(error,GETTEXT("~S: NULL pattern ~S"));
+    STACK_1 = value1;
+  }
   string = STACK_0;
   if (end != length || start != 0) {
     pushSTACK(sfixnum((int)(end-start)));
@@ -91,7 +99,6 @@
     funcall(L(make_array),7);
     string = value1;
   }
-  re = (regex_t*)TheFpointer(STACK_1)->fp_pointer;
   begin_system_call();
   ret = (regmatch_t*)alloca((re->re_nsub+1)*sizeof(regmatch_t));
   end_system_call();

---

From: Denis Bueno <[email-masked]>
Date: Tue Jun 8 13:30:09 2004

> please try the appended patch.

Tried it. Same result. Here's the backtrace:

Break 1 [2]> :a

[1]> *features*
(:REGEXP :CLOS :LOOP :COMPILER :CLISP :ANSI-CL :COMMON-LISP :LISP=CL
  :INTERPRETER :CLISP-DEBUG :SOCKETS :GENERIC-STREAMS :LOGICAL-PATHNAMES  
:SCREEN
  :FFI :GETTEXT :UNICODE :BASE-CHAR=CHARACTER :UNIX)
[2]> (regexp:match "." "aoeu")

Program received signal EXC_BAD_ACCESS, Could not access memory.
0x000035e0 in C_subr_regexp_regexp_exec () at regexi.c:103
103       ret = (regmatch_t*)alloca((re->re_nsub+1)*sizeof(regmatch_t));
(gdb) bt
#0  0x000035e0 in C_subr_regexp_regexp_exec () at regexi.c:103
#1  0x000379ec in funcall_subr (fun={one_o = 2498810}, args_on_stack=8)  
at eval.d:5201
#2  0x00036254 in funcall (fun={one_o = 445571057}, args_on_stack=10)  
at eval.d:4810
#3  0x0003dde8 in interpret_bytecode_ (closure={one_o = 445575229},  
codeptr=0x1a8eef94, byteptr=0x1a8ef01e  
"\031\f?\e???\e???\e???\e???\eC?\eE?\eG?\eI\032?\220<") at eval.d:6841
#4  0x00030bdc in eval_closure (closure={one_o = 445575229}) at  
eval.d:3750
#5  0x0002b8bc in eval1 (form={one_o = 1721542395}) at eval.d:2931
#6  0x0002b1e8 in eval (form={one_o = 1721542395}) at eval.d:2810
#7  0x0002b760 in eval1 (form={one_o = 1721542395}) at eval.d:2899
#8  0x0002b1e8 in eval (form={one_o = 1721542451}) at eval.d:2810
#9  0x0015d580 in C_read_eval_print () at debug.d:311
#10 0x000379ec in funcall_subr (fun={one_o = 2504018}, args_on_stack=2)  
at eval.d:5201
#11 0x00036254 in funcall (fun={one_o = 2533441}, args_on_stack=2) at  
eval.d:4810
#12 0x0003e300 in interpret_bytecode_ (closure={one_o = 445661425},  
codeptr=0x1a8bae64, byteptr=0x1a8bae8a  
"\037\ak\a\211\b\005.\tQ\031\001?\017\v") at eval.d:6856
#13 0x0003954c in funcall_closure (closure={one_o = 445661425},  
args_on_stack=0) at eval.d:5641
#14 0x000361fc in funcall (fun={one_o = 445661425}, args_on_stack=0) at  
eval.d:4805
#15 0x00054c9c in C_driver () at control.d:1943
#16 0x0003e524 in interpret_bytecode_ (closure={one_o = 445361889},  
codeptr=0x1a8bae14, byteptr=0x1a8bae32 "\031\001\032?N4") at  
eval.d:6862
#17 0x0003954c in funcall_closure (closure={one_o = 445361889},  
args_on_stack=0) at eval.d:5641
#18 0x000361fc in funcall (fun={one_o = 445361889}, args_on_stack=0) at  
eval.d:4805
#19 0x0003f61c in interpret_bytecode_ (closure={one_o = 445579685},  
codeptr=0x1a83f780, byteptr=0x1a83f7c2 "\031\001\032\235\227?") at  
eval.d:6912
#20 0x0003954c in funcall_closure (closure={one_o = 445579685},  
args_on_stack=0) at eval.d:5641
#21 0x000361fc in funcall (fun={one_o = 445579685}, args_on_stack=0) at  
eval.d:4805
#22 0x0015dbd4 in driver () at debug.d:380
#23 0x000205c0 in reset (count=4407836) at eval.d:513
#24 0x00042bd4 in interpret_bytecode_ (closure={one_o = 444692129},  
codeptr=0x1a81715c, byteptr=0x1a8172ef "\021\030\001") at eval.d:7438
#25 0x000392d0 in funcall_closure (closure={one_o = 444692129},  
args_on_stack=1) at eval.d:5622
#26 0x00036290 in funcall (fun={one_o = 2533469}, args_on_stack=1) at  
eval.d:4812
#27 0x0001aa84 in main (argc=11, argv=0xbffffba8) at spvw.d:2861
(gdb)

--
Denis Bueno
PGP: http://pgp.mit.edu:11371/pks/lookup?search=0xA1B51B4B&op=index
"MEGAHERTZ: This is a really, really big hertz." - Dave Barry

---

From: Sam Steingold <[email-masked]>
Date: Tue Jun 8 13:44:08 2004

> * Denis Bueno <[email-masked]> [2004-06-08 16:25:19 -0400]:
>

you can edit .gdbinit to avoid this

> 103       ret =

p re
p re->re_nsub

add a break in C_subr_regexp_regexp_compile() and make sure that "re"
here points to the same location which was allocated by my_malloc() in
C_subr_regexp_regexp_compile().

what is "re->re_nsub" when we leave C_subr_regexp_regexp_compile?

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
Life is like a diaper -- short and loaded.

---

From: Denis Bueno <[email-masked]>
Date: Mon Jun 14 06:54:02 2004

(gdb) run
Starting program:  

Break 1 [2]> :a

Breakpoint 10, C_subr_regexp_regexp_compile () at regexi.c:24
24        object pattern = check_string(STACK_4);
(gdb) p re
$3 = (regex_t *) 0x87859393
(gdb) p re->re_nsub
Cannot access memory at address 0x878593ab

... (I did 'help breakpoints' here, &c., the 'continue'd.)

Program received signal EXC_BAD_ACCESS, Could not access memory.
0x000035e0 in C_subr_regexp_regexp_exec () at regexi.c:103
103       ret = (regmatch_t*)alloca((re->re_nsub+1)*sizeof(regmatch_t));
(gdb) p re
$4 = (regex_t *) 0x1100db0
(gdb) p re->re_nsub
$5 = 687865856
(gdb)

Is that what you wanted?

--
Denis Bueno
PGP: http://pgp.mit.edu:11371/pks/lookup?search=0xA1B51B4B&op=index
"All universal moral principles are idle fancies." - Marquis de Sade
Except for that one....

---

From: Sam Steingold <[email-masked]>
Date: Mon Jun 14 07:21:54 2004

> * Denis Bueno <[email-masked]> [2004-06-14 09:51:09 -0400]:
>

of course: re is not initialized yes.
you have to step until _after_ regcomp().

> $4 = (regex_t *) 0x1100db0

good. also, please do

p re
p *re

after regcomp() in C_subr_regexp_regexp_compile() and
before alloca() in C_subr_regexp_regexp_exec()

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
Linux: Telling Microsoft where to go since 1991.

---

From: Denis Bueno <[email-masked]>
Date: Mon Jun 14 11:09:43 2004

(gdb) full
Function "my_type_error" not defined.
Function "closed_display_error" not defined.
(gdb) break C_subr_regexp_regexp_compile
Breakpoint 10 at 0x26ec: file regexi.c, line 24.
(gdb) break C_subr_regexp_regexp_exec
Breakpoint 11 at 0x2eb4: file regexi.c, line 71.
(gdb) break alloc
allocStatus             allocate_cons           allocate_lfloat          
allocate_syntax_table
alloc_segs              allocate_dfloat         allocate_pages           
allocate_vector
alloc_trampoline_r      allocate_ffloat         allocate_perchar_table   
allocate_weakkvt
allocaing               allocate_fpointer       allocate_s16string       
allocate_weakkvt_low
allocaing_room_pointer  allocate_iarray         allocate_s32string       
allocate_xrecord_
allocate_bignum         allocate_imm_s16string  allocate_s8string        
allocated.3
allocate_bit_vector     allocate_imm_s32string  allocate_srecord_        
alloced.0
allocate_bit_vector_0   allocate_imm_s8string   allocate_stream          
allocset
(gdb) break alloca
allocaing               allocate_ffloat         allocate_pages           
allocate_syntax_table
allocaing_room_pointer  allocate_fpointer       allocate_perchar_table   
allocate_vector
allocate_bignum         allocate_iarray         allocate_s16string       
allocate_weakkvt
allocate_bit_vector     allocate_imm_s16string  allocate_s32string       
allocate_weakkvt_low
allocate_bit_vector_0   allocate_imm_s32string  allocate_s8string        
allocate_xrecord_
allocate_cons           allocate_imm_s8string   allocate_srecord_        
allocated.3
allocate_dfloat         allocate_lfloat         allocate_stream
(gdb) break alloca
allocaing               allocate_ffloat         allocate_pages           
allocate_syntax_table
allocaing_room_pointer  allocate_fpointer       allocate_perchar_table   
allocate_vector
allocate_bignum         allocate_iarray         allocate_s16string       
allocate_weakkvt
allocate_bit_vector     allocate_imm_s16string  allocate_s32string       
allocate_weakkvt_low
allocate_bit_vector_0   allocate_imm_s32string  allocate_s8string        
allocate_xrecord_
allocate_cons           allocate_imm_s8string   allocate_srecord_        
allocated.3
allocate_dfloat         allocate_lfloat         allocate_stream
(gdb) break regcomp
Breakpoint 12 at 0x90030bd8
(gdb) run
Starting program:  
/Users/Shared/Download/clisp-2.33.2/build-g/full/lisp.run -B . -M  
full/lispinit.mem -q -norc -i clx/new-clx/demos/clx-demos -p CLX-DEMOS
Reading symbols for shared libraries +. done
STACK depth: 16367
;; Loading file  
/Users/Shared/Download/clisp-2.33.2/build-g/clx/new-clx/demos/clx- 
demos.lisp ...
*** - FIND-SYMBOL: There is no package with name "XLIB"
The following restarts are available:
USE-VALUE      :R1      You may input a value to be used instead.

Break 1 [2]> :a

Breakpoint 10, C_subr_regexp_regexp_compile () at regexi.c:24
24        object pattern = check_string(STACK_4);
(gdb) p re
$1 = (regex_t *) 0x87859393
(gdb) p *reg
No symbol "reg" in current context.
(gdb) p *re
Cannot access memory at address 0x87859393
(gdb) continue
Continuing.

Breakpoint 12, 0x90030bd8 in regcomp ()
(gdb) p re
No symbol "re" in current context.
(gdb) continue
Continuing.

Breakpoint 11, C_subr_regexp_regexp_exec () at regexi.c:71
71        object string = (STACK_5 = check_string(STACK_5));
(gdb) kill
Kill the program being debugged? (y or n) y
(gdb) ful
Function "my_type_error" not defined.
Function "closed_display_error" not defined.
(gdb) full
Function "my_type_error" not defined.
Function "closed_display_error" not defined.
(gdb) run
Starting program:  
/Users/Shared/Download/clisp-2.33.2/build-g/full/lisp.run -B . -M  
full/lispinit.mem -q -norc -i clx/new-clx/demos/clx-demos -p CLX-DEMOS
STACK depth: 16367
;; Loading file  
/Users/Shared/Download/clisp-2.33.2/build-g/clx/new-clx/demos/clx- 
demos.lisp ...
*** - FIND-SYMBOL: There is no package with name "XLIB"
The following restarts are available:
USE-VALUE      :R1      You may input a value to be used instead.

Break 1 [2]> :a

Breakpoint 10, C_subr_regexp_regexp_compile () at regexi.c:24
24        object pattern = check_string(STACK_4);
(gdb) p re
$1 = (regex_t *) 0x87859393
(gdb) continue
Continuing.

Breakpoint 12, 0x90030bd8 in regcomp ()
(gdb) p re
No symbol "re" in current context.
(gdb) step
Single stepping until exit from function regcomp,
which has no line number information.
C_subr_regexp_regexp_compile () at regexi.c:38
38        if (status) {
(gdb) p re
$2 = (regex_t *) 0x1100db0
(gdb) p *re
$3 = {
   buffer = 0xf265 "^",
   allocated = 0,
   used = 1835103331,
   syntax = 17829600,
   fastmap = 0x22202261 <Address 0x22202261 out of bounds>,
   translate = 0x6f657522 <Address 0x6f657522 out of bounds>,
   re_nsub = 687865856,
   can_be_null = 0,
   regs_allocated = 0,
   fastmap_accurate = 0,
   no_sub = 0,
   not_bol = 0,
   not_eol = 0,
   newline_anchor = 0
}
(gdb) continue
Continuing.

Breakpoint 11, C_subr_regexp_regexp_exec () at regexi.c:71
71        object string = (STACK_5 = check_string(STACK_5));
(gdb) p re
$4 = (regex_t *) 0x5f34
(gdb) p *re
$5 = {
   buffer = 0x7fe802a6 <Address 0x7fe802a6 out of bounds>,
   allocated = 2424176744,
   used = 2426273900,
   syntax = 2428371056,
   fastmap = 0x90de0074 <Address 0x90de0074 out of bounds>,
   translate = 0x801e0068 <Address 0x801e0068 out of bounds>,
   re_nsub = 796917760,
   can_be_null = 0,
   regs_allocated = 2,
   fastmap_accurate = 0,
   no_sub = 0,
   not_bol = 0,
   not_eol = 0,
   newline_anchor = 1
}
(gdb)

Are these breakpoints sufficient? I could not find the alloca()  
function ... am I missing something?

---

From: Sam Steingold <[email-masked]>
Date: Mon Jun 14 12:35:06 2004

> * Denis Bueno <[email-masked]> [2004-06-14 14:07:10 -0400]:
>
> (gdb) break alloca

alloca is a GCC built-in, you cannot break in it.

>    translate = 0x6f657522 <Address 0x6f657522 out of bounds>,
               ^^^^^^^^^
ouch!!!

> 71        object string = (STACK_5 = check_string(STACK_5));

at this time re is not initialized yes.
you must step through until it it.
please do it and make sure that C_subr_regexp_regexp_exec gets the same
re as in C_subr_regexp_regexp_compile above.

please look at

       build/regexp/link.sh

and report the NEW_FILES= and NEW_LIBS= lines.
if they do not contain regex.o, this means that you are using the
OS-supplied regexp implementation.
Otherwise this is a platform-specific bug in gnu regexp...

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
Microsoft: announce yesterday, code today, think tomorrow.

---

From: Denis Bueno <[email-masked]>
Date: Mon Jun 14 13:17:47 2004

> alloca is a GCC built-in, you cannot break in it.

Oh.

> re as in C_subr_regexp_regexp_compile above.

There are comments in /* ... */ blocks to the side. Just two of them.

Breakpoint 11, C_subr_regexp_regexp_compile () at regexi.c:24
24        object pattern = check_string(STACK_4);
(gdb) step

...

(gdb) step
C_subr_regexp_regexp_compile () at regexi.c:25
25        int cflags = (missingp(STACK_0) ? 0 : REG_NOSUB) |
(gdb) step

...

(gdb) step
32        re = (regex_t*)my_malloc(sizeof(regex_t));
(gdb) p re
$1 = (regex_t *) 0x87859393
(gdb) p *re
Cannot access memory at address 0x87859393
(gdb) step
my_malloc (size=32) at spvw.d:615
615       var void* ptr = malloc(size);
(gdb) p re
No symbol "re" in current context.
(gdb) step
617       if (ptr)
(gdb) step
618         return ptr;
(gdb) step
621     }
(gdb) step
C_subr_regexp_regexp_compile () at regexi.c:37
37        });
(gdb) p re
$2 = (regex_t *) 0x1100db0                       /* VAL when init'd 
(Denis) */
(gdb) p *re
$3 = {
   buffer = 0x28726567 <Address 0x28726567 out of bounds>,
   allocated = 1702391866,
   used = 1835103331,
   syntax = 1746936366,
   fastmap = 0x22202261 <Address 0x22202261 out of bounds>,
   translate = 0x6f657522 <Address 0x6f657522 out of bounds>,
   re_nsub = 687865856,
   can_be_null = 0,
   regs_allocated = 0,
   fastmap_accurate = 0,
   no_sub = 0,
   not_bol = 0,
   not_eol = 0,
   newline_anchor = 0
}
(gdb) step

...

Breakpoint 10, C_subr_regexp_regexp_exec () at regexi.c:71
71        object string = (STACK_5 = check_string(STACK_5));
(gdb) step
check_string (obj={one_o = 445663237}) at error.d:937
937       while (!stringp(obj)) {

... (many steps)

(gdb) step
C_subr_regexp_regexp_exec () at regexi.c:86
86          re = (regex_t*)TheFpointer(STACK_1)->fp_pointer;
(gdb) step
87          if (re != NULL) break;
(gdb) p re
$6 = (regex_t *) 0x1100db0                   /* Appears to be the same 
as above (Denis) */
(gdb) p *re
$7 = {
   buffer = 0xf265 "^",
   allocated = 0,
   used = 1835103331,
   syntax = 17829728,
   fastmap = 0x22202261 <Address 0x22202261 out of bounds>,
   translate = 0x6f657522 <Address 0x6f657522 out of bounds>,
   re_nsub = 687865856,
   can_be_null = 0,
   regs_allocated = 0,
   fastmap_accurate = 0,
   no_sub = 0,
   not_bol = 0,
   not_eol = 0,
   newline_anchor = 0
}
(gdb)

> OS-supplied regexp implementation.

NEW_FILES="$file_list  regexp.dvi"
NEW_LIBS="$file_list "

> Otherwise this is a platform-specific bug in gnu regexp...

So since regex.o is not in the listing, it is not a platform-specific 
bug in GNU regexp?

--
Denis Bueno
PGP: http://pgp.mit.edu:11371/pks/lookup?search=0xA1B51B4B&op=index
"Anoint, v.: To grease a king or other great functionary already 
sufficiently slippery." - Ambrose Bierce, The Devil's Dictionary

---

From: Sam Steingold <[email-masked]>
Date: Mon Jun 14 13:46:01 2004

> * Denis Bueno <[email-masked]> [2004-06-14 16:13:43 -0400]:
>
> (gdb) p re

good, so we are using the same re object.

> So since regex.o is not in the listing, it is not a platform-specific

no, you are not using the GNU regexp that comes with CLISP.

Now, there are 2 things to get done:

1. get you a working CLISP regexp.

2. get your OS vendor to fix the bug.

For 1, you need to get CLISP to use the GNU regexp implementation that
comes withe CLISP.  Unfortunately, there is no option to force that.
You need to go to your build directory and edit config.cache file.
Find there the line

ac_cv_func_regexec=${ac_cv_func_regexec=yes}

and replace "yes" with "no" in it.
then do "rm -rf regexp" and "make full".
regexp will be re-configured using the cache you just tweaked.
you should see something like

Checking for regexec... (cached) no

and the supplied regexp will be used.

For 2, you need to read your regexp man pages and write a test program
that crashes, and then report it to the party mentioned in the regexp
man pages.  The crash program will look like this:

#include <regex.h>
int main (int argc, char* argv[]) {
  char * pattern = argv[1];
  char * subject = argv[2];
  regex_t re;
  regmatch_t *rm;
  regcomp(&re,pattern,0);
  rm = (regmatch_t*)alloca((re->re_nsub+1)*sizeof(regmatch_t));
  regexec(re,subject,re->re_nsub+1,rm,0);
  return 0;
}

(you should embellish it with printf() calls to show progress)

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
Daddy, what does "format disk c: complete" mean?

---

From: Denis Bueno <[email-masked]>
Date: Mon Jun 14 14:24:49 2004

> and the supplied regexp will be used.

Did that, saw the "Checking..." message, and verified that NEW_FILES 
and NEW_LIBS in build-g/regexp/link.sh include "regex.o". I ran

$ build-g/clisp -K full
...

and it segfaulted again. However, running

$ cd build-g
$ gdb
(gdb) full
(gdb) run

... and then running the lisp code does _not_ segfault. It evaluates to 
the correct result.

So I ran

$ build-g/full/lisp.run -B . -M full/lispinit.mem

and ran the code, and it worked fine.

I don't know what's going on. Do you?

>   regexec(re,subject,re->re_nsub+1,rm,0);

Wrote this, compiled it,

gcc-3.3 -g -o regcrash regex-crash.c -lc

and ran it like so:

$ ./regcrash "." "aoeu"

and

$ ./regcrash . aoeu

just for kicks.

No crash (in particular, no segfault, rather).

> (you should embellish it with printf() calls to show progress)

#include <stdio.h>
#include <stdlib.h>
#include <regex.h>

     printf("Pattern: %s\n", pattern);
     printf("Subject: %s\n", subject);

     regcomp(&re, pattern, 0);
     rm = (regmatch_t*) alloca((re.re_nsub+1) * sizeof(regmatch_t));
     regexec(&re, subject, re.re_nsub + 1, rm, 0);

     return 0;
}

--
Denis Bueno
PGP: http://pgp.mit.edu:11371/pks/lookup?search=0xA1B51B4B&op=index
"To be positive: To be mistaken at the top of one's voice." - Ambrose 
Bierce

---

From: Sam Steingold <[email-masked]>
Date: Mon Jun 14 15:00:14 2004

> * Denis Bueno <[email-masked]> [2004-06-14 17:21:32 -0400]:
>

caching?  try "rm clisp; make clisp"

>      regexec(&re, subject, re.re_nsub + 1, rm, 0);

you should also print re.re_nsub and the matching substrings (see
C_subr_regexp_regexp_exec).

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
Binaries die but source code lives forever.